JSObject.makeCallAsConstructor constructor
JSObject.makeCallAsConstructor(
- JSContext context, {
- JSClass? jsclass,
- JSObjectCallAsConstructorCallback? callAsConstructor,
- bool autoDispose = true,
Convenience method for creating a JavaScript constructor.
The default object constructor takes no arguments and constructs an object of class jsClass with no private data.
jsClass
A JSClass that is the class your constructor will assign to the objects its constructs. jsClass will be used to set the constructor's .prototype property, and to evaluate 'instanceof' expressions. Pass NULL to use the default object class.
callAsConstructor
A JSObjectCallAsConstructorCallback to invoke when your constructor is used in a 'new' expression. Pass NULL to use the default object constructor.
Implementation
JSObject.makeCallAsConstructor(
this.context, {
JSClass? jsclass,
JSObjectCallAsConstructorCallback? callAsConstructor,
bool autoDispose = true,
}) {
_callAsConstructorNC = NativeCallable.isolateLocal((
JSContextRef ctx1,
JSObjectRef constructor,
int argc,
Pointer<JSValueRef> argv,
Pointer<JSValueRef> exception,
) {
final ctxw = JSContext(ctx1);
final jscons = JSObject(ctxw, constructor);
final argvlist = <JSValue>[];
for (int i = 0; i < argc; i++) {
argvlist[i] = JSValue(ctxw, argv[i]);
}
final jsexc = JSException(ctxw, exception);
return callAsConstructor?.call(ctxw, jscons, argc, argvlist, jsexc).ref ??
nullptr;
});
_ref = JSObjectMakeConstructor(
context.ref,
jsclass?.ref ?? nullptr,
_callAsConstructorNC?.nativeFunction ?? nullptr,
);
attach(calloc.nativeFree, _ref.cast(), autoDispose: autoDispose);
}