Ignore:
Timestamp:
Mar 14, 2013, 2:14:01 PM (12 years ago)
Author:
[email protected]
Message:

Objective-C API: Objective-C functions exposed to JavaScript have the wrong type (object instead of function)
https://bugs.webkit.org/show_bug.cgi?id=105892

Reviewed by Geoffrey Garen.

Changed ObjCCallbackFunction to subclass JSCallbackFunction which already has all of the machinery to call
functions using the C API. Since ObjCCallbackFunction is now a JSCell, we changed the old implementation of
ObjCCallbackFunction to be the internal implementation and keep track of all the proper data so that we
don't have to put all of that in the header, which will now be included from C++ files (e.g. JSGlobalObject.cpp).

  • API/JSCallbackFunction.cpp: Change JSCallbackFunction to allow subclassing. Originally it was internally

passing its own Structure up the chain of constructors, but we now want to be able to pass other Structures as well.
(JSC::JSCallbackFunction::JSCallbackFunction):
(JSC::JSCallbackFunction::create):

  • API/JSCallbackFunction.h:

(JSCallbackFunction):

  • API/JSWrapperMap.mm: Changed interface to tryUnwrapBlock.

(tryUnwrapObjcObject):

  • API/ObjCCallbackFunction.h:

(ObjCCallbackFunction): Moved into the JSC namespace, just like JSCallbackFunction.
(JSC::ObjCCallbackFunction::createStructure): Overridden so that the correct ClassInfo gets used since we have
a destructor.
(JSC::ObjCCallbackFunction::impl): Getter for the internal impl.

  • API/ObjCCallbackFunction.mm:

(JSC::ObjCCallbackFunctionImpl::ObjCCallbackFunctionImpl): What used to be ObjCCallbackFunction is now
ObjCCallbackFunctionImpl. It handles the Objective-C specific parts of managing callback functions.
(JSC::ObjCCallbackFunctionImpl::~ObjCCallbackFunctionImpl):
(JSC::objCCallbackFunctionCallAsFunction): Same as the old one, but now it casts to ObjCCallbackFunction and grabs the impl
rather than using JSObjectGetPrivate.
(JSC::ObjCCallbackFunction::ObjCCallbackFunction): New bits to allow being part of the JSCell hierarchy.
(JSC::ObjCCallbackFunction::create):
(JSC::ObjCCallbackFunction::destroy):
(JSC::ObjCCallbackFunctionImpl::call): Handles the actual invocation, just like it used to.
(objCCallbackFunctionForInvocation):
(tryUnwrapBlock): Changed to check the ClassInfo for inheritance directly, rather than going through the C API call.

  • API/tests/testapi.mm: Added new test to make sure that doing Function.prototype.toString.call(f) won't result in

an error when f is an Objective-C method or block underneath the covers.

  • runtime/JSGlobalObject.cpp: Added new Structure for ObjCCallbackFunction.

(JSC::JSGlobalObject::reset):
(JSC::JSGlobalObject::visitChildren):

  • runtime/JSGlobalObject.h:

(JSGlobalObject):
(JSC::JSGlobalObject::objcCallbackFunctionStructure):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/JSGlobalObject.cpp

    r145119 r145848  
    7070#include "NumberConstructor.h"
    7171#include "NumberPrototype.h"
     72#include "ObjCCallbackFunction.h"
    7273#include "ObjectConstructor.h"
    7374#include "ObjectPrototype.h"
     
    231232    m_callbackConstructorStructure.set(exec->globalData(), this, JSCallbackConstructor::createStructure(exec->globalData(), this, m_objectPrototype.get()));
    232233    m_callbackObjectStructure.set(exec->globalData(), this, JSCallbackObject<JSDestructibleObject>::createStructure(exec->globalData(), this, m_objectPrototype.get()));
     234#if JSC_OBJC_API_ENABLED
     235    m_objcCallbackFunctionStructure.set(exec->globalData(), this, ObjCCallbackFunction::createStructure(exec->globalData(), this, m_functionPrototype.get()));
     236#endif
    233237    m_objcWrapperObjectStructure.set(exec->globalData(), this, JSCallbackObject<JSAPIWrapperObject>::createStructure(exec->globalData(), this, m_objectPrototype.get()));
    234238
     
    514518    visitor.append(&thisObject->m_callbackFunctionStructure);
    515519    visitor.append(&thisObject->m_callbackObjectStructure);
     520#if JSC_OBJC_API_ENABLED
     521    visitor.append(&thisObject->m_objcCallbackFunctionStructure);
     522#endif
    516523    visitor.append(&thisObject->m_objcWrapperObjectStructure);
    517524    visitor.append(&thisObject->m_dateStructure);
Note: See TracChangeset for help on using the changeset viewer.