From faa447b256f61d46b4b4963d6bf3e77ccf229e97 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Mon, 3 Apr 2017 17:35:17 -0700 Subject: src: allow ArrayBufferView as instance of Buffer PR-URL: https://github.com/nodejs/node/pull/12223 Reviewed-By: Matteo Collina Reviewed-By: James M Snell Reviewed-By: Anna Henningsen --- src/node_buffer.cc | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'src/node_buffer.cc') diff --git a/src/node_buffer.cc b/src/node_buffer.cc index d8879094fa9..50760df8a38 100644 --- a/src/node_buffer.cc +++ b/src/node_buffer.cc @@ -70,6 +70,7 @@ namespace Buffer { using v8::ArrayBuffer; using v8::ArrayBufferCreationMode; +using v8::ArrayBufferView; using v8::Context; using v8::EscapableHandleScope; using v8::FunctionCallbackInfo; @@ -195,41 +196,41 @@ inline MUST_USE_RESULT bool ParseArrayIndex(Local arg, // Buffer methods bool HasInstance(Local val) { - return val->IsUint8Array(); + return val->IsArrayBufferView(); } bool HasInstance(Local obj) { - return obj->IsUint8Array(); + return obj->IsArrayBufferView(); } char* Data(Local val) { - CHECK(val->IsUint8Array()); - Local ui = val.As(); + CHECK(val->IsArrayBufferView()); + Local ui = val.As(); ArrayBuffer::Contents ab_c = ui->Buffer()->GetContents(); return static_cast(ab_c.Data()) + ui->ByteOffset(); } char* Data(Local obj) { - CHECK(obj->IsUint8Array()); - Local ui = obj.As(); + CHECK(obj->IsArrayBufferView()); + Local ui = obj.As(); ArrayBuffer::Contents ab_c = ui->Buffer()->GetContents(); return static_cast(ab_c.Data()) + ui->ByteOffset(); } size_t Length(Local val) { - CHECK(val->IsUint8Array()); - Local ui = val.As(); + CHECK(val->IsArrayBufferView()); + Local ui = val.As(); return ui->ByteLength(); } size_t Length(Local obj) { - CHECK(obj->IsUint8Array()); - Local ui = obj.As(); + CHECK(obj->IsArrayBufferView()); + Local ui = obj.As(); return ui->ByteLength(); } @@ -800,7 +801,7 @@ void WriteFloatGeneric(const FunctionCallbackInfo& args) { THROW_AND_RETURN_UNLESS_BUFFER(env, args[0]); } - Local ts_obj = args[0].As(); + Local ts_obj = args[0].As(); ArrayBuffer::Contents ts_obj_c = ts_obj->Buffer()->GetContents(); const size_t ts_obj_offset = ts_obj->ByteOffset(); const size_t ts_obj_length = ts_obj->ByteLength(); -- cgit v1.2.3