]>
Commit | Line | Data |
---|---|---|
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" | |
81345200 | 26 | #include "JSCInlines.h" |
9dae56ea A |
27 | #include "JSObject.h" |
28 | #include "JSString.h" | |
9dae56ea | 29 | #include <wtf/MathExtras.h> |
b37bf2e1 | 30 | |
9dae56ea A |
31 | namespace JSC { |
32 | ||
ba379fdc | 33 | bool JSValue::equalSlowCase(ExecState* exec, JSValue v1, JSValue v2) |
b37bf2e1 | 34 | { |
9dae56ea | 35 | return equalSlowCaseInline(exec, v1, v2); |
b37bf2e1 A |
36 | } |
37 | ||
f9bf01c6 | 38 | bool JSValue::strictEqualSlowCase(ExecState* exec, JSValue v1, JSValue v2) |
b37bf2e1 | 39 | { |
f9bf01c6 | 40 | return strictEqualSlowCaseInline(exec, v1, v2); |
b37bf2e1 A |
41 | } |
42 | ||
ba379fdc A |
43 | NEVER_INLINE JSValue jsAddSlowCase(CallFrame* callFrame, JSValue v1, JSValue v2) |
44 | { | |
45 | // exception for the Date exception in defaultValue() | |
46 | JSValue p1 = v1.toPrimitive(callFrame); | |
47 | JSValue p2 = v2.toPrimitive(callFrame); | |
48 | ||
6fe7ccc8 A |
49 | if (p1.isString()) |
50 | return jsString(callFrame, asString(p1), p2.toString(callFrame)); | |
51 | ||
f9bf01c6 A |
52 | if (p2.isString()) |
53 | return jsString(callFrame, p1.toString(callFrame), asString(p2)); | |
ba379fdc | 54 | |
14957cd0 | 55 | return jsNumber(p1.toNumber(callFrame) + p2.toNumber(callFrame)); |
ba379fdc A |
56 | } |
57 | ||
93a37866 | 58 | JSValue jsTypeStringForValue(VM& vm, JSGlobalObject* globalObject, JSValue v) |
ba379fdc A |
59 | { |
60 | if (v.isUndefined()) | |
93a37866 | 61 | return vm.smallStrings.undefinedString(); |
ba379fdc | 62 | if (v.isBoolean()) |
93a37866 | 63 | return vm.smallStrings.booleanString(); |
ba379fdc | 64 | if (v.isNumber()) |
93a37866 | 65 | return vm.smallStrings.numberString(); |
ba379fdc | 66 | if (v.isString()) |
93a37866 | 67 | return vm.smallStrings.stringString(); |
ed1e77d3 A |
68 | if (v.isSymbol()) |
69 | return vm.smallStrings.symbolString(); | |
ba379fdc | 70 | if (v.isObject()) { |
ed1e77d3 | 71 | JSObject* object = asObject(v); |
ba379fdc A |
72 | // Return "undefined" for objects that should be treated |
73 | // as null when doing comparisons. | |
ed1e77d3 | 74 | if (object->structure(vm)->masqueradesAsUndefined(globalObject)) |
93a37866 | 75 | return vm.smallStrings.undefinedString(); |
ed1e77d3 | 76 | if (object->type() == JSFunctionType) |
93a37866 | 77 | return vm.smallStrings.functionString(); |
ed1e77d3 A |
78 | if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) { |
79 | CallData callData; | |
80 | JSObject* object = asObject(v); | |
81 | if (object->methodTable(vm)->getCallData(object, callData) != CallTypeNone) | |
82 | return vm.smallStrings.functionString(); | |
83 | } | |
ba379fdc | 84 | } |
93a37866 A |
85 | return vm.smallStrings.objectString(); |
86 | } | |
87 | ||
88 | JSValue jsTypeStringForValue(CallFrame* callFrame, JSValue v) | |
89 | { | |
90 | return jsTypeStringForValue(callFrame->vm(), callFrame->lexicalGlobalObject(), v); | |
ba379fdc A |
91 | } |
92 | ||
ed1e77d3 | 93 | bool jsIsObjectTypeOrNull(CallFrame* callFrame, JSValue v) |
ba379fdc A |
94 | { |
95 | if (!v.isCell()) | |
96 | return v.isNull(); | |
97 | ||
81345200 | 98 | JSType type = v.asCell()->type(); |
ed1e77d3 | 99 | if (type == StringType || type == SymbolType) |
ba379fdc | 100 | return false; |
6fe7ccc8 | 101 | if (type >= ObjectType) { |
81345200 | 102 | if (asObject(v)->structure(callFrame->vm())->masqueradesAsUndefined(callFrame->lexicalGlobalObject())) |
ba379fdc A |
103 | return false; |
104 | CallData callData; | |
6fe7ccc8 | 105 | JSObject* object = asObject(v); |
81345200 | 106 | if (object->methodTable(callFrame->vm())->getCallData(object, callData) != CallTypeNone) |
ba379fdc A |
107 | return false; |
108 | } | |
109 | return true; | |
110 | } | |
111 | ||
112 | bool jsIsFunctionType(JSValue v) | |
113 | { | |
114 | if (v.isObject()) { | |
115 | CallData callData; | |
6fe7ccc8 A |
116 | JSObject* object = asObject(v); |
117 | if (object->methodTable()->getCallData(object, callData) != CallTypeNone) | |
ba379fdc A |
118 | return true; |
119 | } | |
120 | return false; | |
121 | } | |
122 | ||
9dae56ea | 123 | } // namespace JSC |