@@ -361,6 +361,9 @@ MaybeLocal<Object> GetPerContextExports(Local<Context> context) { |
361 | 361 | return handle_scope.Escape(exports); |
362 | 362 | } |
363 | 363 |
|
| 364 | +// Any initialization logic should be performed in |
| 365 | +// InitializeContext, because embedders don't necessarily |
| 366 | +// call NewContext and so they will experience breakages. |
364 | 367 | Local<Context> NewContext(Isolate* isolate, |
365 | 368 | Local<ObjectTemplate> object_template) { |
366 | 369 | auto context = Context::New(isolate, nullptr, object_template); |
@@ -370,8 +373,6 @@ Local<Context> NewContext(Isolate* isolate, |
370 | 373 | return Local<Context>(); |
371 | 374 | } |
372 | 375 |
|
373 | | - InitializeContextRuntime(context); |
374 | | - |
375 | 376 | return context; |
376 | 377 | } |
377 | 378 |
|
@@ -405,7 +406,7 @@ void InitializeContextRuntime(Local<Context> context) { |
405 | 406 | } |
406 | 407 | } |
407 | 408 |
|
408 | | -bool InitializeContext(Local<Context> context) { |
| 409 | +bool InitializeContextForSnapshot(Local<Context> context) { |
409 | 410 | Isolate* isolate = context->GetIsolate(); |
410 | 411 | HandleScope handle_scope(isolate); |
411 | 412 |
|
@@ -459,6 +460,15 @@ bool InitializeContext(Local<Context> context) { |
459 | 460 | return true; |
460 | 461 | } |
461 | 462 |
|
| 463 | +bool InitializeContext(Local<Context> context) { |
| 464 | + if (!InitializeContextForSnapshot(context)) { |
| 465 | + return false; |
| 466 | + } |
| 467 | + |
| 468 | + InitializeContextRuntime(context); |
| 469 | + return true; |
| 470 | +} |
| 471 | + |
462 | 472 | uv_loop_t* GetCurrentEventLoop(Isolate* isolate) { |
463 | 473 | HandleScope handle_scope(isolate); |
464 | 474 | Local<Context> context = isolate->GetCurrentContext(); |
|