2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
23 #include "operations.h"
30 #include <wtf/MathExtras.h>
39 bool equal(ExecState* exec, JSValue* v1, JSValue* v2)
42 if (JSImmediate::areBothImmediateNumbers(v1, v2))
45 if (v1->isNumber() && v2->isNumber())
46 return v1->uncheckedGetNumber() == v2->uncheckedGetNumber();
48 bool s1 = v1->isString();
49 bool s2 = v2->isString();
51 return static_cast<JSString*>(v1)->value() == static_cast<JSString*>(v2)->value();
53 if (v1->isUndefinedOrNull()) {
54 if (v2->isUndefinedOrNull())
56 if (JSImmediate::isImmediate(v2))
58 return v2->asCell()->structureID()->typeInfo().masqueradesAsUndefined();
61 if (v2->isUndefinedOrNull()) {
62 if (JSImmediate::isImmediate(v1))
64 return v1->asCell()->structureID()->typeInfo().masqueradesAsUndefined();
70 JSValue* p1 = v1->toPrimitive(exec);
71 if (exec->hadException())
78 JSValue* p2 = v2->toPrimitive(exec);
79 if (exec->hadException())
86 double d1 = v1->toNumber(exec);
87 double d2 = v2->toNumber(exec);
91 if (v1->isBoolean()) {
93 return static_cast<double>(v1->getBoolean()) == v2->uncheckedGetNumber();
94 } else if (v2->isBoolean()) {
96 return v1->uncheckedGetNumber() == static_cast<double>(v2->getBoolean());
102 bool strictEqual(JSValue* v1, JSValue* v2)
104 if (JSImmediate::areBothImmediate(v1, v2))
107 if (JSImmediate::isEitherImmediate(v1, v2) & (v1 != JSImmediate::from(0)) & (v2 != JSImmediate::from(0)))
110 return strictEqualSlowCaseInline(v1, v2);
113 bool strictEqualSlowCase(JSValue* v1, JSValue* v2)
115 return strictEqualSlowCaseInline(v1, v2);
118 NEVER_INLINE JSValue* throwOutOfMemoryError(ExecState* exec)
120 JSObject* error = Error::create(exec, GeneralError, "Out of memory");
121 exec->setException(error);