42
42
#include <algorithm> // for std::min
44
JSType JSValueGetType(JSContextRef, JSValueRef value)
44
JSType JSValueGetType(JSContextRef ctx, JSValueRef value)
46
JSC::JSValuePtr jsValue = toJS(value);
46
JSC::ExecState* exec = toJS(ctx);
47
exec->globalData().heap.registerThread();
48
JSC::JSLock lock(exec);
50
JSC::JSValue jsValue = toJS(exec, value);
47
52
if (jsValue.isUndefined())
48
53
return kJSTypeUndefined;
49
54
if (jsValue.isNull())
61
66
using namespace JSC; // placed here to avoid conflict between JSC::JSType and JSType, above.
63
bool JSValueIsUndefined(JSContextRef, JSValueRef value)
68
bool JSValueIsUndefined(JSContextRef ctx, JSValueRef value)
65
JSValuePtr jsValue = toJS(value);
70
ExecState* exec = toJS(ctx);
71
exec->globalData().heap.registerThread();
74
JSValue jsValue = toJS(exec, value);
66
75
return jsValue.isUndefined();
69
bool JSValueIsNull(JSContextRef, JSValueRef value)
78
bool JSValueIsNull(JSContextRef ctx, JSValueRef value)
71
JSValuePtr jsValue = toJS(value);
80
ExecState* exec = toJS(ctx);
81
exec->globalData().heap.registerThread();
84
JSValue jsValue = toJS(exec, value);
72
85
return jsValue.isNull();
75
bool JSValueIsBoolean(JSContextRef, JSValueRef value)
88
bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value)
77
JSValuePtr jsValue = toJS(value);
90
ExecState* exec = toJS(ctx);
91
exec->globalData().heap.registerThread();
94
JSValue jsValue = toJS(exec, value);
78
95
return jsValue.isBoolean();
81
bool JSValueIsNumber(JSContextRef, JSValueRef value)
98
bool JSValueIsNumber(JSContextRef ctx, JSValueRef value)
83
JSValuePtr jsValue = toJS(value);
100
ExecState* exec = toJS(ctx);
101
exec->globalData().heap.registerThread();
104
JSValue jsValue = toJS(exec, value);
84
105
return jsValue.isNumber();
87
bool JSValueIsString(JSContextRef, JSValueRef value)
108
bool JSValueIsString(JSContextRef ctx, JSValueRef value)
89
JSValuePtr jsValue = toJS(value);
110
ExecState* exec = toJS(ctx);
111
exec->globalData().heap.registerThread();
114
JSValue jsValue = toJS(exec, value);
90
115
return jsValue.isString();
93
bool JSValueIsObject(JSContextRef, JSValueRef value)
118
bool JSValueIsObject(JSContextRef ctx, JSValueRef value)
95
JSValuePtr jsValue = toJS(value);
120
ExecState* exec = toJS(ctx);
121
exec->globalData().heap.registerThread();
124
JSValue jsValue = toJS(exec, value);
96
125
return jsValue.isObject();
99
bool JSValueIsObjectOfClass(JSContextRef, JSValueRef value, JSClassRef jsClass)
128
bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass)
101
JSValuePtr jsValue = toJS(value);
130
ExecState* exec = toJS(ctx);
131
exec->globalData().heap.registerThread();
134
JSValue jsValue = toJS(exec, value);
103
136
if (JSObject* o = jsValue.getObject()) {
104
137
if (o->inherits(&JSCallbackObject<JSGlobalObject>::info))
115
148
exec->globalData().heap.registerThread();
116
149
JSLock lock(exec);
118
JSValuePtr jsA = toJS(a);
119
JSValuePtr jsB = toJS(b);
151
JSValue jsA = toJS(exec, a);
152
JSValue jsB = toJS(exec, b);
121
bool result = JSValuePtr::equal(exec, jsA, jsB); // false if an exception is thrown
154
bool result = JSValue::equal(exec, jsA, jsB); // false if an exception is thrown
122
155
if (exec->hadException()) {
124
*exception = toRef(exec->exception());
157
*exception = toRef(exec, exec->exception());
125
158
exec->clearException();
130
bool JSValueIsStrictEqual(JSContextRef, JSValueRef a, JSValueRef b)
163
bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b)
132
JSValuePtr jsA = toJS(a);
133
JSValuePtr jsB = toJS(b);
135
bool result = JSValuePtr::strictEqual(jsA, jsB);
165
ExecState* exec = toJS(ctx);
166
exec->globalData().heap.registerThread();
169
JSValue jsA = toJS(exec, a);
170
JSValue jsB = toJS(exec, b);
172
return JSValue::strictEqual(jsA, jsB);
139
175
bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception)
142
178
exec->globalData().heap.registerThread();
143
179
JSLock lock(exec);
145
JSValuePtr jsValue = toJS(value);
181
JSValue jsValue = toJS(exec, value);
146
183
JSObject* jsConstructor = toJS(constructor);
147
184
if (!jsConstructor->structure()->typeInfo().implementsHasInstance())
149
186
bool result = jsConstructor->hasInstance(exec, jsValue, jsConstructor->get(exec, exec->propertyNames().prototype)); // false if an exception is thrown
150
187
if (exec->hadException()) {
152
*exception = toRef(exec->exception());
189
*exception = toRef(exec, exec->exception());
153
190
exec->clearException();
158
JSValueRef JSValueMakeUndefined(JSContextRef)
160
return toRef(jsUndefined());
163
JSValueRef JSValueMakeNull(JSContextRef)
165
return toRef(jsNull());
168
JSValueRef JSValueMakeBoolean(JSContextRef, bool value)
170
return toRef(jsBoolean(value));
195
JSValueRef JSValueMakeUndefined(JSContextRef ctx)
197
ExecState* exec = toJS(ctx);
198
exec->globalData().heap.registerThread();
201
return toRef(exec, jsUndefined());
204
JSValueRef JSValueMakeNull(JSContextRef ctx)
206
ExecState* exec = toJS(ctx);
207
exec->globalData().heap.registerThread();
210
return toRef(exec, jsNull());
213
JSValueRef JSValueMakeBoolean(JSContextRef ctx, bool value)
215
ExecState* exec = toJS(ctx);
216
exec->globalData().heap.registerThread();
219
return toRef(exec, jsBoolean(value));
173
222
JSValueRef JSValueMakeNumber(JSContextRef ctx, double value)
185
234
exec->globalData().heap.registerThread();
186
235
JSLock lock(exec);
188
return toRef(jsString(exec, string->ustring()));
237
return toRef(exec, jsString(exec, string->ustring()));
191
240
bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
193
242
ExecState* exec = toJS(ctx);
194
JSValuePtr jsValue = toJS(value);
243
exec->globalData().heap.registerThread();
246
JSValue jsValue = toJS(exec, value);
195
247
return jsValue.toBoolean(exec);