diff --git a/src/node_buffer.cc b/src/node_buffer.cc index 3cd047c0e7bf41..d87d38334add84 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -229,6 +229,18 @@ MaybeLocal New(Environment* env, return ui; } +MaybeLocal New(Isolate* isolate, + Local ab, + size_t byte_offset, + size_t length) { + Environment* env = Environment::GetCurrent(isolate); + if (env == nullptr) { + THROW_ERR_BUFFER_CONTEXT_NOT_AVAILABLE(isolate); + return MaybeLocal(); + } + return New(env, ab, byte_offset, length); +} + MaybeLocal New(Isolate* isolate, Local string, diff --git a/src/node_buffer.h b/src/node_buffer.h index 122afc37709f73..11010017ce0df8 100644 --- a/src/node_buffer.h +++ b/src/node_buffer.h @@ -65,6 +65,12 @@ NODE_EXTERN v8::MaybeLocal New(v8::Isolate* isolate, char* data, size_t len); +// Creates a Buffer instance over an existing ArrayBuffer. +NODE_EXTERN v8::MaybeLocal New(v8::Isolate* isolate, + v8::Local ab, + size_t byte_offset, + size_t length); + // This is verbose to be explicit with inline commenting static inline bool IsWithinBounds(size_t off, size_t len, size_t max) { // Asking to seek too far into the buffer diff --git a/src/node_internals.h b/src/node_internals.h index 10ef3bf5ed22d3..2bd0ff78da7c33 100644 --- a/src/node_internals.h +++ b/src/node_internals.h @@ -157,7 +157,7 @@ v8::MaybeLocal New(Environment* env, char* data, size_t length, bool uses_malloc); -// Creates a Buffer instance over an existing Uint8Array. +// Creates a Buffer instance over an existing ArrayBuffer. v8::MaybeLocal New(Environment* env, v8::Local ab, size_t byte_offset,