8066217: ArrayBuffer constructor was erroneous with zero args
Reviewed-by: sundar, hannesw
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArrayBuffer.java Mon Mar 16 17:01:47 2015 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArrayBuffer.java Mon Mar 16 16:17:19 2015 +0100
@@ -26,7 +26,9 @@
package jdk.nashorn.internal.objects;
import static jdk.nashorn.internal.runtime.ECMAErrors.typeError;
+
import java.nio.ByteBuffer;
+
import jdk.nashorn.internal.objects.annotations.Attribute;
import jdk.nashorn.internal.objects.annotations.Constructor;
import jdk.nashorn.internal.objects.annotations.Function;
@@ -101,7 +103,7 @@
}
if (args.length == 0) {
- throw new RuntimeException("missing length argument");
+ return new NativeArrayBuffer(0);
}
return new NativeArrayBuffer(JSType.toInt32(args[0]));
--- a/nashorn/test/script/basic/typedarrays.js Mon Mar 16 17:01:47 2015 +0530
+++ b/nashorn/test/script/basic/typedarrays.js Mon Mar 16 16:17:19 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,