Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Unified Diff: src/d8.cc

Issue 10389140: Improve typed arrays support in d8. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/d8.cc
diff --git a/src/d8.cc b/src/d8.cc
index 26d0bc10e101ad99984c77c9a79ab2f829acc75b..edd201bbdf1f2d40474a999160c4f5d568443ff2 100644
--- a/src/d8.cc
+++ b/src/d8.cc
@@ -315,8 +315,8 @@ static size_t convertToUint(Local<Value> 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<Value> Shell::CreateExternalArray(const Arguments& args,
Local<Value> 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<Value> 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<Value> Shell::CreateExternalArray(const Arguments& args,
array->SetIndexedPropertiesToExternalArrayData(
reinterpret_cast<uint8_t*>(data) + offset, type,
static_cast<int>(length));
- array->Set(String::New("length"),
- Int32::New(static_cast<int32_t>(length)), ReadOnly);
- array->Set(String::New("BYTES_PER_ELEMENT"),
- Int32::New(static_cast<int32_t>(element_size)));
+ array->Set(String::New("byteLength"),
+ Int32::New(static_cast<int32_t>(byteLength)), ReadOnly);
+ if (!is_array_buffer_construct) {
+ array->Set(String::New("length"),
+ Int32::New(static_cast<int32_t>(length)), ReadOnly);
+ array->Set(String::New("byteOffset"),
+ Int32::New(static_cast<int32_t>(offset)), ReadOnly);
+ array->Set(String::New("BYTES_PER_ELEMENT"),
+ Int32::New(static_cast<int32_t>(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;
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698