| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9ca3cc0 commit 05f5c79
26 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 | |
|---|---|---|---|
@@ -197,48 +197,6 @@ inline Environment* Environment::GetCurrent( | |||
| 197 | 197 | return GetCurrent(info.GetIsolate()->GetCurrentContext()); | |
| 198 | 198 | } | |
| 199 | 199 | ||
| 200 | - template <typename T, typename U> | ||
| 201 | - inline T* Environment::GetBindingData(const v8::PropertyCallbackInfo<U>& info) { | ||
| 202 | - return GetBindingData<T>(info.GetIsolate()->GetCurrentContext()); | ||
| 203 | - } | ||
| 204 | - | ||
| 205 | - template <typename T> | ||
| 206 | - inline T* Environment::GetBindingData( | ||
| 207 | - const v8::FunctionCallbackInfo<v8::Value>& info) { | ||
| 208 | - return GetBindingData<T>(info.GetIsolate()->GetCurrentContext()); | ||
| 209 | - } | ||
| 210 | - | ||
| 211 | - template <typename T> | ||
| 212 | - inline T* Environment::GetBindingData(v8::Local<v8::Context> context) { | ||
| 213 | - BindingDataStore* map = static_cast<BindingDataStore*>( | ||
| 214 | - context->GetAlignedPointerFromEmbedderData( | ||
| 215 | - ContextEmbedderIndex::kBindingListIndex)); | ||
| 216 | - DCHECK_NOT_NULL(map); | ||
| 217 | - auto it = map->find(T::type_name); | ||
| 218 | - if (UNLIKELY(it == map->end())) return nullptr; | ||
| 219 | - T* result = static_cast<T*>(it->second.get()); | ||
| 220 | - DCHECK_NOT_NULL(result); | ||
| 221 | - DCHECK_EQ(result->env(), GetCurrent(context)); | ||
| 222 | - return result; | ||
| 223 | - } | ||
| 224 | - | ||
| 225 | - template <typename T> | ||
| 226 | - inline T* Environment::AddBindingData( | ||
| 227 | - v8::Local<v8::Context> context, | ||
| 228 | - v8::Local<v8::Object> target) { | ||
| 229 | - DCHECK_EQ(GetCurrent(context), this); | ||
| 230 | - // This won't compile if T is not a BaseObject subclass. | ||
| 231 | - BaseObjectPtr<T> item = MakeDetachedBaseObject<T>(this, target); | ||
| 232 | - BindingDataStore* map = static_cast<BindingDataStore*>( | ||
| 233 | - context->GetAlignedPointerFromEmbedderData( | ||
| 234 | - ContextEmbedderIndex::kBindingListIndex)); | ||
| 235 | - DCHECK_NOT_NULL(map); | ||
| 236 | - auto result = map->emplace(T::type_name, item); | ||
| 237 | - CHECK(result.second); | ||
| 238 | - DCHECK_EQ(GetBindingData<T>(context), item.get()); | ||
| 239 | - return item.get(); | ||
| 240 | - } | ||
| 241 | - | ||
| 242 | 200 | inline v8::Isolate* Environment::isolate() const { | |
| 243 | 201 | return isolate_; | |
| 244 | 202 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -539,7 +539,8 @@ void Environment::AssignToContext(Local<v8::Context> context, | |||
| 539 | 539 | context->SetAlignedPointerInEmbedderData(ContextEmbedderIndex::kRealm, realm); | |
| 540 | 540 | // Used to retrieve bindings | |
| 541 | 541 | context->SetAlignedPointerInEmbedderData( | |
| 542 | - ContextEmbedderIndex::kBindingListIndex, &(this->bindings_)); | ||
| 542 | + ContextEmbedderIndex::kBindingDataStoreIndex, | ||
| 543 | + realm->binding_data_store()); | ||
| 543 | 544 | ||
| 544 | 545 | // ContextifyContexts will update this to a pointer to the native object. | |
| 545 | 546 | context->SetAlignedPointerInEmbedderData( | |
@@ -1010,7 +1011,6 @@ MaybeLocal<Value> Environment::RunSnapshotDeserializeMain() const { | |||
| 1010 | 1011 | void Environment::RunCleanup() { | |
| 1011 | 1012 | started_cleanup_ = true; | |
| 1012 | 1013 | TRACE_EVENT0(TRACING_CATEGORY_NODE1(environment), "RunCleanup"); | |
| 1013 | - bindings_.clear(); | ||
| 1014 | 1014 | // Only BaseObject's cleanups are registered as per-realm cleanup hooks now. | |
| 1015 | 1015 | // Defer the BaseObject cleanup after handles are cleaned up. | |
| 1016 | 1016 | CleanupHandles(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -571,25 +571,6 @@ class Environment : public MemoryRetainer { | |||
| 571 | 571 | static inline Environment* GetCurrent( | |
| 572 | 572 | const v8::PropertyCallbackInfo<T>& info); | |
| 573 | 573 | ||
| 574 | - // Methods created using SetMethod(), SetPrototypeMethod(), etc. inside | ||
| 575 | - // this scope can access the created T* object using | ||
| 576 | - // GetBindingData<T>(args) later. | ||
| 577 | - template <typename T> | ||
| 578 | - T* AddBindingData(v8::Local<v8::Context> context, | ||
| 579 | - v8::Local<v8::Object> target); | ||
| 580 | - template <typename T, typename U> | ||
| 581 | - static inline T* GetBindingData(const v8::PropertyCallbackInfo<U>& info); | ||
| 582 | - template <typename T> | ||
| 583 | - static inline T* GetBindingData( | ||
| 584 | - const v8::FunctionCallbackInfo<v8::Value>& info); | ||
| 585 | - template <typename T> | ||
| 586 | - static inline T* GetBindingData(v8::Local<v8::Context> context); | ||
| 587 | - | ||
| 588 | - typedef std::unordered_map< | ||
| 589 | - FastStringKey, | ||
| 590 | - BaseObjectPtr<BaseObject>, | ||
| 591 | - FastStringKey::Hash> BindingDataStore; | ||
| 592 | - | ||
| 593 | 574 | // Create an Environment without initializing a main Context. Use | |
| 594 | 575 | // InitializeMainContext() to initialize a main context for it. | |
| 595 | 576 | Environment(IsolateData* isolate_data, | |
@@ -1108,8 +1089,6 @@ class Environment : public MemoryRetainer { | |||
| 1108 | 1089 | void RequestInterruptFromV8(); | |
| 1109 | 1090 | static void CheckImmediate(uv_check_t* handle); | |
| 1110 | 1091 | ||
| 1111 | - BindingDataStore bindings_; | ||
| 1112 | - | ||
| 1113 | 1092 | CleanupQueue cleanup_queue_; | |
| 1114 | 1093 | bool started_cleanup_ = false; | |
| 1115 | 1094 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -37,17 +37,17 @@ void Blob::Initialize( | |||
| 37 | 37 | Local<Value> unused, | |
| 38 | 38 | Local<Context> context, | |
| 39 | 39 | void* priv) { | |
| 40 | - Environment* env = Environment::GetCurrent(context); | ||
| 40 | + Realm* realm = Realm::GetCurrent(context); | ||
| 41 | 41 | ||
| 42 | 42 | BlobBindingData* const binding_data = | |
| 43 | - env->AddBindingData<BlobBindingData>(context, target); | ||
| 43 | + realm->AddBindingData<BlobBindingData>(context, target); | ||
| 44 | 44 | if (binding_data == nullptr) return; | |
| 45 | 45 | ||
| 46 | 46 | SetMethod(context, target, "createBlob", New); | |
| 47 | 47 | SetMethod(context, target, "storeDataObject", StoreDataObject); | |
| 48 | 48 | SetMethod(context, target, "getDataObject", GetDataObject); | |
| 49 | 49 | SetMethod(context, target, "revokeDataObject", RevokeDataObject); | |
| 50 | - FixedSizeBlobCopyJob::Initialize(env, target); | ||
| 50 | + FixedSizeBlobCopyJob::Initialize(realm->env(), target); | ||
| 51 | 51 | } | |
| 52 | 52 | ||
| 53 | 53 | Local<FunctionTemplate> Blob::GetConstructorTemplate(Environment* env) { | |
@@ -236,8 +236,7 @@ std::unique_ptr<worker::TransferData> Blob::CloneForMessaging() const { | |||
| 236 | 236 | ||
| 237 | 237 | void Blob::StoreDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 238 | 238 | Environment* env = Environment::GetCurrent(args); | |
| 239 | - BlobBindingData* binding_data = | ||
| 240 | - Environment::GetBindingData<BlobBindingData>(args); | ||
| 239 | + BlobBindingData* binding_data = Realm::GetBindingData<BlobBindingData>(args); | ||
| 241 | 240 | ||
| 242 | 241 | CHECK(args[0]->IsString()); // ID key | |
| 243 | 242 | CHECK(Blob::HasInstance(env, args[1])); // Blob | |
@@ -260,8 +259,7 @@ void Blob::StoreDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
| 260 | 259 | } | |
| 261 | 260 | ||
| 262 | 261 | void Blob::RevokeDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 263 | - BlobBindingData* binding_data = | ||
| 264 | - Environment::GetBindingData<BlobBindingData>(args); | ||
| 262 | + BlobBindingData* binding_data = Realm::GetBindingData<BlobBindingData>(args); | ||
| 265 | 263 | ||
| 266 | 264 | Environment* env = Environment::GetCurrent(args); | |
| 267 | 265 | CHECK(args[0]->IsString()); // ID key | |
@@ -272,8 +270,7 @@ void Blob::RevokeDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
| 272 | 270 | } | |
| 273 | 271 | ||
| 274 | 272 | void Blob::GetDataObject(const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 275 | - BlobBindingData* binding_data = | ||
| 276 | - Environment::GetBindingData<BlobBindingData>(args); | ||
| 273 | + BlobBindingData* binding_data = Realm::GetBindingData<BlobBindingData>(args); | ||
| 277 | 274 | ||
| 278 | 275 | Environment* env = Environment::GetCurrent(args); | |
| 279 | 276 | CHECK(args[0]->IsString()); | |
@@ -428,8 +425,8 @@ BlobBindingData::StoredDataObject::StoredDataObject( | |||
| 428 | 425 | length(length_), | |
| 429 | 426 | type(type_) {} | |
| 430 | 427 | ||
| 431 | - BlobBindingData::BlobBindingData(Environment* env, Local<Object> wrap) | ||
| 432 | - : SnapshotableObject(env, wrap, type_int) { | ||
| 428 | + BlobBindingData::BlobBindingData(Realm* realm, Local<Object> wrap) | ||
| 429 | + : SnapshotableObject(realm, wrap, type_int) { | ||
| 433 | 430 | MakeWeak(); | |
| 434 | 431 | } | |
| 435 | 432 | ||
@@ -465,9 +462,9 @@ void BlobBindingData::Deserialize(Local<Context> context, | |||
| 465 | 462 | InternalFieldInfoBase* info) { | |
| 466 | 463 | DCHECK_EQ(index, BaseObject::kEmbedderType); | |
| 467 | 464 | HandleScope scope(context->GetIsolate()); | |
| 468 | - Environment* env = Environment::GetCurrent(context); | ||
| 465 | + Realm* realm = Realm::GetCurrent(context); | ||
| 469 | 466 | BlobBindingData* binding = | |
| 470 | - env->AddBindingData<BlobBindingData>(context, holder); | ||
| 467 | + realm->AddBindingData<BlobBindingData>(context, holder); | ||
| 471 | 468 | CHECK_NOT_NULL(binding); | |
| 472 | 469 | } | |
| 473 | 470 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -141,7 +141,7 @@ class FixedSizeBlobCopyJob : public AsyncWrap, public ThreadPoolWork { | |||
| 141 | 141 | ||
| 142 | 142 | class BlobBindingData : public SnapshotableObject { | |
| 143 | 143 | public: | |
| 144 | - explicit BlobBindingData(Environment* env, v8::Local<v8::Object> wrap); | ||
| 144 | + explicit BlobBindingData(Realm* realm, v8::Local<v8::Object> wrap); | ||
| 145 | 145 | ||
| 146 | 146 | using InternalFieldInfo = InternalFieldInfoBase; | |
| 147 | 147 | ||
| 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