From 01dac9a99d60f1b646a9cd1661b41bd5bcf34a2d Mon Sep 17 00:00:00 2001 From: "rossberg@chromium.org" Date: Tue, 15 May 2012 09:21:18 +0000 Subject: [PATCH] Improve typed arrays support in d8. Add properties buffer, byteLength, and byteOffset to typed arrays. R=yangguo@chromium.org BUG= TEST= Review URL: https://chromiumcodereview.appspot.com/10389140 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11560 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/d8.cc | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/d8.cc b/src/d8.cc index 26d0bc1..edd201b 100644 --- a/src/d8.cc +++ b/src/d8.cc @@ -315,8 +315,8 @@ static size_t convertToUint(Local value_in, TryCatch* try_catch) { } -const char kArrayBufferReferencePropName[] = "_is_array_buffer_"; -const char kArrayBufferMarkerPropName[] = "_array_buffer_ref_"; +const char kArrayBufferMarkerPropName[] = "_is_array_buffer_"; +const char kArrayBufferReferencePropName[] = "_array_buffer_ref_"; static const int kExternalArrayAllocationHeaderSize = 2; @@ -353,10 +353,11 @@ Handle Shell::CreateExternalArray(const Arguments& args, Local length_value = (args.Length() < 3) ? (first_arg_is_array_buffer - ? args[0]->ToObject()->Get(String::New("length")) + ? args[0]->ToObject()->Get(String::New("byteLength")) : args[0]) : args[2]; - size_t length = convertToUint(length_value, &try_catch); + size_t byteLength = convertToUint(length_value, &try_catch); + size_t length = byteLength; if (try_catch.HasCaught()) return try_catch.Exception(); void* data = NULL; @@ -368,7 +369,7 @@ Handle Shell::CreateExternalArray(const Arguments& args, data = derived_from->GetIndexedPropertiesExternalArrayData(); size_t array_buffer_length = convertToUint( - derived_from->Get(String::New("length")), + derived_from->Get(String::New("byteLength")), &try_catch); if (try_catch.HasCaught()) return try_catch.Exception(); @@ -451,10 +452,20 @@ Handle Shell::CreateExternalArray(const Arguments& args, array->SetIndexedPropertiesToExternalArrayData( reinterpret_cast(data) + offset, type, static_cast(length)); - array->Set(String::New("length"), - Int32::New(static_cast(length)), ReadOnly); - array->Set(String::New("BYTES_PER_ELEMENT"), - Int32::New(static_cast(element_size))); + array->Set(String::New("byteLength"), + Int32::New(static_cast(byteLength)), ReadOnly); + if (!is_array_buffer_construct) { + array->Set(String::New("length"), + Int32::New(static_cast(length)), ReadOnly); + array->Set(String::New("byteOffset"), + Int32::New(static_cast(offset)), ReadOnly); + array->Set(String::New("BYTES_PER_ELEMENT"), + Int32::New(static_cast(element_size))); + // We currently support 'buffer' property only if constructed from a buffer. + if (first_arg_is_array_buffer) { + array->Set(String::New("buffer"), args[0], ReadOnly); + } + } return array; } -- 2.7.4