diff --git a/test/built-ins/ArrayBuffer/allocation-limit.js b/test/built-ins/ArrayBuffer/allocation-limit.js new file mode 100755 index 0000000000..864ad17014 --- /dev/null +++ b/test/built-ins/ArrayBuffer/allocation-limit.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.2.1 +description: > + Throws a RangeError if requested Data Block is too large. +info: > + ArrayBuffer( length ) + + ... + 6. Return AllocateArrayBuffer(NewTarget, byteLength). + + 6.2.6.1 CreateByteDataBlock(size) + ... + 2. Let db be a new Data Block value consisting of size bytes. If it is + impossible to create such a Data Block, throw a RangeError exception. + ... +---*/ + +assert.throws(RangeError, function() { + // Allocating 7 PiB should fail with a RangeError. + // Math.pow(1024, 5) = 1125899906842624 + new ArrayBuffer(7 * 1125899906842624); +}, "`length` parameter is 7 PiB"); + +assert.throws(RangeError, function() { + // Allocating almost 8 PiB should fail with a RangeError. + // Math.pow(2, 53) = 9007199254740992 + new ArrayBuffer(9007199254740992 - 1); +}, "`length` parameter is Math.pow(2, 53) - 1"); diff --git a/test/built-ins/ArrayBuffer/data-allocation-after-object-creation.js b/test/built-ins/ArrayBuffer/data-allocation-after-object-creation.js new file mode 100755 index 0000000000..cfce2c3e7f --- /dev/null +++ b/test/built-ins/ArrayBuffer/data-allocation-after-object-creation.js @@ -0,0 +1,38 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.2.1 +description: > + The new ArrayBuffer instance is created prior to allocating the Data Block. +info: > + ArrayBuffer( length ) + + ... + 6. Return AllocateArrayBuffer(NewTarget, byteLength). + + AllocateArrayBuffer( constructor, byteLength ) + 1. Let obj be OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%", + «[[ArrayBufferData]], [[ArrayBufferByteLength]]» ). + 2. ReturnIfAbrupt(obj). + ... + 4. Let block be CreateByteDataBlock(byteLength). + 5. ReturnIfAbrupt(block). + ... +features: [Reflect.construct] +---*/ + +function DummyError() { } + +var newTarget = function(){}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get: function() { + throw new DummyError(); + } +}); + +assert.throws(DummyError, function() { + // Allocating 7 PiB should fail with a RangeError. + // Math.pow(1024, 5) = 1125899906842624 + Reflect.construct(ArrayBuffer, [7 * 1125899906842624], newTarget); +}); diff --git a/test/built-ins/ArrayBuffer/length-is-absent.js b/test/built-ins/ArrayBuffer/length-is-absent.js new file mode 100755 index 0000000000..fd657ec2db --- /dev/null +++ b/test/built-ins/ArrayBuffer/length-is-absent.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.2.1 +description: > + The `length` parameter must be a positive, numeric integral value. +info: > + ArrayBuffer( length ) + + ... + 2. Let numberLength be ToNumber(length). + 3. Let byteLength be ToLength(numberLength). + 4. ReturnIfAbrupt(byteLength). + 5. If SameValueZero(numberLength, byteLength) is false, throw a RangeError exception. + ... +---*/ + +assert.throws(RangeError, function() { + new ArrayBuffer(); +}, "`length` parameter absent"); diff --git a/test/built-ins/ArrayBuffer/length-is-not-number.js b/test/built-ins/ArrayBuffer/length-is-not-number.js new file mode 100755 index 0000000000..f40a44588e --- /dev/null +++ b/test/built-ins/ArrayBuffer/length-is-not-number.js @@ -0,0 +1,35 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.2.1 +description: > + The `length` parameter is converted to a number value. +info: > + ArrayBuffer( length ) + + ... + 2. Let numberLength be ToNumber(length). + 3. Let byteLength be ToLength(numberLength). + 4. ReturnIfAbrupt(byteLength). + 5. If SameValueZero(numberLength, byteLength) is false, throw a RangeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(RangeError, function() { + new ArrayBuffer(undefined); +}, "`length` parameter is undefined"); + +var result = new ArrayBuffer(null); +assert.sameValue(result.byteLength, 0, "`length` parameter is null"); + +var result = new ArrayBuffer(true); +assert.sameValue(result.byteLength, 1, "`length` parameter is a Boolean"); + +var result = new ArrayBuffer(""); +assert.sameValue(result.byteLength, 0, "`length` parameter is a String"); + +assert.throws(TypeError, function() { + new ArrayBuffer(Symbol()); +}, "`length` parameter is a Symbol"); diff --git a/test/built-ins/ArrayBuffer/newtarget-prototype-is-not-object.js b/test/built-ins/ArrayBuffer/newtarget-prototype-is-not-object.js new file mode 100755 index 0000000000..a58b531cf6 --- /dev/null +++ b/test/built-ins/ArrayBuffer/newtarget-prototype-is-not-object.js @@ -0,0 +1,48 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.2.1 +description: > + [[Prototype]] defaults to %ArrayBufferPrototype% if NewTarget.prototype is not an object. +info: > + ArrayBuffer( length ) + + ArrayBuffer called with argument length performs the following steps: + + ... + 6. Return AllocateArrayBuffer(NewTarget, byteLength). + + AllocateArrayBuffer( constructor, byteLength ) + 1. Let obj be OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%", + «[[ArrayBufferData]], [[ArrayBufferByteLength]]» ). + 2. ReturnIfAbrupt(obj). + ... +features: [Reflect.construct, Symbol] +---*/ + +function newTarget() { } + +newTarget.prototype = undefined; +var arrayBuffer = Reflect.construct(ArrayBuffer, [1], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), ArrayBuffer.prototype, "newTarget.prototype is undefined"); + +newTarget.prototype = null; +var arrayBuffer = Reflect.construct(ArrayBuffer, [2], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), ArrayBuffer.prototype, "newTarget.prototype is null"); + +newTarget.prototype = true; +var arrayBuffer = Reflect.construct(ArrayBuffer, [3], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), ArrayBuffer.prototype, "newTarget.prototype is a Boolean"); + +newTarget.prototype = ""; +var arrayBuffer = Reflect.construct(ArrayBuffer, [4], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), ArrayBuffer.prototype, "newTarget.prototype is a String"); + +newTarget.prototype = Symbol(); +var arrayBuffer = Reflect.construct(ArrayBuffer, [5], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), ArrayBuffer.prototype, "newTarget.prototype is a Symbol"); + +newTarget.prototype = 1; +var arrayBuffer = Reflect.construct(ArrayBuffer, [6], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), ArrayBuffer.prototype, "newTarget.prototype is a Number"); diff --git a/test/built-ins/ArrayBuffer/number-conversion.js b/test/built-ins/ArrayBuffer/number-conversion.js new file mode 100755 index 0000000000..75bbb3b8f6 --- /dev/null +++ b/test/built-ins/ArrayBuffer/number-conversion.js @@ -0,0 +1,27 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.2.1 +description: > + The `length` parameter is converted to a number value. +info: > + ArrayBuffer( length ) + + ... + 2. Let numberLength be ToNumber(length). + ... +---*/ + +var log = ""; +var lengthValue = { + valueOf: function() { + log += "ok"; + return 10; + } +}; + +var arrayBuffer = new ArrayBuffer(lengthValue); + +assert.sameValue(log, "ok"); +assert.sameValue(arrayBuffer.byteLength, 10); diff --git a/test/built-ins/ArrayBuffer/positive-integer-length.js b/test/built-ins/ArrayBuffer/positive-integer-length.js new file mode 100755 index 0000000000..f1f40800e3 --- /dev/null +++ b/test/built-ins/ArrayBuffer/positive-integer-length.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.2.1 +description: > + The `length` parameter must be a positive, numeric integral value. +info: > + ArrayBuffer( length ) + + ... + 2. Let numberLength be ToNumber(length). + 3. Let byteLength be ToLength(numberLength). + 4. ReturnIfAbrupt(byteLength). + 5. If SameValueZero(numberLength, byteLength) is false, throw a RangeError exception. + ... +---*/ + +assert.throws(RangeError, function() { + new ArrayBuffer(-10); +}, "`length` parameter is negative"); + +assert.throws(RangeError, function() { + new ArrayBuffer(3.8); +}, "`length` parameter is not integral value"); + +assert.throws(RangeError, function() { + // Math.pow(2, 53) = 9007199254740992 + new ArrayBuffer(9007199254740992); +}, "`length` parameter is too large"); + +assert.throws(RangeError, function() { + new ArrayBuffer(+Infinity); +}, "`length` parameter is positive Infinity"); + +assert.throws(RangeError, function() { + new ArrayBuffer(-Infinity); +}, "`length` parameter is negative Infinity"); + +assert.throws(RangeError, function() { + new ArrayBuffer(NaN); +}, "`length` parameter is NaN"); diff --git a/test/built-ins/ArrayBuffer/prototype-from-newtarget.js b/test/built-ins/ArrayBuffer/prototype-from-newtarget.js new file mode 100755 index 0000000000..63a183d758 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype-from-newtarget.js @@ -0,0 +1,34 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.2.1 +description: > + The [[Prototype]] internal slot is computed from NewTarget. +info: > + ArrayBuffer( length ) + + ArrayBuffer called with argument length performs the following steps: + + ... + 6. Return AllocateArrayBuffer(NewTarget, byteLength). + + AllocateArrayBuffer( constructor, byteLength ) + 1. Let obj be OrdinaryCreateFromConstructor(constructor, "%ArrayBufferPrototype%", + «[[ArrayBufferData]], [[ArrayBufferByteLength]]» ). + 2. ReturnIfAbrupt(obj). + ... +features: [Reflect.construct] +---*/ + +var arrayBuffer = Reflect.construct(ArrayBuffer, [8], Object); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), Object.prototype, "NewTarget is built-in Object constructor"); + +var newTarget = function(){}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get: function() { + return Array.prototype; + } +}); +var arrayBuffer = Reflect.construct(ArrayBuffer, [16], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), Array.prototype, "NewTarget is BoundFunction with accessor"); diff --git a/test/built-ins/ArrayBuffer/prototype/constructor.js b/test/built-ins/ArrayBuffer/prototype/constructor.js new file mode 100755 index 0000000000..dd71321368 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/constructor.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.2 +description: > + The `ArrayBuffer.prototype.constructor` property descriptor. +info: > + The initial value of ArrayBuffer.prototype.constructor is the intrinsic + object %ArrayBuffer%. + + 17 ECMAScript Standard Built-in Objects: + Every other data property described in clauses 18 through 26 and in + Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(ArrayBuffer.prototype.constructor, ArrayBuffer); + +verifyNotEnumerable(ArrayBuffer.prototype, "constructor"); +verifyWritable(ArrayBuffer.prototype, "constructor"); +verifyConfigurable(ArrayBuffer.prototype, "constructor"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/context-is-not-arraybuffer-object.js b/test/built-ins/ArrayBuffer/prototype/slice/context-is-not-arraybuffer-object.js new file mode 100755 index 0000000000..ac747ea92d --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/context-is-not-arraybuffer-object.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.slice.call({}); +}, "`this` value is Object"); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.slice.call([]); +}, "`this` value is Array"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/context-is-not-object.js b/test/built-ins/ArrayBuffer/prototype/slice/context-is-not-object.js new file mode 100755 index 0000000000..bc87f95281 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/context-is-not-object.js @@ -0,0 +1,39 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Throws a TypeError if `this` is not an Object. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + ... +features: [Symbol] +---*/ + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.slice.call(undefined); +}, "`this` value is undefined"); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.slice.call(null); +}, "`this` value is null"); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.slice.call(true); +}, "`this` value is Boolean"); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.slice.call(""); +}, "`this` value is String"); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.slice.call(Symbol()); +}, "`this` value is Symbol"); + +assert.throws(TypeError, function() { + ArrayBuffer.prototype.slice.call(1); +}, "`this` value is Number"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/descriptor.js b/test/built-ins/ArrayBuffer/prototype/slice/descriptor.js new file mode 100755 index 0000000000..3efec484b8 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/descriptor.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + ArrayBuffer.prototype.slice has default data property attributes. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Every other data property described in clauses 18 through 26 and in + Annex B.2 has the attributes { [[Writable]]: true, [[Enumerable]]: false, + [[Configurable]]: true } unless otherwise specified. +includes: [propertyHelper.js] +---*/ + +verifyNotEnumerable(ArrayBuffer.prototype, "slice"); +verifyWritable(ArrayBuffer.prototype, "slice"); +verifyConfigurable(ArrayBuffer.prototype, "slice"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/end-default-if-absent.js b/test/built-ins/ArrayBuffer/prototype/slice/end-default-if-absent.js new file mode 100755 index 0000000000..2e5456505e --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/end-default-if-absent.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + The `end` index defaults to [[ArrayBufferByteLength]] if absent. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 9. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). + 10. ReturnIfAbrupt(relativeEnd). + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +var start = 6; +var result = arrayBuffer.slice(start); +assert.sameValue(result.byteLength, 2); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/end-default-if-undefined.js b/test/built-ins/ArrayBuffer/prototype/slice/end-default-if-undefined.js new file mode 100755 index 0000000000..65469b8d67 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/end-default-if-undefined.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + The `end` index defaults to [[ArrayBufferByteLength]] if undefined. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 9. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). + 10. ReturnIfAbrupt(relativeEnd). + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +var start = 6, end = undefined; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 2); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/end-exceeds-length.js b/test/built-ins/ArrayBuffer/prototype/slice/end-exceeds-length.js new file mode 100755 index 0000000000..84c6272e0b --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/end-exceeds-length.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Large `end` index is clamped to [[ArrayBufferByteLength]]. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 8. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +var start = 1, end = 12; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 7, "slice(1, 12)"); + +var start = 2, end = 0x100000000; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 6, "slice(2, 0x100000000)"); + +var start = 3, end = +Infinity; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 5, "slice(3, Infinity)"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/extensible.js b/test/built-ins/ArrayBuffer/prototype/slice/extensible.js new file mode 100755 index 0000000000..bcb5c647a4 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/extensible.js @@ -0,0 +1,16 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + ArrayBuffer.prototype.slice is extensible. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Unless specified otherwise, the [[Extensible]] internal slot + of a built-in object initially has the value true. +---*/ + +assert(Object.isExtensible(ArrayBuffer.prototype.slice)); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/length.js b/test/built-ins/ArrayBuffer/prototype/slice/length.js new file mode 100755 index 0000000000..90f20d259c --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/length.js @@ -0,0 +1,29 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + ArrayBuffer.prototype.slice.length is 2. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, has a length + property whose value is an integer. Unless otherwise specified, this + value is equal to the largest number of named arguments shown in the + subclause headings for the function description, including optional + parameters. However, rest parameters shown using the form “...name” + are not included in the default argument count. + + Unless otherwise specified, the length property of a built-in Function + object has the attributes { [[Writable]]: false, [[Enumerable]]: false, + [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(ArrayBuffer.prototype.slice.length, 2); + +verifyNotEnumerable(ArrayBuffer.prototype.slice, "length"); +verifyNotWritable(ArrayBuffer.prototype.slice, "length"); +verifyConfigurable(ArrayBuffer.prototype.slice, "length"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/name.js b/test/built-ins/ArrayBuffer/prototype/slice/name.js new file mode 100755 index 0000000000..949362d6d1 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/name.js @@ -0,0 +1,26 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + ArrayBuffer.prototype.slice.name is "slice". +info: > + ArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(ArrayBuffer.prototype.slice.name, "slice"); + +verifyNotEnumerable(ArrayBuffer.prototype.slice, "name"); +verifyNotWritable(ArrayBuffer.prototype.slice, "name"); +verifyConfigurable(ArrayBuffer.prototype.slice, "name"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/negative-end.js b/test/built-ins/ArrayBuffer/prototype/slice/negative-end.js new file mode 100755 index 0000000000..d4b8edfc51 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/negative-end.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Negative `end` index is relative to [[ArrayBufferByteLength]]. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 8. If relativeEnd < 0, let final be max((len + relativeEnd),0); else let final be min(relativeEnd, len). + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +var start = 2, end = -4; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 2, "slice(2, -4)"); + +var start = 2, end = -10; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(2, -10)"); + +var start = 2, end = -Infinity; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(2, -Infinity)"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/negative-start.js b/test/built-ins/ArrayBuffer/prototype/slice/negative-start.js new file mode 100755 index 0000000000..cfae7b0764 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/negative-start.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Negative `start` index is relative to [[ArrayBufferByteLength]]. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 8. If relativeStart < 0, let first be max((len + relativeStart),0); else let first be min(relativeStart, len). + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +var start = -5, end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 3, "slice(-5, 6)"); + +var start = -12, end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 6, "slice(-12, 6)"); + +var start = -Infinity, end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 6, "slice(-Infinity, 6)"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/nonconstructor.js b/test/built-ins/ArrayBuffer/prototype/slice/nonconstructor.js new file mode 100755 index 0000000000..3a1b160193 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/nonconstructor.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + ArrayBuffer.prototype.slice is not a constructor function. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified + in the description of a particular function. +---*/ + +assert.sameValue(Object.prototype.hasOwnProperty.call(ArrayBuffer.prototype.slice, "prototype"), false); + +var arrayBuffer = new ArrayBuffer(8); +assert.throws(TypeError, function() { new arrayBuffer.slice(); }); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/number-conversion.js b/test/built-ins/ArrayBuffer/prototype/slice/number-conversion.js new file mode 100755 index 0000000000..7ed956ee70 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/number-conversion.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + ToInteger(start) is called before ToInteger(end). +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 6. Let relativeStart be ToInteger(start). + 7. ReturnIfAbrupt(relativeStart). + ... + 9. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). + 10. ReturnIfAbrupt(relativeEnd). + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +var log = ""; +var start = { + valueOf: function() { + log += "start-"; + return 0; + } +}; +var end = { + valueOf: function() { + log += "end"; + return 8; + } +}; + +arrayBuffer.slice(start, end); +assert.sameValue(log, "start-end"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/species-constructor-is-not-object.js b/test/built-ins/ArrayBuffer/prototype/slice/species-constructor-is-not-object.js new file mode 100755 index 0000000000..9d60c565e5 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/species-constructor-is-not-object.js @@ -0,0 +1,42 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Throws TypeError if `constructor` property is not an object. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + ... + 2. Let C be Get(O, "constructor"). + 3. ReturnIfAbrupt(C). + 4. If C is undefined, return defaultConstructor. + 5. If Type(C) is not Object, throw a TypeError exception. + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +function callSlice() { arrayBuffer.slice(); } + +arrayBuffer.constructor = null; +assert.throws(TypeError, callSlice, "`constructor` value is null"); + +arrayBuffer.constructor = true; +assert.throws(TypeError, callSlice, "`constructor` value is Boolean"); + +arrayBuffer.constructor = ""; +assert.throws(TypeError, callSlice, "`constructor` value is String"); + +arrayBuffer.constructor = Symbol(); +assert.throws(TypeError, callSlice, "`constructor` value is Symbol"); + +arrayBuffer.constructor = 1; +assert.throws(TypeError, callSlice, "`constructor` value is Number"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/species-constructor-is-undefined.js b/test/built-ins/ArrayBuffer/prototype/slice/species-constructor-is-undefined.js new file mode 100755 index 0000000000..33512075ee --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/species-constructor-is-undefined.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Uses default constructor is `constructor` property is undefined. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + ... + 2. Let C be Get(O, "constructor"). + 3. ReturnIfAbrupt(C). + 4. If C is undefined, return defaultConstructor. + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); +arrayBuffer.constructor = undefined; + +var result = arrayBuffer.slice(); +assert.sameValue(Object.getPrototypeOf(result), ArrayBuffer.prototype); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/species-is-not-constructor.js b/test/built-ins/ArrayBuffer/prototype/slice/species-is-not-constructor.js new file mode 100755 index 0000000000..6a883a3fdc --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/species-is-not-constructor.js @@ -0,0 +1,37 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Throws a TypeError if species constructor is not a constructor function. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + ... + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). + ... + 9. If IsConstructor(S) is true, return S. + 10. Throw a TypeError exception. +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; + +var arrayBuffer = new ArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +function callSlice() { arrayBuffer.slice(); } + +speciesConstructor[Symbol.species] = {}; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Object"); + +speciesConstructor[Symbol.species] = Function.prototype; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Function.prototype"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/species-is-not-object.js b/test/built-ins/ArrayBuffer/prototype/slice/species-is-not-object.js new file mode 100755 index 0000000000..4057829fba --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/species-is-not-object.js @@ -0,0 +1,43 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Throws a TypeError if species constructor is not an object. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + ... + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). + 8. If S is either undefined or null, return defaultConstructor. + 9. If IsConstructor(S) is true, return S. + 10. Throw a TypeError exception. +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; + +var arrayBuffer = new ArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +function callSlice() { arrayBuffer.slice(); } + +speciesConstructor[Symbol.species] = true; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Boolean"); + +speciesConstructor[Symbol.species] = ""; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is String"); + +speciesConstructor[Symbol.species] = Symbol(); +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Symbol"); + +speciesConstructor[Symbol.species] = 1; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Number"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/species-is-null.js b/test/built-ins/ArrayBuffer/prototype/slice/species-is-null.js new file mode 100755 index 0000000000..9d3405ad9f --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/species-is-null.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Uses default constructor is species constructor is null. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + ... + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). + 8. If S is either undefined or null, return defaultConstructor. + ... +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = null; + +var arrayBuffer = new ArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +var result = arrayBuffer.slice(); +assert.sameValue(Object.getPrototypeOf(result), ArrayBuffer.prototype); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/species-is-undefined.js b/test/built-ins/ArrayBuffer/prototype/slice/species-is-undefined.js new file mode 100755 index 0000000000..de6e4edecf --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/species-is-undefined.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Uses default constructor is species constructor is undefined. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + ... + + 7.3.20 SpeciesConstructor ( O, defaultConstructor ) + ... + 6. Let S be Get(C, @@species). + 7. ReturnIfAbrupt(S). + 8. If S is either undefined or null, return defaultConstructor. + ... +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = undefined; + +var arrayBuffer = new ArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +var result = arrayBuffer.slice(); +assert.sameValue(Object.getPrototypeOf(result), ArrayBuffer.prototype); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/species-returns-larger-arraybuffer.js b/test/built-ins/ArrayBuffer/prototype/slice/species-returns-larger-arraybuffer.js new file mode 100755 index 0000000000..c57044c7ea --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/species-returns-larger-arraybuffer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Does not throw TypeError if new ArrayBuffer is too large. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + 15. Let new be Construct(ctor, «newLen»). + 16. ReturnIfAbrupt(new). + ... + 20. If the value of new’s [[ArrayBufferByteLength]] internal slot < newLen, throw a TypeError exception. + ... +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return new ArrayBuffer(10); +}; + +var arrayBuffer = new ArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +var result = arrayBuffer.slice(); +assert.sameValue(result.byteLength, 10); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/species-returns-not-arraybuffer.js b/test/built-ins/ArrayBuffer/prototype/slice/species-returns-not-arraybuffer.js new file mode 100755 index 0000000000..116f134f72 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/species-returns-not-arraybuffer.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Throws a TypeError if new object is not an ArrayBuffer instance. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + 15. Let new be Construct(ctor, «newLen»). + 16. ReturnIfAbrupt(new). + 17. If new does not have an [[ArrayBufferData]] internal slot, throw a TypeError exception. + ... +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return {}; +}; + +var arrayBuffer = new ArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +assert.throws(TypeError, function() { + arrayBuffer.slice(); +}); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/species-returns-same-arraybuffer.js b/test/built-ins/ArrayBuffer/prototype/slice/species-returns-same-arraybuffer.js new file mode 100755 index 0000000000..f5871d339f --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/species-returns-same-arraybuffer.js @@ -0,0 +1,33 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Throws a TypeError if species constructor returns `this` value. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + 1. Let O be the this value. + ... + 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + 15. Let new be Construct(ctor, «newLen»). + 16. ReturnIfAbrupt(new). + ... + 19. If SameValue(new, O) is true, throw a TypeError exception. + ... +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return arrayBuffer; +}; + +var arrayBuffer = new ArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +assert.throws(TypeError, function() { + arrayBuffer.slice(); +}); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/species-returns-smaller-arraybuffer.js b/test/built-ins/ArrayBuffer/prototype/slice/species-returns-smaller-arraybuffer.js new file mode 100755 index 0000000000..d14f5da165 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/species-returns-smaller-arraybuffer.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Throws a TypeError if new ArrayBuffer is too small. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + 15. Let new be Construct(ctor, «newLen»). + 16. ReturnIfAbrupt(new). + ... + 20. If the value of new’s [[ArrayBufferByteLength]] internal slot < newLen, throw a TypeError exception. + ... +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return new ArrayBuffer(4); +}; + +var arrayBuffer = new ArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +assert.throws(TypeError, function() { + arrayBuffer.slice(); +}); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/species.js b/test/built-ins/ArrayBuffer/prototype/slice/species.js new file mode 100755 index 0000000000..9aa718a606 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/species.js @@ -0,0 +1,32 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + New ArrayBuffer instance is created from SpeciesConstructor. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 13. Let ctor be SpeciesConstructor(O, %ArrayBuffer%). + 14. ReturnIfAbrupt(ctor). + 15. Let new be Construct(ctor, «newLen»). + 16. ReturnIfAbrupt(new). + ... + 26. Return new. +features: [Symbol.species] +---*/ + +var resultBuffer; + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return resultBuffer = new ArrayBuffer(length); +}; + +var arrayBuffer = new ArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +var result = arrayBuffer.slice(); +assert.sameValue(result, resultBuffer); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/start-default-if-absent.js b/test/built-ins/ArrayBuffer/prototype/slice/start-default-if-absent.js new file mode 100755 index 0000000000..1b32c7b93f --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/start-default-if-absent.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + The `start` index defaults to 0 if absent. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 6. Let relativeStart be ToInteger(start). + 7. ReturnIfAbrupt(relativeStart). + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +var result = arrayBuffer.slice(); +assert.sameValue(result.byteLength, 8); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/start-default-if-undefined.js b/test/built-ins/ArrayBuffer/prototype/slice/start-default-if-undefined.js new file mode 100755 index 0000000000..52a526d7a8 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/start-default-if-undefined.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + The `start` index defaults to 0 if undefined. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 6. Let relativeStart be ToInteger(start). + 7. ReturnIfAbrupt(relativeStart). + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +var start = undefined, end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 6); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/start-exceeds-end.js b/test/built-ins/ArrayBuffer/prototype/slice/start-exceeds-end.js new file mode 100755 index 0000000000..e5f9cddadd --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/start-exceeds-end.js @@ -0,0 +1,20 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Returns zero-length buffer if `start` index exceeds `end` index. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 12. Let newLen be max(final-first,0). + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +var start = 5, end = 4; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/start-exceeds-length.js b/test/built-ins/ArrayBuffer/prototype/slice/start-exceeds-length.js new file mode 100755 index 0000000000..c95259e59e --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/start-exceeds-length.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + Large `start` index is clamped to [[ArrayBufferByteLength]]. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 8. If relativeStart < 0, let first be max((len + relativeStart),0); else let first be min(relativeStart, len). + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +var start = 10, end = 8; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(10, 8)"); + +var start = 0x100000000, end = 7; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(0x100000000, 7)"); + +var start = +Infinity, end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(+Infinity, 6)"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/tointeger-conversion-end.js b/test/built-ins/ArrayBuffer/prototype/slice/tointeger-conversion-end.js new file mode 100755 index 0000000000..52b7476b52 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/tointeger-conversion-end.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + The `end` index parameter is converted to an integral numeric value. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 9. If end is undefined, let relativeEnd be len; else let relativeEnd be ToInteger(end). + 10. ReturnIfAbrupt(relativeEnd). + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +var start = 0, end = 4.5; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 4, "slice(0, 4.5)"); + +var start = 0, end = NaN; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(0, NaN)"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/tointeger-conversion-start.js b/test/built-ins/ArrayBuffer/prototype/slice/tointeger-conversion-start.js new file mode 100755 index 0000000000..d2ed415499 --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/tointeger-conversion-start.js @@ -0,0 +1,25 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.4.3 +description: > + The `start` index parameter is converted to an integral numeric value. +info: > + ArrayBuffer.prototype.slice ( start, end ) + + ... + 6. Let relativeStart be ToInteger(start). + 7. ReturnIfAbrupt(relativeStart). + ... +---*/ + +var arrayBuffer = new ArrayBuffer(8); + +var start = 4.5, end = 8; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 4, "slice(4.5, 8)"); + +var start = NaN, end = 8; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 8, "slice(NaN, 8)"); diff --git a/test/built-ins/ArrayBuffer/undefined-newtarget.js b/test/built-ins/ArrayBuffer/undefined-newtarget.js new file mode 100755 index 0000000000..c6349c2404 --- /dev/null +++ b/test/built-ins/ArrayBuffer/undefined-newtarget.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.2.1 +description: > + Throws a TypeError if ArrayBuffer is called as a function. +info: > + ArrayBuffer( length ) + + ArrayBuffer called with argument length performs the following steps: + + 1. If NewTarget is undefined, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + ArrayBuffer(); +}); + +assert.throws(TypeError, function() { + ArrayBuffer(10); +}); diff --git a/test/built-ins/ArrayBuffer/zero-length.js b/test/built-ins/ArrayBuffer/zero-length.js new file mode 100755 index 0000000000..19b03635c0 --- /dev/null +++ b/test/built-ins/ArrayBuffer/zero-length.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.1.2.1 +description: > + The `length` parameter can be zero. +info: > + ArrayBuffer( length ) + + ... + 2. Let numberLength be ToNumber(length). + 3. Let byteLength be ToLength(numberLength). + 4. ReturnIfAbrupt(byteLength). + 5. If SameValueZero(numberLength, byteLength) is false, throw a RangeError exception. + ... +---*/ + +var positiveZero = new ArrayBuffer(+0); +assert.sameValue(positiveZero.byteLength, 0); + +var negativeZero = new ArrayBuffer(-0); +assert.sameValue(negativeZero.byteLength, 0);