@@ -110,17 +110,15 @@ Local<Name> Uint32ToName(Local<Context> context, uint32_t index) {
110110} // anonymous namespace
111111
112112BaseObjectPtr<ContextifyContext> ContextifyContext::New (
113- Environment* env,
114- Local<Object> sandbox_obj,
115- const ContextOptions& options) {
113+ Environment* env, Local<Object> sandbox_obj, ContextOptions* options) {
116114 HandleScope scope (env->isolate ());
117115 Local<ObjectTemplate> object_template = env->contextify_global_template ();
118116 DCHECK (!object_template.IsEmpty ());
119117 const SnapshotData* snapshot_data = env->isolate_data ()->snapshot_data ();
120118
121119 MicrotaskQueue* queue =
122- options. microtask_queue_wrap
123- ? options. microtask_queue_wrap -> microtask_queue () .get ()
120+ options-> own_microtask_queue
121+ ? options-> own_microtask_queue .get ()
124122 : env->isolate ()->GetCurrentContext ()->GetMicrotaskQueue ();
125123
126124 Local<Context> v8_context;
@@ -132,19 +130,16 @@ BaseObjectPtr<ContextifyContext> ContextifyContext::New(
132130 return New (v8_context, env, sandbox_obj, options);
133131}
134132
135- void ContextifyContext::MemoryInfo (MemoryTracker* tracker) const {
136- if (microtask_queue_wrap_) {
137- tracker->TrackField (" microtask_queue_wrap" ,
138- microtask_queue_wrap_->object ());
139- }
140- }
133+ void ContextifyContext::MemoryInfo (MemoryTracker* tracker) const {}
141134
142135ContextifyContext::ContextifyContext (Environment* env,
143136 Local<Object> wrapper,
144137 Local<Context> v8_context,
145- const ContextOptions& options)
138+ ContextOptions* options)
146139 : BaseObject(env, wrapper),
147- microtask_queue_wrap_ (options.microtask_queue_wrap) {
140+ microtask_queue_ (options->own_microtask_queue
141+ ? options->own_microtask_queue.release()
142+ : nullptr) {
148143 context_.Reset (env->isolate (), v8_context);
149144 // This should only be done after the initial initializations of the context
150145 // global object is finished.
@@ -240,7 +235,7 @@ BaseObjectPtr<ContextifyContext> ContextifyContext::New(
240235 Local<Context> v8_context,
241236 Environment* env,
242237 Local<Object> sandbox_obj,
243- const ContextOptions& options) {
238+ ContextOptions* options) {
244239 HandleScope scope (env->isolate ());
245240 // This only initializes part of the context. The primordials are
246241 // only initialized when needed because even deserializing them slows
@@ -268,14 +263,14 @@ BaseObjectPtr<ContextifyContext> ContextifyContext::New(
268263 v8_context->AllowCodeGenerationFromStrings (false );
269264 v8_context->SetEmbedderData (
270265 ContextEmbedderIndex::kAllowCodeGenerationFromStrings ,
271- options. allow_code_gen_strings );
266+ options-> allow_code_gen_strings );
272267 v8_context->SetEmbedderData (ContextEmbedderIndex::kAllowWasmCodeGeneration ,
273- options. allow_code_gen_wasm );
268+ options-> allow_code_gen_wasm );
274269
275- Utf8Value name_val (env->isolate (), options. name );
270+ Utf8Value name_val (env->isolate (), options-> name );
276271 ContextInfo info (*name_val);
277- if (!options. origin .IsEmpty ()) {
278- Utf8Value origin_val (env->isolate (), options. origin );
272+ if (!options-> origin .IsEmpty ()) {
273+ Utf8Value origin_val (env->isolate (), options-> origin );
279274 info.origin = *origin_val;
280275 }
281276
@@ -374,16 +369,14 @@ void ContextifyContext::MakeContext(const FunctionCallbackInfo<Value>& args) {
374369 CHECK (args[4 ]->IsBoolean ());
375370 options.allow_code_gen_wasm = args[4 ].As <Boolean>();
376371
377- if (args[5 ]->IsObject () &&
378- !env->microtask_queue_ctor_template ().IsEmpty () &&
379- env->microtask_queue_ctor_template ()->HasInstance (args[5 ])) {
380- options.microtask_queue_wrap .reset (
381- Unwrap<MicrotaskQueueWrap>(args[5 ].As <Object>()));
372+ if (args[5 ]->IsBoolean () && args[5 ]->BooleanValue (env->isolate ())) {
373+ options.own_microtask_queue =
374+ MicrotaskQueue::New (env->isolate (), MicrotasksPolicy::kExplicit );
382375 }
383376
384377 TryCatchScope try_catch (env);
385378 BaseObjectPtr<ContextifyContext> context_ptr =
386- ContextifyContext::New (env, sandbox, options);
379+ ContextifyContext::New (env, sandbox, & options);
387380
388381 if (try_catch.HasCaught ()) {
389382 if (!try_catch.HasTerminated ())
@@ -987,7 +980,7 @@ void ContextifyScript::RunInContext(const FunctionCallbackInfo<Value>& args) {
987980 CHECK (args[0 ]->IsObject () || args[0 ]->IsNull ());
988981
989982 Local<Context> context;
990- std::shared_ptr< MicrotaskQueue> microtask_queue;
983+ v8:: MicrotaskQueue* microtask_queue = nullptr ;
991984
992985 if (args[0 ]->IsObject ()) {
993986 Local<Object> sandbox = args[0 ].As <Object>();
@@ -1036,7 +1029,7 @@ bool ContextifyScript::EvalMachine(Local<Context> context,
10361029 const bool display_errors,
10371030 const bool break_on_sigint,
10381031 const bool break_on_first_line,
1039- std::shared_ptr< MicrotaskQueue> mtask_queue,
1032+ MicrotaskQueue* mtask_queue,
10401033 const FunctionCallbackInfo<Value>& args) {
10411034 Context::Scope context_scope (context);
10421035
@@ -1068,7 +1061,7 @@ bool ContextifyScript::EvalMachine(Local<Context> context,
10681061 bool received_signal = false ;
10691062 auto run = [&]() {
10701063 MaybeLocal<Value> result = script->Run (context);
1071- if (!result.IsEmpty () && mtask_queue)
1064+ if (!result.IsEmpty () && mtask_queue != nullptr )
10721065 mtask_queue->PerformCheckpoint (env->isolate ());
10731066 return result;
10741067 };
@@ -1122,7 +1115,6 @@ bool ContextifyScript::EvalMachine(Local<Context> context,
11221115 return true ;
11231116}
11241117
1125-
11261118ContextifyScript::ContextifyScript (Environment* env, Local<Object> object)
11271119 : BaseObject(env, object),
11281120 id_ (env->get_next_script_id ()) {
@@ -1376,46 +1368,12 @@ static void MeasureMemory(const FunctionCallbackInfo<Value>& args) {
13761368 args.GetReturnValue ().Set (promise);
13771369}
13781370
1379- MicrotaskQueueWrap::MicrotaskQueueWrap (Environment* env, Local<Object> obj)
1380- : BaseObject(env, obj),
1381- microtask_queue_(
1382- MicrotaskQueue::New (env->isolate (), MicrotasksPolicy::kExplicit)) {
1383- MakeWeak ();
1384- }
1385-
1386- const std::shared_ptr<MicrotaskQueue>&
1387- MicrotaskQueueWrap::microtask_queue () const {
1388- return microtask_queue_;
1389- }
1390-
1391- void MicrotaskQueueWrap::New (const FunctionCallbackInfo<Value>& args) {
1392- CHECK (args.IsConstructCall ());
1393- new MicrotaskQueueWrap (Environment::GetCurrent (args), args.This ());
1394- }
1395-
1396- void MicrotaskQueueWrap::CreatePerIsolateProperties (
1397- IsolateData* isolate_data, Local<ObjectTemplate> target) {
1398- Isolate* isolate = isolate_data->isolate ();
1399- HandleScope scope (isolate);
1400- Local<FunctionTemplate> tmpl = NewFunctionTemplate (isolate, New);
1401- tmpl->InstanceTemplate ()->SetInternalFieldCount (
1402- ContextifyScript::kInternalFieldCount );
1403- isolate_data->set_microtask_queue_ctor_template (tmpl);
1404- SetConstructorFunction (isolate, target, " MicrotaskQueue" , tmpl);
1405- }
1406-
1407- void MicrotaskQueueWrap::RegisterExternalReferences (
1408- ExternalReferenceRegistry* registry) {
1409- registry->Register (New);
1410- }
1411-
14121371void CreatePerIsolateProperties (IsolateData* isolate_data,
14131372 Local<ObjectTemplate> target) {
14141373 Isolate* isolate = isolate_data->isolate ();
14151374
14161375 ContextifyContext::CreatePerIsolateProperties (isolate_data, target);
14171376 ContextifyScript::CreatePerIsolateProperties (isolate_data, target);
1418- MicrotaskQueueWrap::CreatePerIsolateProperties (isolate_data, target);
14191377
14201378 SetMethod (isolate, target, " startSigintWatchdog" , StartSigintWatchdog);
14211379 SetMethod (isolate, target, " stopSigintWatchdog" , StopSigintWatchdog);
@@ -1470,7 +1428,6 @@ static void CreatePerContextProperties(Local<Object> target,
14701428void RegisterExternalReferences (ExternalReferenceRegistry* registry) {
14711429 ContextifyContext::RegisterExternalReferences (registry);
14721430 ContextifyScript::RegisterExternalReferences (registry);
1473- MicrotaskQueueWrap::RegisterExternalReferences (registry);
14741431
14751432 registry->Register (StartSigintWatchdog);
14761433 registry->Register (StopSigintWatchdog);
0 commit comments