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>
34 bool JSValue::equalSlowCase(ExecState* exec, JSValue v1, JSValue v2)
36 return equalSlowCaseInline(exec, v1, v2);
39 bool JSValue::strictEqualSlowCase(ExecState* exec, JSValue v1, JSValue v2)
41 return strictEqualSlowCaseInline(exec, v1, v2);
44 NEVER_INLINE JSValue jsAddSlowCase(CallFrame* callFrame, JSValue v1, JSValue v2)
46 // exception for the Date exception in defaultValue()
47 JSValue p1 = v1.toPrimitive(callFrame);
48 JSValue p2 = v2.toPrimitive(callFrame);
52 ? jsString(callFrame, asString(p1), asString(p2))
53 : jsString(callFrame, asString(p1), jsString(callFrame, p2.toString(callFrame)));
56 return jsString(callFrame, jsString(callFrame, p1.toString(callFrame)), asString(p2));
58 return jsNumber(p1.toNumber(callFrame) + p2.toNumber(callFrame));
61 JSValue jsTypeStringForValue(CallFrame* callFrame, JSValue v)
64 return jsNontrivialString(callFrame, "undefined");
66 return jsNontrivialString(callFrame, "boolean");
68 return jsNontrivialString(callFrame, "number");
70 return jsNontrivialString(callFrame, "string");
72 // Return "undefined" for objects that should be treated
73 // as null when doing comparisons.
74 if (asObject(v)->structure()->typeInfo().masqueradesAsUndefined())
75 return jsNontrivialString(callFrame, "undefined");
77 JSObject* object = asObject(v);
78 if (object->methodTable()->getCallData(object, callData) != CallTypeNone)
79 return jsNontrivialString(callFrame, "function");
81 return jsNontrivialString(callFrame, "object");
84 bool jsIsObjectType(JSValue v)
89 JSType type = v.asCell()->structure()->typeInfo().type();
90 if (type == NumberType || type == StringType)
92 if (type >= ObjectType) {
93 if (asObject(v)->structure()->typeInfo().masqueradesAsUndefined())
96 JSObject* object = asObject(v);
97 if (object->methodTable()->getCallData(object, callData) != CallTypeNone)
103 bool jsIsFunctionType(JSValue v)
107 JSObject* object = asObject(v);
108 if (object->methodTable()->getCallData(object, callData) != CallTypeNone)