Skip to content

Commit

Permalink
src: add way to get IsolateData and allocator from Environment
Browse files Browse the repository at this point in the history
Add a way to get the current `IsolateData*` and, from it, the current
Node.js `ArrayBufferAllocator` if there is one. This can be useful
for re-using either one of these structures as an embedder.

PR-URL: #36441
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
addaleax authored and MylesBorins committed Aug 31, 2021
1 parent 658a266 commit 577d228
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/api/environment.cc
Expand Up @@ -466,6 +466,14 @@ MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform() {
return per_process::v8_platform.Platform();
}

IsolateData* GetEnvironmentIsolateData(Environment* env) {
return env->isolate_data();
}

ArrayBufferAllocator* GetArrayBufferAllocator(IsolateData* isolate_data) {
return isolate_data->node_allocator();
}

MultiIsolatePlatform* GetMultiIsolatePlatform(Environment* env) {
return GetMultiIsolatePlatform(env->isolate_data());
}
Expand Down
2 changes: 2 additions & 0 deletions src/node.h
Expand Up @@ -500,6 +500,8 @@ NODE_EXTERN void DefaultProcessExitHandler(Environment* env, int exit_code);

// This may return nullptr if context is not associated with a Node instance.
NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local<v8::Context> context);
NODE_EXTERN IsolateData* GetEnvironmentIsolateData(Environment* env);
NODE_EXTERN ArrayBufferAllocator* GetArrayBufferAllocator(IsolateData* data);

NODE_EXTERN void OnFatalError(const char* location, const char* message);
NODE_EXTERN void PromiseRejectCallback(v8::PromiseRejectMessage message);
Expand Down
3 changes: 3 additions & 0 deletions test/cctest/test_environment.cc
Expand Up @@ -627,6 +627,9 @@ TEST_F(NodeZeroIsolateTestFixture, CtrlCWithOnlySafeTerminationTest) {
{}),
node::FreeEnvironment};
CHECK(environment);
EXPECT_EQ(node::GetEnvironmentIsolateData(environment.get()),
isolate_data.get());
EXPECT_EQ(node::GetArrayBufferAllocator(isolate_data.get()), nullptr);

v8::Local<v8::Value> main_ret =
node::LoadEnvironment(environment.get(),
Expand Down

0 comments on commit 577d228

Please sign in to comment.