8066217: ArrayBuffer constructor was erroneous with zero args

Reviewed-by: sundar, hannesw
This commit is contained in:
Marcus Lagergren 2015-03-16 16:17:19 +01:00
parent cf37646b3f
commit 999ce35e84
2 changed files with 14 additions and 1 deletions

View File

@ -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 @@ public final class NativeArrayBuffer extends ScriptObject {
}
if (args.length == 0) {
throw new RuntimeException("missing length argument");
return new NativeArrayBuffer(0);
}
return new NativeArrayBuffer(JSType.toInt32(args[0]));

View File

@ -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,