]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/Operations.cpp
JavaScriptCore-1218.34.tar.gz
[apple/javascriptcore.git] / runtime / Operations.cpp
CommitLineData
b37bf2e1 1/*
9dae56ea
A
2 * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
3 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
b37bf2e1
A
4 *
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.
9 *
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.
14 *
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.
19 *
20 */
21
b37bf2e1 22#include "config.h"
9dae56ea
A
23#include "Operations.h"
24
25#include "Error.h"
26#include "JSObject.h"
27#include "JSString.h"
28#include <math.h>
29#include <stdio.h>
30#include <wtf/MathExtras.h>
b37bf2e1 31
9dae56ea
A
32namespace JSC {
33
ba379fdc 34bool JSValue::equalSlowCase(ExecState* exec, JSValue v1, JSValue v2)
b37bf2e1 35{
9dae56ea 36 return equalSlowCaseInline(exec, v1, v2);
b37bf2e1
A
37}
38
f9bf01c6 39bool JSValue::strictEqualSlowCase(ExecState* exec, JSValue v1, JSValue v2)
b37bf2e1 40{
f9bf01c6 41 return strictEqualSlowCaseInline(exec, v1, v2);
b37bf2e1
A
42}
43
ba379fdc
A
44NEVER_INLINE JSValue jsAddSlowCase(CallFrame* callFrame, JSValue v1, JSValue v2)
45{
46 // exception for the Date exception in defaultValue()
47 JSValue p1 = v1.toPrimitive(callFrame);
48 JSValue p2 = v2.toPrimitive(callFrame);
49
6fe7ccc8
A
50 if (p1.isString())
51 return jsString(callFrame, asString(p1), p2.toString(callFrame));
52
f9bf01c6
A
53 if (p2.isString())
54 return jsString(callFrame, p1.toString(callFrame), asString(p2));
ba379fdc 55
14957cd0 56 return jsNumber(p1.toNumber(callFrame) + p2.toNumber(callFrame));
ba379fdc
A
57}
58
93a37866 59JSValue jsTypeStringForValue(VM& vm, JSGlobalObject* globalObject, JSValue v)
ba379fdc
A
60{
61 if (v.isUndefined())
93a37866 62 return vm.smallStrings.undefinedString();
ba379fdc 63 if (v.isBoolean())
93a37866 64 return vm.smallStrings.booleanString();
ba379fdc 65 if (v.isNumber())
93a37866 66 return vm.smallStrings.numberString();
ba379fdc 67 if (v.isString())
93a37866 68 return vm.smallStrings.stringString();
ba379fdc
A
69 if (v.isObject()) {
70 // Return "undefined" for objects that should be treated
71 // as null when doing comparisons.
93a37866
A
72 if (asObject(v)->structure()->masqueradesAsUndefined(globalObject))
73 return vm.smallStrings.undefinedString();
ba379fdc 74 CallData callData;
6fe7ccc8
A
75 JSObject* object = asObject(v);
76 if (object->methodTable()->getCallData(object, callData) != CallTypeNone)
93a37866 77 return vm.smallStrings.functionString();
ba379fdc 78 }
93a37866
A
79 return vm.smallStrings.objectString();
80}
81
82JSValue jsTypeStringForValue(CallFrame* callFrame, JSValue v)
83{
84 return jsTypeStringForValue(callFrame->vm(), callFrame->lexicalGlobalObject(), v);
ba379fdc
A
85}
86
93a37866 87bool jsIsObjectType(CallFrame* callFrame, JSValue v)
ba379fdc
A
88{
89 if (!v.isCell())
90 return v.isNull();
91
14957cd0 92 JSType type = v.asCell()->structure()->typeInfo().type();
93a37866 93 if (type == StringType)
ba379fdc 94 return false;
6fe7ccc8 95 if (type >= ObjectType) {
93a37866 96 if (asObject(v)->structure()->masqueradesAsUndefined(callFrame->lexicalGlobalObject()))
ba379fdc
A
97 return false;
98 CallData callData;
6fe7ccc8
A
99 JSObject* object = asObject(v);
100 if (object->methodTable()->getCallData(object, callData) != CallTypeNone)
ba379fdc
A
101 return false;
102 }
103 return true;
104}
105
106bool jsIsFunctionType(JSValue v)
107{
108 if (v.isObject()) {
109 CallData callData;
6fe7ccc8
A
110 JSObject* object = asObject(v);
111 if (object->methodTable()->getCallData(object, callData) != CallTypeNone)
ba379fdc
A
112 return true;
113 }
114 return false;
115}
116
9dae56ea 117} // namespace JSC