mirror of https://github.com/tc39/test262.git
Merge pull request #448 from anba/arraybuffer_coverage
Add tests for ArrayBuffer and ArrayBuffer.prototype.slice
This commit is contained in:
commit
07eafc6651
|
@ -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");
|
|
@ -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);
|
||||||
|
});
|
|
@ -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");
|
|
@ -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");
|
|
@ -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");
|
|
@ -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);
|
|
@ -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");
|
|
@ -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");
|
|
@ -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");
|
23
test/built-ins/ArrayBuffer/prototype/slice/context-is-not-arraybuffer-object.js
vendored
Executable file
23
test/built-ins/ArrayBuffer/prototype/slice/context-is-not-arraybuffer-object.js
vendored
Executable file
|
@ -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");
|
|
@ -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");
|
|
@ -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");
|
|
@ -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);
|
|
@ -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);
|
|
@ -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)");
|
|
@ -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));
|
|
@ -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");
|
|
@ -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");
|
|
@ -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)");
|
|
@ -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)");
|
|
@ -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(); });
|
|
@ -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");
|
42
test/built-ins/ArrayBuffer/prototype/slice/species-constructor-is-not-object.js
vendored
Executable file
42
test/built-ins/ArrayBuffer/prototype/slice/species-constructor-is-not-object.js
vendored
Executable file
|
@ -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");
|
28
test/built-ins/ArrayBuffer/prototype/slice/species-constructor-is-undefined.js
vendored
Executable file
28
test/built-ins/ArrayBuffer/prototype/slice/species-constructor-is-undefined.js
vendored
Executable file
|
@ -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);
|
37
test/built-ins/ArrayBuffer/prototype/slice/species-is-not-constructor.js
vendored
Executable file
37
test/built-ins/ArrayBuffer/prototype/slice/species-is-not-constructor.js
vendored
Executable file
|
@ -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");
|
|
@ -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");
|
|
@ -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);
|
|
@ -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);
|
31
test/built-ins/ArrayBuffer/prototype/slice/species-returns-larger-arraybuffer.js
vendored
Executable file
31
test/built-ins/ArrayBuffer/prototype/slice/species-returns-larger-arraybuffer.js
vendored
Executable file
|
@ -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);
|
31
test/built-ins/ArrayBuffer/prototype/slice/species-returns-not-arraybuffer.js
vendored
Executable file
31
test/built-ins/ArrayBuffer/prototype/slice/species-returns-not-arraybuffer.js
vendored
Executable file
|
@ -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();
|
||||||
|
});
|
33
test/built-ins/ArrayBuffer/prototype/slice/species-returns-same-arraybuffer.js
vendored
Executable file
33
test/built-ins/ArrayBuffer/prototype/slice/species-returns-same-arraybuffer.js
vendored
Executable file
|
@ -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();
|
||||||
|
});
|
32
test/built-ins/ArrayBuffer/prototype/slice/species-returns-smaller-arraybuffer.js
vendored
Executable file
32
test/built-ins/ArrayBuffer/prototype/slice/species-returns-smaller-arraybuffer.js
vendored
Executable file
|
@ -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();
|
||||||
|
});
|
|
@ -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);
|
|
@ -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);
|
21
test/built-ins/ArrayBuffer/prototype/slice/start-default-if-undefined.js
vendored
Executable file
21
test/built-ins/ArrayBuffer/prototype/slice/start-default-if-undefined.js
vendored
Executable file
|
@ -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);
|
|
@ -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);
|
|
@ -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)");
|
|
@ -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)");
|
25
test/built-ins/ArrayBuffer/prototype/slice/tointeger-conversion-start.js
vendored
Executable file
25
test/built-ins/ArrayBuffer/prototype/slice/tointeger-conversion-start.js
vendored
Executable file
|
@ -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)");
|
|
@ -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);
|
||||||
|
});
|
|
@ -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);
|
Loading…
Reference in New Issue