-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
Closed
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4c48b52
src: add public API to create isolate and context
helloshuangzi 32f988b
src: use unique_ptr to save Free calls
helloshuangzi e658fb7
src: use custom deleter for allocator and isolateData
helloshuangzi 666c25f
src: polish indention
helloshuangzi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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,35 @@ 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) { | ||
std::unique_ptr<ArrayBufferAllocator, decltype(&FreeArrayBufferAllocator)> | ||
allocator(CreateArrayBufferAllocator(), &FreeArrayBufferAllocator); | ||
Isolate* const isolate = NewIsolate(allocator.get()); | ||
if (isolate == nullptr) | ||
return 12; // Signal internal error. | ||
|
||
{ | ||
Mutex::ScopedLock scoped_lock(node_isolate_mutex); | ||
CHECK_EQ(node_isolate, nullptr); | ||
|
@@ -4611,15 +4640,18 @@ inline int Start(uv_loop_t* event_loop, | |
Locker locker(isolate); | ||
Isolate::Scope isolate_scope(isolate); | ||
HandleScope handle_scope(isolate); | ||
IsolateData isolate_data( | ||
std::unique_ptr<IsolateData, decltype(&FreeIsolateData)> isolate_data( | ||
CreateIsolateData( | ||
isolate, | ||
event_loop, | ||
v8_platform.Platform(), | ||
allocator.zero_fill_field()); | ||
allocator.get()), | ||
&FreeIsolateData); | ||
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.get(), argc, argv, exec_argc, exec_argv); | ||
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. Likewise, four spaces. |
||
} | ||
|
||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Tiniest of nits but can you indent by four spaces (and the arguments to CreateIsolateData() by eight)? Helps it stand out as a line continuation.
One glorious day when we switch to clang-format that will all be automatic.