summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/node_buffer.cc12
-rw-r--r--src/node_buffer.h6
-rw-r--r--src/node_internals.h2
3 files changed, 19 insertions, 1 deletions
diff --git a/src/node_buffer.cc b/src/node_buffer.cc
index 3cd047c0e7..d87d38334a 100644
--- a/src/node_buffer.cc
+++ b/src/node_buffer.cc
@@ -229,6 +229,18 @@ MaybeLocal<Uint8Array> New(Environment* env,
return ui;
}
+MaybeLocal<Uint8Array> New(Isolate* isolate,
+ Local<ArrayBuffer> 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<Uint8Array>();
+ }
+ return New(env, ab, byte_offset, length);
+}
+
MaybeLocal<Object> New(Isolate* isolate,
Local<String> string,
diff --git a/src/node_buffer.h b/src/node_buffer.h
index 122afc3770..11010017ce 100644
--- a/src/node_buffer.h
+++ b/src/node_buffer.h
@@ -65,6 +65,12 @@ NODE_EXTERN v8::MaybeLocal<v8::Object> New(v8::Isolate* isolate,
char* data,
size_t len);
+// Creates a Buffer instance over an existing ArrayBuffer.
+NODE_EXTERN v8::MaybeLocal<v8::Uint8Array> New(v8::Isolate* isolate,
+ v8::Local<v8::ArrayBuffer> 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 10ef3bf5ed..2bd0ff78da 100644
--- a/src/node_internals.h
+++ b/src/node_internals.h
@@ -157,7 +157,7 @@ v8::MaybeLocal<v8::Object> 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<v8::Uint8Array> New(Environment* env,
v8::Local<v8::ArrayBuffer> ab,
size_t byte_offset,