src: introduce node::Realm

To distinguish per-context values from the node::Environment, split
those values to a new node::Realm structure and consolidate
bootstrapping methods with it.

PR-URL: https://github.com/nodejs/node/pull/44179
Refs: https://github.com/nodejs/node/issues/42528
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
Chengzhong Wu authored and GitHub committed 2022-08-31 14:41:42 +00:00
1 parent ad3c7bcb03
commit 81d9cdb8cd
21 files changed
+1142 -830

No files matched your search

+11 -11
View File
@@ -5,6 +5,7 @@
#include "node_metadata.h"
#include "node_options-inl.h"
#include "node_process-inl.h"
#include "node_realm-inl.h"
#include "node_revert.h"
#include "util-inl.h"
@@ -77,13 +78,13 @@ static void GetParentProcessId(Local<Name> property,
info.GetReturnValue().Set(uv_os_getppid());
}
MaybeLocal<Object> CreateProcessObject(Environment* env) {
Isolate* isolate = env->isolate();
MaybeLocal<Object> CreateProcessObject(Realm* realm) {
Isolate* isolate = realm->isolate();
EscapableHandleScope scope(isolate);
Local<Context> context = env->context();
Local<Context> context = realm->context();
Local<FunctionTemplate> process_template = FunctionTemplate::New(isolate);
process_template->SetClassName(env->process_string());
process_template->SetClassName(realm->env()->process_string());
Local<Function> process_ctor;
Local<Object> process;
if (!process_template->GetFunction(context).ToLocal(&process_ctor) ||
@@ -94,19 +95,18 @@ MaybeLocal<Object> CreateProcessObject(Environment* env) {
// process[exiting_aliased_Uint32Array]
if (process
->SetPrivate(context,
env->exiting_aliased_Uint32Array(),
env->exiting().GetJSArray())
realm->env()->exiting_aliased_Uint32Array(),
realm->env()->exiting().GetJSArray())
.IsNothing()) {
return {};
}
// process.version
READONLY_PROPERTY(process,
"version",
FIXED_ONE_BYTE_STRING(env->isolate(), NODE_VERSION));
READONLY_PROPERTY(
process, "version", FIXED_ONE_BYTE_STRING(isolate, NODE_VERSION));
// process.versions
Local<Object> versions = Object::New(env->isolate());
Local<Object> versions = Object::New(isolate);
READONLY_PROPERTY(process, "versions", versions);
#define V(key) \
@@ -124,7 +124,7 @@ MaybeLocal<Object> CreateProcessObject(Environment* env) {
READONLY_STRING_PROPERTY(process, "platform", per_process::metadata.platform);
// process.release
Local<Object> release = Object::New(env->isolate());
Local<Object> release = Object::New(isolate);
READONLY_PROPERTY(process, "release", release);
READONLY_STRING_PROPERTY(release, "name", per_process::metadata.release.name);
#if NODE_VERSION_IS_LTS