2 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #import "JavaScriptCore.h"
29 #if JSC_OBJC_API_ENABLED
31 #import "APICallbackFunction.h"
34 #import "JSCJSValueInlines.h"
36 #import "JSCellInlines.h"
37 #import "JSContextInternal.h"
38 #import "JSWrapperMap.h"
39 #import "JSValueInternal.h"
40 #import "ObjCCallbackFunction.h"
41 #import "ObjcRuntimeExtras.h"
42 #import <objc/runtime.h>
43 #import <wtf/RetainPtr.h>
45 class CallbackArgument {
47 virtual ~CallbackArgument();
48 virtual void set(NSInvocation *, NSInteger, JSContext *, JSValueRef, JSValueRef*) = 0;
50 std::unique_ptr<CallbackArgument> m_next;
53 CallbackArgument::~CallbackArgument()
57 class CallbackArgumentBoolean : public CallbackArgument {
58 virtual void set(NSInvocation *invocation, NSInteger argumentNumber, JSContext *context, JSValueRef argument, JSValueRef*) override
60 bool value = JSValueToBoolean([context JSGlobalContextRef], argument);
61 [invocation setArgument:&value atIndex:argumentNumber];
66 class CallbackArgumentInteger : public CallbackArgument {
67 virtual void set(NSInvocation *invocation, NSInteger argumentNumber, JSContext *context, JSValueRef argument, JSValueRef* exception) override
69 T value = (T)JSC::toInt32(JSValueToNumber([context JSGlobalContextRef], argument, exception));
70 [invocation setArgument:&value atIndex:argumentNumber];
75 class CallbackArgumentDouble : public CallbackArgument {
76 virtual void set(NSInvocation *invocation, NSInteger argumentNumber, JSContext *context, JSValueRef argument, JSValueRef* exception) override
78 T value = (T)JSValueToNumber([context JSGlobalContextRef], argument, exception);
79 [invocation setArgument:&value atIndex:argumentNumber];
83 class CallbackArgumentJSValue : public CallbackArgument {
84 virtual void set(NSInvocation *invocation, NSInteger argumentNumber, JSContext *context, JSValueRef argument, JSValueRef*) override
86 JSValue *value = [JSValue valueWithJSValueRef:argument inContext:context];
87 [invocation setArgument:&value atIndex:argumentNumber];
91 class CallbackArgumentId : public CallbackArgument {
92 virtual void set(NSInvocation *invocation, NSInteger argumentNumber, JSContext *context, JSValueRef argument, JSValueRef*) override
94 id value = valueToObject(context, argument);
95 [invocation setArgument:&value atIndex:argumentNumber];
99 class CallbackArgumentOfClass : public CallbackArgument {
101 CallbackArgumentOfClass(Class cls)
107 virtual void set(NSInvocation *invocation, NSInteger argumentNumber, JSContext *context, JSValueRef argument, JSValueRef* exception) override
109 JSGlobalContextRef contextRef = [context JSGlobalContextRef];
111 id object = tryUnwrapObjcObject(contextRef, argument);
112 if (object && [object isKindOfClass:m_class.get()]) {
113 [invocation setArgument:&object atIndex:argumentNumber];
117 if (JSValueIsNull(contextRef, argument) || JSValueIsUndefined(contextRef, argument)) {
119 [invocation setArgument:&object atIndex:argumentNumber];
123 *exception = toRef(JSC::createTypeError(toJS(contextRef), ASCIILiteral("Argument does not match Objective-C Class")));
126 RetainPtr<Class> m_class;
129 class CallbackArgumentNSNumber : public CallbackArgument {
130 virtual void set(NSInvocation *invocation, NSInteger argumentNumber, JSContext *context, JSValueRef argument, JSValueRef* exception) override
132 id value = valueToNumber([context JSGlobalContextRef], argument, exception);
133 [invocation setArgument:&value atIndex:argumentNumber];
137 class CallbackArgumentNSString : public CallbackArgument {
138 virtual void set(NSInvocation *invocation, NSInteger argumentNumber, JSContext *context, JSValueRef argument, JSValueRef* exception) override
140 id value = valueToString([context JSGlobalContextRef], argument, exception);
141 [invocation setArgument:&value atIndex:argumentNumber];
145 class CallbackArgumentNSDate : public CallbackArgument {
146 virtual void set(NSInvocation *invocation, NSInteger argumentNumber, JSContext *context, JSValueRef argument, JSValueRef* exception) override
148 id value = valueToDate([context JSGlobalContextRef], argument, exception);
149 [invocation setArgument:&value atIndex:argumentNumber];
153 class CallbackArgumentNSArray : public CallbackArgument {
154 virtual void set(NSInvocation *invocation, NSInteger argumentNumber, JSContext *context, JSValueRef argument, JSValueRef* exception) override
156 id value = valueToArray([context JSGlobalContextRef], argument, exception);
157 [invocation setArgument:&value atIndex:argumentNumber];
161 class CallbackArgumentNSDictionary : public CallbackArgument {
162 virtual void set(NSInvocation *invocation, NSInteger argumentNumber, JSContext *context, JSValueRef argument, JSValueRef* exception) override
164 id value = valueToDictionary([context JSGlobalContextRef], argument, exception);
165 [invocation setArgument:&value atIndex:argumentNumber];
169 class CallbackArgumentStruct : public CallbackArgument {
171 CallbackArgumentStruct(NSInvocation *conversionInvocation, const char* encodedType)
172 : m_conversionInvocation(conversionInvocation)
173 , m_buffer(encodedType)
178 virtual void set(NSInvocation *invocation, NSInteger argumentNumber, JSContext *context, JSValueRef argument, JSValueRef*) override
180 JSValue *value = [JSValue valueWithJSValueRef:argument inContext:context];
181 [m_conversionInvocation invokeWithTarget:value];
182 [m_conversionInvocation getReturnValue:m_buffer];
183 [invocation setArgument:m_buffer atIndex:argumentNumber];
186 RetainPtr<NSInvocation> m_conversionInvocation;
187 StructBuffer m_buffer;
190 class ArgumentTypeDelegate {
192 typedef std::unique_ptr<CallbackArgument> ResultType;
195 static ResultType typeInteger()
197 return std::make_unique<CallbackArgumentInteger<T>>();
201 static ResultType typeDouble()
203 return std::make_unique<CallbackArgumentDouble<T>>();
206 static ResultType typeBool()
208 return std::make_unique<CallbackArgumentBoolean>();
211 static ResultType typeVoid()
213 RELEASE_ASSERT_NOT_REACHED();
217 static ResultType typeId()
219 return std::make_unique<CallbackArgumentId>();
222 static ResultType typeOfClass(const char* begin, const char* end)
224 StringRange copy(begin, end);
225 Class cls = objc_getClass(copy);
229 if (cls == [JSValue class])
230 return std::make_unique<CallbackArgumentJSValue>();
231 if (cls == [NSString class])
232 return std::make_unique<CallbackArgumentNSString>();
233 if (cls == [NSNumber class])
234 return std::make_unique<CallbackArgumentNSNumber>();
235 if (cls == [NSDate class])
236 return std::make_unique<CallbackArgumentNSDate>();
237 if (cls == [NSArray class])
238 return std::make_unique<CallbackArgumentNSArray>();
239 if (cls == [NSDictionary class])
240 return std::make_unique<CallbackArgumentNSDictionary>();
242 return std::make_unique<CallbackArgumentOfClass>(cls);
245 static ResultType typeBlock(const char*, const char*)
250 static ResultType typeStruct(const char* begin, const char* end)
252 StringRange copy(begin, end);
253 if (NSInvocation *invocation = valueToTypeInvocationFor(copy))
254 return std::make_unique<CallbackArgumentStruct>(invocation, copy);
259 class CallbackResult {
261 virtual ~CallbackResult()
265 virtual JSValueRef get(NSInvocation *, JSContext *, JSValueRef*) = 0;
268 class CallbackResultVoid : public CallbackResult {
269 virtual JSValueRef get(NSInvocation *, JSContext *context, JSValueRef*) override
271 return JSValueMakeUndefined([context JSGlobalContextRef]);
275 class CallbackResultId : public CallbackResult {
276 virtual JSValueRef get(NSInvocation *invocation, JSContext *context, JSValueRef*) override
279 [invocation getReturnValue:&value];
280 return objectToValue(context, value);
285 class CallbackResultNumeric : public CallbackResult {
286 virtual JSValueRef get(NSInvocation *invocation, JSContext *context, JSValueRef*) override
289 [invocation getReturnValue:&value];
290 return JSValueMakeNumber([context JSGlobalContextRef], value);
294 class CallbackResultBoolean : public CallbackResult {
295 virtual JSValueRef get(NSInvocation *invocation, JSContext *context, JSValueRef*) override
298 [invocation getReturnValue:&value];
299 return JSValueMakeBoolean([context JSGlobalContextRef], value);
303 class CallbackResultStruct : public CallbackResult {
305 CallbackResultStruct(NSInvocation *conversionInvocation, const char* encodedType)
306 : m_conversionInvocation(conversionInvocation)
307 , m_buffer(encodedType)
312 virtual JSValueRef get(NSInvocation *invocation, JSContext *context, JSValueRef*) override
314 [invocation getReturnValue:m_buffer];
316 [m_conversionInvocation setArgument:m_buffer atIndex:2];
317 [m_conversionInvocation setArgument:&context atIndex:3];
318 [m_conversionInvocation invokeWithTarget:[JSValue class]];
321 [m_conversionInvocation getReturnValue:&value];
322 return valueInternalValue(value);
325 RetainPtr<NSInvocation> m_conversionInvocation;
326 StructBuffer m_buffer;
329 class ResultTypeDelegate {
331 typedef std::unique_ptr<CallbackResult> ResultType;
334 static ResultType typeInteger()
336 return std::make_unique<CallbackResultNumeric<T>>();
340 static ResultType typeDouble()
342 return std::make_unique<CallbackResultNumeric<T>>();
345 static ResultType typeBool()
347 return std::make_unique<CallbackResultBoolean>();
350 static ResultType typeVoid()
352 return std::make_unique<CallbackResultVoid>();
355 static ResultType typeId()
357 return std::make_unique<CallbackResultId>();
360 static ResultType typeOfClass(const char*, const char*)
362 return std::make_unique<CallbackResultId>();
365 static ResultType typeBlock(const char*, const char*)
367 return std::make_unique<CallbackResultId>();
370 static ResultType typeStruct(const char* begin, const char* end)
372 StringRange copy(begin, end);
373 if (NSInvocation *invocation = typeToValueInvocationFor(copy))
374 return std::make_unique<CallbackResultStruct>(invocation, copy);
381 CallbackInstanceMethod,
388 class ObjCCallbackFunctionImpl {
390 ObjCCallbackFunctionImpl(NSInvocation *invocation, CallbackType type, Class instanceClass, std::unique_ptr<CallbackArgument> arguments, std::unique_ptr<CallbackResult> result)
392 , m_instanceClass(instanceClass)
393 , m_invocation(invocation)
394 , m_arguments(WTF::move(arguments))
395 , m_result(WTF::move(result))
397 ASSERT((type != CallbackInstanceMethod && type != CallbackInitMethod) || instanceClass);
400 void destroy(Heap& heap)
402 // We need to explicitly release the target since we didn't call
403 // -retainArguments on m_invocation (and we don't want to do so).
404 if (m_type == CallbackBlock || m_type == CallbackClassMethod)
405 heap.releaseSoon(adoptNS([m_invocation.get() target]));
406 m_instanceClass = nil;
409 JSValueRef call(JSContext *context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);
413 return m_type == CallbackBlock ? [m_invocation target] : nil;
416 id wrappedConstructor()
420 return [m_invocation target];
421 case CallbackInitMethod:
422 return m_instanceClass.get();
428 bool isConstructible()
430 return !!wrappedBlock() || m_type == CallbackInitMethod;
437 RetainPtr<Class> m_instanceClass;
438 RetainPtr<NSInvocation> m_invocation;
439 std::unique_ptr<CallbackArgument> m_arguments;
440 std::unique_ptr<CallbackResult> m_result;
443 static JSValueRef objCCallbackFunctionCallAsFunction(JSContextRef callerContext, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
445 // Retake the API lock - we need this for a few reasons:
446 // (1) We don't want to support the C-API's confusing drops-locks-once policy - should only drop locks if we can do so recursively.
447 // (2) We're calling some JSC internals that require us to be on the 'inside' - e.g. createTypeError.
448 // (3) We need to be locked (per context would be fine) against conflicting usage of the ObjCCallbackFunction's NSInvocation.
449 JSC::JSLockHolder locker(toJS(callerContext));
451 ObjCCallbackFunction* callback = static_cast<ObjCCallbackFunction*>(toJS(function));
452 ObjCCallbackFunctionImpl* impl = callback->impl();
453 JSContext *context = [JSContext contextWithJSGlobalContextRef:toGlobalRef(callback->globalObject()->globalExec())];
455 CallbackData callbackData;
458 [context beginCallbackWithData:&callbackData calleeValue:function thisValue:thisObject argumentCount:argumentCount arguments:arguments];
459 result = impl->call(context, thisObject, argumentCount, arguments, exception);
460 if (context.exception)
461 *exception = valueInternalValue(context.exception);
462 [context endCallbackWithData:&callbackData];
467 static JSObjectRef objCCallbackFunctionCallAsConstructor(JSContextRef callerContext, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
469 JSC::JSLockHolder locker(toJS(callerContext));
471 ObjCCallbackFunction* callback = static_cast<ObjCCallbackFunction*>(toJS(constructor));
472 ObjCCallbackFunctionImpl* impl = callback->impl();
473 JSContext *context = [JSContext contextWithJSGlobalContextRef:toGlobalRef(toJS(callerContext)->lexicalGlobalObject()->globalExec())];
475 CallbackData callbackData;
478 [context beginCallbackWithData:&callbackData calleeValue:constructor thisValue:nullptr argumentCount:argumentCount arguments:arguments];
479 result = impl->call(context, nullptr, argumentCount, arguments, exception);
480 if (context.exception)
481 *exception = valueInternalValue(context.exception);
482 [context endCallbackWithData:&callbackData];
485 JSGlobalContextRef contextRef = [context JSGlobalContextRef];
489 if (!JSValueIsObject(contextRef, result)) {
490 *exception = toRef(JSC::createTypeError(toJS(contextRef), ASCIILiteral("Objective-C blocks called as constructors must return an object.")));
493 return (JSObjectRef)result;
496 const JSC::ClassInfo ObjCCallbackFunction::s_info = { "CallbackFunction", &Base::s_info, 0, CREATE_METHOD_TABLE(ObjCCallbackFunction) };
498 ObjCCallbackFunction::ObjCCallbackFunction(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSObjectCallAsFunctionCallback functionCallback, JSObjectCallAsConstructorCallback constructCallback, std::unique_ptr<ObjCCallbackFunctionImpl> impl)
499 : Base(vm, globalObject->objcCallbackFunctionStructure())
500 , m_functionCallback(functionCallback)
501 , m_constructCallback(constructCallback)
502 , m_impl(WTF::move(impl))
506 ObjCCallbackFunction* ObjCCallbackFunction::create(JSC::VM& vm, JSC::JSGlobalObject* globalObject, const String& name, std::unique_ptr<ObjCCallbackFunctionImpl> impl)
508 ObjCCallbackFunction* function = new (NotNull, allocateCell<ObjCCallbackFunction>(vm.heap)) ObjCCallbackFunction(vm, globalObject, objCCallbackFunctionCallAsFunction, objCCallbackFunctionCallAsConstructor, WTF::move(impl));
509 function->finishCreation(vm, name);
513 void ObjCCallbackFunction::destroy(JSCell* cell)
515 ObjCCallbackFunction& function = *jsCast<ObjCCallbackFunction*>(cell);
516 function.impl()->destroy(*Heap::heap(cell));
517 function.~ObjCCallbackFunction();
521 CallType ObjCCallbackFunction::getCallData(JSCell*, CallData& callData)
523 callData.native.function = APICallbackFunction::call<ObjCCallbackFunction>;
527 ConstructType ObjCCallbackFunction::getConstructData(JSCell* cell, ConstructData& constructData)
529 ObjCCallbackFunction* callback = jsCast<ObjCCallbackFunction*>(cell);
530 if (!callback->impl()->isConstructible())
531 return Base::getConstructData(cell, constructData);
532 constructData.native.function = APICallbackFunction::construct<ObjCCallbackFunction>;
533 return ConstructTypeHost;
536 String ObjCCallbackFunctionImpl::name()
538 if (m_type == CallbackInitMethod)
539 return class_getName(m_instanceClass.get());
540 // FIXME: Maybe we could support having the selector as the name of the non-init
541 // functions to make it a bit more user-friendly from the JS side?
545 JSValueRef ObjCCallbackFunctionImpl::call(JSContext *context, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
547 JSGlobalContextRef contextRef = [context JSGlobalContextRef];
550 size_t firstArgument;
552 case CallbackInitMethod: {
553 RELEASE_ASSERT(!thisObject);
554 target = [m_instanceClass alloc];
555 if (!target || ![target isKindOfClass:m_instanceClass.get()]) {
556 *exception = toRef(JSC::createTypeError(toJS(contextRef), ASCIILiteral("self type check failed for Objective-C instance method")));
557 return JSValueMakeUndefined(contextRef);
559 [m_invocation setTarget:target];
563 case CallbackInstanceMethod: {
564 target = tryUnwrapObjcObject(contextRef, thisObject);
565 if (!target || ![target isKindOfClass:m_instanceClass.get()]) {
566 *exception = toRef(JSC::createTypeError(toJS(contextRef), ASCIILiteral("self type check failed for Objective-C instance method")));
567 return JSValueMakeUndefined(contextRef);
569 [m_invocation setTarget:target];
573 case CallbackClassMethod:
580 size_t argumentNumber = 0;
581 for (CallbackArgument* argument = m_arguments.get(); argument; argument = argument->m_next.get()) {
582 JSValueRef value = argumentNumber < argumentCount ? arguments[argumentNumber] : JSValueMakeUndefined(contextRef);
583 argument->set(m_invocation.get(), argumentNumber + firstArgument, context, value, exception);
585 return JSValueMakeUndefined(contextRef);
589 [m_invocation invoke];
591 JSValueRef result = m_result->get(m_invocation.get(), context, exception);
593 // Balance our call to -alloc with a call to -autorelease. We have to do this after calling -init
594 // because init family methods are allowed to release the allocated object and return something
595 // else in its place.
596 if (m_type == CallbackInitMethod) {
597 id objcResult = tryUnwrapObjcObject(contextRef, result);
599 [objcResult autorelease];
607 static bool blockSignatureContainsClass()
609 static bool containsClass = ^{
610 id block = ^(NSString *string){ return string; };
611 return _Block_has_signature(block) && strstr(_Block_signature(block), "NSString");
613 return containsClass;
616 static inline bool skipNumber(const char*& position)
618 if (!isASCIIDigit(*position))
620 while (isASCIIDigit(*++position)) { }
624 static JSObjectRef objCCallbackFunctionForInvocation(JSContext *context, NSInvocation *invocation, CallbackType type, Class instanceClass, const char* signatureWithObjcClasses)
626 if (!signatureWithObjcClasses)
629 const char* position = signatureWithObjcClasses;
631 auto result = parseObjCType<ResultTypeDelegate>(position);
632 if (!result || !skipNumber(position))
636 case CallbackInitMethod:
637 case CallbackInstanceMethod:
638 case CallbackClassMethod:
639 // Methods are passed two implicit arguments - (id)self, and the selector.
640 if ('@' != *position++ || !skipNumber(position) || ':' != *position++ || !skipNumber(position))
644 // Blocks are passed one implicit argument - the block, of type "@?".
645 if (('@' != *position++) || ('?' != *position++) || !skipNumber(position))
647 // Only allow arguments of type 'id' if the block signature contains the NS type information.
648 if ((!blockSignatureContainsClass() && strchr(position, '@')))
653 std::unique_ptr<CallbackArgument> arguments;
654 auto* nextArgument = &arguments;
655 unsigned argumentCount = 0;
657 auto argument = parseObjCType<ArgumentTypeDelegate>(position);
658 if (!argument || !skipNumber(position))
661 *nextArgument = WTF::move(argument);
662 nextArgument = &(*nextArgument)->m_next;
666 JSC::ExecState* exec = toJS([context JSGlobalContextRef]);
667 JSC::JSLockHolder locker(exec);
668 auto impl = std::make_unique<JSC::ObjCCallbackFunctionImpl>(invocation, type, instanceClass, WTF::move(arguments), WTF::move(result));
669 const String& name = impl->name();
670 return toRef(JSC::ObjCCallbackFunction::create(exec->vm(), exec->lexicalGlobalObject(), name, WTF::move(impl)));
673 JSObjectRef objCCallbackFunctionForInit(JSContext *context, Class cls, Protocol *protocol, SEL sel, const char* types)
675 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[NSMethodSignature signatureWithObjCTypes:types]];
676 [invocation setSelector:sel];
677 return objCCallbackFunctionForInvocation(context, invocation, CallbackInitMethod, cls, _protocol_getMethodTypeEncoding(protocol, sel, YES, YES));
680 JSObjectRef objCCallbackFunctionForMethod(JSContext *context, Class cls, Protocol *protocol, BOOL isInstanceMethod, SEL sel, const char* types)
682 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[NSMethodSignature signatureWithObjCTypes:types]];
683 [invocation setSelector:sel];
684 // We need to retain the target Class because m_invocation doesn't retain it by default (and we don't want it to).
685 // FIXME: What releases it?
686 if (!isInstanceMethod)
687 [invocation setTarget:[cls retain]];
688 return objCCallbackFunctionForInvocation(context, invocation, isInstanceMethod ? CallbackInstanceMethod : CallbackClassMethod, isInstanceMethod ? cls : nil, _protocol_getMethodTypeEncoding(protocol, sel, YES, isInstanceMethod));
691 JSObjectRef objCCallbackFunctionForBlock(JSContext *context, id target)
693 if (!_Block_has_signature(target))
695 const char* signature = _Block_signature(target);
696 NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[NSMethodSignature signatureWithObjCTypes:signature]];
698 // We don't want to use -retainArguments because that leaks memory. Arguments
699 // would be retained indefinitely between invocations of the callback.
700 // Additionally, we copy the target because we want the block to stick around
701 // until the ObjCCallbackFunctionImpl is destroyed.
702 [invocation setTarget:[target copy]];
704 return objCCallbackFunctionForInvocation(context, invocation, CallbackBlock, nil, signature);
707 id tryUnwrapConstructor(JSObjectRef object)
709 if (!toJS(object)->inherits(JSC::ObjCCallbackFunction::info()))
711 JSC::ObjCCallbackFunctionImpl* impl = static_cast<JSC::ObjCCallbackFunction*>(toJS(object))->impl();
712 if (!impl->isConstructible())
714 return impl->wrappedConstructor();