kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 1 | /* |
weinig@apple.com | 2947a91 | 2008-07-07 02:49:29 +0000 | [diff] [blame] | 2 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) |
weinig@apple.com | 5080014 | 2008-07-05 05:44:38 +0000 | [diff] [blame] | 3 | * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 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 |
mjs | cdff33b | 2006-01-23 21:41:36 +0000 | [diff] [blame] | 17 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
ggaren | 07d4ce6 | 2005-07-14 18:27:04 +0000 | [diff] [blame] | 18 | * Boston, MA 02110-1301, USA. |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 19 | * |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
mjs | b64c50a | 2005-10-03 21:13:12 +0000 | [diff] [blame] | 22 | #include "config.h" |
cwzwarich@webkit.org | 0b51a73 | 2008-11-05 23:21:32 +0000 | [diff] [blame] | 23 | #include "Operations.h" |
darin | eba979c | 2005-09-04 01:18:13 +0000 | [diff] [blame] | 24 | |
weinig@apple.com | 5080014 | 2008-07-05 05:44:38 +0000 | [diff] [blame] | 25 | #include "Error.h" |
fpizlo@apple.com | fb7eff2 | 2014-02-11 01:45:50 +0000 | [diff] [blame] | 26 | #include "JSCInlines.h" |
darin@apple.com | 3dcb636 | 2008-06-16 04:00:19 +0000 | [diff] [blame] | 27 | #include "JSObject.h" |
weinig@apple.com | 5080014 | 2008-07-05 05:44:38 +0000 | [diff] [blame] | 28 | #include "JSString.h" |
darin | 6c5f29d | 2006-07-05 04:13:32 +0000 | [diff] [blame] | 29 | #include <wtf/MathExtras.h> |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 30 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 31 | namespace JSC { |
darin | 140be37 | 2005-04-20 10:14:35 +0000 | [diff] [blame] | 32 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 33 | bool JSValue::equalSlowCase(ExecState* exec, JSValue v1, JSValue v2) |
mjs@apple.com | 8ac5469 | 2008-09-25 00:26:38 +0000 | [diff] [blame] | 34 | { |
| 35 | return equalSlowCaseInline(exec, v1, v2); |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 36 | } |
| 37 | |
barraclough@apple.com | b749f0b | 2009-12-07 23:14:04 +0000 | [diff] [blame] | 38 | bool JSValue::strictEqualSlowCase(ExecState* exec, JSValue v1, JSValue v2) |
mjs@apple.com | 1011aaa | 2008-09-16 06:08:51 +0000 | [diff] [blame] | 39 | { |
barraclough@apple.com | b749f0b | 2009-12-07 23:14:04 +0000 | [diff] [blame] | 40 | return strictEqualSlowCaseInline(exec, v1, v2); |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame] | 41 | } |
| 42 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 43 | NEVER_INLINE JSValue jsAddSlowCase(CallFrame* callFrame, JSValue v1, JSValue v2) |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 44 | { |
| 45 | // exception for the Date exception in defaultValue() |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 46 | JSValue p1 = v1.toPrimitive(callFrame); |
| 47 | JSValue p2 = v2.toPrimitive(callFrame); |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 48 | |
ggaren@apple.com | 64be5e9 | 2012-01-24 07:34:10 +0000 | [diff] [blame] | 49 | if (p1.isString()) |
| 50 | return jsString(callFrame, asString(p1), p2.toString(callFrame)); |
| 51 | |
barraclough@apple.com | b61916c | 2009-12-11 22:57:39 +0000 | [diff] [blame] | 52 | if (p2.isString()) |
ggaren@apple.com | 64be5e9 | 2012-01-24 07:34:10 +0000 | [diff] [blame] | 53 | return jsString(callFrame, p1.toString(callFrame), asString(p2)); |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 54 | |
oliver@apple.com | 5b67d9e | 2010-10-25 22:40:53 +0000 | [diff] [blame] | 55 | return jsNumber(p1.toNumber(callFrame) + p2.toNumber(callFrame)); |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 56 | } |
| 57 | |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 58 | JSValue jsTypeStringForValue(VM& vm, JSGlobalObject* globalObject, JSValue v) |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 59 | { |
| 60 | if (v.isUndefined()) |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 61 | return vm.smallStrings.undefinedString(); |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 62 | if (v.isBoolean()) |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 63 | return vm.smallStrings.booleanString(); |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 64 | if (v.isNumber()) |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 65 | return vm.smallStrings.numberString(); |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 66 | if (v.isString()) |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 67 | return vm.smallStrings.stringString(); |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 68 | if (v.isSymbol()) |
| 69 | return vm.smallStrings.symbolString(); |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 70 | if (v.isObject()) { |
fpizlo@apple.com | 19f3e01 | 2015-04-29 21:27:48 +0000 | [diff] [blame] | 71 | JSObject* object = asObject(v); |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 72 | // Return "undefined" for objects that should be treated |
| 73 | // as null when doing comparisons. |
fpizlo@apple.com | 19f3e01 | 2015-04-29 21:27:48 +0000 | [diff] [blame] | 74 | if (object->structure(vm)->masqueradesAsUndefined(globalObject)) |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 75 | return vm.smallStrings.undefinedString(); |
fpizlo@apple.com | 19f3e01 | 2015-04-29 21:27:48 +0000 | [diff] [blame] | 76 | if (object->type() == JSFunctionType) |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 77 | return vm.smallStrings.functionString(); |
fpizlo@apple.com | 19f3e01 | 2015-04-29 21:27:48 +0000 | [diff] [blame] | 78 | if (object->inlineTypeFlags() & TypeOfShouldCallGetCallData) { |
| 79 | CallData callData; |
| 80 | JSObject* object = asObject(v); |
utatane.tea@gmail.com | f76f1b4 | 2016-03-05 17:01:04 +0000 | [diff] [blame] | 81 | if (object->methodTable(vm)->getCallData(object, callData) != CallType::None) |
fpizlo@apple.com | 19f3e01 | 2015-04-29 21:27:48 +0000 | [diff] [blame] | 82 | return vm.smallStrings.functionString(); |
| 83 | } |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 84 | } |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 85 | return vm.smallStrings.objectString(); |
oliver@apple.com | e722ad0 | 2013-01-09 02:37:29 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | JSValue jsTypeStringForValue(CallFrame* callFrame, JSValue v) |
| 89 | { |
ggaren@apple.com | 9a9a4b5 | 2013-04-18 19:32:17 +0000 | [diff] [blame] | 90 | return jsTypeStringForValue(callFrame->vm(), callFrame->lexicalGlobalObject(), v); |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 91 | } |
| 92 | |
utatane.tea@gmail.com | 0bfb74c | 2015-02-24 23:01:58 +0000 | [diff] [blame] | 93 | bool jsIsObjectTypeOrNull(CallFrame* callFrame, JSValue v) |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 94 | { |
| 95 | if (!v.isCell()) |
| 96 | return v.isNull(); |
| 97 | |
mhahnenberg@apple.com | b6f8519 | 2014-02-27 01:27:18 +0000 | [diff] [blame] | 98 | JSType type = v.asCell()->type(); |
utatane.tea@gmail.com | 947fa4e | 2015-01-31 01:23:56 +0000 | [diff] [blame] | 99 | if (type == StringType || type == SymbolType) |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 100 | return false; |
weinig@apple.com | 58576b2 | 2011-09-16 21:34:20 +0000 | [diff] [blame] | 101 | if (type >= ObjectType) { |
mhahnenberg@apple.com | b6f8519 | 2014-02-27 01:27:18 +0000 | [diff] [blame] | 102 | if (asObject(v)->structure(callFrame->vm())->masqueradesAsUndefined(callFrame->lexicalGlobalObject())) |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 103 | return false; |
| 104 | CallData callData; |
mhahnenberg@apple.com | 6fb47cf | 2011-10-10 22:32:00 +0000 | [diff] [blame] | 105 | JSObject* object = asObject(v); |
utatane.tea@gmail.com | f76f1b4 | 2016-03-05 17:01:04 +0000 | [diff] [blame] | 106 | if (object->methodTable(callFrame->vm())->getCallData(object, callData) != CallType::None) |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 107 | return false; |
| 108 | } |
| 109 | return true; |
| 110 | } |
| 111 | |
ggaren@apple.com | dc067b6 | 2009-05-01 22:43:39 +0000 | [diff] [blame] | 112 | bool jsIsFunctionType(JSValue v) |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 113 | { |
| 114 | if (v.isObject()) { |
| 115 | CallData callData; |
mhahnenberg@apple.com | 6fb47cf | 2011-10-10 22:32:00 +0000 | [diff] [blame] | 116 | JSObject* object = asObject(v); |
utatane.tea@gmail.com | f76f1b4 | 2016-03-05 17:01:04 +0000 | [diff] [blame] | 117 | if (object->methodTable()->getCallData(object, callData) != CallType::None) |
ggaren@apple.com | bb63926 | 2009-02-20 06:04:21 +0000 | [diff] [blame] | 118 | return true; |
| 119 | } |
| 120 | return false; |
| 121 | } |
| 122 | |
cwzwarich@webkit.org | 3f782f6 | 2008-09-08 01:28:33 +0000 | [diff] [blame] | 123 | } // namespace JSC |