Changeset 143637 in webkit
- Timestamp:
- Feb 21, 2013 12:00:33 PM (11 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 50 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/JavaScriptCore/API/JSBase.h
r139004 r143637 141 141 142 142 /* Enable the Objective-C API for platforms with a modern runtime. */ 143 #undef JS_OBJC_API_ENABLED 144 #define JS_OBJC_API_ENABLED (defined(__clang__) && defined(__APPLE__) && defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 && !defined(__i386__)) 143 #if !defined(JSC_OBJC_API_ENABLED) 144 #define JSC_OBJC_API_ENABLED (defined(__clang__) && defined(__APPLE__) && defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 && !defined(__i386__)) 145 #endif 145 146 146 147 #endif /* JSBase_h */ -
trunk/Source/JavaScriptCore/API/JSBlockAdaptor.h
r142319 r143637 26 26 #import <JavaScriptCore/JavaScriptCore.h> 27 27 28 #if JS _OBJC_API_ENABLED28 #if JSC_OBJC_API_ENABLED 29 29 30 30 @interface JSBlockAdaptor : NSObject -
trunk/Source/JavaScriptCore/API/JSBlockAdaptor.mm
r142319 r143637 27 27 #import "JavaScriptCore.h" 28 28 29 #if JS _OBJC_API_ENABLED29 #if JSC_OBJC_API_ENABLED 30 30 31 31 #import "APICast.h" -
trunk/Source/JavaScriptCore/API/JSContext.h
r142319 r143637 24 24 */ 25 25 26 #ifndef JSContext_h 27 #define JSContext_h 28 26 29 #include <JavaScriptCore/JavaScript.h> 27 30 28 #if JS _OBJC_API_ENABLED31 #if JSC_OBJC_API_ENABLED 29 32 30 33 @class JSVirtualMachine, JSValue; … … 49 52 // Evaluate a string of JavaScript code. 50 53 - (JSValue *)evaluateScript:(NSString *)script; 54 55 // Return the C API version of this context. This function is for convenience 56 // at the boundaries when converting code from the C API to the Objective-C API. 57 - (JSGlobalContextRef)globalContextRef; 51 58 52 59 // This method retrieves the global object of the JavaScript execution context. … … 115 122 116 123 #endif 124 125 #endif // JSContext_h -
trunk/Source/JavaScriptCore/API/JSContext.mm
r141490 r143637 38 38 #import <wtf/HashSet.h> 39 39 40 #if JS _OBJC_API_ENABLED40 #if JSC_OBJC_API_ENABLED 41 41 42 42 @implementation JSContext { … … 49 49 @synthesize exceptionHandler; 50 50 51 - (JSGlobalContextRef)globalContextRef 52 { 53 return m_context; 54 } 55 51 56 - (id)init 52 57 { … … 68 73 }; 69 74 70 toJS(m_context)->lexicalGlobalObject()->m_apiData = self;71 75 return self; 72 76 } … … 168 172 @implementation JSContext(Internal) 169 173 174 - (id)initWithGlobalContextRef:(JSGlobalContextRef)context 175 { 176 self = [super init]; 177 if (!self) 178 return nil; 179 180 JSC::JSGlobalObject* globalObject = toJS(context)->lexicalGlobalObject(); 181 m_virtualMachine = [[JSVirtualMachine virtualMachineWithContextGroupRef:toRef(&globalObject->globalData())] retain]; 182 ASSERT(m_virtualMachine); 183 m_context = JSGlobalContextRetain(context); 184 m_wrapperMap = [[JSWrapperMap alloc] initWithContext:self]; 185 186 self.exceptionHandler = ^(JSContext *context, JSValue *exceptionValue) { 187 context.exception = exceptionValue; 188 }; 189 190 return self; 191 } 192 170 193 JSGlobalContextRef contextInternalContext(JSContext *context) 171 194 { … … 175 198 - (void)dealloc 176 199 { 177 toJS(m_context)->lexicalGlobalObject()->m_apiData = 0;178 200 [m_wrapperMap release]; 179 201 JSGlobalContextRelease(m_context); … … 221 243 } 222 244 223 - (JSValue *)wrapperForObj ect:(id)object245 - (JSValue *)wrapperForObjCObject:(id)object 224 246 { 225 247 // Lock access to m_wrapperMap 226 248 JSC::JSLockHolder lock(toJS(m_context)); 227 return [m_wrapperMap wrapperForObject:object]; 249 return [m_wrapperMap jsWrapperForObject:object]; 250 } 251 252 - (JSValue *)wrapperForJSObject:(JSValueRef)value 253 { 254 JSC::JSLockHolder lock(toJS(m_context)); 255 return [m_wrapperMap objcWrapperForJSValueRef:value]; 256 } 257 258 + (JSContext *)contextWithGlobalContextRef:(JSGlobalContextRef)globalContext 259 { 260 JSVirtualMachine *virtualMachine = [JSVirtualMachine virtualMachineWithContextGroupRef:toRef(&toJS(globalContext)->globalData())]; 261 JSContext *context = [virtualMachine contextForGlobalContextRef:globalContext]; 262 if (!context) { 263 context = [[[JSContext alloc] initWithGlobalContextRef:globalContext] autorelease]; 264 [virtualMachine addContext:context forGlobalContextRef:globalContext]; 265 } 266 return context; 228 267 } 229 268 -
trunk/Source/JavaScriptCore/API/JSContextInternal.h
r141176 r143637 24 24 */ 25 25 26 #ifndef JSContextInternal_h 27 #define JSContextInternal_h 28 26 29 #import <JavaScriptCore/JavaScriptCore.h> 27 30 28 #if JS _OBJC_API_ENABLED31 #if JSC_OBJC_API_ENABLED 29 32 30 #import "JSContext.h"33 #import <JavaScriptCore/JSContext.h> 31 34 32 35 struct CallbackData { … … 57 60 @interface JSContext(Internal) 58 61 59 JSGlobalContextRef contextInternalContext(JSContext *); 62 - (id)initWithGlobalContextRef:(JSGlobalContextRef)context; 63 64 JS_EXPORT_PRIVATE JSGlobalContextRef contextInternalContext(JSContext *); 60 65 61 66 - (void)notifyException:(JSValueRef)exception; … … 66 71 - (void)endCallbackWithData:(CallbackData *)callbackData; 67 72 68 - (JSValue *)wrapperForObject:(id)object; 73 - (JSValue *)wrapperForObjCObject:(id)object; 74 - (JSValue *)wrapperForJSObject:(JSValueRef)value; 75 76 + (JSContext *)contextWithGlobalContextRef:(JSGlobalContextRef)globalContext; 69 77 70 78 @property (readonly, retain) JSWrapperMap *wrapperMap; … … 73 81 74 82 #endif 83 84 #endif // JSContextInternal_h -
trunk/Source/JavaScriptCore/API/JSExport.h
r142319 r143637 26 26 #import <JavaScriptCore/JavaScriptCore.h> 27 27 28 #if JS _OBJC_API_ENABLED28 #if JSC_OBJC_API_ENABLED 29 29 30 30 // When a JavaScript value is created from an instance of an Objective-C class -
trunk/Source/JavaScriptCore/API/JSValue.h
r142319 r143637 24 24 */ 25 25 26 #if JS_OBJC_API_ENABLED 26 #ifndef JSValue_h 27 #define JSValue_h 28 29 #if JSC_OBJC_API_ENABLED 27 30 28 31 @class JSContext; … … 102 105 + (JSValue *)valueWithNullInContext:(JSContext *)context; 103 106 + (JSValue *)valueWithUndefinedInContext:(JSContext *)context; 107 108 // Return the C API version of this value. This function is for convenience 109 // at the boundaries when converting code from the C API to the Objective-C API. 110 - (JSValueRef)JSValueRef; 104 111 105 112 // Convert this value to a corresponding Objective-C object, according to the … … 293 300 #endif 294 301 302 #endif // JSValue_h -
trunk/Source/JavaScriptCore/API/JSValue.mm
r142319 r143637 25 25 26 26 #include "config.h" 27 //#import "JSValue.h"28 27 29 28 #import "APICast.h" … … 46 45 #import <wtf/text/StringHash.h> 47 46 48 #if JS _OBJC_API_ENABLED47 #if JSC_OBJC_API_ENABLED 49 48 50 49 NSString * const JSPropertyDescriptorWritableKey = @"writable"; … … 57 56 @implementation JSValue { 58 57 JSValueRef m_value; 58 } 59 60 - (JSValueRef)JSValueRef 61 { 62 return m_value; 59 63 } 60 64 … … 891 895 } 892 896 893 return (ObjcContainerConvertor::Task){ object, valueInternalValue([context wrapperForObj ect:object]), ContainerNone };897 return (ObjcContainerConvertor::Task){ object, valueInternalValue([context wrapperForObjCObject:object]), ContainerNone }; 894 898 } 895 899 … … 942 946 + (JSValue *)valueWithValue:(JSValueRef)value inContext:(JSContext *)context 943 947 { 944 return [ [[JSValue alloc] initWithValue:value inContext:context] autorelease];948 return [context wrapperForJSObject:value]; 945 949 } 946 950 -
trunk/Source/JavaScriptCore/API/JSValueInternal.h
r140718 r143637 24 24 */ 25 25 26 #ifndef JSValueInternal_h 27 #define JSValueInternal_h 28 26 29 #import <JavaScriptCore/JavaScriptCore.h> 27 #import "JSValue.h"30 #import <JavaScriptCore/JSValue.h> 28 31 29 #if JS _OBJC_API_ENABLED32 #if JSC_OBJC_API_ENABLED 30 33 31 34 @interface JSValue(Internal) … … 53 56 54 57 #endif 58 59 #endif // JSValueInternal_h -
trunk/Source/JavaScriptCore/API/JSVirtualMachine.h
r138664 r143637 26 26 #import <JavaScriptCore/JavaScriptCore.h> 27 27 28 #if JS _OBJC_API_ENABLED28 #if JSC_OBJC_API_ENABLED 29 29 30 30 // An instance of JSVirtualMachine represents a single JavaScript "object space" -
trunk/Source/JavaScriptCore/API/JSVirtualMachine.mm
r138664 r143637 28 28 #import "JavaScriptCore.h" 29 29 30 #if JS _OBJC_API_ENABLED30 #if JSC_OBJC_API_ENABLED 31 31 32 32 #import "APICast.h" 33 33 #import "JSVirtualMachineInternal.h" 34 34 35 static NSMapTable *globalWrapperCache = 0; 36 37 static Mutex& wrapperCacheLock() 38 { 39 DEFINE_STATIC_LOCAL(Mutex, mutex, ()); 40 return mutex; 41 } 42 43 static void initWrapperCache() 44 { 45 ASSERT(!globalWrapperCache); 46 NSPointerFunctionsOptions keyOptions = NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality; 47 NSPointerFunctionsOptions valueOptions = NSPointerFunctionsWeakMemory | NSPointerFunctionsObjectPersonality; 48 globalWrapperCache = [[NSMapTable alloc] initWithKeyOptions:keyOptions valueOptions:valueOptions capacity:0]; 49 } 50 51 static NSMapTable *wrapperCache() 52 { 53 if (!globalWrapperCache) 54 initWrapperCache(); 55 return globalWrapperCache; 56 } 57 58 @interface JSVMWrapperCache : NSObject 59 + (void)addWrapper:(JSVirtualMachine *)wrapper forJSContextGroupRef:(JSContextGroupRef)group; 60 + (JSVirtualMachine *)wrapperForJSContextGroupRef:(JSContextGroupRef)group; 61 @end 62 63 @implementation JSVMWrapperCache 64 65 + (void)addWrapper:(JSVirtualMachine *)wrapper forJSContextGroupRef:(JSContextGroupRef)group 66 { 67 MutexLocker locker(wrapperCacheLock()); 68 NSMapInsert(wrapperCache(), group, wrapper); 69 } 70 71 + (JSVirtualMachine *)wrapperForJSContextGroupRef:(JSContextGroupRef)group 72 { 73 MutexLocker locker(wrapperCacheLock()); 74 return static_cast<JSVirtualMachine *>(NSMapGet(wrapperCache(), group)); 75 } 76 77 @end 78 35 79 @implementation JSVirtualMachine { 36 80 JSContextGroupRef m_group; 81 NSMapTable *m_contextCache; 37 82 } 38 83 39 84 - (id)init 40 85 { 86 JSContextGroupRef group = JSContextGroupCreate(); 87 self = [self initWithContextGroupRef:group]; 88 // The extra JSContextGroupRetain is balanced here. 89 JSContextGroupRelease(group); 90 return self; 91 } 92 93 - (id)initWithContextGroupRef:(JSContextGroupRef)group 94 { 41 95 self = [super init]; 42 96 if (!self) 43 97 return nil; 44 45 m_group = JSContextGroupCreate(); 46 toJS(m_group)->m_apiData = self; 98 99 m_group = JSContextGroupRetain(group); 100 101 NSPointerFunctionsOptions keyOptions = NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality; 102 NSPointerFunctionsOptions valueOptions = NSPointerFunctionsWeakMemory | NSPointerFunctionsObjectPersonality; 103 m_contextCache = [[NSMapTable alloc] initWithKeyOptions:keyOptions valueOptions:valueOptions capacity:0]; 104 47 105 return self; 48 106 } … … 54 112 - (void)dealloc 55 113 { 56 toJS(m_group)->m_apiData = 0;57 114 JSContextGroupRelease(m_group); 58 115 [super dealloc]; … … 64 121 } 65 122 123 + (JSVirtualMachine *)virtualMachineWithContextGroupRef:(JSContextGroupRef)group 124 { 125 JSVirtualMachine *virtualMachine = [JSVMWrapperCache wrapperForJSContextGroupRef:group]; 126 if (!virtualMachine) { 127 virtualMachine = [[[JSVirtualMachine alloc] initWithContextGroupRef:group] autorelease]; 128 [JSVMWrapperCache addWrapper:virtualMachine forJSContextGroupRef:group]; 129 } 130 return virtualMachine; 131 } 132 133 - (JSContext *)contextForGlobalContextRef:(JSGlobalContextRef)globalContext 134 { 135 return static_cast<JSContext *>(NSMapGet(m_contextCache, globalContext)); 136 } 137 138 - (void)addContext:(JSContext *)wrapper forGlobalContextRef:(JSGlobalContextRef)globalContext 139 { 140 NSMapInsert(m_contextCache, globalContext, wrapper); 141 } 142 66 143 @end 144 67 145 68 146 #endif -
trunk/Source/JavaScriptCore/API/JSVirtualMachineInternal.h
r138689 r143637 24 24 */ 25 25 26 #import "JSVirtualMachine.h" 26 #ifndef JSVirtualMachineInternal_h 27 #define JSVirtualMachineInternal_h 28 29 #import <JavaScriptCore/JSVirtualMachine.h> 27 30 #import <JavaScriptCore/JavaScriptCore.h> 28 31 29 #if JS _OBJC_API_ENABLED32 #if JSC_OBJC_API_ENABLED 30 33 31 34 @interface JSVirtualMachine(Internal) … … 33 36 JSContextGroupRef getGroupFromVirtualMachine(JSVirtualMachine *); 34 37 38 + (JSVirtualMachine *)virtualMachineWithContextGroupRef:(JSContextGroupRef)group; 39 40 - (JSContext *)contextForGlobalContextRef:(JSGlobalContextRef)globalContext; 41 - (void)addContext:(JSContext *)wrapper forGlobalContextRef:(JSGlobalContextRef)globalContext; 42 35 43 @end 36 44 37 45 #endif 46 47 #endif // JSVirtualMachineInternal_h -
trunk/Source/JavaScriptCore/API/JSWrapperMap.h
r138689 r143637 28 28 #import <objc/objc-runtime.h> 29 29 30 #if JS _OBJC_API_ENABLED30 #if JSC_OBJC_API_ENABLED 31 31 32 32 @interface JSWrapperMap : NSObject … … 34 34 - (id)initWithContext:(JSContext *)context; 35 35 36 - (JSValue *)wrapperForObject:(id)object; 36 - (JSValue *)jsWrapperForObject:(id)object; 37 38 - (JSValue *)objcWrapperForJSValueRef:(JSValueRef)value; 37 39 38 40 @end -
trunk/Source/JavaScriptCore/API/JSWrapperMap.mm
r142319 r143637 27 27 #import "JavaScriptCore.h" 28 28 29 #if JS _OBJC_API_ENABLED29 #if JSC_OBJC_API_ENABLED 30 30 31 31 #import "APICast.h" … … 383 383 384 384 // Set [Prototype]. 385 prototype[@"__proto__"] = [JSValue valueWithValue:toRef(superClassInfo->m_prototype.get()) inContext:m_context];385 JSObjectSetPrototype(contextInternalContext(m_context), toRef(m_prototype.get()), toRef(superClassInfo->m_prototype.get())); 386 386 387 387 [constructor release]; … … 426 426 JSContext *m_context; 427 427 NSMutableDictionary *m_classMap; 428 JSC::WeakGCMap<id, JSC::JSObject> m_cachedWrappers; 428 JSC::WeakGCMap<id, JSC::JSObject> m_cachedJSWrappers; 429 NSMapTable *m_cachedObjCWrappers; 429 430 } 430 431 … … 435 436 return nil; 436 437 438 NSPointerFunctionsOptions keyOptions = NSPointerFunctionsOpaqueMemory | NSPointerFunctionsOpaquePersonality; 439 NSPointerFunctionsOptions valueOptions = NSPointerFunctionsWeakMemory | NSPointerFunctionsObjectPersonality; 440 m_cachedObjCWrappers = [[NSMapTable alloc] initWithKeyOptions:keyOptions valueOptions:valueOptions capacity:0]; 441 437 442 m_context = context; 438 443 m_classMap = [[NSMutableDictionary alloc] init]; … … 462 467 } 463 468 464 - (JSValue *) wrapperForObject:(id)object465 { 466 JSC::JSObject* jsWrapper = m_cached Wrappers.get(object);469 - (JSValue *)jsWrapperForObject:(id)object 470 { 471 JSC::JSObject* jsWrapper = m_cachedJSWrappers.get(object); 467 472 if (jsWrapper) 468 473 return [JSValue valueWithValue:toRef(jsWrapper) inContext:m_context]; … … 483 488 JSC::ExecState* exec = toJS(contextInternalContext(m_context)); 484 489 jsWrapper = toJS(exec, valueInternalValue(wrapper)).toObject(exec); 485 m_cachedWrappers.set(object, jsWrapper); 490 m_cachedJSWrappers.set(object, jsWrapper); 491 return wrapper; 492 } 493 494 - (JSValue *)objcWrapperForJSValueRef:(JSValueRef)value 495 { 496 JSValue *wrapper = static_cast<JSValue *>(NSMapGet(m_cachedObjCWrappers, value)); 497 if (!wrapper) { 498 wrapper = [[[JSValue alloc] initWithValue:value inContext:m_context] autorelease]; 499 NSMapInsert(m_cachedObjCWrappers, value, wrapper); 500 } 486 501 return wrapper; 487 502 } -
trunk/Source/JavaScriptCore/API/JavaScriptCore.h
r140718 r143637 30 30 #include <JavaScriptCore/JSStringRefCF.h> 31 31 32 #if defined(__OBJC__) && JS _OBJC_API_ENABLED32 #if defined(__OBJC__) && JSC_OBJC_API_ENABLED 33 33 34 34 #import "JSContext.h" -
trunk/Source/JavaScriptCore/API/ObjCCallbackFunction.h
r138689 r143637 26 26 #import <JavaScriptCore/JavaScriptCore.h> 27 27 28 #if JS _OBJC_API_ENABLED28 #if JSC_OBJC_API_ENABLED 29 29 30 30 JSObjectRef objCCallbackFunctionForMethod(JSContext *, Class, Protocol *, BOOL isInstanceMethod, SEL, const char* types); -
trunk/Source/JavaScriptCore/API/ObjCCallbackFunction.mm
r141805 r143637 27 27 #import "JavaScriptCore.h" 28 28 29 #if JS _OBJC_API_ENABLED29 #if JSC_OBJC_API_ENABLED 30 30 31 31 #import "APICast.h" … … 33 33 #import "Error.h" 34 34 #import "JSBlockAdaptor.h" 35 #import "JSCJSValueInlines.h" 36 #import "JSCell.h" 37 #import "JSCellInlines.h" 35 38 #import "JSContextInternal.h" 36 39 #import "JSWrapperMap.h" … … 427 430 { 428 431 ASSERT(type != CallbackInstanceMethod || instanceClass); 429 if (m_type != CallbackInstanceMethod)430 [[m_invocation.get() target] retain];431 432 } 432 433 … … 443 444 { 444 445 return m_context.get(); 446 } 447 448 void setContext(JSContext *context) 449 { 450 ASSERT(!m_context.get()); 451 m_context.set(context); 445 452 } 446 453 … … 475 482 JSContext *context = callback->context(); 476 483 if (!context) { 477 // FIXME: https://bugs.webkit.org/show_bug.cgi?id=105894 478 // Rather than requiring that the context be retained, it would probably be more 479 // appropriate to use a new JSContext instance (creating one if necessary). 480 *exception = toRef(JSC::createTypeError(toJS(callerContext), "Objective-C callback function context released")); 481 return JSValueMakeUndefined(callerContext); 484 context = [JSContext contextWithGlobalContextRef:toGlobalRef(toJS(callerContext)->lexicalGlobalObject()->globalExec())]; 485 callback->setContext(context); 482 486 } 483 487 … … 611 615 JSValue *value = [JSValue valueWithValue:functionObject inContext:context]; 612 616 value[@"length"] = @(argumentCount); 613 value[@"__proto__"] = context[@"Function"][@"prototype"];617 JSObjectSetPrototype(contextInternalContext(context), functionObject, valueInternalValue(context[@"Function"][@"prototype"])); 614 618 value[@"toString"] = [context evaluateScript:@"(function(){ return '" 615 619 "function <Objective-C>() {" "\\n" … … 635 639 const char* signature = _Block_signature(target); 636 640 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[NSMethodSignature signatureWithObjCTypes:signature]]; 637 [invocation setTarget: target];641 [invocation setTarget:[target copy]]; 638 642 return objCCallbackFunctionForInvocation(context, invocation, CallbackBlock, nil, signature); 639 643 } -
trunk/Source/JavaScriptCore/API/tests/testapi.c
r142838 r143637 52 52 #endif 53 53 54 #if JS _OBJC_API_ENABLED54 #if JSC_OBJC_API_ENABLED 55 55 void testObjectiveCAPI(void); 56 56 #endif … … 1048 1048 #endif 1049 1049 1050 #if JS _OBJC_API_ENABLED1050 #if JSC_OBJC_API_ENABLED 1051 1051 testObjectiveCAPI(); 1052 1052 #endif -
trunk/Source/JavaScriptCore/API/tests/testapi.mm
r141914 r143637 32 32 extern "C" void testObjectiveCAPI(void); 33 33 34 #if JS _OBJC_API_ENABLED34 #if JSC_OBJC_API_ENABLED 35 35 36 36 @protocol ParentObject <JSExport> … … 58 58 - (NSString *)testArgumentTypesWithInt:(int)i double:(double)d boolean:(BOOL)b string:(NSString *)s number:(NSNumber *)n array:(NSArray *)a dictionary:(NSDictionary *)o 59 59 ); 60 - (void)callback:( void(^)(int))block;60 - (void)callback:(JSValue *)function; 61 61 @end 62 62 … … 86 86 return [NSString stringWithFormat:@"%d,%g,%d,%@,%d,%@,%@", i, d, b==YES?true:false,s,[n intValue],a[1],o[@"x"]]; 87 87 } 88 - (void)callback:( void(^)(int))block89 { 90 block(42);88 - (void)callback:(JSValue *)function 89 { 90 [function callWithArguments:[NSArray arrayWithObject:[NSNumber numberWithInt:42]]]; 91 91 } 92 92 @end … … 483 483 JSContext *context2 = [[JSContext alloc] initWithVirtualMachine:context1.virtualMachine]; 484 484 JSValue *value = [JSValue valueWithDouble:42 inContext:context2]; 485 checkResult(@"value.context == context2", value.context == context2);486 485 context1[@"passValueBetweenContexts"] = value; 487 486 JSValue *result = [context1 evaluateScript:@"passValueBetweenContexts"]; 488 checkResult(@"result.context == context1", result.context == context1);489 487 checkResult(@"[value isEqualToObject:result]", [value isEqualToObject:result]); 490 488 } -
trunk/Source/JavaScriptCore/ChangeLog
r143562 r143637 1 2013-02-20 Mark Hahnenberg <mhahnenberg@apple.com> 2 3 Objective-C API: Need a way to use the Objective-C JavaScript API with WebKit 4 https://bugs.webkit.org/show_bug.cgi?id=106059 5 6 Reviewed by Geoffrey Garen. 7 8 * API/JSBase.h: Renamed enable flag for API. 9 * API/JSBlockAdaptor.h: Using new flag. 10 * API/JSBlockAdaptor.mm: Ditto. 11 * API/JSContext.h: Add convenience C API conversion function for JSGlobalContextRef. 12 * API/JSContext.mm: 13 (-[JSContext JSGlobalContextRef]): Implementation of C API convenience function. 14 (-[JSContext initWithVirtualMachine:]): We don't use the m_apiData field any more. 15 (-[JSContext initWithGlobalContextRef:]): init method for allocating new JSContexts given a JSGlobalContextRef. 16 (-[JSContext dealloc]): No more m_apiData. 17 (-[JSContext wrapperForObjCObject:]): Renamed wrapperForObject. 18 (-[JSContext wrapperForJSObject:]): Fetches or allocates the JSValue for the specified JSValueRef in this JSContext. 19 (+[JSContext contextWithGlobalContextRef:]): Helper function to grab the lightweight JSContext wrapper for a given 20 JSGlobalContextRef from the global wrapper cache or allocate a new one if there isn't already one. 21 * API/JSContextInternal.h: New flag, new method declaration for initWithGlobalContextRef. 22 * API/JSExport.h: New flag. 23 * API/JSValue.h: New flag and new C API convenience method. 24 * API/JSValue.mm: 25 (-[JSValue JSValueRef]): Implementation of the C API convenience method. 26 (objectToValueWithoutCopy): 27 (+[JSValue valueWithValue:inContext:]): We now ask the JSContext for an Objective-C JSValue wrapper, which it can cache 28 in its internal JSWrapperMap. 29 * API/JSValueInternal.h: 30 * API/JSVirtualMachine.h: 31 * API/JSVirtualMachine.mm: Added global cache that maps JSContextGroupRef -> JSVirtualMachine lightweight wrappers. 32 (wrapperCacheLock): 33 (initWrapperCache): 34 (+[JSVMWrapperCache addWrapper:forJSContextGroupRef:]): 35 (+[JSVMWrapperCache wrapperForJSContextGroupRef:]): 36 (-[JSVirtualMachine init]): 37 (-[JSVirtualMachine initWithContextGroupRef:]): 38 (-[JSVirtualMachine dealloc]): 39 (+[JSVirtualMachine virtualMachineWithContextGroupRef:]): 40 (-[JSVirtualMachine contextForGlobalContextRef:]): 41 (-[JSVirtualMachine addContext:forGlobalContextRef:]): 42 * API/JSVirtualMachineInternal.h: 43 * API/JSWrapperMap.h: 44 * API/JSWrapperMap.mm: 45 (-[JSObjCClassInfo allocateConstructorAndPrototypeWithSuperClassInfo:]): We use the JSObjectSetPrototype C API call because 46 setting the __proto__ property causes all sorts of bad things to happen behind the scenes, which can cause crashes based on 47 when it gets called. 48 (-[JSWrapperMap initWithContext:]): 49 (-[JSWrapperMap jsWrapperForObject:]): 50 (-[JSWrapperMap objcWrapperForJSValueRef:]): 51 * API/JavaScriptCore.h: 52 * API/ObjCCallbackFunction.h: 53 * API/ObjCCallbackFunction.mm: 54 (ObjCCallbackFunction::ObjCCallbackFunction): We never actually should have retained the target in the case that we had a 55 block as a callback. Blocks are initially allocated on the stack and are only moved to the heap if we call their copy method. 56 Retaining the block on the stack was a bad idea because if that stack frame ever went away and we called the block later, 57 we'd crash and burn. 58 (ObjCCallbackFunction::setContext): We need a new setter for when the weak reference to a JSContext inside an ObjCCallbackFunction 59 disappears, we can allocate a new one in its place. 60 (ObjCCallbackFunction): 61 (objCCallbackFunctionCallAsFunction): Reset the callback's context if it's ever destroyed. 62 (objCCallbackFunctionForInvocation): Again, don't set the __proto__ property because it uses black magic that can cause us to crash 63 depending on when this is called. 64 (objCCallbackFunctionForBlock): Here is where we copy the block to the heap when we're first creating the callback object for it. 65 * API/tests/testapi.c: 66 (main): 67 * API/tests/testapi.mm: We're going to get rid of the automatic block conversion, since that is causing leaks. I changed it 68 here in this test just so that it wouldn't mask any other potential leaks. Also modified some of the tests since JSContexts are 69 just lightweight wrappers now, we're not guaranteed to get the same pointer back from the call to [JSValue context] as the one 70 that the value was created in. 71 (-[TestObject callback:]): 72 * JavaScriptCore.xcodeproj/project.pbxproj: 73 * runtime/JSGlobalData.cpp: 74 (JSC::JSGlobalData::JSGlobalData): No more m_apiData. 75 * runtime/JSGlobalData.h: Ditto. 76 * runtime/JSGlobalObject.cpp: 77 (JSC::JSGlobalObject::JSGlobalObject): Ditto. 78 * runtime/JSGlobalObject.h: 79 1 80 2013-02-19 Filip Pizlo <fpizlo@apple.com> 2 81 -
trunk/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
r143392 r143637 589 589 86E3C615167BABD7006D760A /* JSVirtualMachine.h in Headers */ = {isa = PBXBuildFile; fileRef = 86E3C60F167BAB87006D760A /* JSVirtualMachine.h */; settings = {ATTRIBUTES = (Public, ); }; }; 590 590 86E3C616167BABEE006D760A /* JSContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = 86E3C608167BAB87006D760A /* JSContext.mm */; }; 591 86E3C617167BABEE006D760A /* JSContextInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 86E3C609167BAB87006D760A /* JSContextInternal.h */; };591 86E3C617167BABEE006D760A /* JSContextInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 86E3C609167BAB87006D760A /* JSContextInternal.h */; settings = {ATTRIBUTES = (Private, ); }; }; 592 592 86E3C618167BABEE006D760A /* JSWrapperMap.mm in Sources */ = {isa = PBXBuildFile; fileRef = 86E3C60B167BAB87006D760A /* JSWrapperMap.mm */; }; 593 593 86E3C619167BABEE006D760A /* JSWrapperMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 86E3C60C167BAB87006D760A /* JSWrapperMap.h */; }; 594 594 86E3C61A167BABEE006D760A /* JSValue.mm in Sources */ = {isa = PBXBuildFile; fileRef = 86E3C60D167BAB87006D760A /* JSValue.mm */; }; 595 86E3C61B167BABEE006D760A /* JSValueInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 86E3C60E167BAB87006D760A /* JSValueInternal.h */; };595 86E3C61B167BABEE006D760A /* JSValueInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 86E3C60E167BAB87006D760A /* JSValueInternal.h */; settings = {ATTRIBUTES = (Private, ); }; }; 596 596 86E3C61C167BABEE006D760A /* JSVirtualMachine.mm in Sources */ = {isa = PBXBuildFile; fileRef = 86E3C610167BAB87006D760A /* JSVirtualMachine.mm */; }; 597 86E3C61D167BABEE006D760A /* JSVirtualMachineInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 86E3C611167BAB87006D760A /* JSVirtualMachineInternal.h */; };597 86E3C61D167BABEE006D760A /* JSVirtualMachineInternal.h in Headers */ = {isa = PBXBuildFile; fileRef = 86E3C611167BAB87006D760A /* JSVirtualMachineInternal.h */; settings = {ATTRIBUTES = (Private, ); }; }; 598 598 86E85539111B9968001AF51E /* JSStringBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = 86E85538111B9968001AF51E /* JSStringBuilder.h */; }; 599 599 86EBF2FF1560F06A008E9222 /* NameConstructor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 86EBF2F91560F036008E9222 /* NameConstructor.cpp */; }; … … 2929 2929 0F63945515D07057006A597C /* ArrayProfile.h in Headers */, 2930 2930 BC18C3E70E16F5CD00B34460 /* ArrayPrototype.h in Headers */, 2931 86E3C61D167BABEE006D760A /* JSVirtualMachineInternal.h in Headers */, 2931 2932 BC18C5240E16FC8A00B34460 /* ArrayPrototype.lut.h in Headers */, 2933 86E3C617167BABEE006D760A /* JSContextInternal.h in Headers */, 2934 86E3C61B167BABEE006D760A /* JSValueInternal.h in Headers */, 2932 2935 0FB7F39615ED8E4600F167B2 /* ArrayStorage.h in Headers */, 2933 2936 9688CB150ED12B4E001D649F /* AssemblerBuffer.h in Headers */, … … 3126 3129 BC18C41D0E16F5CD00B34460 /* JSClassRef.h in Headers */, 3127 3130 86E3C613167BABD7006D760A /* JSContext.h in Headers */, 3128 86E3C617167BABEE006D760A /* JSContextInternal.h in Headers */,3129 3131 BC18C41E0E16F5CD00B34460 /* JSContextRef.h in Headers */, 3130 3132 148CD1D8108CF902008163C6 /* JSContextRefPrivate.h in Headers */, … … 3161 3163 6507D29E0E871E5E00D7D896 /* JSTypeInfo.h in Headers */, 3162 3164 86E3C612167BABD7006D760A /* JSValue.h in Headers */, 3163 86E3C61B167BABEE006D760A /* JSValueInternal.h in Headers */,3164 3165 BC18C42C0E16F5CD00B34460 /* JSValueRef.h in Headers */, 3165 3166 BC18C42D0E16F5CD00B34460 /* JSVariableObject.h in Headers */, 3166 3167 86E3C615167BABD7006D760A /* JSVirtualMachine.h in Headers */, 3167 86E3C61D167BABEE006D760A /* JSVirtualMachineInternal.h in Headers */,3168 3168 A7482E93116A7CAD003B0712 /* JSWeakObjectMapRefInternal.h in Headers */, 3169 3169 A7482B9311671147003B0712 /* JSWeakObjectMapRefPrivate.h in Headers */, -
trunk/Source/JavaScriptCore/runtime/JSGlobalData.cpp
r143279 r143637 188 188 #endif 189 189 , m_newStringsSinceLastHashConst(0) 190 , m_apiData(0)191 190 #if ENABLE(ASSEMBLER) 192 191 , m_canUseAssembler(enableAssembler(executableAllocator)) -
trunk/Source/JavaScriptCore/runtime/JSGlobalData.h
r143279 r143637 480 480 JS_EXPORT_PRIVATE void discardAllCode(); 481 481 482 void *m_apiData;483 484 482 private: 485 483 friend class LLIntOffsetsExtractor; -
trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp
r143147 r143637 117 117 , m_evalEnabled(true) 118 118 , m_globalObjectMethodTable(globalObjectMethodTable ? globalObjectMethodTable : &s_globalObjectMethodTable) 119 , m_apiData(0)120 119 { 121 120 } -
trunk/Source/JavaScriptCore/runtime/JSGlobalObject.h
r143171 r143637 197 197 bool hasProfiler() const { return globalObjectMethodTable()->supportsProfiling(this); } 198 198 199 void* m_apiData;200 201 199 protected: 202 200 JS_EXPORT_PRIVATE explicit JSGlobalObject(JSGlobalData&, Structure*, const GlobalObjectMethodTable* = 0); -
trunk/Source/WTF/ChangeLog
r143618 r143637 1 2013-02-19 Mark Hahnenberg <mhahnenberg@apple.com> 2 3 Objective-C API: Need a way to use the Objective-C JavaScript API with WebKit 4 https://bugs.webkit.org/show_bug.cgi?id=106059 5 6 Reviewed by Geoffrey Garen. 7 8 * wtf/FeatureDefines.h: Added enable flag for JSC Objective-C API so it can be used in 9 export files. 10 1 11 2013-02-21 Martin Robinson <mrobinson@igalia.com> 2 12 -
trunk/Source/WTF/wtf/FeatureDefines.h
r143505 r143637 567 567 #endif 568 568 569 #if !defined(JSC_OBJC_API_ENABLED) 570 #define JSC_OBJC_API_ENABLED (defined(__clang__) && defined(__APPLE__) && defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090 && !defined(__i386__)) 571 #endif 572 569 573 #if !defined(ENABLE_LEGACY_CSS_VENDOR_PREFIXES) 570 574 #define ENABLE_LEGACY_CSS_VENDOR_PREFIXES 0 -
trunk/Source/WebCore/ChangeLog
r143636 r143637 1 2013-02-19 Mark Hahnenberg <mhahnenberg@apple.com> 2 3 Objective-C API: Need a way to use the Objective-C JavaScript API with WebKit 4 https://bugs.webkit.org/show_bug.cgi?id=106059 5 6 Reviewed by Geoffrey Garen. 7 8 * WebCore.exp.in: 9 * bindings/js/JSDOMWindowShell.cpp: 10 (WebCore::JSDOMWindowShell::setWindow): Since we're basically abandoning a JSDOMWindow here, we call 11 garbageCollectSoon(). 12 * bindings/js/JSDOMWindowShell.h: 13 * bindings/js/ScriptController.h: New function to get the JSContext for the global object of the current main world. 14 * bindings/js/ScriptControllerMac.mm: 15 (WebCore::ScriptController::javaScriptContext): Ditto. 16 * bindings/objc/WebScriptObject.h: Added ifdef guards. Also new convenience conversion function for the JSC Obj-C API. 17 * bindings/objc/WebScriptObject.mm: JSC::JSValue and JSValue conflict with one another, so we have to be more specific. 18 (-[WebScriptObject _globalContextRef]): Useful helper function for getting the JSGlobalContextRef of a particular WebScriptObject. 19 (-[WebScriptObject callWebScriptMethod:withArguments:]): 20 (-[WebScriptObject evaluateWebScript:]): 21 (-[WebScriptObject valueForKey:]): 22 (-[WebScriptObject webScriptValueAtIndex:]): 23 (+[WebScriptObject _convertValueToObjcValue:JSC::originRootObject:rootObject:]): 24 (-[WebScriptObject JSValue]): Implementation of convenience WebScriptObject conversion function to new Objective-C API. 25 * bindings/objc/WebScriptObjectPrivate.h: 26 1 27 2013-02-21 Kentaro Hara <haraken@chromium.org> 2 28 -
trunk/Source/WebCore/WebCore.exp.in
r143428 r143637 502 502 __ZN7WebCore16ScriptController13executeScriptERKN3WTF6StringEb 503 503 __ZN7WebCore16ScriptController17canExecuteScriptsENS_33ReasonForCallingCanExecuteScriptsE 504 #if JSC_OBJC_API_ENABLED 505 __ZN7WebCore16ScriptController17javaScriptContextEv 506 #endif 504 507 __ZN7WebCore16ScriptController18windowScriptObjectEv 505 508 __ZN7WebCore16ScriptController20executeScriptInWorldEPNS_15DOMWrapperWorldERKN3WTF6StringEb -
trunk/Source/WebCore/bindings/js/JSDOMWindowShell.cpp
r131088 r143637 31 31 32 32 #include "Frame.h" 33 #include "GCController.h" 33 34 #include "JSDOMWindow.h" 34 35 #include "DOMWindow.h" … … 59 60 { 60 61 static_cast<JSDOMWindowShell*>(cell)->JSDOMWindowShell::~JSDOMWindowShell(); 62 } 63 64 void JSDOMWindowShell::setWindow(JSC::JSGlobalData& globalData, JSDOMWindow* window) 65 { 66 ASSERT_ARG(window, window); 67 setTarget(globalData, window); 68 structure()->setGlobalObject(*JSDOMWindow::commonJSGlobalData(), window); 69 gcController().garbageCollectSoon(); 61 70 } 62 71 -
trunk/Source/WebCore/bindings/js/JSDOMWindowShell.h
r129685 r143637 45 45 46 46 JSDOMWindow* window() const { return JSC::jsCast<JSDOMWindow*>(target()); } 47 void setWindow(JSC::JSGlobalData& globalData, JSDOMWindow* window) 48 { 49 ASSERT_ARG(window, window); 50 setTarget(globalData, window); 51 structure()->setGlobalObject(*JSDOMWindow::commonJSGlobalData(), window); 52 } 47 void setWindow(JSC::JSGlobalData&, JSDOMWindow*); 53 48 void setWindow(PassRefPtr<DOMWindow>); 54 49 -
trunk/Source/WebCore/bindings/js/ScriptController.h
r133006 r143637 27 27 #include "ScriptControllerBase.h" 28 28 #include "ScriptInstance.h" 29 #include <JavaScriptCore/JSBase.h> 29 30 #include <heap/Strong.h> 30 31 #include <wtf/Forward.h> … … 35 36 #include <wtf/RetainPtr.h> 36 37 OBJC_CLASS WebScriptObject; 38 OBJC_CLASS JSContext; 37 39 #endif 38 40 … … 152 154 #if PLATFORM(MAC) 153 155 WebScriptObject* windowScriptObject(); 156 #if JSC_OBJC_API_ENABLED 157 JSContext *javaScriptContext(); 158 #endif 154 159 #endif 155 160 -
trunk/Source/WebCore/bindings/js/ScriptControllerMac.mm
r129964 r143637 42 42 #import "runtime_root.h" 43 43 #import <JavaScriptCore/APICast.h> 44 #import <JavaScriptCore/JSContextInternal.h> 44 45 #import <runtime/JSLock.h> 45 46 … … 110 111 } 111 112 113 #if JSC_OBJC_API_ENABLED 114 JSContext *ScriptController::javaScriptContext() 115 { 116 if (!canExecuteScripts(NotAboutToExecuteScript)) 117 return 0; 118 JSContext *context = [JSContext contextWithGlobalContextRef:toGlobalRef(bindingRootObject()->globalObject()->globalExec())]; 119 return context; 120 } 121 #endif 122 112 123 void ScriptController::updatePlatformScriptObjects() 113 124 { -
trunk/Source/WebCore/bindings/objc/WebScriptObject.h
r37476 r143637 24 24 */ 25 25 26 #ifndef WebScriptObject_h 27 #define WebScriptObject_h 28 26 29 #import <Foundation/Foundation.h> 27 30 #import <JavaScriptCore/JSBase.h> … … 190 193 // WebScriptObject -------------------------------------------------- 191 194 195 @class JSValue; 192 196 @class WebScriptObjectPrivate; 193 197 @class WebFrame; … … 298 302 - (void)setException:(NSString *)description; 299 303 304 305 #if JSC_OBJC_API_ENABLED 306 /*! 307 @method JSValue 308 @result The equivalent Objective-C JSValue for this WebScriptObject. 309 @discussion Use this method to bridge between the WebScriptObject and 310 JavaScriptCore Objective-C APIs. 311 */ 312 - (JSValue *)JSValue; 313 #endif 314 300 315 @end 301 316 … … 317 332 318 333 #endif 334 335 #endif // WebScriptObject_h -
trunk/Source/WebCore/bindings/objc/WebScriptObject.mm
r142163 r143637 44 44 #import "runtime_root.h" 45 45 #import <JavaScriptCore/APICast.h> 46 #import <JavaScriptCore/JSContextInternal.h> 47 #import <JavaScriptCore/JSValueInternal.h> 46 48 #import <interpreter/CallFrame.h> 47 49 #import <runtime/InitializeThreading.h> … … 54 56 #include <wtf/text/WTFString.h> 55 57 56 using namespace JSC;57 58 using namespace JSC::Bindings; 58 59 using namespace WebCore; 60 61 using JSC::CallData; 62 using JSC::CallType; 63 using JSC::CallTypeNone; 64 using JSC::ExecState; 65 using JSC::Identifier; 66 using JSC::JSLockHolder; 67 using JSC::JSObject; 68 using JSC::MarkedArgumentBuffer; 69 using JSC::PutPropertySlot; 70 using JSC::jsCast; 71 using JSC::jsUndefined; 72 using JSC::makeSource; 59 73 60 74 namespace WebCore { … … 237 251 } 238 252 253 - (JSGlobalContextRef)_globalContextRef 254 { 255 if (![self _isSafeScript]) 256 return nil; 257 return toGlobalRef([self _rootObject]->globalObject()->globalExec()); 258 } 259 239 260 - (oneway void)release 240 261 { … … 305 326 ASSERT(!exec->hadException()); 306 327 307 JS Value function = [self _imp]->get(exec, Identifier(exec, String(name)));328 JSC::JSValue function = [self _imp]->get(exec, Identifier(exec, String(name))); 308 329 CallData callData; 309 330 CallType callType = getCallData(function, callData); … … 318 339 319 340 [self _rootObject]->globalObject()->globalData().timeoutChecker.start(); 320 JS Value result = JSMainThreadExecState::call(exec, function, callType, callData, [self _imp], argList);341 JSC::JSValue result = JSMainThreadExecState::call(exec, function, callType, callData, [self _imp], argList); 321 342 [self _rootObject]->globalObject()->globalData().timeoutChecker.stop(); 322 343 … … 344 365 345 366 [self _rootObject]->globalObject()->globalData().timeoutChecker.start(); 346 JS Value returnValue = JSMainThreadExecState::evaluate(exec, makeSource(String(script)), JSC::JSValue(), 0);367 JSC::JSValue returnValue = JSMainThreadExecState::evaluate(exec, makeSource(String(script)), JSC::JSValue(), 0); 347 368 [self _rootObject]->globalObject()->globalData().timeoutChecker.stop(); 348 369 … … 386 407 JSLockHolder lock(exec); 387 408 388 JS Value result = [self _imp]->get(exec, Identifier(exec, String(key)));409 JSC::JSValue result = [self _imp]->get(exec, Identifier(exec, String(key))); 389 410 390 411 if (exec->hadException()) { … … 465 486 466 487 JSLockHolder lock(exec); 467 JS Value result = [self _imp]->get(exec, index);488 JSC::JSValue result = [self _imp]->get(exec, index); 468 489 469 490 if (exec->hadException()) { … … 512 533 } 513 534 514 + (id)_convertValueToObjcValue:(JS Value)value originRootObject:(RootObject*)originRootObject rootObject:(RootObject*)rootObject535 + (id)_convertValueToObjcValue:(JSC::JSValue)value originRootObject:(RootObject*)originRootObject rootObject:(RootObject*)rootObject 515 536 { 516 537 if (value.isObject()) { … … 556 577 } 557 578 579 580 #if JSC_OBJC_API_ENABLED 581 - (JSValue *)JSValue 582 { 583 if (![self _isSafeScript]) 584 return 0; 585 586 return [JSValue valueWithValue:[self JSObject] 587 inContext:[JSContext contextWithGlobalContextRef:[self _globalContextRef]]]; 588 } 589 #endif 590 558 591 @end 559 592 -
trunk/Source/WebCore/bindings/objc/WebScriptObjectPrivate.h
r140718 r143637 58 58 - (JSC::Bindings::RootObject*)_rootObject; 59 59 - (JSC::Bindings::RootObject*)_originRootObject; 60 - (JSGlobalContextRef)_globalContextRef; 60 61 @end 61 62 -
trunk/Source/WebKit/mac/ChangeLog
r143505 r143637 1 2013-02-19 Mark Hahnenberg <mhahnenberg@apple.com> 2 3 Objective-C API: Need a way to use the Objective-C JavaScript API with WebKit 4 https://bugs.webkit.org/show_bug.cgi?id=106059 5 6 Reviewed by Geoffrey Garen. 7 8 Addition of appropriate delegate callbacks and support to the WebKit API. 9 10 * WebCoreSupport/WebFrameLoaderClient.mm: 11 * WebView/WebDelegateImplementationCaching.h: 12 (WebFrameLoadDelegateImplementationCache): 13 * WebView/WebFrame.h: 14 * WebView/WebFrame.mm: 15 (-[WebFrame _stringByEvaluatingJavaScriptFromString:forceUserGesture:]): 16 (-[WebFrame _stringByEvaluatingJavaScriptFromString:withGlobalObject:inScriptWorld:]): 17 (-[WebFrame _javaScriptContextForScriptWorld:]): 18 (-[WebFrame javaScriptContext]): 19 * WebView/WebFrameLoadDelegate.h: 20 * WebView/WebFramePrivate.h: 21 * WebView/WebScriptDebugDelegate.mm: 22 (-[WebScriptCallFrame _convertValueToObjcValue:JSC::]): 23 (-[WebScriptCallFrame exception]): 24 (-[WebScriptCallFrame evaluateWebScript:]): 25 * WebView/WebScriptWorld.h: 26 * WebView/WebScriptWorld.mm: 27 (+[WebScriptWorld scriptWorldForJavaScriptContext:]): 28 * WebView/WebView.mm: 29 (-[WebView _cacheFrameLoadDelegateImplementations]): 30 (aeDescFromJSValue): 31 (-[WebView aeDescByEvaluatingJavaScriptFromString:]): 32 (-[WebView _computedStyleIncludingVisitedInfo:forElement:]): 33 1 34 2013-02-20 Dirk Schulze <krit@webkit.org> 2 35 -
trunk/Source/WebKit/mac/WebCoreSupport/WebFrameLoaderClient.mm
r142977 r143637 75 75 #import "WebUIDelegatePrivate.h" 76 76 #import "WebViewInternal.h" 77 #import <JavaScriptCore/JSContextInternal.h> 77 78 #import <WebCore/AuthenticationCF.h> 78 79 #import <WebCore/AuthenticationMac.h> … … 118 119 #import <WebCore/SharedBuffer.h> 119 120 #import <WebCore/WebCoreObjCExtras.h> 121 #import <WebCore/WebScriptObjectPrivate.h> 120 122 #import <WebCore/Widget.h> 121 123 #import <WebKit/DOMElement.h> … … 1951 1953 ScriptController *script = frame->script(); 1952 1954 1955 #if JSC_OBJC_API_ENABLED 1956 if (implementations->didCreateJavaScriptContextForFrameFunc) { 1957 CallFrameLoadDelegate(implementations->didCreateJavaScriptContextForFrameFunc, webView, @selector(webView:didCreateJavaScriptContext:forFrame:), 1958 script->javaScriptContext(), m_webFrame.get()); 1959 } else if (implementations->didClearWindowObjectForFrameFunc) { 1960 #else 1953 1961 if (implementations->didClearWindowObjectForFrameFunc) { 1962 #endif 1954 1963 CallFrameLoadDelegate(implementations->didClearWindowObjectForFrameFunc, webView, @selector(webView:didClearWindowObject:forFrame:), 1955 1964 script->windowScriptObject(), m_webFrame.get()); -
trunk/Source/WebKit/mac/WebView/WebDelegateImplementationCaching.h
r139000 r143637 53 53 54 54 struct WebFrameLoadDelegateImplementationCache { 55 #if JSC_OBJC_API_ENABLED 56 IMP didCreateJavaScriptContextForFrameFunc; 57 #endif 55 58 IMP didClearWindowObjectForFrameFunc; 56 59 IMP didClearWindowObjectForFrameInScriptWorldFunc; -
trunk/Source/WebKit/mac/WebView/WebFrame.h
r55349 r143637 32 32 @class DOMDocument; 33 33 @class DOMHTMLElement; 34 @class JSContext; 34 35 @class NSURLRequest; 35 36 @class WebArchive; … … 214 215 */ 215 216 - (JSGlobalContextRef)globalContext; 217 218 #if JSC_OBJC_API_ENABLED 219 /*! 220 @method javaScriptContext 221 @result The frame's global JavaScript execution context. Use this method to 222 bridge between the WebKit and Objective-C JavaScriptCore API. 223 */ 224 - (JSContext *)javaScriptContext; 225 #endif // JSC_OBJC_API_ENABLED 226 216 227 @end -
trunk/Source/WebKit/mac/WebView/WebFrame.mm
r142977 r143637 54 54 #import "WebViewInternal.h" 55 55 #import <JavaScriptCore/APICast.h> 56 #import <JavaScriptCore/JSContextInternal.h> 56 57 #import <WebCore/AXObjectCache.h> 57 58 #import <WebCore/AccessibilityObject.h> … … 107 108 using JSC::JSGlobalObject; 108 109 using JSC::JSLock; 109 using JSC::JSValue;110 110 111 111 /* … … 581 581 RetainPtr<WebFrame> protect(self); // Executing arbitrary JavaScript can destroy the frame. 582 582 583 JS Value result = _private->coreFrame->script()->executeScript(string, forceUserGesture).jsValue();583 JSC::JSValue result = _private->coreFrame->script()->executeScript(string, forceUserGesture).jsValue(); 584 584 585 585 if (!_private->coreFrame) // In case the script removed our frame from the page. … … 1060 1060 RetainPtr<WebFrame> webFrame(kit(frame)); // Running arbitrary JavaScript can destroy the frame. 1061 1061 1062 JS Value result = frame->script()->executeScriptInWorld(core(world), string, true).jsValue();1062 JSC::JSValue result = frame->script()->executeScriptInWorld(core(world), string, true).jsValue(); 1063 1063 1064 1064 if (!webFrame->_private->coreFrame) // In case the script removed our frame from the page. … … 1086 1086 return toGlobalRef(coreFrame->script()->globalObject(coreWorld)->globalExec()); 1087 1087 } 1088 1089 #if JSC_OBJC_API_ENABLED 1090 - (JSContext *)_javaScriptContextForScriptWorld:(WebScriptWorld *)world 1091 { 1092 JSGlobalContextRef globalContextRef = [self _globalContextForScriptWorld:world]; 1093 if (!globalContextRef) 1094 return 0; 1095 return [JSContext contextWithGlobalContextRef:globalContextRef]; 1096 } 1097 #endif 1088 1098 1089 1099 - (void)setAllowsScrollersToOverlapContent:(BOOL)flag … … 1472 1482 } 1473 1483 1484 #if JSC_OBJC_API_ENABLED 1485 - (JSContext *)javaScriptContext 1486 { 1487 Frame* coreFrame = _private->coreFrame; 1488 if (!coreFrame) 1489 return 0; 1490 return coreFrame->script()->javaScriptContext(); 1491 } 1492 #endif 1493 1474 1494 @end -
trunk/Source/WebKit/mac/WebView/WebFrameLoadDelegate.h
r37474 r143637 195 195 - (void)webView:(WebView *)webView windowScriptObjectAvailable:(WebScriptObject *)windowScriptObject WEBKIT_OBJC_METHOD_ANNOTATION(AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0); 196 196 197 #if JSC_OBJC_API_ENABLED 198 /*! 199 @method webView:didCreateJavaScriptContext:contextForFrame: 200 @abstract Notifies the delegate that a new JavaScript context has been created created. 201 @param webView The WebView sending the message. 202 @param context The JSContext representing the frame's JavaScript window object. 203 @param frame The WebFrame to which the context belongs. 204 @discussion If a delegate implements webView:didCreateJavaScriptContext:forFrame: along with either 205 webView:didClearWindowObject:forFrame: or webView:windowScriptObjectAvailable:, only 206 webView:didCreateJavaScriptContext:forFrame will be invoked. This enables a delegate to implement 207 multiple versions to maintain backwards compatibility with older versions of WebKit. 208 */ 209 - (void)webView:(WebView *)webView didCreateJavaScriptContext:(JSContext *)context forFrame:(WebFrame *)frame; 210 #endif 211 197 212 @end -
trunk/Source/WebKit/mac/WebView/WebFramePrivate.h
r142171 r143637 96 96 - (JSGlobalContextRef)_globalContextForScriptWorld:(WebScriptWorld *)world; 97 97 98 #if JSC_OBJC_API_ENABLED 99 - (JSContext *)_javaScriptContextForScriptWorld:(WebScriptWorld *)world; 100 #endif 101 98 102 - (void)_replaceSelectionWithFragment:(DOMDocumentFragment *)fragment selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace matchStyle:(BOOL)matchStyle; 99 103 - (void)_replaceSelectionWithText:(NSString *)text selectReplacement:(BOOL)selectReplacement smartReplace:(BOOL)smartReplace; -
trunk/Source/WebKit/mac/WebView/WebScriptDebugDelegate.mm
r128267 r143637 56 56 @interface WebScriptCallFrame (WebScriptDebugDelegateInternal) 57 57 58 - (id)_convertValueToObjcValue:(JS Value)value;58 - (id)_convertValueToObjcValue:(JSC::JSValue)value; 59 59 60 60 @end … … 114 114 } 115 115 116 - (id)_convertValueToObjcValue:(JS Value)value116 - (id)_convertValueToObjcValue:(JSC::JSValue)value 117 117 { 118 118 if (!value) … … 215 215 return nil; 216 216 217 JS Value exception = _private->debuggerCallFrame->exception();217 JSC::JSValue exception = _private->debuggerCallFrame->exception(); 218 218 return exception ? [self _convertValueToObjcValue:exception] : nil; 219 219 } … … 242 242 DynamicGlobalObjectScope globalObjectScope(globalObject->globalData(), globalObject); 243 243 244 JS Value exception;245 JS Value result = evaluateInGlobalCallFrame(script, exception, globalObject);244 JSC::JSValue exception; 245 JSC::JSValue result = evaluateInGlobalCallFrame(script, exception, globalObject); 246 246 if (exception) 247 247 return [self _convertValueToObjcValue:exception]; … … 249 249 } 250 250 251 JS Value exception;252 JS Value result = _private->debuggerCallFrame->evaluate(script, exception);251 JSC::JSValue exception; 252 JSC::JSValue result = _private->debuggerCallFrame->evaluate(script, exception); 253 253 if (exception) 254 254 return [self _convertValueToObjcValue:exception]; -
trunk/Source/WebKit/mac/WebView/WebScriptWorld.h
r95901 r143637 23 23 */ 24 24 25 typedef struct OpaqueJSContext* JSGlobalContextRef; 25 #include <JavaScriptCore/JSBase.h> 26 26 27 @class JSContext; 27 28 @class WebScriptWorldPrivate; 28 29 … … 36 37 37 38 + (WebScriptWorld *)scriptWorldForGlobalContext:(JSGlobalContextRef)globalContext; 39 #if JSC_OBJC_API_ENABLED 40 + (WebScriptWorld *)scriptWorldForJavaScriptContext:(JSContext *)context; 41 #endif 38 42 39 43 - (void)unregisterWorld; -
trunk/Source/WebKit/mac/WebView/WebScriptWorld.mm
r95901 r143637 29 29 #import <WebCore/ScriptController.h> 30 30 #import <JavaScriptCore/APICast.h> 31 #import <JavaScriptCore/JSContextInternal.h> 31 32 32 33 #import <wtf/RefPtr.h> … … 107 108 } 108 109 110 #if JSC_OBJC_API_ENABLED 111 + (WebScriptWorld *)scriptWorldForJavaScriptContext:(JSContext *)context 112 { 113 return [self scriptWorldForGlobalContext:contextInternalContext(context)]; 114 } 115 #endif 116 109 117 @end 110 118 -
trunk/Source/WebKit/mac/WebView/WebView.mm
r143428 r143637 1660 1660 cache->didReplaceStateWithinPageForFrameFunc = getMethod(delegate, @selector(webView:didReplaceStateWithinPageForFrame:)); 1661 1661 cache->didPopStateWithinPageForFrameFunc = getMethod(delegate, @selector(webView:didPopStateWithinPageForFrame:)); 1662 #if JSC_OBJC_API_ENABLED 1663 cache->didCreateJavaScriptContextForFrameFunc = getMethod(delegate, @selector(webView:didCreateJavaScriptContext:forFrame:)); 1664 #endif 1662 1665 cache->didClearWindowObjectForFrameFunc = getMethod(delegate, @selector(webView:didClearWindowObject:forFrame:)); 1663 1666 cache->didClearWindowObjectForFrameInScriptWorldFunc = getMethod(delegate, @selector(webView:didClearWindowObjectForFrame:inScriptWorld:)); … … 4917 4920 } 4918 4921 4919 static NSAppleEventDescriptor* aeDescFromJSValue(ExecState* exec, JS Value jsValue)4922 static NSAppleEventDescriptor* aeDescFromJSValue(ExecState* exec, JSC::JSValue jsValue) 4920 4923 { 4921 4924 NSAppleEventDescriptor* aeDesc = 0; … … 4958 4961 } 4959 4962 } 4960 JS Value primitive = object->toPrimitive(exec);4963 JSC::JSValue primitive = object->toPrimitive(exec); 4961 4964 if (exec->hadException()) { 4962 4965 exec->clearException(); … … 4978 4981 if (!coreFrame->document()) 4979 4982 return nil; 4980 JS Value result = coreFrame->script()->executeScript(script, true).jsValue();4983 JSC::JSValue result = coreFrame->script()->executeScript(script, true).jsValue(); 4981 4984 if (!result) // FIXME: pass errors 4982 4985 return 0; … … 6700 6703 if (!value) 6701 6704 return JSValueMakeUndefined(context); 6702 JS Value jsValue = toJS(exec, value);6705 JSC::JSValue jsValue = toJS(exec, value); 6703 6706 if (!jsValue.inherits(&JSElement::s_info)) 6704 6707 return JSValueMakeUndefined(context); -
trunk/Tools/ChangeLog
r143635 r143637 1 2013-02-19 Mark Hahnenberg <mhahnenberg@apple.com> 2 3 Objective-C API: Need a way to use the Objective-C JavaScript API with WebKit 4 https://bugs.webkit.org/show_bug.cgi?id=106059 5 6 Reviewed by Geoffrey Garen. 7 8 Added new tests for the WebKit API portion of the JSC Objective-C API. 9 10 * TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: 11 * TestWebKitAPI/Tests/mac/JSContextBackForwardCache1.html: Added. 12 * TestWebKitAPI/Tests/mac/JSContextBackForwardCache2.html: Added. 13 * TestWebKitAPI/Tests/mac/WebViewDidCreateJavaScriptContext.mm: Added. 14 (-[MyConsole log:]): 15 (-[MyConsole printHelloWorld]): 16 (-[MyConsole add:to:]): 17 (-[DidCreateJavaScriptContextFrameLoadDelegate webView:didFinishLoadForFrame:]): 18 (-[DidCreateJavaScriptContextFrameLoadDelegate webView:didCreateJavaScriptContext:forFrame:]): 19 (TestWebKitAPI): 20 (TestWebKitAPI::TEST): 21 1 22 2013-02-21 Stephen Chenney <schenney@chromium.org> 2 23 -
trunk/Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj
r143067 r143637 178 178 C0C5D3BE14598B6F00A802A6 /* GetBackingScaleFactor.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */; }; 179 179 C0C5D3C61459912900A802A6 /* GetBackingScaleFactor_Bundle.mm in Sources */ = {isa = PBXBuildFile; fileRef = C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */; }; 180 C2CF975A16CEC7140054E99D /* JSContextBackForwardCache2.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C2CF975916CEC69E0054E99D /* JSContextBackForwardCache2.html */; }; 181 C2CF975B16CEC71B0054E99D /* JSContextBackForwardCache1.html in Copy Resources */ = {isa = PBXBuildFile; fileRef = C2CF975816CEC69E0054E99D /* JSContextBackForwardCache1.html */; }; 182 C2EB2DD316CAC7AC009B52EE /* WebViewDidCreateJavaScriptContext.mm in Sources */ = {isa = PBXBuildFile; fileRef = C2EB2DD116CAC7AC009B52EE /* WebViewDidCreateJavaScriptContext.mm */; }; 180 183 C507E8A714C6545B005D6B3B /* InspectorBar.mm in Sources */ = {isa = PBXBuildFile; fileRef = C507E8A614C6545B005D6B3B /* InspectorBar.mm */; }; 181 184 C51AFB99169F49FF009CCF66 /* FindMatches.mm in Sources */ = {isa = PBXBuildFile; fileRef = C51AFB98169F49FF009CCF66 /* FindMatches.mm */; }; … … 227 230 dstSubfolderSpec = 7; 228 231 files = ( 232 C2CF975B16CEC71B0054E99D /* JSContextBackForwardCache1.html in Copy Resources */, 233 C2CF975A16CEC7140054E99D /* JSContextBackForwardCache2.html in Copy Resources */, 229 234 1A9E52C913E65EF4006917F5 /* 18-characters.html in Copy Resources */, 230 235 379028B914FAC24C007E6B43 /* acceptsFirstMouse.html in Copy Resources */, … … 457 462 C0C5D3BC14598B6F00A802A6 /* GetBackingScaleFactor.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GetBackingScaleFactor.mm; sourceTree = "<group>"; }; 458 463 C0C5D3BD14598B6F00A802A6 /* GetBackingScaleFactor_Bundle.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = GetBackingScaleFactor_Bundle.mm; sourceTree = "<group>"; }; 464 C2CF975816CEC69E0054E99D /* JSContextBackForwardCache1.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = JSContextBackForwardCache1.html; sourceTree = "<group>"; }; 465 C2CF975916CEC69E0054E99D /* JSContextBackForwardCache2.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = JSContextBackForwardCache2.html; sourceTree = "<group>"; }; 466 C2EB2DD116CAC7AC009B52EE /* WebViewDidCreateJavaScriptContext.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebViewDidCreateJavaScriptContext.mm; sourceTree = "<group>"; }; 459 467 C507E8A614C6545B005D6B3B /* InspectorBar.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = InspectorBar.mm; sourceTree = "<group>"; }; 460 468 C51AFB98169F49FF009CCF66 /* FindMatches.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = FindMatches.mm; sourceTree = "<group>"; }; … … 818 826 37E38C33169B7D010084C28C /* WebViewDidRemoveFrameFromHierarchy.mm */, 819 827 A5E2027215B2181900C13E14 /* WindowlessWebViewWithMedia.mm */, 828 C2EB2DD116CAC7AC009B52EE /* WebViewDidCreateJavaScriptContext.mm */, 820 829 ); 821 830 path = mac; … … 825 834 isa = PBXGroup; 826 835 children = ( 836 C2CF975816CEC69E0054E99D /* JSContextBackForwardCache1.html */, 837 C2CF975916CEC69E0054E99D /* JSContextBackForwardCache2.html */, 827 838 379028B814FABE49007E6B43 /* acceptsFirstMouse.html */, 828 839 B55F11B9151916E600915916 /* Ahem.ttf */, … … 934 945 08FB7793FE84155DC02AAC07 /* Project object */ = { 935 946 isa = PBXProject; 947 attributes = { 948 }; 936 949 buildConfigurationList = 1DEB927808733DD40010E9CD /* Build configuration list for PBXProject "TestWebKitAPI" */; 937 950 compatibilityVersion = "Xcode 3.1"; … … 1009 1022 9B4F8FA4159D52B1002D9F94 /* HTMLCollectionNamedItem.mm in Sources */, 1010 1023 9B26FC6C159D061000CC3765 /* HTMLFormCollectionNamedItem.mm in Sources */, 1024 C2EB2DD316CAC7AC009B52EE /* WebViewDidCreateJavaScriptContext.mm in Sources */, 1011 1025 BC575AAD126E83B9006F0F12 /* InjectedBundleBasic.cpp in Sources */, 1012 1026 378E64731632646D00B6C676 /* InjectedBundleFrameHitTest.cpp in Sources */,
Note: See TracChangeset
for help on using the changeset viewer.