| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e79f0c2 commit b45c22b
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -316,16 +316,23 @@ inline Environment* Environment::GetCurrent(v8::Local<v8::Context> context) { | |||
| 316 | 316 | ||
| 317 | 317 | inline Environment* Environment::GetCurrent( | |
| 318 | 318 | const v8::FunctionCallbackInfo<v8::Value>& info) { | |
| 319 | - CHECK(info.Data()->IsExternal()); | ||
| 320 | - return static_cast<Environment*>(info.Data().As<v8::External>()->Value()); | ||
| 319 | + return GetFromCallbackData(info.Data()); | ||
| 321 | 320 | } | |
| 322 | 321 | ||
| 323 | 322 | template <typename T> | |
| 324 | 323 | inline Environment* Environment::GetCurrent( | |
| 325 | 324 | const v8::PropertyCallbackInfo<T>& info) { | |
| 326 | - CHECK(info.Data()->IsExternal()); | ||
| 327 | - return static_cast<Environment*>( | ||
| 328 | - info.Data().template As<v8::External>()->Value()); | ||
| 325 | + return GetFromCallbackData(info.Data()); | ||
| 326 | + } | ||
| 327 | + | ||
| 328 | + inline Environment* Environment::GetFromCallbackData(v8::Local<v8::Value> val) { | ||
| 329 | + DCHECK(val->IsObject()); | ||
| 330 | + v8::Local<v8::Object> obj = val.As<v8::Object>(); | ||
| 331 | + DCHECK_GE(obj->InternalFieldCount(), 1); | ||
| 332 | + Environment* env = | ||
| 333 | + static_cast<Environment*>(obj->GetAlignedPointerFromInternalField(0)); | ||
| 334 | + DCHECK(env->as_callback_data_template()->HasInstance(obj)); | ||
| 335 | + return env; | ||
| 329 | 336 | } | |
| 330 | 337 | ||
| 331 | 338 | inline Environment* Environment::GetThreadLocalEnv() { | |
@@ -857,7 +864,7 @@ inline v8::Local<v8::FunctionTemplate> | |||
| 857 | 864 | v8::Local<v8::Signature> signature, | |
| 858 | 865 | v8::ConstructorBehavior behavior, | |
| 859 | 866 | v8::SideEffectType side_effect_type) { | |
| 860 | - v8::Local<v8::External> external = as_external(); | ||
| 867 | + v8::Local<v8::Object> external = as_callback_data(); | ||
| 861 | 868 | return v8::FunctionTemplate::New(isolate(), callback, external, | |
| 862 | 869 | signature, 0, behavior, side_effect_type); | |
| 863 | 870 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,8 +25,8 @@ using v8::ArrayBuffer; | |||
| 25 | 25 | using v8::Boolean; | |
| 26 | 26 | using v8::Context; | |
| 27 | 27 | using v8::EmbedderGraph; | |
| 28 | - using v8::External; | ||
| 29 | 28 | using v8::Function; | |
| 29 | + using v8::FunctionTemplate; | ||
| 30 | 30 | using v8::HandleScope; | |
| 31 | 31 | using v8::Integer; | |
| 32 | 32 | using v8::Isolate; | |
@@ -195,7 +195,16 @@ Environment::Environment(IsolateData* isolate_data, | |||
| 195 | 195 | // We'll be creating new objects so make sure we've entered the context. | |
| 196 | 196 | HandleScope handle_scope(isolate()); | |
| 197 | 197 | Context::Scope context_scope(context); | |
| 198 | - set_as_external(External::New(isolate(), this)); | ||
| 198 | + { | ||
| 199 | + Local<FunctionTemplate> templ = FunctionTemplate::New(isolate()); | ||
| 200 | + templ->InstanceTemplate()->SetInternalFieldCount(1); | ||
| 201 | + Local<Object> obj = | ||
| 202 | + templ->GetFunction(context).ToLocalChecked()->NewInstance( | ||
| 203 | + context).ToLocalChecked(); | ||
| 204 | + obj->SetAlignedPointerInInternalField(0, this); | ||
| 205 | + set_as_callback_data(obj); | ||
| 206 | + set_as_callback_data_template(templ); | ||
| 207 | + } | ||
| 199 | 208 | ||
| 200 | 209 | // We create new copies of the per-Environment option sets, so that it is | |
| 201 | 210 | // easier to modify them after Environment creation. The defaults are | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -319,7 +319,8 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2; | |||
| 319 | 319 | V(zero_return_string, "ZERO_RETURN") | |
| 320 | 320 | ||
| 321 | 321 | #define ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES(V) \ | |
| 322 | - V(as_external, v8::External) \ | ||
| 322 | + V(as_callback_data, v8::Object) \ | ||
| 323 | + V(as_callback_data_template, v8::FunctionTemplate) \ | ||
| 323 | 324 | V(async_hooks_after_function, v8::Function) \ | |
| 324 | 325 | V(async_hooks_before_function, v8::Function) \ | |
| 325 | 326 | V(async_hooks_binding, v8::Object) \ | |
@@ -661,6 +662,8 @@ class Environment { | |||
| 661 | 662 | static inline Environment* GetCurrent( | |
| 662 | 663 | const v8::PropertyCallbackInfo<T>& info); | |
| 663 | 664 | ||
| 665 | + static inline Environment* GetFromCallbackData(v8::Local<v8::Value> val); | ||
| 666 | + | ||
| 664 | 667 | static uv_key_t thread_local_env; | |
| 665 | 668 | static inline Environment* GetThreadLocalEnv(); | |
| 666 | 669 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,7 +111,7 @@ void FSEventWrap::Initialize(Local<Object> target, | |||
| 111 | 111 | Local<FunctionTemplate> get_initialized_templ = | |
| 112 | 112 | FunctionTemplate::New(env->isolate(), | |
| 113 | 113 | GetInitialized, | |
| 114 | - env->as_external(), | ||
| 114 | + env->as_callback_data(), | ||
| 115 | 115 | Signature::New(env->isolate(), t)); | |
| 116 | 116 | ||
| 117 | 117 | t->PrototypeTemplate()->SetAccessorProperty( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -369,7 +369,7 @@ void SecureContext::Initialize(Environment* env, Local<Object> target) { | |||
| 369 | 369 | Local<FunctionTemplate> ctx_getter_templ = | |
| 370 | 370 | FunctionTemplate::New(env->isolate(), | |
| 371 | 371 | CtxGetter, | |
| 372 | - env->as_external(), | ||
| 372 | + env->as_callback_data(), | ||
| 373 | 373 | Signature::New(env->isolate(), t)); | |
| 374 | 374 | ||
| 375 | 375 | ||
@@ -4762,7 +4762,7 @@ void DiffieHellman::Initialize(Environment* env, Local<Object> target) { | |||
| 4762 | 4762 | Local<FunctionTemplate> verify_error_getter_templ = | |
| 4763 | 4763 | FunctionTemplate::New(env->isolate(), | |
| 4764 | 4764 | DiffieHellman::VerifyErrorGetter, | |
| 4765 | - env->as_external(), | ||
| 4765 | + env->as_callback_data(), | ||
| 4766 | 4766 | Signature::New(env->isolate(), t), | |
| 4767 | 4767 | /* length */ 0, | |
| 4768 | 4768 | ConstructorBehavior::kThrow, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -212,7 +212,7 @@ static void EnvEnumerator(const PropertyCallbackInfo<Array>& info) { | |||
| 212 | 212 | ||
| 213 | 213 | MaybeLocal<Object> CreateEnvVarProxy(Local<Context> context, | |
| 214 | 214 | Isolate* isolate, | |
| 215 | - Local<Value> data) { | ||
| 215 | + Local<Object> data) { | ||
| 216 | 216 | EscapableHandleScope scope(isolate); | |
| 217 | 217 | Local<ObjectTemplate> env_proxy_template = ObjectTemplate::New(isolate); | |
| 218 | 218 | env_proxy_template->SetHandler(NamedPropertyHandlerConfiguration( | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,7 +9,7 @@ namespace node { | |||
| 9 | 9 | ||
| 10 | 10 | v8::MaybeLocal<v8::Object> CreateEnvVarProxy(v8::Local<v8::Context> context, | |
| 11 | 11 | v8::Isolate* isolate, | |
| 12 | - v8::Local<v8::Value> data); | ||
| 12 | + v8::Local<v8::Object> data); | ||
| 13 | 13 | ||
| 14 | 14 | // Most of the time, it's best to use `console.error` to write | |
| 15 | 15 | // to the process.stderr stream. However, in some cases, such as | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -92,7 +92,7 @@ MaybeLocal<Object> CreateProcessObject( | |||
| 92 | 92 | title_string, | |
| 93 | 93 | ProcessTitleGetter, | |
| 94 | 94 | env->owns_process_state() ? ProcessTitleSetter : nullptr, | |
| 95 | - env->as_external(), | ||
| 95 | + env->as_callback_data(), | ||
| 96 | 96 | DEFAULT, | |
| 97 | 97 | None, | |
| 98 | 98 | SideEffectType::kHasNoSideEffect) | |
@@ -152,7 +152,7 @@ MaybeLocal<Object> CreateProcessObject( | |||
| 152 | 152 | .ToLocalChecked()).FromJust(); | |
| 153 | 153 | ||
| 154 | 154 | Local<Object> env_var_proxy; | |
| 155 | - if (!CreateEnvVarProxy(context, isolate, env->as_external()) | ||
| 155 | + if (!CreateEnvVarProxy(context, isolate, env->as_callback_data()) | ||
| 156 | 156 | .ToLocal(&env_var_proxy)) | |
| 157 | 157 | return MaybeLocal<Object>(); | |
| 158 | 158 | ||
@@ -322,7 +322,7 @@ MaybeLocal<Object> CreateProcessObject( | |||
| 322 | 322 | debug_port_string, | |
| 323 | 323 | DebugPortGetter, | |
| 324 | 324 | env->owns_process_state() ? DebugPortSetter : nullptr, | |
| 325 | - env->as_external()) | ||
| 325 | + env->as_callback_data()) | ||
| 326 | 326 | .FromJust()); | |
| 327 | 327 | ||
| 328 | 328 | // process._rawDebug: may be overwritten later in JS land, but should be | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,7 +137,7 @@ Local<FunctionTemplate> LibuvStreamWrap::GetConstructorTemplate( | |||
| 137 | 137 | Local<FunctionTemplate> get_write_queue_size = | |
| 138 | 138 | FunctionTemplate::New(env->isolate(), | |
| 139 | 139 | GetWriteQueueSize, | |
| 140 | - env->as_external(), | ||
| 140 | + env->as_callback_data(), | ||
| 141 | 141 | Signature::New(env->isolate(), tmpl)); | |
| 142 | 142 | tmpl->PrototypeTemplate()->SetAccessorProperty( | |
| 143 | 143 | env->write_queue_size_string(), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -927,7 +927,7 @@ void TLSWrap::Initialize(Local<Object> target, | |||
| 927 | 927 | Local<FunctionTemplate> get_write_queue_size = | |
| 928 | 928 | FunctionTemplate::New(env->isolate(), | |
| 929 | 929 | GetWriteQueueSize, | |
| 930 | - env->as_external(), | ||
| 930 | + env->as_callback_data(), | ||
| 931 | 931 | Signature::New(env->isolate(), t)); | |
| 932 | 932 | t->PrototypeTemplate()->SetAccessorProperty( | |
| 933 | 933 | env->write_queue_size_string(), | |
| Back | FazBrowse Home | New Git URL |
0 commit comments