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"
26 #include "JSCInlines.h"
29 #include <wtf/MathExtras.h>
33 bool JSValue::equalSlowCase(ExecState
* exec
, JSValue v1
, JSValue v2
)
35 return equalSlowCaseInline(exec
, v1
, v2
);
38 bool JSValue::strictEqualSlowCase(ExecState
* exec
, JSValue v1
, JSValue v2
)
40 return strictEqualSlowCaseInline(exec
, v1
, v2
);
43 NEVER_INLINE JSValue
jsAddSlowCase(CallFrame
* callFrame
, JSValue v1
, JSValue v2
)
45 // exception for the Date exception in defaultValue()
46 JSValue p1
= v1
.toPrimitive(callFrame
);
47 JSValue p2
= v2
.toPrimitive(callFrame
);
50 return jsString(callFrame
, asString(p1
), p2
.toString(callFrame
));
53 return jsString(callFrame
, p1
.toString(callFrame
), asString(p2
));
55 return jsNumber(p1
.toNumber(callFrame
) + p2
.toNumber(callFrame
));
58 JSValue
jsTypeStringForValue(VM
& vm
, JSGlobalObject
* globalObject
, JSValue v
)
61 return vm
.smallStrings
.undefinedString();
63 return vm
.smallStrings
.booleanString();
65 return vm
.smallStrings
.numberString();
67 return vm
.smallStrings
.stringString();
69 return vm
.smallStrings
.symbolString();
71 JSObject
* object
= asObject(v
);
72 // Return "undefined" for objects that should be treated
73 // as null when doing comparisons.
74 if (object
->structure(vm
)->masqueradesAsUndefined(globalObject
))
75 return vm
.smallStrings
.undefinedString();
76 if (object
->type() == JSFunctionType
)
77 return vm
.smallStrings
.functionString();
78 if (object
->inlineTypeFlags() & TypeOfShouldCallGetCallData
) {
80 JSObject
* object
= asObject(v
);
81 if (object
->methodTable(vm
)->getCallData(object
, callData
) != CallTypeNone
)
82 return vm
.smallStrings
.functionString();
85 return vm
.smallStrings
.objectString();
88 JSValue
jsTypeStringForValue(CallFrame
* callFrame
, JSValue v
)
90 return jsTypeStringForValue(callFrame
->vm(), callFrame
->lexicalGlobalObject(), v
);
93 bool jsIsObjectTypeOrNull(CallFrame
* callFrame
, JSValue v
)
98 JSType type
= v
.asCell()->type();
99 if (type
== StringType
|| type
== SymbolType
)
101 if (type
>= ObjectType
) {
102 if (asObject(v
)->structure(callFrame
->vm())->masqueradesAsUndefined(callFrame
->lexicalGlobalObject()))
105 JSObject
* object
= asObject(v
);
106 if (object
->methodTable(callFrame
->vm())->getCallData(object
, callData
) != CallTypeNone
)
112 bool jsIsFunctionType(JSValue v
)
116 JSObject
* object
= asObject(v
);
117 if (object
->methodTable()->getCallData(object
, callData
) != CallTypeNone
)