mirror of
https://github.com/nodejs/node.git
synced 2026-11-24 21:50:36 -05:00
src: expose ArrayBuffer version of Buffer::New()
This can be useful to create `Buffer` instances for already-existing `ArrayBuffer`s, e.g. ones created manually from a backing store with a free callback (of which our variant in the public API has some limitations). PR-URL: https://github.com/nodejs/node/pull/30476 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
db8144be31
commit
8d6a90384d
3 files changed
+19
-1
No files matched your search
@@ -231,6 +231,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,
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -160,7 +160,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,
|
||||
|
||||
Reference in new issue
Block a user