| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 0fc45f8 commit 4d5318c
40 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -176,6 +176,10 @@ void AsyncWrap::EmitAfter(Environment* env, double async_id) { | |||
| 176 | 176 | ||
| 177 | 177 | class PromiseWrap : public AsyncWrap { | |
| 178 | 178 | public: | |
| 179 | + enum InternalFields { | ||
| 180 | + kIsChainedPromiseField = AsyncWrap::kInternalFieldCount, | ||
| 181 | + kInternalFieldCount | ||
| 182 | + }; | ||
| 179 | 183 | PromiseWrap(Environment* env, Local<Object> object, bool silent) | |
| 180 | 184 | : AsyncWrap(env, object, PROVIDER_PROMISE, kInvalidAsyncId, silent) { | |
| 181 | 185 | MakeWeak(); | |
@@ -185,9 +189,6 @@ class PromiseWrap : public AsyncWrap { | |||
| 185 | 189 | SET_MEMORY_INFO_NAME(PromiseWrap) | |
| 186 | 190 | SET_SELF_SIZE(PromiseWrap) | |
| 187 | 191 | ||
| 188 | - static constexpr int kIsChainedPromiseField = 1; | ||
| 189 | - static constexpr int kInternalFieldCount = 2; | ||
| 190 | - | ||
| 191 | 192 | static PromiseWrap* New(Environment* env, | |
| 192 | 193 | Local<Promise> promise, | |
| 193 | 194 | PromiseWrap* parent_wrap, | |
@@ -214,15 +215,16 @@ PromiseWrap* PromiseWrap::New(Environment* env, | |||
| 214 | 215 | void PromiseWrap::getIsChainedPromise(Local<String> property, | |
| 215 | 216 | const PropertyCallbackInfo<Value>& info) { | |
| 216 | 217 | info.GetReturnValue().Set( | |
| 217 | - info.Holder()->GetInternalField(kIsChainedPromiseField)); | ||
| 218 | + info.Holder()->GetInternalField(PromiseWrap::kIsChainedPromiseField)); | ||
| 218 | 219 | } | |
| 219 | 220 | ||
| 220 | 221 | static PromiseWrap* extractPromiseWrap(Local<Promise> promise) { | |
| 221 | - Local<Value> resource_object_value = promise->GetInternalField(0); | ||
| 222 | - if (resource_object_value->IsObject()) { | ||
| 223 | - return Unwrap<PromiseWrap>(resource_object_value.As<Object>()); | ||
| 224 | - } | ||
| 225 | - return nullptr; | ||
| 222 | + // This check is imperfect. If the internal field is set, it should | ||
| 223 | + // be an object. If it's not, we just ignore it. Ideally v8 would | ||
| 224 | + // have had GetInternalField returning a MaybeLocal but this works | ||
| 225 | + // for now. | ||
| 226 | + Local<Value> obj = promise->GetInternalField(0); | ||
| 227 | + return obj->IsObject() ? Unwrap<PromiseWrap>(obj.As<Object>()) : nullptr; | ||
| 226 | 228 | } | |
| 227 | 229 | ||
| 228 | 230 | static void PromiseHook(PromiseHookType type, Local<Promise> promise, | |
@@ -560,7 +562,7 @@ void AsyncWrap::Initialize(Local<Object> target, | |||
| 560 | 562 | function_template->SetClassName(class_name); | |
| 561 | 563 | function_template->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
| 562 | 564 | auto instance_template = function_template->InstanceTemplate(); | |
| 563 | - instance_template->SetInternalFieldCount(1); | ||
| 565 | + instance_template->SetInternalFieldCount(AsyncWrap::kInternalFieldCount); | ||
| 564 | 566 | auto function = | |
| 565 | 567 | function_template->GetFunction(env->context()).ToLocalChecked(); | |
| 566 | 568 | target->Set(env->context(), class_name, function).Check(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,7 +43,9 @@ BaseObject::BaseObject(Environment* env, v8::Local<v8::Object> object) | |||
| 43 | 43 | : persistent_handle_(env->isolate(), object), env_(env) { | |
| 44 | 44 | CHECK_EQ(false, object.IsEmpty()); | |
| 45 | 45 | CHECK_GT(object->InternalFieldCount(), 0); | |
| 46 | - object->SetAlignedPointerInInternalField(0, static_cast<void*>(this)); | ||
| 46 | + object->SetAlignedPointerInInternalField( | ||
| 47 | + BaseObject::kSlot, | ||
| 48 | + static_cast<void*>(this)); | ||
| 47 | 49 | env->AddCleanupHook(DeleteMe, static_cast<void*>(this)); | |
| 48 | 50 | env->modify_base_object_count(1); | |
| 49 | 51 | } | |
@@ -67,7 +69,7 @@ BaseObject::~BaseObject() { | |||
| 67 | 69 | ||
| 68 | 70 | { | |
| 69 | 71 | v8::HandleScope handle_scope(env()->isolate()); | |
| 70 | - object()->SetAlignedPointerInInternalField(0, nullptr); | ||
| 72 | + object()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr); | ||
| 71 | 73 | } | |
| 72 | 74 | } | |
| 73 | 75 | ||
@@ -100,7 +102,8 @@ Environment* BaseObject::env() const { | |||
| 100 | 102 | ||
| 101 | 103 | BaseObject* BaseObject::FromJSObject(v8::Local<v8::Object> obj) { | |
| 102 | 104 | CHECK_GT(obj->InternalFieldCount(), 0); | |
| 103 | - return static_cast<BaseObject*>(obj->GetAlignedPointerFromInternalField(0)); | ||
| 105 | + return static_cast<BaseObject*>( | ||
| 106 | + obj->GetAlignedPointerFromInternalField(BaseObject::kSlot)); | ||
| 104 | 107 | } | |
| 105 | 108 | ||
| 106 | 109 | ||
@@ -148,11 +151,12 @@ BaseObject::MakeLazilyInitializedJSTemplate(Environment* env) { | |||
| 148 | 151 | auto constructor = [](const v8::FunctionCallbackInfo<v8::Value>& args) { | |
| 149 | 152 | DCHECK(args.IsConstructCall()); | |
| 150 | 153 | DCHECK_GT(args.This()->InternalFieldCount(), 0); | |
| 151 | - args.This()->SetAlignedPointerInInternalField(0, nullptr); | ||
| 154 | + args.This()->SetAlignedPointerInInternalField(BaseObject::kSlot, nullptr); | ||
| 152 | 155 | }; | |
| 153 | 156 | ||
| 154 | 157 | v8::Local<v8::FunctionTemplate> t = env->NewFunctionTemplate(constructor); | |
| 155 | - t->InstanceTemplate()->SetInternalFieldCount(1); | ||
| 158 | + t->InstanceTemplate()->SetInternalFieldCount( | ||
| 159 | + BaseObject::kInternalFieldCount); | ||
| 156 | 160 | return t; | |
| 157 | 161 | } | |
| 158 | 162 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -36,6 +36,8 @@ class BaseObjectPtrImpl; | |||
| 36 | 36 | ||
| 37 | 37 | class BaseObject : public MemoryRetainer { | |
| 38 | 38 | public: | |
| 39 | + enum InternalFields { kSlot, kInternalFieldCount }; | ||
| 40 | + | ||
| 39 | 41 | // Associates this object with `object`. It uses the 0th internal field for | |
| 40 | 42 | // that, and in particular aborts if there is no such field. | |
| 41 | 43 | inline BaseObject(Environment* env, v8::Local<v8::Object> object); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2223,7 +2223,8 @@ void Initialize(Local<Object> target, | |||
| 2223 | 2223 | ||
| 2224 | 2224 | Local<FunctionTemplate> channel_wrap = | |
| 2225 | 2225 | env->NewFunctionTemplate(ChannelWrap::New); | |
| 2226 | - channel_wrap->InstanceTemplate()->SetInternalFieldCount(1); | ||
| 2226 | + channel_wrap->InstanceTemplate()->SetInternalFieldCount( | ||
| 2227 | + ChannelWrap::kInternalFieldCount); | ||
| 2227 | 2228 | channel_wrap->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
| 2228 | 2229 | ||
| 2229 | 2230 | env->SetProtoMethod(channel_wrap, "queryAny", Query<QueryAnyWrap>); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -97,7 +97,8 @@ void FSEventWrap::Initialize(Local<Object> target, | |||
| 97 | 97 | ||
| 98 | 98 | auto fsevent_string = FIXED_ONE_BYTE_STRING(env->isolate(), "FSEvent"); | |
| 99 | 99 | Local<FunctionTemplate> t = env->NewFunctionTemplate(New); | |
| 100 | - t->InstanceTemplate()->SetInternalFieldCount(1); | ||
| 100 | + t->InstanceTemplate()->SetInternalFieldCount( | ||
| 101 | + FSEventWrap::kInternalFieldCount); | ||
| 101 | 102 | t->SetClassName(fsevent_string); | |
| 102 | 103 | ||
| 103 | 104 | t->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -341,7 +341,7 @@ BaseObjectPtr<AsyncWrap> CreateHeapSnapshotStream( | |||
| 341 | 341 | Local<FunctionTemplate> os = FunctionTemplate::New(env->isolate()); | |
| 342 | 342 | os->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
| 343 | 343 | Local<ObjectTemplate> ost = os->InstanceTemplate(); | |
| 344 | - ost->SetInternalFieldCount(StreamBase::kStreamBaseFieldCount); | ||
| 344 | + ost->SetInternalFieldCount(StreamBase::kInternalFieldCount); | ||
| 345 | 345 | os->SetClassName( | |
| 346 | 346 | FIXED_ONE_BYTE_STRING(env->isolate(), "HeapSnapshotStream")); | |
| 347 | 347 | StreamBase::AddMethods(env, os); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -105,7 +105,8 @@ class JSBindingsConnection : public AsyncWrap { | |||
| 105 | 105 | Local<String> class_name = ConnectionType::GetClassName(env); | |
| 106 | 106 | Local<FunctionTemplate> tmpl = | |
| 107 | 107 | env->NewFunctionTemplate(JSBindingsConnection::New); | |
| 108 | - tmpl->InstanceTemplate()->SetInternalFieldCount(1); | ||
| 108 | + tmpl->InstanceTemplate()->SetInternalFieldCount( | ||
| 109 | + JSBindingsConnection::kInternalFieldCount); | ||
| 109 | 110 | tmpl->SetClassName(class_name); | |
| 110 | 111 | tmpl->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
| 111 | 112 | env->SetProtoMethod(tmpl, "dispatch", JSBindingsConnection::Dispatch); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -204,7 +204,7 @@ void JSStream::Initialize(Local<Object> target, | |||
| 204 | 204 | FIXED_ONE_BYTE_STRING(env->isolate(), "JSStream"); | |
| 205 | 205 | t->SetClassName(jsStreamString); | |
| 206 | 206 | t->InstanceTemplate() | |
| 207 | - ->SetInternalFieldCount(StreamBase::kStreamBaseFieldCount); | ||
| 207 | + ->SetInternalFieldCount(StreamBase::kInternalFieldCount); | ||
| 208 | 208 | t->Inherit(AsyncWrap::GetConstructorTemplate(env)); | |
| 209 | 209 | ||
| 210 | 210 | env->SetProtoMethod(t, "finishWrite", Finish<WriteWrap>); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1636,7 +1636,8 @@ void ModuleWrap::Initialize(Local<Object> target, | |||
| 1636 | 1636 | ||
| 1637 | 1637 | Local<FunctionTemplate> tpl = env->NewFunctionTemplate(New); | |
| 1638 | 1638 | tpl->SetClassName(FIXED_ONE_BYTE_STRING(isolate, "ModuleWrap")); | |
| 1639 | - tpl->InstanceTemplate()->SetInternalFieldCount(1); | ||
| 1639 | + tpl->InstanceTemplate()->SetInternalFieldCount( | ||
| 1640 | + ModuleWrap::kInternalFieldCount); | ||
| 1640 | 1641 | ||
| 1641 | 1642 | env->SetProtoMethod(tpl, "link", Link); | |
| 1642 | 1643 | env->SetProtoMethod(tpl, "instantiate", Instantiate); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -145,7 +145,7 @@ MaybeLocal<Object> ContextifyContext::CreateDataWrapper(Environment* env) { | |||
| 145 | 145 | return MaybeLocal<Object>(); | |
| 146 | 146 | } | |
| 147 | 147 | ||
| 148 | - wrapper->SetAlignedPointerInInternalField(0, this); | ||
| 148 | + wrapper->SetAlignedPointerInInternalField(ContextifyContext::kSlot, this); | ||
| 149 | 149 | return wrapper; | |
| 150 | 150 | } | |
| 151 | 151 | ||
@@ -232,7 +232,8 @@ MaybeLocal<Context> ContextifyContext::CreateV8Context( | |||
| 232 | 232 | void ContextifyContext::Init(Environment* env, Local<Object> target) { | |
| 233 | 233 | Local<FunctionTemplate> function_template = | |
| 234 | 234 | FunctionTemplate::New(env->isolate()); | |
| 235 | - function_template->InstanceTemplate()->SetInternalFieldCount(1); | ||
| 235 | + function_template->InstanceTemplate()->SetInternalFieldCount( | ||
| 236 | + ContextifyContext::kInternalFieldCount); | ||
| 236 | 237 | env->set_script_data_constructor_function( | |
| 237 | 238 | function_template->GetFunction(env->context()).ToLocalChecked()); | |
| 238 | 239 | ||
@@ -331,7 +332,8 @@ template <typename T> | |||
| 331 | 332 | ContextifyContext* ContextifyContext::Get(const PropertyCallbackInfo<T>& args) { | |
| 332 | 333 | Local<Value> data = args.Data(); | |
| 333 | 334 | return static_cast<ContextifyContext*>( | |
| 334 | - data.As<Object>()->GetAlignedPointerFromInternalField(0)); | ||
| 335 | + data.As<Object>()->GetAlignedPointerFromInternalField( | ||
| 336 | + ContextifyContext::kSlot)); | ||
| 335 | 337 | } | |
| 336 | 338 | ||
| 337 | 339 | // static | |
@@ -628,7 +630,8 @@ void ContextifyScript::Init(Environment* env, Local<Object> target) { | |||
| 628 | 630 | FIXED_ONE_BYTE_STRING(env->isolate(), "ContextifyScript"); | |
| 629 | 631 | ||
| 630 | 632 | Local<FunctionTemplate> script_tmpl = env->NewFunctionTemplate(New); | |
| 631 | - script_tmpl->InstanceTemplate()->SetInternalFieldCount(1); | ||
| 633 | + script_tmpl->InstanceTemplate()->SetInternalFieldCount( | ||
| 634 | + ContextifyScript::kInternalFieldCount); | ||
| 632 | 635 | script_tmpl->SetClassName(class_name); | |
| 633 | 636 | env->SetProtoMethod(script_tmpl, "createCachedData", CreateCachedData); | |
| 634 | 637 | env->SetProtoMethod(script_tmpl, "runInContext", RunInContext); | |
@@ -1251,7 +1254,8 @@ void Initialize(Local<Object> target, | |||
| 1251 | 1254 | { | |
| 1252 | 1255 | Local<FunctionTemplate> tpl = FunctionTemplate::New(env->isolate()); | |
| 1253 | 1256 | tpl->SetClassName(FIXED_ONE_BYTE_STRING(env->isolate(), "CompiledFnEntry")); | |
| 1254 | - tpl->InstanceTemplate()->SetInternalFieldCount(1); | ||
| 1257 | + tpl->InstanceTemplate()->SetInternalFieldCount( | ||
| 1258 | + CompiledFnEntry::kInternalFieldCount); | ||
| 1255 | 1259 | ||
| 1256 | 1260 | env->set_compiled_fn_entry_template(tpl->InstanceTemplate()); | |
| 1257 | 1261 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments