Lines 28-33
Link Here
|
28 |
|
28 |
|
29 |
#import "DOMInternal.h" |
29 |
#import "DOMInternal.h" |
30 |
#import "Frame.h" |
30 |
#import "Frame.h" |
|
|
31 |
#import "PlatformString.h" |
31 |
#import "WebCoreObjCExtras.h" |
32 |
#import "WebCoreObjCExtras.h" |
32 |
#import "WebCoreFrameBridge.h" |
33 |
#import "WebCoreFrameBridge.h" |
33 |
#import <JavaScriptCore/context.h> |
34 |
#import <JavaScriptCore/context.h> |
Lines 37-42
Link Here
|
37 |
|
38 |
|
38 |
using namespace KJS; |
39 |
using namespace KJS; |
39 |
using namespace KJS::Bindings; |
40 |
using namespace KJS::Bindings; |
|
|
41 |
using namespace WebCore; |
40 |
|
42 |
|
41 |
#define LOG_EXCEPTION(exec) \ |
43 |
#define LOG_EXCEPTION(exec) \ |
42 |
if (Interpreter::shouldPrintExceptions()) \ |
44 |
if (Interpreter::shouldPrintExceptions()) \ |
Lines 106-118
static void _didExecute(WebScriptObject
Link Here
|
106 |
{ |
108 |
{ |
107 |
ASSERT(JSLock::lockCount() > 0); |
109 |
ASSERT(JSLock::lockCount() > 0); |
108 |
|
110 |
|
109 |
if (![obj _rootObject] || ![obj _rootObject]->isValid()) |
111 |
RootObject* root = [obj _rootObject]; |
|
|
112 |
if (!root) |
110 |
return; |
113 |
return; |
111 |
|
114 |
|
112 |
ExecState* exec = [obj _rootObject]->interpreter()->globalExec(); |
115 |
ExecState* exec = root->interpreter()->globalExec(); |
113 |
KJSDidExecuteFunctionPtr func = Instance::didExecuteFunction(); |
116 |
KJSDidExecuteFunctionPtr func = Instance::didExecuteFunction(); |
114 |
if (func) |
117 |
if (func) |
115 |
func(exec, static_cast<JSObject*>([obj _rootObject]->interpreter()->globalObject())); |
118 |
func(exec, static_cast<JSObject*>(root->interpreter()->globalObject())); |
116 |
} |
119 |
} |
117 |
|
120 |
|
118 |
- (void)_setImp:(JSObject*)imp originRootObject:(PassRefPtr<RootObject>)originRootObject rootObject:(PassRefPtr<RootObject>)rootObject |
121 |
- (void)_setImp:(JSObject*)imp originRootObject:(PassRefPtr<RootObject>)originRootObject rootObject:(PassRefPtr<RootObject>)rootObject |
Lines 144-156
static void _didExecute(WebScriptObject
Link Here
|
144 |
return self; |
147 |
return self; |
145 |
} |
148 |
} |
146 |
|
149 |
|
147 |
- (JSObject *)_imp |
150 |
- (JSObject*)_imp |
148 |
{ |
151 |
{ |
149 |
// Associate the WebScriptObject with the JS wrapper for the ObjC DOM wrapper. |
152 |
// Associate the WebScriptObject with the JS wrapper for the ObjC DOM wrapper. |
150 |
// This is done on lazily, on demand. |
153 |
// This is done on lazily, on demand. |
151 |
if (!_private->imp && _private->isCreatedByDOMWrapper) |
154 |
if (!_private->imp && _private->isCreatedByDOMWrapper) |
152 |
[self _initializeScriptDOMNodeImp]; |
155 |
[self _initializeScriptDOMNodeImp]; |
153 |
return _private->imp; |
156 |
return _private->rootObject && _private->rootObject->isValid() ? _private->imp : 0; |
154 |
} |
157 |
} |
155 |
|
158 |
|
156 |
- (BOOL)_hasImp |
159 |
- (BOOL)_hasImp |
Lines 170-181
static void _didExecute(WebScriptObject
Link Here
|
170 |
|
173 |
|
171 |
- (BOOL)_isSafeScript |
174 |
- (BOOL)_isSafeScript |
172 |
{ |
175 |
{ |
173 |
if (!_private->originRootObject || !_private->rootObject) |
176 |
if (!_private->originRootObject) |
174 |
return true; |
177 |
return true; |
175 |
|
178 |
|
176 |
if (!_private->originRootObject->isValid() || !_private->rootObject->isValid()) |
179 |
if (!_private->originRootObject->isValid() || !_private->rootObject || !_private->rootObject->isValid()) |
177 |
return false; |
180 |
return false; |
178 |
|
181 |
|
179 |
return _private->originRootObject->interpreter()->isSafeScript(_private->rootObject->interpreter()); |
182 |
return _private->originRootObject->interpreter()->isSafeScript(_private->rootObject->interpreter()); |
180 |
} |
183 |
} |
181 |
|
184 |
|
Lines 259-279
static List listFromNSArray(ExecState *e
Link Here
|
259 |
|
262 |
|
260 |
- (id)callWebScriptMethod:(NSString *)name withArguments:(NSArray *)args |
263 |
- (id)callWebScriptMethod:(NSString *)name withArguments:(NSArray *)args |
261 |
{ |
264 |
{ |
262 |
if (![self _rootObject]) |
|
|
263 |
return nil; |
264 |
|
265 |
if (![self _isSafeScript]) |
265 |
if (![self _isSafeScript]) |
266 |
return nil; |
266 |
return nil; |
267 |
|
267 |
|
268 |
// Lookup the function object. |
268 |
// Look up the function object. |
269 |
ExecState* exec = [self _rootObject]->interpreter()->globalExec(); |
269 |
ExecState* exec = [self _rootObject]->interpreter()->globalExec(); |
270 |
ASSERT(!exec->hadException()); |
270 |
ASSERT(!exec->hadException()); |
271 |
|
271 |
|
272 |
JSLock lock; |
272 |
JSLock lock; |
273 |
|
273 |
|
274 |
JSValue *v = convertObjcValueToValue(exec, &name, ObjcObjectType, [self _rootObject]); |
274 |
JSValue* func = [self _imp]->get(exec, String(name)); |
275 |
Identifier identifier(v->toString(exec)); |
|
|
276 |
JSValue *func = [self _imp]->get(exec, identifier); |
277 |
|
275 |
|
278 |
if (!func || !func->isObject()) |
276 |
if (!func || !func->isObject()) |
279 |
// Maybe throw an exception here? |
277 |
// Maybe throw an exception here? |
Lines 284-293
static List listFromNSArray(ExecState *e
Link Here
|
284 |
if (!funcImp->implementsCall()) |
282 |
if (!funcImp->implementsCall()) |
285 |
return 0; |
283 |
return 0; |
286 |
|
284 |
|
287 |
JSObject *thisObj = const_cast<JSObject*>([self _imp]); |
|
|
288 |
List argList = listFromNSArray(exec, args, [self _rootObject]); |
285 |
List argList = listFromNSArray(exec, args, [self _rootObject]); |
|
|
286 |
|
287 |
if (![self _isSafeScript]) |
288 |
return nil; |
289 |
|
289 |
[self _rootObject]->interpreter()->startTimeoutCheck(); |
290 |
[self _rootObject]->interpreter()->startTimeoutCheck(); |
290 |
JSValue *result = funcImp->call(exec, thisObj, argList); |
291 |
JSValue *result = funcImp->call(exec, [self _imp], argList); |
291 |
[self _rootObject]->interpreter()->stopTimeoutCheck(); |
292 |
[self _rootObject]->interpreter()->stopTimeoutCheck(); |
292 |
|
293 |
|
293 |
if (exec->hadException()) { |
294 |
if (exec->hadException()) { |
Lines 306-314
static List listFromNSArray(ExecState *e
Link Here
|
306 |
|
307 |
|
307 |
- (id)evaluateWebScript:(NSString *)script |
308 |
- (id)evaluateWebScript:(NSString *)script |
308 |
{ |
309 |
{ |
309 |
if (![self _rootObject]) |
|
|
310 |
return nil; |
311 |
|
312 |
if (![self _isSafeScript]) |
310 |
if (![self _isSafeScript]) |
313 |
return nil; |
311 |
return nil; |
314 |
|
312 |
|
Lines 318-326
static List listFromNSArray(ExecState *e
Link Here
|
318 |
JSValue *result; |
316 |
JSValue *result; |
319 |
JSLock lock; |
317 |
JSLock lock; |
320 |
|
318 |
|
321 |
JSValue *v = convertObjcValueToValue(exec, &script, ObjcObjectType, [self _rootObject]); |
|
|
322 |
[self _rootObject]->interpreter()->startTimeoutCheck(); |
319 |
[self _rootObject]->interpreter()->startTimeoutCheck(); |
323 |
Completion completion = [self _rootObject]->interpreter()->evaluate(UString(), 0, v->toString(exec)); |
320 |
Completion completion = [self _rootObject]->interpreter()->evaluate(UString(), 0, String(script)); |
324 |
[self _rootObject]->interpreter()->stopTimeoutCheck(); |
321 |
[self _rootObject]->interpreter()->stopTimeoutCheck(); |
325 |
ComplType type = completion.complType(); |
322 |
ComplType type = completion.complType(); |
326 |
|
323 |
|
Lines 346-354
static List listFromNSArray(ExecState *e
Link Here
|
346 |
|
343 |
|
347 |
- (void)setValue:(id)value forKey:(NSString *)key |
344 |
- (void)setValue:(id)value forKey:(NSString *)key |
348 |
{ |
345 |
{ |
349 |
if (![self _rootObject]) |
|
|
350 |
return; |
351 |
|
352 |
if (![self _isSafeScript]) |
346 |
if (![self _isSafeScript]) |
353 |
return; |
347 |
return; |
354 |
|
348 |
|
Lines 356-363
static List listFromNSArray(ExecState *e
Link Here
|
356 |
ASSERT(!exec->hadException()); |
350 |
ASSERT(!exec->hadException()); |
357 |
|
351 |
|
358 |
JSLock lock; |
352 |
JSLock lock; |
359 |
JSValue *v = convertObjcValueToValue(exec, &key, ObjcObjectType, [self _rootObject]); |
353 |
[self _imp]->put(exec, String(key), convertObjcValueToValue(exec, &value, ObjcObjectType, [self _rootObject])); |
360 |
[self _imp]->put(exec, Identifier(v->toString(exec)), convertObjcValueToValue(exec, &value, ObjcObjectType, [self _rootObject])); |
|
|
361 |
|
354 |
|
362 |
if (exec->hadException()) { |
355 |
if (exec->hadException()) { |
363 |
LOG_EXCEPTION(exec); |
356 |
LOG_EXCEPTION(exec); |
Lines 369-377
static List listFromNSArray(ExecState *e
Link Here
|
369 |
|
362 |
|
370 |
- (id)valueForKey:(NSString *)key |
363 |
- (id)valueForKey:(NSString *)key |
371 |
{ |
364 |
{ |
372 |
if (![self _rootObject]) |
|
|
373 |
return nil; |
374 |
|
375 |
if (![self _isSafeScript]) |
365 |
if (![self _isSafeScript]) |
376 |
return nil; |
366 |
return nil; |
377 |
|
367 |
|
Lines 379-386
static List listFromNSArray(ExecState *e
Link Here
|
379 |
ASSERT(!exec->hadException()); |
369 |
ASSERT(!exec->hadException()); |
380 |
|
370 |
|
381 |
JSLock lock; |
371 |
JSLock lock; |
382 |
JSValue *v = convertObjcValueToValue(exec, &key, ObjcObjectType, [self _rootObject]); |
372 |
JSValue *result = [self _imp]->get(exec, String(key)); |
383 |
JSValue *result = [self _imp]->get(exec, Identifier(v->toString(exec))); |
|
|
384 |
|
373 |
|
385 |
if (exec->hadException()) { |
374 |
if (exec->hadException()) { |
386 |
LOG_EXCEPTION(exec); |
375 |
LOG_EXCEPTION(exec); |
Lines 399-407
static List listFromNSArray(ExecState *e
Link Here
|
399 |
|
388 |
|
400 |
- (void)removeWebScriptKey:(NSString *)key |
389 |
- (void)removeWebScriptKey:(NSString *)key |
401 |
{ |
390 |
{ |
402 |
if (![self _rootObject]) |
|
|
403 |
return; |
404 |
|
405 |
if (![self _isSafeScript]) |
391 |
if (![self _isSafeScript]) |
406 |
return; |
392 |
return; |
407 |
|
393 |
|
Lines 409-416
static List listFromNSArray(ExecState *e
Link Here
|
409 |
ASSERT(!exec->hadException()); |
395 |
ASSERT(!exec->hadException()); |
410 |
|
396 |
|
411 |
JSLock lock; |
397 |
JSLock lock; |
412 |
JSValue *v = convertObjcValueToValue(exec, &key, ObjcObjectType, [self _rootObject]); |
398 |
[self _imp]->deleteProperty(exec, String(key)); |
413 |
[self _imp]->deleteProperty(exec, Identifier(v->toString(exec))); |
|
|
414 |
|
399 |
|
415 |
if (exec->hadException()) { |
400 |
if (exec->hadException()) { |
416 |
LOG_EXCEPTION(exec); |
401 |
LOG_EXCEPTION(exec); |
Lines 422-453
static List listFromNSArray(ExecState *e
Link Here
|
422 |
|
407 |
|
423 |
- (NSString *)stringRepresentation |
408 |
- (NSString *)stringRepresentation |
424 |
{ |
409 |
{ |
425 |
if (![self _rootObject]) |
|
|
426 |
// This is a workaround for a gcc 3.3 internal compiler error. |
427 |
return @"Undefined"; |
428 |
|
429 |
if (![self _isSafeScript]) |
410 |
if (![self _isSafeScript]) |
430 |
// This is a workaround for a gcc 3.3 internal compiler error. |
411 |
// This is a workaround for a gcc 3.3 internal compiler error. |
431 |
return @"Undefined"; |
412 |
return @"Undefined"; |
432 |
|
413 |
|
433 |
JSLock lock; |
414 |
JSLock lock; |
434 |
JSObject *thisObj = const_cast<JSObject*>([self _imp]); |
|
|
435 |
ExecState* exec = [self _rootObject]->interpreter()->globalExec(); |
415 |
ExecState* exec = [self _rootObject]->interpreter()->globalExec(); |
436 |
|
416 |
|
437 |
id result = convertValueToObjcValue(exec, thisObj, ObjcObjectType).objectValue; |
417 |
id result = convertValueToObjcValue(exec, [self _imp], ObjcObjectType).objectValue; |
438 |
|
418 |
|
439 |
id resultObj = [result description]; |
419 |
NSString *description = [result description]; |
440 |
|
420 |
|
441 |
_didExecute(self); |
421 |
_didExecute(self); |
442 |
|
422 |
|
443 |
return resultObj; |
423 |
return description; |
444 |
} |
424 |
} |
445 |
|
425 |
|
446 |
- (id)webScriptValueAtIndex:(unsigned)index |
426 |
- (id)webScriptValueAtIndex:(unsigned)index |
447 |
{ |
427 |
{ |
448 |
if (![self _rootObject]) |
|
|
449 |
return nil; |
450 |
|
451 |
if (![self _isSafeScript]) |
428 |
if (![self _isSafeScript]) |
452 |
return nil; |
429 |
return nil; |
453 |
|
430 |
|
Lines 472-480
static List listFromNSArray(ExecState *e
Link Here
|
472 |
|
449 |
|
473 |
- (void)setWebScriptValueAtIndex:(unsigned)index value:(id)value |
450 |
- (void)setWebScriptValueAtIndex:(unsigned)index value:(id)value |
474 |
{ |
451 |
{ |
475 |
if (![self _rootObject]) |
|
|
476 |
return; |
477 |
|
478 |
if (![self _isSafeScript]) |
452 |
if (![self _isSafeScript]) |
479 |
return; |
453 |
return; |
480 |
|
454 |
|
Lines 510-520
static List listFromNSArray(ExecState *e
Link Here
|
510 |
|
484 |
|
511 |
- (JSObjectRef)JSObject |
485 |
- (JSObjectRef)JSObject |
512 |
{ |
486 |
{ |
513 |
if (![self _rootObject]) |
|
|
514 |
return nil; |
515 |
|
516 |
if (![self _isSafeScript]) |
487 |
if (![self _isSafeScript]) |
517 |
return nil; |
488 |
return NULL; |
518 |
|
489 |
|
519 |
return toRef([self _imp]); |
490 |
return toRef([self _imp]); |
520 |
} |
491 |
} |