diff options
author | James M Snell <jasnell@gmail.com> | 2020-04-11 05:42:37 +0300 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2020-04-14 03:21:43 +0300 |
commit | cecb08f0c828dd5da8e4c6f8414bb1f9c778319e (patch) | |
tree | 04352ecba6680b8a689c0b3ea8f620de84c5c7b5 /src/node_http2.cc | |
parent | 81c03bcebd3841e5bcbd3af0a03e102b80d10d12 (diff) |
src: add AliasedStruct utility
For http2 (and eventually QUIC) we have a struct that is backed
by a v8::BackingStore and exposed to the JavaScript side as an
ArrayBuffer and TypedArray. This is similar to AliasedBuffer
except that it is fronted by a struct on the C++ side.
```c++
struct foo {
uint32_t ex1;
uint32_t ex2;
};
AliasedStruct<foo> foo_;
foo_->ex1 = 1;
foo_->ex2 = 2;
foo_.GetArrayBuffer();
```
Signed-off-by: James M Snell <jasnell@gmail.com>
PR-URL: https://github.com/nodejs/node/pull/32778
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Gerhard Stöbich <deb2001-github@yahoo.de>
Diffstat (limited to 'src/node_http2.cc')
-rw-r--r-- | src/node_http2.cc | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/src/node_http2.cc b/src/node_http2.cc index d884be3e755..7477bfbb6d8 100644 --- a/src/node_http2.cc +++ b/src/node_http2.cc @@ -1,4 +1,5 @@ #include "aliased_buffer.h" +#include "aliased_struct-inl.h" #include "debug_utils-inl.h" #include "memory_tracker-inl.h" #include "node.h" @@ -18,7 +19,6 @@ namespace node { using v8::Array; using v8::ArrayBuffer; using v8::ArrayBufferView; -using v8::BackingStore; using v8::Boolean; using v8::Context; using v8::Float64Array; @@ -471,6 +471,7 @@ Http2Session::Http2Session(Http2State* http2_state, Local<Object> wrap, nghttp2_session_type type) : AsyncWrap(http2_state->env(), wrap, AsyncWrap::PROVIDER_HTTP2SESSION), + js_fields_(http2_state->env()->isolate()), session_type_(type), http2_state_(http2_state) { MakeWeak(); @@ -518,14 +519,8 @@ Http2Session::Http2Session(Http2State* http2_state, outgoing_storage_.reserve(1024); outgoing_buffers_.reserve(32); - // Make the js_fields_ property accessible to JS land. - js_fields_store_ = - ArrayBuffer::NewBackingStore(env()->isolate(), sizeof(SessionJSFields)); - js_fields_ = new(js_fields_store_->Data()) SessionJSFields; - - Local<ArrayBuffer> ab = ArrayBuffer::New(env()->isolate(), js_fields_store_); Local<Uint8Array> uint8_arr = - Uint8Array::New(ab, 0, kSessionUint8FieldCount); + Uint8Array::New(js_fields_.GetArrayBuffer(), 0, kSessionUint8FieldCount); USE(wrap->Set(env()->context(), env()->fields_string(), uint8_arr)); } @@ -536,7 +531,6 @@ Http2Session::~Http2Session() { // current_nghttp2_memory_ check passes. session_.reset(); CHECK_EQ(current_nghttp2_memory_, 0); - js_fields_->~SessionJSFields(); } std::string Http2Session::diagnostic_name() const { |