Revision: 14518
Author: [email protected]
Date: Thu May 2 05:27:03 2013
Log: More typed array constructors.
[email protected]
Review URL: https://codereview.chromium.org/14845012
http://code.google.com/p/v8/source/detail?r=14518
Modified:
/branches/bleeding_edge/src/messages.js
/branches/bleeding_edge/src/typedarray.js
/branches/bleeding_edge/test/mjsunit/harmony/typedarrays.js
=======================================
--- /branches/bleeding_edge/src/messages.js Fri Apr 26 07:26:54 2013
+++ /branches/bleeding_edge/src/messages.js Thu May 2 05:27:03 2013
@@ -101,6 +101,8 @@
observe_type_non_string: ["Invalid changeRecord with
non-string 'type' property"],
observe_notify_non_notifier: ["notify called on non-notifier object"],
proto_poison_pill: ["Generic use of __proto__ accessor not
allowed"],
+ parameterless_typed_array_constr:
+ ["%0"," constructor should have at least
one argument."],
// RangeError
invalid_array_length: ["Invalid array length"],
invalid_array_buffer_length: ["Invalid array buffer length"],
=======================================
--- /branches/bleeding_edge/src/typedarray.js Thu May 2 04:36:48 2013
+++ /branches/bleeding_edge/src/typedarray.js Thu May 2 05:27:03 2013
@@ -122,13 +122,28 @@
var buffer = new $ArrayBuffer(byteLength);
%TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength);
}
+
+ function ConstructByArrayLike(obj, arrayLike) {
+ var length = arrayLike.length;
+ var l = IS_UNDEFINED(length) ? 0 : TO_POSITIVE_INTEGER(length);
+ var byteLength = l * elementSize;
+ var buffer = new $ArrayBuffer(byteLength);
+ %TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength);
+ for (var i = 0; i < l; i++) {
+ obj[i] = arrayLike[i];
+ }
+ }
return function (arg1, arg2, arg3) {
if (%_IsConstructCall()) {
if (IS_ARRAYBUFFER(arg1)) {
ConstructByArrayBuffer(this, arg1, arg2, arg3);
- } else {
+ } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || IS_BOOLEAN(arg1)) {
ConstructByLength(this, arg1);
+ } else if (!IS_UNDEFINED(arg1)){
+ ConstructByArrayLike(this, arg1);
+ } else {
+ throw MakeTypeError("parameterless_typed_array_constr", name);
}
} else {
return new constructor(arg1, arg2, arg3);
=======================================
--- /branches/bleeding_edge/test/mjsunit/harmony/typedarrays.js Thu May 2
04:36:48 2013
+++ /branches/bleeding_edge/test/mjsunit/harmony/typedarrays.js Thu May 2
05:27:03 2013
@@ -203,8 +203,29 @@
assertThrows(function() { new proto(unalignedArrayBuffer)},
RangeError);
assertThrows(function() { new proto(unalignedArrayBuffer,
5*elementSize)},
RangeError);
+ assertThrows(function() { new proto() }, TypeError);
}
+ var aFromString = new proto("30");
+ assertSame(elementSize, aFromString.BYTES_PER_ELEMENT);
+ assertSame(30, aFromString.length);
+ assertSame(30*elementSize, aFromString.byteLength);
+ assertSame(0, aFromString.byteOffset);
+ assertSame(30*elementSize, aFromString.buffer.byteLength);
+
+ var jsArray = [];
+ for (i = 0; i < 30; i++) {
+ jsArray.push(typicalElement);
+ }
+ var aFromArray = new proto(jsArray);
+ assertSame(elementSize, aFromArray.BYTES_PER_ELEMENT);
+ assertSame(30, aFromArray.length);
+ assertSame(30*elementSize, aFromArray.byteLength);
+ assertSame(0, aFromArray.byteOffset);
+ assertSame(30*elementSize, aFromArray.buffer.byteLength);
+ for (i = 0; i < 30; i++) {
+ assertSame(typicalElement, aFromArray[i]);
+ }
}
TestTypedArray(Uint8Array, 1, 0xFF);
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.