JSClass constructor
JSClass(
- JSContext ctx, {
- required JSClassDef classDef,
- List<
JSCFunctionListEntry> ? funcs, - JSValue? constructor,
- bool autoDispose = true,
Implementation
JSClass(
this.ctx, {
required this.classDef,
this.funcs,
JSValue? constructor,
bool autoDispose = true,
}) {
_classID = calloc.call(sizeOf<Uint32>());
assert(_classID != null);
classID = newClassID(_classID!);
final rt = ctx.runtime.ref;
JS_NewClass(rt, _classID!.value, classDef.ref);
proto = JSValue.obj(ctx);
ctx.setClassProto(_classID!.value, proto!);
if (funcs != null && funcs!.isNotEmpty) {
proto!.setPropertyFunctionList(funcs!);
}
if (constructor != null) {
JS_SetConstructor(ctx.ref, constructor.ref.ref, proto!.ref.ref);
/// ctx.globalObject.definePropertyValueStr('xxx', proto) not worked!
/// must use this
/// constructor.setPropertyFunctionList() // must use JSCFunctionListEntry.defPropXXX
/// ctx.globalObject.definePropertyValueStr('xxx', constructor)
}
attach(calloc.nativeFree, _classID!.cast(), autoDispose: autoDispose);
}