diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2020-04-19 22:51:05 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-05-06 07:44:04 +0300 |
commit | 86fdaa745572a3bec4370ac7bd05d18e6bf64c01 (patch) | |
tree | 45890dbc713ad29edd830fd2aa17f592909ccbb7 /src/node_http2.cc | |
parent | f446b2058dcfaf9d4e2f6bdfe555bc4437f41acf (diff) |
src: retrieve binding data from the context
Instead of passing them through the data bound to function
templates, store references to them in a list embedded inside
the context.
This makes the function templates more context-independent,
and makes it possible to embed binding data in non-main contexts.
Co-authored-by: Anna Henningsen <anna@addaleax.net>
PR-URL: https://github.com/nodejs/node/pull/33139
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/node_http2.cc')
-rw-r--r-- | src/node_http2.cc | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/src/node_http2.cc b/src/node_http2.cc index 6637166e954..25f353bb147 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -2351,7 +2351,7 @@ void HttpErrorString(const FunctionCallbackInfo<Value>& args) { // would be suitable, for instance, for creating the Base64 // output for an HTTP2-Settings header field. void PackSettings(const FunctionCallbackInfo<Value>& args) { - Http2State* state = Unwrap<Http2State>(args.Data()); + Http2State* state = Environment::GetBindingData<Http2State>(args); args.GetReturnValue().Set(Http2Settings::Pack(state)); } @@ -2359,7 +2359,7 @@ void PackSettings(const FunctionCallbackInfo<Value>& args) { // default SETTINGS. RefreshDefaultSettings updates that TypedArray with the // default values. void RefreshDefaultSettings(const FunctionCallbackInfo<Value>& args) { - Http2State* state = Unwrap<Http2State>(args.Data()); + Http2State* state = Environment::GetBindingData<Http2State>(args); Http2Settings::RefreshDefaults(state); } @@ -2423,7 +2423,7 @@ void Http2Session::RefreshState(const FunctionCallbackInfo<Value>& args) { // Constructor for new Http2Session instances. void Http2Session::New(const FunctionCallbackInfo<Value>& args) { - Http2State* state = Unwrap<Http2State>(args.Data()); + Http2State* state = Environment::GetBindingData<Http2State>(args); Environment* env = state->env(); CHECK(args.IsConstructCall()); SessionType type = @@ -2941,6 +2941,9 @@ void Http2State::MemoryInfo(MemoryTracker* tracker) const { tracker->TrackField("root_buffer", root_buffer); } +// TODO(addaleax): Remove once we're on C++17. +constexpr FastStringKey Http2State::binding_data_name; + // Set up the process.binding('http2') binding. void Initialize(Local<Object> target, Local<Value> unused, @@ -2950,9 +2953,8 @@ void Initialize(Local<Object> target, Isolate* isolate = env->isolate(); HandleScope handle_scope(isolate); - Environment::BindingScope<Http2State> binding_scope(env); - if (!binding_scope) return; - Http2State* state = binding_scope.data; + Http2State* const state = env->AddBindingData<Http2State>(context, target); + if (state == nullptr) return; #define SET_STATE_TYPEDARRAY(name, field) \ target->Set(context, \ |