-
Notifications
You must be signed in to change notification settings - Fork 30.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
src: add public API to create isolate and context #20639
Changes from 1 commit
4c48b52
32f988b
e658fb7
666c25f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4425,10 +4425,21 @@ int EmitExit(Environment* env) { | |
} | ||
|
||
|
||
ArrayBufferAllocator* CreateArrayBufferAllocator() { | ||
return new ArrayBufferAllocator; | ||
} | ||
|
||
|
||
void FreeArrayBufferAllocator(ArrayBufferAllocator* allocator) { | ||
delete allocator; | ||
} | ||
|
||
|
||
IsolateData* CreateIsolateData(Isolate* isolate, uv_loop_t* loop) { | ||
return new IsolateData(isolate, loop, nullptr); | ||
} | ||
|
||
|
||
IsolateData* CreateIsolateData( | ||
Isolate* isolate, | ||
uv_loop_t* loop, | ||
|
@@ -4437,6 +4448,15 @@ IsolateData* CreateIsolateData( | |
} | ||
|
||
|
||
IsolateData* CreateIsolateData( | ||
Isolate* isolate, | ||
uv_loop_t* loop, | ||
MultiIsolatePlatform* platform, | ||
ArrayBufferAllocator* allocator) { | ||
return new IsolateData(isolate, loop, platform, allocator->zero_fill_field()); | ||
} | ||
|
||
|
||
void FreeIsolateData(IsolateData* isolate_data) { | ||
delete isolate_data; | ||
} | ||
|
@@ -4580,26 +4600,34 @@ bool AllowWasmCodeGenerationCallback( | |
return wasm_code_gen->IsUndefined() || wasm_code_gen->IsTrue(); | ||
} | ||
|
||
inline int Start(uv_loop_t* event_loop, | ||
int argc, const char* const* argv, | ||
int exec_argc, const char* const* exec_argv) { | ||
Isolate* NewIsolate(ArrayBufferAllocator* allocator) { | ||
Isolate::CreateParams params; | ||
ArrayBufferAllocator allocator; | ||
params.array_buffer_allocator = &allocator; | ||
params.array_buffer_allocator = allocator; | ||
#ifdef NODE_ENABLE_VTUNE_PROFILING | ||
params.code_event_handler = vTune::GetVtuneCodeEventHandler(); | ||
#endif | ||
|
||
Isolate* const isolate = Isolate::New(params); | ||
Isolate* isolate = Isolate::New(params); | ||
if (isolate == nullptr) | ||
return 12; // Signal internal error. | ||
return nullptr; | ||
|
||
isolate->AddMessageListener(OnMessage); | ||
isolate->SetAbortOnUncaughtExceptionCallback(ShouldAbortOnUncaughtException); | ||
isolate->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit); | ||
isolate->SetFatalErrorHandler(OnFatalError); | ||
isolate->SetAllowWasmCodeGenerationCallback(AllowWasmCodeGenerationCallback); | ||
|
||
return isolate; | ||
} | ||
|
||
inline int Start(uv_loop_t* event_loop, | ||
int argc, const char* const* argv, | ||
int exec_argc, const char* const* exec_argv) { | ||
ArrayBufferAllocator* allocator = CreateArrayBufferAllocator(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use a std::unique_ptr with a custom deleter, or simply use a stack-allocated ArrayBufferAllocator. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Updated with unique_ptr, and I don't have to customize deleter for usage in node.cc because it can get the full definition here. As to the public API/ABI, do you think I can keep it with raw pointer by following the existing pattern? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, raw pointers are the way to go, that avoids trouble when Node.js and the add-on use different allocators. |
||
Isolate* const isolate = NewIsolate(allocator); | ||
if (isolate == nullptr) | ||
return 12; // Signal internal error. | ||
|
||
{ | ||
Mutex::ScopedLock scoped_lock(node_isolate_mutex); | ||
CHECK_EQ(node_isolate, nullptr); | ||
|
@@ -4611,15 +4639,16 @@ inline int Start(uv_loop_t* event_loop, | |
Locker locker(isolate); | ||
Isolate::Scope isolate_scope(isolate); | ||
HandleScope handle_scope(isolate); | ||
IsolateData isolate_data( | ||
IsolateData* isolate_data = CreateIsolateData( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
isolate, | ||
event_loop, | ||
v8_platform.Platform(), | ||
allocator.zero_fill_field()); | ||
allocator); | ||
if (track_heap_objects) { | ||
isolate->GetHeapProfiler()->StartTrackingHeapObjects(true); | ||
} | ||
exit_code = Start(isolate, &isolate_data, argc, argv, exec_argc, exec_argv); | ||
exit_code = Start(isolate, isolate_data, argc, argv, exec_argc, exec_argv); | ||
FreeIsolateData(isolate_data); | ||
} | ||
|
||
{ | ||
|
@@ -4629,6 +4658,7 @@ inline int Start(uv_loop_t* event_loop, | |
} | ||
|
||
isolate->Dispose(); | ||
FreeArrayBufferAllocator(allocator); | ||
|
||
return exit_code; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new ArrayBufferAllocator()
- i.e., include parentheses.