changeset 1239:4ba23f4c0ed6

8066217: ArrayBuffer constructor was erroneous with zero args Reviewed-by: sundar, hannesw
author lagergren
date Tue, 17 Mar 2015 08:56:42 +0100
parents a9229fb1634b
children e024db176497
files src/jdk/nashorn/internal/objects/NativeArrayBuffer.java test/script/basic/typedarrays.js
diffstat 2 files changed, 12 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Thu Mar 12 13:45:00 2015 -0700
+++ b/src/jdk/nashorn/internal/objects/NativeArrayBuffer.java	Tue Mar 17 08:56:42 2015 +0100
@@ -101,7 +101,7 @@
         }
 
         if (args.length == 0) {
-            throw new RuntimeException("missing length argument");
+            return new NativeArrayBuffer(0);
         }
 
         return new NativeArrayBuffer(JSType.toInt32(args[0]));
--- a/test/script/basic/typedarrays.js	Thu Mar 12 13:45:00 2015 -0700
+++ b/test/script/basic/typedarrays.js	Tue Mar 17 08:56:42 2015 +0100
@@ -28,6 +28,17 @@
  * @run
  */
 
+//JDK-8066217, constructor for arraybuffer not behaving as per spec
+function checkLength(ab, l) {
+    if (ab.byteLength != l) {
+        throw "length error: " + ab.byteLength + " != " + l;
+    }
+}
+checkLength(new ArrayBuffer(), 0);
+checkLength(new ArrayBuffer(0), 0);
+checkLength(new ArrayBuffer(1024), 1024);
+checkLength(new ArrayBuffer(1,2,3), 1);
+checkLength(new ArrayBuffer([17]), 17);
 
 var typeDefinitions = [
 Int8Array,