embedding: make NewIsolate()
API more flexible · nodejs/node@5e64acd (original) (raw)
`@@ -164,21 +164,17 @@ void FreeArrayBufferAllocator(ArrayBufferAllocator* allocator) {
`
164
164
`delete allocator;
`
165
165
`}
`
166
166
``
167
``
`-
Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) {
`
168
``
`-
Isolate::CreateParams params;
`
169
``
`-
params.array_buffer_allocator = allocator;
`
``
167
`+
void SetIsolateCreateParams(Isolate::CreateParams* params,
`
``
168
`+
ArrayBufferAllocator* allocator) {
`
``
169
`+
if (allocator != nullptr)
`
``
170
`+
params->array_buffer_allocator = allocator;
`
``
171
+
170
172
`#ifdef NODE_ENABLE_VTUNE_PROFILING
`
171
``
`-
params.code_event_handler = vTune::GetVtuneCodeEventHandler();
`
``
173
`+
params->code_event_handler = vTune::GetVtuneCodeEventHandler();
`
172
174
`#endif
`
``
175
`+
}
`
173
176
``
174
``
`-
Isolate* isolate = Isolate::Allocate();
`
175
``
`-
if (isolate == nullptr) return nullptr;
`
176
``
-
177
``
`-
// Register the isolate on the platform before the isolate gets initialized,
`
178
``
`-
// so that the isolate can access the platform during initialization.
`
179
``
`-
per_process::v8_platform.Platform()->RegisterIsolate(isolate, event_loop);
`
180
``
`-
Isolate::Initialize(isolate, params);
`
181
``
-
``
177
`+
void SetIsolateUpForNode(v8::Isolate* isolate) {
`
182
178
` isolate->AddMessageListenerWithErrorLevel(
`
183
179
` OnMessage,
`
184
180
` Isolate::MessageErrorLevel::kMessageError |
`
`@@ -187,7 +183,29 @@ Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) {
`
187
183
` isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit);
`
188
184
` isolate->SetFatalErrorHandler(OnFatalError);
`
189
185
` isolate->SetAllowWasmCodeGenerationCallback(AllowWasmCodeGenerationCallback);
`
``
186
`+
isolate->SetPromiseRejectCallback(task_queue::PromiseRejectCallback);
`
190
187
`v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate);
`
``
188
`+
}
`
``
189
+
``
190
`+
Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) {
`
``
191
`+
return NewIsolate(allocator, event_loop, GetMainThreadMultiIsolatePlatform());
`
``
192
`+
}
`
``
193
+
``
194
`+
Isolate* NewIsolate(ArrayBufferAllocator* allocator,
`
``
195
`+
uv_loop_t* event_loop,
`
``
196
`+
MultiIsolatePlatform* platform) {
`
``
197
`+
Isolate::CreateParams params;
`
``
198
`+
SetIsolateCreateParams(¶ms, allocator);
`
``
199
+
``
200
`+
Isolate* isolate = Isolate::Allocate();
`
``
201
`+
if (isolate == nullptr) return nullptr;
`
``
202
+
``
203
`+
// Register the isolate on the platform before the isolate gets initialized,
`
``
204
`+
// so that the isolate can access the platform during initialization.
`
``
205
`+
platform->RegisterIsolate(isolate, event_loop);
`
``
206
`+
Isolate::Initialize(isolate, params);
`
``
207
+
``
208
`+
SetIsolateUpForNode(isolate);
`
191
209
``
192
210
`return isolate;
`
193
211
`}
`