mirror of https://github.com/tc39/test262.git
fixup! Add tests for TypedArrays constructors
This commit is contained in:
parent
f8a4229bfd
commit
7a8120fb63
|
@ -12,7 +12,7 @@ info: >
|
|||
object has an [[ArrayBufferData]] internal slot.
|
||||
|
||||
...
|
||||
9. If offset modulo elementSize ≠ 0, throw a RangeError exception.
|
||||
10. If offset modulo elementSize ≠ 0, throw a RangeError exception.
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
---*/
|
||||
|
|
|
@ -20,10 +20,12 @@ includes: [testTypedArray.js]
|
|||
testWithTypedArrayConstructors(function(TA) {
|
||||
var bpe = TA.BYTES_PER_ELEMENT;
|
||||
|
||||
var buffer = new ArrayBuffer(bpe * 4);
|
||||
var buffer = new ArrayBuffer(bpe);
|
||||
|
||||
var ta1 = new TA(buffer);
|
||||
var ta2 = new TA(buffer);
|
||||
|
||||
assert.sameValue(ta1.buffer, buffer);
|
||||
assert.sameValue(ta2.buffer, buffer);
|
||||
assert.sameValue(ta1.buffer, ta2.buffer);
|
||||
});
|
||||
|
|
|
@ -24,10 +24,10 @@ includes: [testTypedArray.js]
|
|||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(4);
|
||||
var bytesPerElement = TA.BYTES_PER_ELEMENT;
|
||||
var length = typedArray.length;
|
||||
|
||||
assert.sameValue(length, 4, "length");
|
||||
assert.sameValue(typedArray.constructor, TA);
|
||||
assert.sameValue(
|
||||
Object.getPrototypeOf(typedArray), TA.prototype,
|
||||
"Object.getPrototypeOf(typedArray)"
|
||||
|
|
|
@ -22,7 +22,6 @@ var typedArraySample = new Int8Array(length);
|
|||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var typedArray = new TA(typedArraySample);
|
||||
var bytesPerElement = TA.BYTES_PER_ELEMENT;
|
||||
|
||||
assert.notSameValue(typedArray, typedArraySample);
|
||||
assert.sameValue(typedArray.length, length);
|
||||
|
|
|
@ -16,7 +16,6 @@ info: >
|
|||
6. Perform ? AllocateTypedArrayBuffer(O, len).
|
||||
...
|
||||
includes: [testTypedArray.js]
|
||||
features: [Symbol]
|
||||
---*/
|
||||
|
||||
var obj = {
|
||||
|
|
|
@ -30,15 +30,17 @@ features: [Symbol.species]
|
|||
var sample1 = new Int8Array();
|
||||
var sample2 = new Int16Array();
|
||||
|
||||
var ctor = function() {
|
||||
throw new Test262Error();
|
||||
};
|
||||
var m = { m() {} }.m;
|
||||
ctor[Symbol.species] = m;
|
||||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === Int8Array ? sample2 : sample1;
|
||||
var ctor = {};
|
||||
var o = { m() {} };
|
||||
|
||||
sample.buffer.constructor = ctor;
|
||||
|
||||
ctor[Symbol.species] = o.m;
|
||||
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
|
|
@ -32,58 +32,29 @@ var sample2 = new Int16Array();
|
|||
|
||||
testWithTypedArrayConstructors(function(TA) {
|
||||
var sample = TA === Int8Array ? sample2 : sample1;
|
||||
Object.defineProperty(sample.buffer, "constructor", {
|
||||
get: function() {
|
||||
return 1;
|
||||
},
|
||||
configurable: true
|
||||
});
|
||||
|
||||
sample.buffer.constructor = 1;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
Object.defineProperty(sample.buffer, "constructor", {
|
||||
get: function() {
|
||||
return true;
|
||||
},
|
||||
configurable: true
|
||||
});
|
||||
|
||||
sample.buffer.constructor = true;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
Object.defineProperty(sample.buffer, "constructor", {
|
||||
get: function() {
|
||||
return '';
|
||||
},
|
||||
configurable: true
|
||||
});
|
||||
|
||||
sample.buffer.constructor = "";
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
Object.defineProperty(sample.buffer, "constructor", {
|
||||
get: function() {
|
||||
return null;
|
||||
},
|
||||
configurable: true
|
||||
});
|
||||
|
||||
sample.buffer.constructor = null;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
||||
var s = Symbol('1');
|
||||
Object.defineProperty(sample.buffer, "constructor", {
|
||||
get: function() {
|
||||
return s;
|
||||
},
|
||||
configurable: true
|
||||
});
|
||||
|
||||
var s = Symbol("1");
|
||||
sample.buffer.constructor = s;
|
||||
assert.throws(TypeError, function() {
|
||||
new TA(sample);
|
||||
});
|
||||
|
|
|
@ -25,5 +25,7 @@ testWithTypedArrayConstructors(function(TA) {
|
|||
|
||||
assert.sameValue(typedArray.length, 7);
|
||||
assert.notSameValue(typedArray, sample);
|
||||
assert.notSameValue(typedArray.buffer, sample.buffer);
|
||||
assert.sameValue(typedArray.constructor, TA);
|
||||
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue