~ubuntu-branches/ubuntu/karmic/webkit/karmic-proposed

« back to all changes in this revision

Viewing changes to JavaScriptCore/API/JSValueRef.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gustavo Noronha Silva
  • Date: 2009-05-15 18:30:58 UTC
  • mto: (4.4.1 sid) (1.2.2 upstream) (16.1.1 lucid)
  • mto: This revision was merged to the branch mainline in revision 8.
  • Revision ID: james.westby@ubuntu.com-20090515183058-35m5or0ufm5tutud
Tags: upstream-1.1.7
ImportĀ upstreamĀ versionĀ 1.1.7

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
 
42
42
#include <algorithm> // for std::min
43
43
 
44
 
JSType JSValueGetType(JSContextRef, JSValueRef value)
 
44
JSType JSValueGetType(JSContextRef ctx, JSValueRef value)
45
45
{
46
 
    JSC::JSValuePtr jsValue = toJS(value);
 
46
    JSC::ExecState* exec = toJS(ctx);
 
47
    exec->globalData().heap.registerThread();
 
48
    JSC::JSLock lock(exec);
 
49
 
 
50
    JSC::JSValue jsValue = toJS(exec, value);
 
51
 
47
52
    if (jsValue.isUndefined())
48
53
        return kJSTypeUndefined;
49
54
    if (jsValue.isNull())
60
65
 
61
66
using namespace JSC; // placed here to avoid conflict between JSC::JSType and JSType, above.
62
67
 
63
 
bool JSValueIsUndefined(JSContextRef, JSValueRef value)
 
68
bool JSValueIsUndefined(JSContextRef ctx, JSValueRef value)
64
69
{
65
 
    JSValuePtr jsValue = toJS(value);
 
70
    ExecState* exec = toJS(ctx);
 
71
    exec->globalData().heap.registerThread();
 
72
    JSLock lock(exec);
 
73
 
 
74
    JSValue jsValue = toJS(exec, value);
66
75
    return jsValue.isUndefined();
67
76
}
68
77
 
69
 
bool JSValueIsNull(JSContextRef, JSValueRef value)
 
78
bool JSValueIsNull(JSContextRef ctx, JSValueRef value)
70
79
{
71
 
    JSValuePtr jsValue = toJS(value);
 
80
    ExecState* exec = toJS(ctx);
 
81
    exec->globalData().heap.registerThread();
 
82
    JSLock lock(exec);
 
83
 
 
84
    JSValue jsValue = toJS(exec, value);
72
85
    return jsValue.isNull();
73
86
}
74
87
 
75
 
bool JSValueIsBoolean(JSContextRef, JSValueRef value)
 
88
bool JSValueIsBoolean(JSContextRef ctx, JSValueRef value)
76
89
{
77
 
    JSValuePtr jsValue = toJS(value);
 
90
    ExecState* exec = toJS(ctx);
 
91
    exec->globalData().heap.registerThread();
 
92
    JSLock lock(exec);
 
93
 
 
94
    JSValue jsValue = toJS(exec, value);
78
95
    return jsValue.isBoolean();
79
96
}
80
97
 
81
 
bool JSValueIsNumber(JSContextRef, JSValueRef value)
 
98
bool JSValueIsNumber(JSContextRef ctx, JSValueRef value)
82
99
{
83
 
    JSValuePtr jsValue = toJS(value);
 
100
    ExecState* exec = toJS(ctx);
 
101
    exec->globalData().heap.registerThread();
 
102
    JSLock lock(exec);
 
103
 
 
104
    JSValue jsValue = toJS(exec, value);
84
105
    return jsValue.isNumber();
85
106
}
86
107
 
87
 
bool JSValueIsString(JSContextRef, JSValueRef value)
 
108
bool JSValueIsString(JSContextRef ctx, JSValueRef value)
88
109
{
89
 
    JSValuePtr jsValue = toJS(value);
 
110
    ExecState* exec = toJS(ctx);
 
111
    exec->globalData().heap.registerThread();
 
112
    JSLock lock(exec);
 
113
 
 
114
    JSValue jsValue = toJS(exec, value);
90
115
    return jsValue.isString();
91
116
}
92
117
 
93
 
bool JSValueIsObject(JSContextRef, JSValueRef value)
 
118
bool JSValueIsObject(JSContextRef ctx, JSValueRef value)
94
119
{
95
 
    JSValuePtr jsValue = toJS(value);
 
120
    ExecState* exec = toJS(ctx);
 
121
    exec->globalData().heap.registerThread();
 
122
    JSLock lock(exec);
 
123
 
 
124
    JSValue jsValue = toJS(exec, value);
96
125
    return jsValue.isObject();
97
126
}
98
127
 
99
 
bool JSValueIsObjectOfClass(JSContextRef, JSValueRef value, JSClassRef jsClass)
 
128
bool JSValueIsObjectOfClass(JSContextRef ctx, JSValueRef value, JSClassRef jsClass)
100
129
{
101
 
    JSValuePtr jsValue = toJS(value);
 
130
    ExecState* exec = toJS(ctx);
 
131
    exec->globalData().heap.registerThread();
 
132
    JSLock lock(exec);
 
133
 
 
134
    JSValue jsValue = toJS(exec, value);
102
135
    
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);
117
150
 
118
 
    JSValuePtr jsA = toJS(a);
119
 
    JSValuePtr jsB = toJS(b);
 
151
    JSValue jsA = toJS(exec, a);
 
152
    JSValue jsB = toJS(exec, b);
120
153
 
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()) {
123
156
        if (exception)
124
 
            *exception = toRef(exec->exception());
 
157
            *exception = toRef(exec, exec->exception());
125
158
        exec->clearException();
126
159
    }
127
160
    return result;
128
161
}
129
162
 
130
 
bool JSValueIsStrictEqual(JSContextRef, JSValueRef a, JSValueRef b)
 
163
bool JSValueIsStrictEqual(JSContextRef ctx, JSValueRef a, JSValueRef b)
131
164
{
132
 
    JSValuePtr jsA = toJS(a);
133
 
    JSValuePtr jsB = toJS(b);
134
 
    
135
 
    bool result = JSValuePtr::strictEqual(jsA, jsB);
136
 
    return result;
 
165
    ExecState* exec = toJS(ctx);
 
166
    exec->globalData().heap.registerThread();
 
167
    JSLock lock(exec);
 
168
 
 
169
    JSValue jsA = toJS(exec, a);
 
170
    JSValue jsB = toJS(exec, b);
 
171
 
 
172
    return JSValue::strictEqual(jsA, jsB);
137
173
}
138
174
 
139
175
bool JSValueIsInstanceOfConstructor(JSContextRef ctx, JSValueRef value, JSObjectRef constructor, JSValueRef* exception)
142
178
    exec->globalData().heap.registerThread();
143
179
    JSLock lock(exec);
144
180
 
145
 
    JSValuePtr jsValue = toJS(value);
 
181
    JSValue jsValue = toJS(exec, value);
 
182
 
146
183
    JSObject* jsConstructor = toJS(constructor);
147
184
    if (!jsConstructor->structure()->typeInfo().implementsHasInstance())
148
185
        return false;
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()) {
151
188
        if (exception)
152
 
            *exception = toRef(exec->exception());
 
189
            *exception = toRef(exec, exec->exception());
153
190
        exec->clearException();
154
191
    }
155
192
    return result;
156
193
}
157
194
 
158
 
JSValueRef JSValueMakeUndefined(JSContextRef)
159
 
{
160
 
    return toRef(jsUndefined());
161
 
}
162
 
 
163
 
JSValueRef JSValueMakeNull(JSContextRef)
164
 
{
165
 
    return toRef(jsNull());
166
 
}
167
 
 
168
 
JSValueRef JSValueMakeBoolean(JSContextRef, bool value)
169
 
