Ignore:
Timestamp:
Aug 27, 2020, 9:41:27 AM (5 years ago)
Author:
[email protected]
Message:

JSClassRef should work with JS class syntax.
https://bugs.webkit.org/show_bug.cgi?id=215047

Reviewed by Darin Adler.

This is done by checking if value returned by the
callAsConstructor parameter to JSObjectMakeConstructor returns an
object allocated as the jsClass parameter. When that happens we
replace the prototype of the returned object with the prototype of
the new.target. Ideally we would have passed the derived classes
constructor from the beginning of our support for JS subclassing
but at this point that's probably not compatible with too many
applications.

  • API/APICallbackFunction.h:

(JSC::APICallbackFunction::construct):

  • API/JSObjectRef.h:
  • API/tests/testapi.cpp:

(APIString::APIString):
(TestAPI::markedJSValueArrayAndGC):
(TestAPI::classDefinitionWithJSSubclass):
(testCAPIViaCpp):

  • API/tests/testapi.mm:

(testObjectiveCAPI):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSObjectRef.h

    r248833 r266236  
    340340
    341341A NULL callback specifies that the default object callback should substitute, except in the case of hasProperty, where it specifies that getProperty should substitute.
     342
     343It is not possible to use JS subclassing with objects created from a class definition that sets callAsConstructor by default. Subclassing is supported via the JSObjectMakeConstructor function, however.
    342344*/
    343345typedef struct {
     
    427429@param callAsConstructor A JSObjectCallAsConstructorCallback to invoke when your constructor is used in a 'new' expression. Pass NULL to use the default object constructor.
    428430@result A JSObject that is a constructor. The object's prototype will be the default object prototype.
    429 @discussion The default object constructor takes no arguments and constructs an object of class jsClass with no private data.
     431@discussion The default object constructor takes no arguments and constructs an object of class jsClass with no private data. If the constructor is inherited via JS subclassing and the value returned from callAsConstructor was created with jsClass, then the returned object will have it's prototype overridden to the derived class's prototype.
    430432*/
    431433JS_EXPORT JSObjectRef JSObjectMakeConstructor(JSContextRef ctx, JSClassRef jsClass, JSObjectCallAsConstructorCallback callAsConstructor);
Note: See TracChangeset for help on using the changeset viewer.