]>
git.saurik.com Git - apple/javascriptcore.git/blob - kjs/operations.cpp
1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
24 #include "operations.h"
30 #include <wtf/MathExtras.h>
39 bool equal(ExecState
*exec
, JSValue
*v1
, JSValue
*v2
)
41 JSType t1
= v1
->type();
42 JSType t2
= v2
->type();
45 if (t1
== UndefinedType
)
47 if (t2
== UndefinedType
)
50 if (t1
== BooleanType
)
52 if (t2
== BooleanType
)
55 if (t1
== NumberType
&& t2
== StringType
) {
57 } else if (t1
== StringType
&& t2
== NumberType
)
61 if ((t1
== StringType
|| t1
== NumberType
) && t2
== ObjectType
) {
62 v2
= v2
->toPrimitive(exec
);
63 if (exec
->hadException())
65 return equal(exec
, v1
, v2
);
67 if (t1
== NullType
&& t2
== ObjectType
)
68 return static_cast<JSObject
*>(v2
)->masqueradeAsUndefined();
69 if (t1
== ObjectType
&& (t2
== StringType
|| t2
== NumberType
)) {
70 v1
= v1
->toPrimitive(exec
);
71 if (exec
->hadException())
73 return equal(exec
, v1
, v2
);
75 if (t1
== ObjectType
&& t2
== NullType
)
76 return static_cast<JSObject
*>(v1
)->masqueradeAsUndefined();
82 if (t1
== UndefinedType
|| t1
== NullType
)
85 if (t1
== NumberType
) {
86 double d1
= v1
->toNumber(exec
);
87 double d2
= v2
->toNumber(exec
);
92 return static_cast<StringImp
*>(v1
)->value() == static_cast<StringImp
*>(v2
)->value();
94 if (t1
== BooleanType
)
95 return v1
->toBoolean(exec
) == v2
->toBoolean(exec
);
101 bool strictEqual(ExecState
*exec
, JSValue
*v1
, JSValue
*v2
)
103 JSType t1
= v1
->type();
104 JSType t2
= v2
->type();
108 if (t1
== UndefinedType
|| t1
== NullType
)
110 if (t1
== NumberType
) {
111 double n1
= v1
->toNumber(exec
);
112 double n2
= v2
->toNumber(exec
);
116 } else if (t1
== StringType
)
117 return v1
->toString(exec
) == v2
->toString(exec
);
118 else if (t2
== BooleanType
)
119 return v1
->toBoolean(exec
) == v2
->toBoolean(exec
);
123 /* TODO: joined objects */