{
170
 
    return toRef(jsBoolean(value));
 
195
JSValueRef JSValueMakeUndefined(JSContextRef ctx)
 
196
{
 
197
    ExecState* exec = toJS(ctx);
 
198
    exec->globalData().heap.registerThread();
 
199
    JSLock lock(exec);
 
200
 
 
201
    return toRef(exec, jsUndefined());
 
202
}
 
203
 
 
204
JSValueRef JSValueMakeNull(JSContextRef ctx)
 
205
{
 
206
    ExecState* exec = toJS(ctx);
 
207
    exec->globalData().heap.registerThread();
 
208
    JSLock lock(exec);
 
209
 
 
210
    return toRef(exec, jsNull());
 
211
}
 
212
 
 
213
JSValueRef JSValueMakeBoolean(JSContextRef ctx, bool value)
 
214
{
 
215
    ExecState* exec = toJS(ctx);
 
216
    exec->globalData().heap.registerThread();
 
217
    JSLock lock(exec);
 
218
 
 
219
    return toRef(exec, jsBoolean(value));
171
220
}
172
221
 
173
222
JSValueRef JSValueMakeNumber(JSContextRef ctx, double value)
176
225
    exec->globalData().heap.registerThread();
177
226
    JSLock lock(exec);
178
227
 
179
 
    return toRef(jsNumber(exec, value));
 
228
    return toRef(exec, jsNumber(exec, value));
180
229
}
181
230
 
182
231
JSValueRef JSValueMakeString(JSContextRef ctx, JSStringRef string)
185
234
    exec->globalData().heap.registerThread();
186
235
    JSLock lock(exec);
187
236
 
188
 
    return toRef(jsString(exec, string->ustring()));
 
237
    return toRef(exec, jsString(exec, string->ustring()));
189
238
}
190
239
 
191
240
bool JSValueToBoolean(JSContextRef ctx, JSValueRef value)
192
241
{
193
242
    ExecState* exec = toJS(ctx);
194
 
    JSValuePtr jsValue = toJS(value);
 
243
    exec->globalData().heap.registerThread();
 
244
    JSLock lock(exec);
 
245
 
 
246
    JSValue jsValue = toJS(exec, value);
195
247
    return jsValue.toBoolean(exec);
196
248
}
197
249
 
201
253
    exec->globalData().heap.registerThread();
202
254
    JSLock lock(exec);
203
255
 
204
 
    JSValuePtr jsValue = toJS(value);
 
256
    JSValue jsValue = toJS(exec, value);
205
257
 
206
258
    double number = jsValue.toNumber(exec);
207
259
    if (exec->hadException()) {
208
260
        if (exception)
209
 
            *exception = toRef(exec->exception());
 
261
            *exception = toRef(exec, exec->exception());
210
262
        exec->clearException();
211
263
        number = NaN;
212
264
    }
219
271
    exec->globalData().heap.registerThread();
220
272
    JSLock lock(exec);
221
273
 
222
 
    JSValuePtr jsValue = toJS(value);
 
274
    JSValue jsValue = toJS(exec, value);
223
275
    
224
276
    RefPtr<OpaqueJSString> stringRef(OpaqueJSString::create(jsValue.toString(exec)));
225
277
    if (exec->hadException()) {
226
278
        if (exception)
227
 
            *exception = toRef(exec->exception());
 
279
            *exception = toRef(exec, exec->exception());
228
280
        exec->clearException();
229
281
        stringRef.clear();
230
282
    }
237
289
    exec->globalData().heap.registerThread();
238
290
    JSLock lock(exec);
239
291
 
240
 
    JSValuePtr jsValue = toJS(value);
 
292
    JSValue jsValue = toJS(exec, value);
241
293
    
242
294
    JSObjectRef objectRef = toRef(jsValue.toObject(exec));
243
295
    if (exec->hadException()) {
244
296
        if (exception)
245
 
            *exception = toRef(exec->exception());
 
297
            *exception = toRef(exec, exec->exception());
246
298
        exec->clearException();
247
299
        objectRef = 0;
248
300
    }
255
307
    exec->globalData().heap.registerThread();
256
308
    JSLock lock(exec);
257
309
 
258
 
    JSValuePtr jsValue = toJS(value);
 
310
    JSValue jsValue = toJS(exec, value);
259
311
    gcProtect(jsValue);
260
312
}
261
313
 
265
317
    exec->globalData().heap.registerThread();
266
318
    JSLock lock(exec);
267
319
 
268
 
    JSValuePtr jsValue = toJS(value);
 
320
    JSValue jsValue = toJS(exec, value);
269
321
    gcUnprotect(jsValue);
270
322
}