diff --git a/benchmark/vm/compile-script-in-isolate-cache.js b/benchmark/vm/compile-script-in-isolate-cache.js index 7eceb0eba0d215..7c909d840b4316 100644 --- a/benchmark/vm/compile-script-in-isolate-cache.js +++ b/benchmark/vm/compile-script-in-isolate-cache.js @@ -5,17 +5,17 @@ const common = require('../common.js'); const fs = require('fs'); const vm = require('vm'); -const fixtures = require('../../test/common/fixtures.js'); -const scriptPath = fixtures.path('snapshot', 'typescript.js'); +const path = require('path'); const bench = common.createBenchmark(main, { type: ['with-dynamic-import-callback', 'without-dynamic-import-callback'], - n: [100], + filename: ['test/fixtures/snapshot/typescript.js', 'test/fixtures/syntax/good_syntax.js'], + n: [1000], }); -const scriptSource = fs.readFileSync(scriptPath, 'utf8'); - -function main({ n, type }) { +function main({ n, type, filename }) { + const scriptPath = path.resolve(__dirname, '..', '..', filename); + const scriptSource = fs.readFileSync(scriptPath, 'utf8'); let script; bench.start(); const options = {}; diff --git a/src/node_contextify.cc b/src/node_contextify.cc index 895f7b9d096166..79952f4e4e309c 100644 --- a/src/node_contextify.cc +++ b/src/node_contextify.cc @@ -22,6 +22,7 @@ #include "node_contextify.h" #include "base_object-inl.h" +#include "cppgc/allocation.h" #include "memory_tracker-inl.h" #include "module_wrap.h" #include "node_context_data.h" @@ -915,6 +916,12 @@ void ContextifyScript::RegisterExternalReferences( registry->Register(RunInContext); } +ContextifyScript* ContextifyScript::New(Environment* env, + Local object) { + return cppgc::MakeGarbageCollected( + env->isolate()->GetCppHeap()->GetAllocationHandle(), env, object); +} + void ContextifyScript::New(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); Isolate* isolate = env->isolate(); @@ -965,8 +972,7 @@ void ContextifyScript::New(const FunctionCallbackInfo& args) { id_symbol = args[7].As(); } - ContextifyScript* contextify_script = - new ContextifyScript(env, args.This()); + ContextifyScript* contextify_script = New(env, args.This()); if (*TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( TRACING_CATEGORY_NODE2(vm, script)) != 0) { @@ -1025,8 +1031,6 @@ void ContextifyScript::New(const FunctionCallbackInfo& args) { } contextify_script->script_.Reset(isolate, v8_script); - contextify_script->script_.SetWeak(); - contextify_script->object()->SetInternalField(kUnboundScriptSlot, v8_script); std::unique_ptr new_cached_data; if (produce_cached_data) { @@ -1128,12 +1132,10 @@ bool ContextifyScript::InstanceOf(Environment* env, void ContextifyScript::CreateCachedData( const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - ContextifyScript* wrapped_script; - ASSIGN_OR_RETURN_UNWRAP(&wrapped_script, args.This()); - Local unbound_script = - PersistentToLocal::Default(env->isolate(), wrapped_script->script_); + ContextifyScript* wrapped_script = wrapped_script = + Unwrap(args.This()); std::unique_ptr cached_data( - ScriptCompiler::CreateCodeCache(unbound_script)); + ScriptCompiler::CreateCodeCache(wrapped_script->unbound_script())); if (!cached_data) { args.GetReturnValue().Set(Buffer::New(env, 0).ToLocalChecked()); } else { @@ -1147,9 +1149,8 @@ void ContextifyScript::CreateCachedData( void ContextifyScript::RunInContext(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); - - ContextifyScript* wrapped_script; - ASSIGN_OR_RETURN_UNWRAP(&wrapped_script, args.This()); + ContextifyScript* wrapped_script = wrapped_script = + Unwrap(args.This()); CHECK_EQ(args.Length(), 5); CHECK(args[0]->IsObject() || args[0]->IsNull()); @@ -1218,11 +1219,10 @@ bool ContextifyScript::EvalMachine(Local context, } TryCatchScope try_catch(env); - ContextifyScript* wrapped_script; - ASSIGN_OR_RETURN_UNWRAP(&wrapped_script, args.This(), false); - Local unbound_script = - PersistentToLocal::Default(env->isolate(), wrapped_script->script_); - Local