Skip to content

Commit 6b48408

Browse files
committed
fix: implicit constructor calling for subclasses
1 parent 3b593dc commit 6b48408

File tree

1 file changed

+22
-3
lines changed

1 file changed

+22
-3
lines changed

NativeScript/ffi/Class.mm

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,13 +202,32 @@ void setupObjCClassDecorator(napi_env env) {
202202

203203
id object = nil;
204204

205+
ObjCBridgeState* bridgeState = ObjCBridgeState::InstanceData(env);
206+
207+
Class cls = (Class)data;
208+
209+
if (jsThis != nullptr) {
210+
napi_value constructor;
211+
napi_get_named_property(env, jsThis, "constructor", &constructor);
212+
Class newTargetCls = nil;
213+
napi_unwrap(env, constructor, (void**)&newTargetCls);
214+
215+
if (newTargetCls != nil) {
216+
cls = newTargetCls;
217+
}
218+
}
219+
205220
if (jsType == napi_external) {
206221
return jsThis;
207222
} else {
208-
Class cls = (Class)data;
209-
object = [cls new];
223+
bool supercall = class_conformsToProtocol(cls, @protocol(ObjCBridgeClassBuilderProtocol));
210224

211-
ObjCBridgeState* bridgeState = ObjCBridgeState::InstanceData(env);
225+
if (supercall) {
226+
ClassBuilder* builder = (ClassBuilder*)bridgeState->classesByPointer[cls];
227+
if (!builder->isFinal) builder->build();
228+
}
229+
230+
object = [cls new];
212231
jsThis = bridgeState->proxyNativeObject(env, jsThis, object);
213232
}
214233

0 commit comments

Comments
 (0)