| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent d627164 commit 973287a
27 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -482,7 +482,7 @@ Which explains that the unregistered external reference is | |||
| 482 | 482 | ||
| 483 | 483 | Some internal bindings, such as the HTTP parser, maintain internal state that | |
| 484 | 484 | only affects that particular binding. In that case, one common way to store | |
| 485 | - that state is through the use of `Environment::AddBindingData`, which gives | ||
| 485 | + that state is through the use of `Realm::AddBindingData`, which gives | ||
| 486 | 486 | binding functions access to an object for storing such state. | |
| 487 | 487 | That object is always a [`BaseObject`][]. | |
| 488 | 488 | ||
@@ -507,7 +507,7 @@ class BindingData : public BaseObject { | |||
| 507 | 507 | ||
| 508 | 508 | // Available for binding functions, e.g. the HTTP Parser constructor: | |
| 509 | 509 | static void New(const FunctionCallbackInfo<Value>& args) { | |
| 510 | - BindingData* binding_data = Environment::GetBindingData<BindingData>(args); | ||
| 510 | + BindingData* binding_data = Realm::GetBindingData<BindingData>(args); | ||
| 511 | 511 | new Parser(binding_data, args.This()); | |
| 512 | 512 | } | |
| 513 | 513 | ||
@@ -517,12 +517,12 @@ void InitializeHttpParser(Local<Object> target, | |||
| 517 | 517 | Local<Value> unused, | |
| 518 | 518 | Local<Context> context, | |
| 519 | 519 | void* priv) { | |
| 520 | - Environment* env = Environment::GetCurrent(context); | ||
| 520 | + Realm* realm = Realm::GetCurrent(context); | ||
| 521 | 521 | BindingData* const binding_data = | |
| 522 | - env->AddBindingData<BindingData>(context, target); | ||
| 522 | + realm->AddBindingData<BindingData>(context, target); | ||
| 523 | 523 | if (binding_data == nullptr) return; | |
| 524 | 524 | ||
| 525 | - Local<FunctionTemplate> t = env->NewFunctionTemplate(Parser::New); | ||
| 525 | + Local<FunctionTemplate> t = NewFunctionTemplate(realm->isolate(), Parser::New); | ||
| 526 | 526 | ... | |
| 527 | 527 | } | |
| 528 | 528 | ``` | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,7 +33,10 @@ | |||
| 33 | 33 | namespace node { | |
| 34 | 34 | ||
| 35 | 35 | BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> object) | |
| 36 | - : BaseObject(env->principal_realm(), object) {} | ||
| 36 | + : BaseObject(env->principal_realm(), object) { | ||
| 37 | + // TODO(legendecas): Check the shorthand is only used in the principal realm | ||
| 38 | + // while allowing to create a BaseObject in a vm context. | ||
| 39 | + } | ||
| 37 | 40 | ||
| 38 | 41 | // static | |
| 39 | 42 | v8::Local<v8::FunctionTemplate> BaseObject::GetConstructorTemplate( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -874,14 +874,14 @@ class FdEntry final : public EntryImpl { | |||
| 874 | 874 | uv_fs_close(nullptr, &req, file, nullptr); | |
| 875 | 875 | return nullptr; | |
| 876 | 876 | } | |
| 877 | + Realm* realm = entry->env()->principal_realm(); | ||
| 877 | 878 | return std::make_shared<ReaderImpl>( | |
| 878 | - BaseObjectPtr<fs::FileHandle>( | ||
| 879 | - fs::FileHandle::New(entry->env()->GetBindingData<fs::BindingData>( | ||
| 880 | - entry->env()->context()), | ||
| 881 | - file, | ||
| 882 | - Local<Object>(), | ||
| 883 | - entry->start_, | ||
| 884 | - entry->end_)), | ||
| 879 | + BaseObjectPtr<fs::FileHandle>(fs::FileHandle::New( | ||
| 880 | + realm->GetBindingData<fs::BindingData>(realm->context()), | ||
| 881 | + file, | ||
| 882 | + Local<Object>(), | ||
| 883 | + entry->start_, | ||
| 884 | + entry->end_)), | ||
| 885 | 885 | entry); | |
| 886 | 886 | } | |
| 887 | 887 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -201,48 +201,6 @@ inline Environment* Environment::GetCurrent( | |||
| 201 | 201 | return GetCurrent(info.GetIsolate()->GetCurrentContext()); | |
| 202 | 202 | } | |
| 203 | 203 | ||
| 204 | - template <typename T, typename U> | ||
| 205 | - inline T* Environment::GetBindingData(const v8::PropertyCallbackInfo<U>& info) { | ||
| 206 | - return GetBindingData<T>(info.GetIsolate()->GetCurrentContext()); | ||
| 207 | - } | ||
| 208 | - | ||
| 209 | - template <typename T> | ||
| 210 | - inline T* Environment::GetBindingData( | ||
| 211 | - const v8::FunctionCallbackInfo<v8::Value>& info) { | ||
| 212 | - return GetBindingData<T>(info.GetIsolate()->GetCurrentContext()); | ||
| 213 | - } | ||
| 214 | - | ||
| 215 | - template <typename T> | ||
| 216 | - inline T* Environment::GetBindingData(v8::Local<v8::Context> context) { | ||
| 217 | - BindingDataStore* map = static_cast<BindingDataStore*>( | ||
| 218 | - context->GetAlignedPointerFromEmbedderData( | ||
| 219 | - ContextEmbedderIndex::kBindingListIndex)); | ||
| 220 | - DCHECK_NOT_NULL(map); | ||
| 221 | - auto it = map->find(T::type_name); | ||
| 222 | - if (UNLIKELY(it == map->end())) return nullptr; | ||
| 223 | - T* result = static_cast<T*>(it->second.get()); | ||
| 224 | - DCHECK_NOT_NULL(result); | ||
| 225 | - DCHECK_EQ(result->env(), GetCurrent(context)); | ||
| 226 | - return result; | ||
| 227 | - } | ||
| 228 | - | ||
| 229 | - template <typename T> | ||
| 230 | - inline T* Environment::AddBindingData( | ||
| 231 | - v8::Local<v8::Context> context, | ||
| 232 | - v8::Local<v8::Object> target) { | ||
| 233 | - DCHECK_EQ(GetCurrent(context), this); | ||
| 234 | - // This won't compile if T is not a BaseObject subclass. | ||
| 235 | - BaseObjectPtr<T> item = MakeDetachedBaseObject<T>(this, target); | ||
| 236 | - BindingDataStore* map = static_cast<BindingDataStore*>( | ||
| 237 | - context->GetAlignedPointerFromEmbedderData( | ||
| 238 | - ContextEmbedderIndex::kBindingListIndex)); | ||
| 239 | - DCHECK_NOT_NULL(map); | ||
| 240 | - auto result = map->emplace(T::type_name, item); | ||
| 241 | - CHECK(result.second); | ||
| 242 | - DCHECK_EQ(GetBindingData<T>(context), item.get()); | ||
| 243 | - return item.get(); | ||
| 244 | - } | ||
| 245 | - | ||
| 246 | 204 | inline v8::Isolate* Environment::isolate() const { | |
| 247 | 205 | return isolate_; | |
| 248 | 206 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -545,7 +545,8 @@ void Environment::AssignToContext(Local<v8::Context> context, | |||
| 545 | 545 | context->SetAlignedPointerInEmbedderData(ContextEmbedderIndex::kRealm, realm); | |
| 546 | 546 | // Used to retrieve bindings | |
| 547 | 547 | context->SetAlignedPointerInEmbedderData( | |
| 548 | - ContextEmbedderIndex::kBindingListIndex, &(this->bindings_)); | ||
| 548 | + ContextEmbedderIndex::kBindingDataStoreIndex, | ||
| 549 | + realm->binding_data_store()); | ||
| 549 | 550 | ||
| 550 | 551 | // ContextifyContexts will update this to a pointer to the native object. | |
| 551 | 552 | context->SetAlignedPointerInEmbedderData( | |
@@ -1018,7 +1019,6 @@ MaybeLocal<Value> Environment::RunSnapshotDeserializeMain() const { | |||
| 1018 | 1019 | void Environment::RunCleanup() { | |
| 1019 | 1020 | started_cleanup_ = true; | |
| 1020 | 1021 | TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment), "RunCleanup"); | |
| 1021 | - bindings_.clear(); | ||
| 1022 | 1022 | // Only BaseObject's cleanups are registered as per-realm cleanup hooks now. | |
| 1023 | 1023 | // Defer the BaseObject cleanup after handles are cleaned up. | |
| 1024 | 1024 | CleanupHandles(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -587,25 +587,6 @@ class Environment : public MemoryRetainer { | |||
| 587 | 587 | static inline Environment* GetCurrent( | |
| 588 | 588 | const v8::PropertyCallbackInfo<T>& info); | |
| 589 | 589 | ||
| 590 | - // Methods created using SetMethod(), SetPrototypeMethod(), etc. inside | ||
| 591 | - // this scope can access the created T* object using | ||
| 592 | - // GetBindingData<T>(args) later. | ||
| 593 | - template <typename T> | ||
| 594 | - T* AddBindingData(v8::Local<v8::Context> context, | ||
| 595 | - v8::Local<v8::Object> target); | ||
| 596 | - template <typename T, typename U> | ||
| 597 | - static inline T* GetBindingData(const v8::PropertyCallbackInfo<U>& info); | ||
| 598 | - template <typename T> | ||
| 599 | - static inline T* GetBindingData( | ||
| 600 | - const v8::FunctionCallbackInfo<v8::Value>& info); | ||
| 601 | - template <typename T> | ||
| 602 | - static inline T* GetBindingData(v8::Local<v8::Context> context); | ||
| 603 | - | ||
| 604 | - typedef std::unordered_map< | ||
| 605 | - FastStringKey, | ||
| 606 | - BaseObjectPtr<BaseObject>, | ||
| 607 | - FastStringKey::Hash> BindingDataStore; | ||
| 608 | - | ||
| 609 | 590 | // Create an Environment without initializing a main Context. Use | |
| 610 | 591 | // InitializeMainContext() to initialize a main context for it. | |
| 611 | 592 | Environment(IsolateData* isolate_data, | |
@@ -1124,8 +1105,6 @@ class Environment : public MemoryRetainer { | |||
| 1124 | 1105 | void RequestInterruptFromV8(); | |
| 1125 | 1106 | static void CheckImmediate(uv_check_t* handle); | |
| 1126 | 1107 | ||
| 1127 | - BindingDataStore bindings_; | ||
| 1128 | - | ||
| 1129 | 1108 | CleanupQueue cleanup_queue_; | |
| 1130 | 1109 | bool started_cleanup_ = false; | |
| 1131 | 1110 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -110,10 +110,10 @@ void Blob::Initialize( | |||
| 110 | 110 | Local<Value> unused, | |
| 111 | 111 | Local<Context> context, | |
| 112 | 112 | void* priv) { | |
| 113 | - Environment* env = Environment::GetCurrent(context); | ||
| 113 | + Realm* realm = Realm::GetCurrent(context); | ||
| 114 | 114 | ||
| 115 | 115 | BlobBindingData* const binding_data = | |
| 116 | - env->AddBindingData<BlobBindingData>(context, target); | ||
| 116 | + realm->AddBindingData<BlobBindingData>(context, target); | ||
| 117 | 117 | if (binding_data == nullptr) return; | |
| 118 | 118 | ||
| 119 | 119 | SetMethod(context, target, "createBlob", New); | |
@@ -394,8 +394,7 @@ std::unique_ptr<worker::TransferData> Blob::CloneForMessaging() const { | |||
| 394 | 394 | ||
| 395 | 395 | void Blob::StoreDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 396 | 396 | Environment* env = Environment::GetCurrent(args); | |
| 397 | - BlobBindingData* binding_data = | ||
| 398 | - Environment::GetBindingData<BlobBindingData>(args); | ||
| 397 | + BlobBindingData* binding_data = Realm::GetBindingData<BlobBindingData>(args); | ||
| 399 | 398 | ||
| 400 | 399 | CHECK(args[0]->IsString()); // ID key | |
| 401 | 400 | CHECK(Blob::HasInstance(env, args[1])); // Blob | |
@@ -418,8 +417,7 @@ void Blob::StoreDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
| 418 | 417 | } | |
| 419 | 418 | ||
| 420 | 419 | void Blob::RevokeDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 421 | - BlobBindingData* binding_data = | ||
| 422 | - Environment::GetBindingData<BlobBindingData>(args); | ||
| 420 | + BlobBindingData* binding_data = Realm::GetBindingData<BlobBindingData>(args); | ||
| 423 | 421 | ||
| 424 | 422 | Environment* env = Environment::GetCurrent(args); | |
| 425 | 423 | CHECK(args[0]->IsString()); // ID key | |
@@ -430,8 +428,7 @@ void Blob::RevokeDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
| 430 | 428 | } | |
| 431 | 429 | ||
| 432 | 430 | void Blob::GetDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 433 | - BlobBindingData* binding_data = | ||
| 434 | - Environment::GetBindingData<BlobBindingData>(args); | ||
| 431 | + BlobBindingData* binding_data = Realm::GetBindingData<BlobBindingData>(args); | ||
| 435 | 432 | ||
| 436 | 433 | Environment* env = Environment::GetCurrent(args); | |
| 437 | 434 | CHECK(args[0]->IsString()); | |
@@ -477,8 +474,8 @@ BlobBindingData::StoredDataObject::StoredDataObject( | |||
| 477 | 474 | length(length_), | |
| 478 | 475 | type(type_) {} | |
| 479 | 476 | ||
| 480 | - BlobBindingData::BlobBindingData(Environment* env, Local<Object> wrap) | ||
| 481 | - : SnapshotableObject(env, wrap, type_int) { | ||
| 477 | + BlobBindingData::BlobBindingData(Realm* realm, Local<Object> wrap) | ||
| 478 | + : SnapshotableObject(realm, wrap, type_int) { | ||
| 482 | 479 | MakeWeak(); | |
| 483 | 480 | } | |
| 484 | 481 | ||
@@ -516,9 +513,9 @@ void BlobBindingData::Deserialize(Local<Context> context, | |||
| 516 | 513 | InternalFieldInfoBase* info) { | |
| 517 | 514 | DCHECK_EQ(index, BaseObject::kEmbedderType); | |
| 518 | 515 | HandleScope scope(context->GetIsolate()); | |
| 519 | - Environment* env = Environment::GetCurrent(context); | ||
| 516 | + Realm* realm = Realm::GetCurrent(context); | ||
| 520 | 517 | BlobBindingData* binding = | |
| 521 | - env->AddBindingData<BlobBindingData>(context, holder); | ||
| 518 | + realm->AddBindingData<BlobBindingData>(context, holder); | ||
| 522 | 519 | CHECK_NOT_NULL(binding); | |
| 523 | 520 | } | |
| 524 | 521 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,7 +111,7 @@ class Blob : public BaseObject { | |||
| 111 | 111 | ||
| 112 | 112 | class BlobBindingData : public SnapshotableObject { | |
| 113 | 113 | public: | |
| 114 | - explicit BlobBindingData(Environment* env, v8::Local<v8::Object> wrap); | ||
| 114 | + explicit BlobBindingData(Realm* realm, v8::Local<v8::Object> wrap); | ||
| 115 | 115 | ||
| 116 | 116 | using InternalFieldInfo = InternalFieldInfoBase; | |
| 117 | 117 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,8 +24,8 @@ namespace node { | |||
| 24 | 24 | #define NODE_CONTEXT_ALLOW_WASM_CODE_GENERATION_INDEX 34 | |
| 25 | 25 | #endif | |
| 26 | 26 | ||
| 27 | - #ifndef NODE_BINDING_LIST | ||
| 28 | - #define NODE_BINDING_LIST_INDEX 35 | ||
| 27 | + #ifndef NODE_BINDING_DATA_STORE_INDEX | ||
| 28 | + #define NODE_BINDING_DATA_STORE_INDEX 35 | ||
| 29 | 29 | #endif | |
| 30 | 30 | ||
| 31 | 31 | #ifndef NODE_CONTEXT_ALLOW_CODE_GENERATION_FROM_STRINGS_INDEX | |
@@ -51,7 +51,7 @@ enum ContextEmbedderIndex { | |||
| 51 | 51 | kEnvironment = NODE_CONTEXT_EMBEDDER_DATA_INDEX, | |
| 52 | 52 | kSandboxObject = NODE_CONTEXT_SANDBOX_OBJECT_INDEX, | |
| 53 | 53 | kAllowWasmCodeGeneration = NODE_CONTEXT_ALLOW_WASM_CODE_GENERATION_INDEX, | |
| 54 | - kBindingListIndex = NODE_BINDING_LIST_INDEX, | ||
| 54 | + kBindingDataStoreIndex = NODE_BINDING_DATA_STORE_INDEX, | ||
| 55 | 55 | kAllowCodeGenerationFromStrings = | |
| 56 | 56 | NODE_CONTEXT_ALLOW_CODE_GENERATION_FROM_STRINGS_INDEX, | |
| 57 | 57 | kContextifyContext = NODE_CONTEXT_CONTEXTIFY_CONTEXT_INDEX, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -277,7 +277,7 @@ FSReqBase* GetReqWrap(const v8::FunctionCallbackInfo<v8::Value>& args, | |||
| 277 | 277 | return Unwrap<FSReqBase>(value.As<v8::Object>()); | |
| 278 | 278 | } | |
| 279 | 279 | ||
| 280 | - BindingData* binding_data = Environment::GetBindingData<BindingData>(args); | ||
| 280 | + BindingData* binding_data = Realm::GetBindingData<BindingData>(args); | ||
| 281 | 281 | Environment* env = binding_data->env(); | |
| 282 | 282 | if (value->StrictEquals(env->fs_use_promises_symbol())) { | |
| 283 | 283 | if (use_bigint) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments