Reviewers: Benedikt Meurer, rossberg,

Message:
PTAL

Description:
Allow parameterless typed array constructors.

ES6 spec tacitly allows them, and they are allowed in Firefox and in
WebKit/Blink.

[email protected],[email protected]

Please review this at https://codereview.chromium.org/18769005/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/messages.js
  M src/typedarray.js
  M test/mjsunit/harmony/typedarrays.js


Index: src/messages.js
diff --git a/src/messages.js b/src/messages.js
index 6c9e2d79b26d12d87e1dc5b03b99cc7e7318d2ad..35f3255fd911f00a503d868faeea11822e87ecfe 100644
--- a/src/messages.js
+++ b/src/messages.js
@@ -104,8 +104,6 @@ var kMessages = {
   observe_perform_non_function:  ["Cannot perform non-function"],
   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."],
   not_typed_array:               ["this is not a typed array."],
   invalid_argument:              ["invalid_argument"],
data_view_not_array_buffer: ["First argument to DataView constructor must be an ArrayBuffer"],
Index: src/typedarray.js
diff --git a/src/typedarray.js b/src/typedarray.js
index 0d903550495be2a6d792d279b547e7229ebf4ce5..57d0c60f9ba00dfd4a00e1649d872057d76269f8 100644
--- a/src/typedarray.js
+++ b/src/typedarray.js
@@ -89,12 +89,11 @@ function CreateTypedArrayConstructor(name, elementSize, arrayId, constructor) {
     if (%_IsConstructCall()) {
       if (IS_ARRAYBUFFER(arg1)) {
         ConstructByArrayBuffer(this, arg1, arg2, arg3);
-      } else if (IS_NUMBER(arg1) || IS_STRING(arg1) || IS_BOOLEAN(arg1)) {
+      } else if (IS_NUMBER(arg1) || IS_STRING(arg1) ||
+                 IS_BOOLEAN(arg1) || IS_UNDEFINED(arg1)) {
         ConstructByLength(this, arg1);
-      } else if (!IS_UNDEFINED(arg1)){
-        ConstructByArrayLike(this, arg1);
       } else {
-        throw MakeTypeError("parameterless_typed_array_constr", [name]);
+        ConstructByArrayLike(this, arg1);
       }
     } else {
       throw MakeTypeError("constructor_not_function", [name])
Index: test/mjsunit/harmony/typedarrays.js
diff --git a/test/mjsunit/harmony/typedarrays.js b/test/mjsunit/harmony/typedarrays.js index e1b0e653d602e8fde9094ab8656d5fc476b39a25..99364c8101757a2b3b178807e3a88e22664adbd4 100644
--- a/test/mjsunit/harmony/typedarrays.js
+++ b/test/mjsunit/harmony/typedarrays.js
@@ -219,7 +219,6 @@ function TestTypedArray(proto, elementSize, typicalElement) { assertThrows(function() { new proto(unalignedArrayBuffer)}, RangeError); assertThrows(function() { new proto(unalignedArrayBuffer, 5*elementSize)},
                  RangeError);
-    assertThrows(function() { new proto() }, TypeError);
   }

   var aFromString = new proto("30");
@@ -250,6 +249,12 @@ function TestTypedArray(proto, elementSize, typicalElement) {
   assertSame(0, aOverAbLen0.length);
   assertSame(0, aOverAbLen0.byteLength);
   assertSame(0, aOverAbLen0.byteOffset);
+
+  var aNoParam = new proto();
+  assertSame(elementSize, aNoParam.BYTES_PER_ELEMENT);
+  assertSame(0, aNoParam.length);
+  assertSame(0, aNoParam.byteLength);
+  assertSame(0, aNoParam.byteOffset);
 }

 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.


Reply via email to