source:
webkit/trunk/JavaScriptCore/runtime/Operations.cpp@
43383
Last change on this file since 43383 was 43122, checked in by [email protected], 16 years ago | |
---|---|
2009-05-01 Geoffrey Garen <[email protected]>
JavaScriptGlue:
2009-05-01 Geoffrey Garen <[email protected]>
WebCore:
2009-05-01 Geoffrey Garen <[email protected]>
WebKit/mac:
2009-05-01 Geoffrey Garen <[email protected]>
WebKit/qt:
2009-05-01 Geoffrey Garen <[email protected]>
WebKit/win:
2009-05-01 Geoffrey Garen <[email protected]>
WebKit/wx:
2009-05-01 Geoffrey Garen <[email protected]>
|
|
|
|
File size: 3.7 KB |
Line | |
---|---|
1 | /* |
2 | * Copyright (C) 1999-2000 Harri Porten ([email protected]) |
3 | * Copyright (C) 2008 Apple Inc. All Rights Reserved. |
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 | |
22 | #include "config.h" |
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> |
31 | |
32 | #if HAVE(FLOAT_H) |
33 | #include <float.h> |
34 | #endif |
35 | |
36 | namespace JSC { |
37 | |
38 | bool JSValue::equalSlowCase(ExecState* exec, JSValue v1, JSValue v2) |
39 | { |
40 | return equalSlowCaseInline(exec, v1, v2); |
41 | } |
42 | |
43 | bool JSValue::strictEqualSlowCase(JSValue v1, JSValue v2) |
44 | { |
45 | return strictEqualSlowCaseInline(v1, v2); |
46 | } |
47 | |
48 | NEVER_INLINE JSValue throwOutOfMemoryError(ExecState* exec) |
49 | { |
50 | JSObject* error = Error::create(exec, GeneralError, "Out of memory"); |
51 | exec->setException(error); |
52 | return error; |
53 | } |
54 | |
55 | NEVER_INLINE JSValue jsAddSlowCase(CallFrame* callFrame, JSValue v1, JSValue v2) |
56 | { |
57 | // exception for the Date exception in defaultValue() |
58 | JSValue p1 = v1.toPrimitive(callFrame); |
59 | JSValue p2 = v2.toPrimitive(callFrame); |
60 | |
61 | if (p1.isString() || p2.isString()) { |
62 | RefPtr<UString::Rep> value = concatenate(p1.toString(callFrame).rep(), p2.toString(callFrame).rep()); |
63 | if (!value) |
64 | return throwOutOfMemoryError(callFrame); |
65 | return jsString(callFrame, value.release()); |
66 | } |
67 | |
68 | return jsNumber(callFrame, p1.toNumber(callFrame) + p2.toNumber(callFrame)); |
69 | } |
70 | |
71 | JSValue jsTypeStringForValue(CallFrame* callFrame, JSValue v) |
72 | { |
73 | if (v.isUndefined()) |
74 | return jsNontrivialString(callFrame, "undefined"); |
75 | if (v.isBoolean()) |
76 | return jsNontrivialString(callFrame, "boolean"); |
77 | if (v.isNumber()) |
78 | return jsNontrivialString(callFrame, "number"); |
79 | if (v.isString()) |
80 | return jsNontrivialString(callFrame, "string"); |
81 | if (v.isObject()) { |
82 | // Return "undefined" for objects that should be treated |
83 | // as null when doing comparisons. |
84 | if (asObject(v)->structure()->typeInfo().masqueradesAsUndefined()) |
85 | return jsNontrivialString(callFrame, "undefined"); |
86 | CallData callData; |
87 | if (asObject(v)->getCallData(callData) != CallTypeNone) |
88 | return jsNontrivialString(callFrame, "function"); |
89 | } |
90 | return jsNontrivialString(callFrame, "object"); |
91 | } |
92 | |
93 | bool jsIsObjectType(JSValue v) |
94 | { |
95 | if (!v.isCell()) |
96 | return v.isNull(); |
97 | |
98 | JSType type = asCell(v)->structure()->typeInfo().type(); |
99 | if (type == NumberType || type == StringType) |
100 | return false; |
101 | if (type == ObjectType) { |
102 | if (asObject(v)->structure()->typeInfo().masqueradesAsUndefined()) |
103 | return false; |
104 | CallData callData; |
105 | if (asObject(v)->getCallData(callData) != CallTypeNone) |
106 | return false; |
107 | } |
108 | return true; |
109 | } |
110 | |
111 | bool jsIsFunctionType(JSValue v) |
112 | { |
113 | if (v.isObject()) { |
114 | CallData callData; |
115 | if (asObject(v)->getCallData(callData) != CallTypeNone) |
116 | return true; |
117 | } |
118 | return false; |
119 | } |
120 | |
121 | } // namespace JSC |