Skip to content

Commit 581b4b4

Browse files
authored
FIx constructor prototype chain for JSC in NAPI (#1160)
1 parent ec45222 commit 581b4b4

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

Dependencies/napi/napi-direct/source/js_native_api_javascriptcore.cc

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ namespace {
208208
return napi_set_last_error(env, napi_generic_failure);
209209
}
210210

211-
JSObjectRef constructor{JSObjectMakeConstructor(env->context, info->_class, CallAsConstructor)};
212-
JSObjectRef prototype{JSObjectMake(env->context, info->_prototypeClass, info)};
211+
JSObjectRef constructor{JSObjectMakeConstructor(env->context, nullptr, CallAsConstructor)};
212+
JSObjectRef prototype{JSObjectMake(env->context, info->_class, info)};
213213
JSObjectSetPrototype(env->context, prototype, JSObjectGetPrototype(env->context, constructor));
214214
JSObjectSetPrototype(env->context, constructor, prototype);
215215

@@ -229,18 +229,13 @@ namespace {
229229
, _name{name, (length == NAPI_AUTO_LENGTH ? std::strlen(name) : length)}
230230
, _cb{cb}
231231
, _data{data} {
232-
JSClassDefinition definition{kJSClassDefinitionEmpty};
233-
definition.className = _name.data();
234-
_class = JSClassCreate(&definition);
235-
236-
JSClassDefinition prototypeDefinition{kJSClassDefinitionEmpty};
237-
prototypeDefinition.className = _name.data();
238-
prototypeDefinition.finalize = Finalize;
239-
_prototypeClass = JSClassCreate(&prototypeDefinition);
232+
JSClassDefinition classDefinition{kJSClassDefinitionEmpty};
233+
classDefinition.className = _name.data();
234+
classDefinition.finalize = Finalize;
235+
_class = JSClassCreate(&classDefinition);
240236
}
241237

242238
~ConstructorInfo() {
243-
JSClassRelease(_prototypeClass);
244239
JSClassRelease(_class);
245240
}
246241

@@ -261,7 +256,7 @@ namespace {
261256
// Make sure any errors encountered last time we were in N-API are gone.
262257
napi_clear_last_error(info->_env);
263258

264-
JSObjectRef instance{JSObjectMake(ctx, info->_class, nullptr)};
259+
JSObjectRef instance{JSObjectMake(ctx, nullptr, nullptr)};
265260
JSObjectSetPrototype(ctx, instance, JSObjectGetPrototype(ctx, constructor));
266261

267262
napi_callback_info__ cbinfo{};
@@ -294,7 +289,6 @@ namespace {
294289
napi_callback _cb;
295290
void* _data;
296291
JSClassRef _class;
297-
JSClassRef _prototypeClass;
298292
};
299293

300294
class FunctionInfo : public NativeInfo {

0 commit comments

Comments
 (0)