Skip to content

Commit b08affe

Browse files
committed
jsc: fix creating constructors
JSC sometiems deletes values proteced using JSValueProtect.
1 parent 7b15b0f commit b08affe

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

test-app/runtime/src/main/cpp/runtime/metadata/MetadataNode.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,22 +1352,25 @@ napi_value MetadataNode::GetConstructorFunctionInternal(napi_env env, MetadataTr
13521352
auto cache = GetMetadataNodeCache(env);
13531353
auto itFound = cache->CtorFuncCache.find(treeNode);
13541354
if (itFound != cache->CtorFuncCache.end()) {
1355-
instanceMethodsCallbackData = itFound->second.instanceMethodCallbacks;
13561355
if (itFound->second.constructorFunction != nullptr) {
13571356
auto value = napi_util::get_ref_value(env, itFound->second.constructorFunction);
13581357
if (!napi_util::is_null_or_undefined(env, value)) {
1358+
instanceMethodsCallbackData = itFound->second.instanceMethodCallbacks;
13591359
return value;
13601360
}
13611361
}
13621362
}
13631363

13641364
if (itFound != cache->CtorFuncCache.end()) {
1365+
#ifndef __JSC__
1366+
for (auto data: itFound->second.instanceMethodCallbacks) {
1367+
delete data;
1368+
}
1369+
#endif
1370+
itFound->second.instanceMethodCallbacks.clear();
13651371
if (itFound->second.constructorFunction != nullptr) {
13661372
napi_delete_reference(env, itFound->second.constructorFunction);
13671373
}
1368-
for (const auto &data: itFound->second.instanceMethodCallbacks) {
1369-
delete data;
1370-
}
13711374
cache->CtorFuncCache.erase(itFound);
13721375
}
13731376

0 commit comments

Comments
 (0)