src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeArrayBuffer.java

Print this page

        

@@ -24,11 +24,13 @@
  */
 
 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;
 import jdk.nashorn.internal.objects.annotations.Getter;
 import jdk.nashorn.internal.objects.annotations.ScriptClass;

@@ -99,11 +101,13 @@
         if (!newObj) {
             throw typeError("constructor.requires.new", "ArrayBuffer");
         }
 
         if (args.length == 0) {
-            throw new RuntimeException("missing length argument");
+            //For ES6 rev28+ we should throw a TypeError here. None of the other runtimes
+            //currently do it, though, so I have chosen to not implement that for now.
+            return new NativeArrayBuffer(0);
         }
 
         return new NativeArrayBuffer(JSType.toInt32(args[0]));
     }