GeezerVison is showing github.com — src: introduce node::Realm · nodejs/node@81d9cdb
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: node.gyp +4Lines changed: 4 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 512 | 512 | 'src/node_process_events.cc', | 513 | 513 | 'src/node_process_methods.cc', | 514 | 514 | 'src/node_process_object.cc', | | 515 | + 'src/node_realm.cc', | 515 | 516 | 'src/node_report.cc', | 516 | 517 | 'src/node_report_module.cc', | 517 | 518 | 'src/node_report_utils.cc', | | 570 | 571 | 'src/connection_wrap.h', | 571 | 572 | 'src/debug_utils.h', | 572 | 573 | 'src/debug_utils-inl.h', | | 574 | + 'src/env_properties.h', | 573 | 575 | 'src/env.h', | 574 | 576 | 'src/env-inl.h', | 575 | 577 | 'src/handle_wrap.h', | | 617 | 619 | 'src/node_platform.h', | 618 | 620 | 'src/node_process.h', | 619 | 621 | 'src/node_process-inl.h', | | 622 | + 'src/node_realm.h', | | 623 | + 'src/node_realm-inl.h', | 620 | 624 | 'src/node_report.h', | 621 | 625 | 'src/node_revert.h', | 622 | 626 | 'src/node_root_certs.h', | |
Collapse file Copy file name to clipboardExpand all lines: src/api/environment.cc +7-4Lines changed: 7 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 5 | 5 | #include "node_internals.h" | 6 | 6 | #include "node_options-inl.h" | 7 | 7 | #include "node_platform.h" | | 8 | +#include "node_realm-inl.h" | 8 | 9 | #include "node_shadow_realm.h" | 9 | 10 | #include "node_v8_platform-inl.h" | 10 | 11 | #include "node_wasm_web_api.h" | @@ -378,7 +379,7 @@ Environment* CreateEnvironment( | 378 | 379 | } | 379 | 380 | #endif | 380 | 381 |
| 381 | | - if (env->RunBootstrapping().IsEmpty()) { | | 382 | + if (env->principal_realm()->RunBootstrapping().IsEmpty()) { | 382 | 383 | FreeEnvironment(env); | 383 | 384 | return nullptr; | 384 | 385 | } | @@ -453,11 +454,13 @@ MaybeLocal<Value> LoadEnvironment( | 453 | 454 | builtins::BuiltinLoader::Add( | 454 | 455 | name.c_str(), UnionBytes(**main_utf16, main_utf16->length())); | 455 | 456 | env->set_main_utf16(std::move(main_utf16)); | | 457 | + Realm* realm = env->principal_realm(); | | 458 | + | 456 | 459 | // Arguments must match the parameters specified in | 457 | 460 | // BuiltinLoader::LookupAndCompile(). | 458 | | - std::vector<Local<Value>> args = {env->process_object(), | 459 | | - env->builtin_module_require()}; | 460 | | - return ExecuteBootstrapper(env, name.c_str(), &args); | | 461 | + std::vector<Local<Value>> args = {realm->process_object(), | | 462 | + realm->builtin_module_require()}; | | 463 | + return realm->ExecuteBootstrapper(name.c_str(), &args); | 461 | 464 | }); | 462 | 465 | } | 463 | 466 |
| |
Collapse file Copy file name to clipboardExpand all lines: src/base_object-inl.h +6Lines changed: 6 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 32 | 32 |
| 33 | 33 | namespace node { | 34 | 34 |
| | 35 | +// static | | 36 | +v8::Local<v8::FunctionTemplate> BaseObject::GetConstructorTemplate( | | 37 | + Environment* env) { | | 38 | + return BaseObject::GetConstructorTemplate(env->isolate_data()); | | 39 | +} | | 40 | + | 35 | 41 | void BaseObject::Detach() { | 36 | 42 | CHECK_GT(pointer_data()->strong_ptr_count, 0); | 37 | 43 | pointer_data()->is_detached = true; | |
Collapse file Copy file name to clipboardExpand all lines: src/base_object.h +4-1Lines changed: 4 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 31 | 31 | namespace node { | 32 | 32 |
| 33 | 33 | class Environment; | | 34 | +class IsolateData; | 34 | 35 | template <typename T, bool kIsWeak> | 35 | 36 | class BaseObjectPtrImpl; | 36 | 37 |
| @@ -111,8 +112,10 @@ class BaseObject : public MemoryRetainer { | 111 | 112 | // a BaseObjectPtr to this object. | 112 | 113 | inline void Detach(); | 113 | 114 |
| 114 | | - static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( | | 115 | + static inline v8::Local<v8::FunctionTemplate> GetConstructorTemplate( | 115 | 116 | Environment* env); | | 117 | + static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( | | 118 | + IsolateData* isolate_data); | 116 | 119 |
| 117 | 120 | // Interface for transferring BaseObject instances using the .postMessage() | 118 | 121 | // method of MessagePorts (and, by extension, Workers). | |
Collapse file Copy file name to clipboardExpand all lines: src/env-inl.h +20-17Lines changed: 20 additions & 17 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 31 | 31 | #include "node_context_data.h" | 32 | 32 | #include "node_internals.h" | 33 | 33 | #include "node_perf_common.h" | | 34 | +#include "node_realm-inl.h" | 34 | 35 | #include "util-inl.h" | 35 | 36 | #include "uv.h" | 36 | 37 | #include "v8.h" | @@ -614,15 +615,7 @@ inline void Environment::set_can_call_into_js(bool can_call_into_js) { | 614 | 615 | } | 615 | 616 |
| 616 | 617 | inline bool Environment::has_run_bootstrapping_code() const { | 617 | | - return has_run_bootstrapping_code_; | 618 | | -} | 619 | | - | 620 | | -inline void Environment::DoneBootstrapping() { | 621 | | - has_run_bootstrapping_code_ = true; | 622 | | - // This adjusts the return value of base_object_created_after_bootstrap() so | 623 | | - // that tests that check the count do not have to account for internally | 624 | | - // created BaseObjects. | 625 | | - base_object_created_by_bootstrap_ = base_object_count_; | | 618 | + return principal_realm_->has_run_bootstrapping_code(); | 626 | 619 | } | 627 | 620 |
| 628 | 621 | inline bool Environment::has_serialized_options() const { | @@ -830,14 +823,18 @@ void Environment::modify_base_object_count(int64_t delta) { | 830 | 823 | base_object_count_ += delta; | 831 | 824 | } | 832 | 825 |
| 833 | | -int64_t Environment::base_object_created_after_bootstrap() const { | 834 | | - return base_object_count_ - base_object_created_by_bootstrap_; | 835 | | -} | 836 | | - | 837 | 826 | int64_t Environment::base_object_count() const { | 838 | 827 | return base_object_count_; | 839 | 828 | } | 840 | 829 |
| | 830 | +inline void Environment::set_base_object_created_by_bootstrap(int64_t count) { | | 831 | + base_object_created_by_bootstrap_ = base_object_count_; | | 832 | +} | | 833 | + | | 834 | +int64_t Environment::base_object_created_after_bootstrap() const { | | 835 | + return base_object_count_ - base_object_created_by_bootstrap_; | | 836 | +} | | 837 | + | 841 | 838 | void Environment::set_main_utf16(std::unique_ptr<v8::String::Value> str) { | 842 | 839 | CHECK(!main_utf16_); | 843 | 840 | main_utf16_ = std::move(str); | @@ -902,16 +899,22 @@ void Environment::set_process_exit_handler( | 902 | 899 |
| 903 | 900 | #define V(PropertyName, TypeName) \ | 904 | 901 | inline v8::Local<TypeName> Environment::PropertyName() const { \ | 905 | | - return PersistentToLocal::Strong(PropertyName##_); \ | | 902 | + DCHECK_NOT_NULL(principal_realm_); \ | | 903 | + return principal_realm_->PropertyName(); \ | 906 | 904 | } \ | 907 | 905 | inline void Environment::set_##PropertyName(v8::Local<TypeName> value) { \ | 908 | | - PropertyName##_.Reset(isolate(), value); \ | | 906 | + DCHECK_NOT_NULL(principal_realm_); \ | | 907 | + principal_realm_->set_##PropertyName(value); \ | 909 | 908 | } | 910 | | - ENVIRONMENT_STRONG_PERSISTENT_VALUES(V) | | 909 | + PER_REALM_STRONG_PERSISTENT_VALUES(V) | 911 | 910 | #undef V | 912 | 911 |
| 913 | 912 | v8::Local<v8::Context> Environment::context() const { | 914 | | - return PersistentToLocal::Strong(context_); | | 913 | + return principal_realm()->context(); | | 914 | +} | | 915 | + | | 916 | +Realm* Environment::principal_realm() const { | | 917 | + return principal_realm_.get(); | 915 | 918 | } | 916 | 919 |
| 917 | 920 | } // namespace node | |
|