fixup! rename test files + review fixes

This commit is contained in:
Leonardo Balter 2016-02-04 17:06:56 -02:00
parent d033b160cb
commit 0a30413b49
76 changed files with 86 additions and 70 deletions

View File

@ -20,16 +20,12 @@ testWithTypedArrayConstructors(function(TA) {
var ta1 = new TA(buffer, offset, 2); var ta1 = new TA(buffer, offset, 2);
assert.sameValue(ta1.length, 2, "ta1.length"); assert.sameValue(ta1.length, 2, "ta1.length");
assert.sameValue(ta1.buffer, buffer, "ta1.buffer"); assert.sameValue(ta1.buffer, buffer, "ta1.buffer");
assert.sameValue( assert.sameValue(ta1.constructor, TA);
Object.getPrototypeOf(ta1), TA.prototype, assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);
"Object.getPrototypeOf(ta1)"
);
var ta2 = new TA(buffer, offset, 0); var ta2 = new TA(buffer, offset, 0);
assert.sameValue(ta2.length, 0, "ta2.length"); assert.sameValue(ta2.length, 0, "ta2.length");
assert.sameValue(ta2.buffer, buffer, "ta2.buffer"); assert.sameValue(ta2.buffer, buffer, "ta2.buffer");
assert.sameValue( assert.sameValue(ta2.constructor, TA);
Object.getPrototypeOf(ta2), TA.prototype, assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
"Object.getPrototypeOf(ta2)"
);
}); });

View File

@ -22,10 +22,12 @@ testWithTypedArrayConstructors(function(TA) {
var ta1 = new TA(buffer, 0, length); var ta1 = new TA(buffer, 0, length);
assert.sameValue(ta1.length, length); assert.sameValue(ta1.length, length);
assert.sameValue(ta1.buffer, buffer); assert.sameValue(ta1.buffer, buffer);
assert.sameValue(ta1.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);
var ta2 = new TA(buffer, 0, 0); var ta2 = new TA(buffer, 0, 0);
assert.sameValue(ta2.length, 0); assert.sameValue(ta2.length, 0);
assert.sameValue(ta2.buffer, buffer); assert.sameValue(ta2.buffer, buffer);
assert.sameValue(ta2.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
}); });

View File

@ -16,26 +16,29 @@ includes: [testTypedArray.js]
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var bpe = TA.BYTES_PER_ELEMENT; var bpe = TA.BYTES_PER_ELEMENT;
var length = 4; var buffer = new ArrayBuffer(bpe * 2);
var buffer = new ArrayBuffer(bpe * length * 4);
var ta1 = new TA(buffer, 0, -1); var ta1 = new TA(buffer, 0, -1);
assert.sameValue(ta1.length, 0); assert.sameValue(ta1.length, 0);
assert.sameValue(ta1.buffer, buffer); assert.sameValue(ta1.buffer, buffer);
assert.sameValue(ta1.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);
var ta2 = new TA(buffer, 0, -Infinity); var ta2 = new TA(buffer, 0, -Infinity);
assert.sameValue(ta2.length, 0); assert.sameValue(ta2.length, 0);
assert.sameValue(ta2.buffer, buffer); assert.sameValue(ta2.buffer, buffer);
assert.sameValue(ta2.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
var ta3 = new TA(buffer, 8, -1); var ta3 = new TA(buffer, bpe, -1);
assert.sameValue(ta3.length, 0); assert.sameValue(ta3.length, 0);
assert.sameValue(ta3.buffer, buffer); assert.sameValue(ta3.buffer, buffer);
assert.sameValue(ta3.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta3), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta3), TA.prototype);
var ta4 = new TA(buffer, 8, -Infinity); var ta4 = new TA(buffer, bpe, -Infinity);
assert.sameValue(ta4.length, 0); assert.sameValue(ta4.length, 0);
assert.sameValue(ta4.buffer, buffer); assert.sameValue(ta4.buffer, buffer);
assert.sameValue(ta4.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta4), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta4), TA.prototype);
}); });

View File

@ -20,10 +20,12 @@ testWithTypedArrayConstructors(function(TA) {
var ta1 = new TA(buffer, bpe * 2); var ta1 = new TA(buffer, bpe * 2);
assert.sameValue(ta1.length, 2); assert.sameValue(ta1.length, 2);
assert.sameValue(ta1.buffer, buffer); assert.sameValue(ta1.buffer, buffer);
assert.sameValue(ta1.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);
var ta2 = new TA(buffer, 0); var ta2 = new TA(buffer, 0);
assert.sameValue(ta2.length, 4); assert.sameValue(ta2.length, 4);
assert.sameValue(ta2.buffer, buffer); assert.sameValue(ta2.buffer, buffer);
assert.sameValue(ta2.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
}); });

View File

@ -20,10 +20,11 @@ info: >
includes: [testTypedArray.js] includes: [testTypedArray.js]
---*/ ---*/
var buffer = new ArrayBuffer(8);
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var bpe = TA.BYTES_PER_ELEMENT;
var buffer = new ArrayBuffer(bpe);
assert.throws(RangeError, function() { assert.throws(RangeError, function() {
new TA(buffer, 0, 16); new TA(buffer, 0, bpe * 2);
}); });
}); });

View File

@ -20,14 +20,15 @@ info: >
includes: [testTypedArray.js] includes: [testTypedArray.js]
---*/ ---*/
var buffer = new ArrayBuffer(8);
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var bpe = TA.BYTES_PER_ELEMENT;
var buffer = new ArrayBuffer(bpe);
assert.throws(RangeError, function() { assert.throws(RangeError, function() {
new TA(buffer, 16); new TA(buffer, bpe * 2);
}); });
assert.throws(RangeError, function() { assert.throws(RangeError, function() {
new TA(buffer, 16, undefined); new TA(buffer, bpe * 2, undefined);
}); });
}); });

View File

@ -3,7 +3,7 @@
/*--- /*---
id: sec-typedarray-buffer-byteoffset-length id: sec-typedarray-buffer-byteoffset-length
description: > description: >
Return new typedArray from undefined defined offset Return new typedArray from undefined offset and length
info: > info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
@ -20,11 +20,13 @@ testWithTypedArrayConstructors(function(TA) {
var ta1 = new TA(buffer1); var ta1 = new TA(buffer1);
assert.sameValue(ta1.length, 4); assert.sameValue(ta1.length, 4);
assert.sameValue(ta1.buffer, buffer1); assert.sameValue(ta1.buffer, buffer1);
assert.sameValue(ta1.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);
var buffer2 = new ArrayBuffer(0); var buffer2 = new ArrayBuffer(0);
var ta2 = new TA(buffer2); var ta2 = new TA(buffer2);
assert.sameValue(ta2.length, 0); assert.sameValue(ta2.length, 0);
assert.sameValue(ta2.buffer, buffer2); assert.sameValue(ta2.buffer, buffer2);
assert.sameValue(ta2.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
}); });

View File

@ -43,5 +43,6 @@ newTarget.prototype = proto;
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [buffer], newTarget); var ta = Reflect.construct(TA, [buffer], newTarget);
assert.sameValue(ta.constructor, Object);
assert.sameValue(Object.getPrototypeOf(ta), proto); assert.sameValue(Object.getPrototypeOf(ta), proto);
}); });

View File

@ -41,5 +41,6 @@ newTarget.prototype = null;
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [buffer], newTarget); var ta = Reflect.construct(TA, [buffer], newTarget);
assert.sameValue(ta.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
}); });

View File

@ -0,0 +1,28 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
id: sec-typedarray-length
description: >
Does not throw when length is -0
info: >
22.2.4.2 TypedArray ( length )
This description applies only if the TypedArray function is called with at
least one argument and the Type of the first argument is not Object.
...
4. Let numberLength be ? ToNumber(length).
5. Let elementLength be ToLength(numberLength).
6. If SameValueZero(numberLength, elementLength) is false, throw a RangeError
exception.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var typedArray = new TA(-0);
assert.sameValue(typedArray.length, 0, "length");
assert.sameValue(typedArray.constructor, TA);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
});

View File

@ -28,8 +28,5 @@ testWithTypedArrayConstructors(function(TA) {
assert.sameValue(length, 4, "length"); assert.sameValue(length, 4, "length");
assert.sameValue(typedArray.constructor, TA); assert.sameValue(typedArray.constructor, TA);
assert.sameValue( assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
Object.getPrototypeOf(typedArray), TA.prototype,
"Object.getPrototypeOf(typedArray)"
);
}); });

View File

@ -39,5 +39,6 @@ newTarget.prototype = proto;
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [1], newTarget); var ta = Reflect.construct(TA, [1], newTarget);
assert.sameValue(ta.constructor, Object);
assert.sameValue(Object.getPrototypeOf(ta), proto); assert.sameValue(Object.getPrototypeOf(ta), proto);
}); });

View File

@ -37,5 +37,6 @@ newTarget.prototype = null;
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [1], newTarget); var ta = Reflect.construct(TA, [1], newTarget);
assert.sameValue(ta.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
}); });

View File

@ -39,5 +39,6 @@ newTarget.prototype = proto;
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [], newTarget); var ta = Reflect.construct(TA, [], newTarget);
assert.sameValue(ta.constructor, Object);
assert.sameValue(Object.getPrototypeOf(ta), proto); assert.sameValue(Object.getPrototypeOf(ta), proto);
}); });

View File

@ -37,5 +37,6 @@ newTarget.prototype = null;
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [], newTarget); var ta = Reflect.construct(TA, [], newTarget);
assert.sameValue(ta.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
}); });

View File

@ -22,5 +22,6 @@ testWithTypedArrayConstructors(function(TA) {
assert.sameValue(typedArray.length, 2); assert.sameValue(typedArray.length, 2);
assert.sameValue(typedArray[0], 7); assert.sameValue(typedArray[0], 7);
assert.sameValue(typedArray[1], 42); assert.sameValue(typedArray[1], 42);
assert.sameValue(typedArray.constructor, TA);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
}); });

View File

@ -24,5 +24,6 @@ testWithTypedArrayConstructors(function(TA) {
assert.sameValue(typedArray.length, 2); assert.sameValue(typedArray.length, 2);
assert.sameValue(typedArray[0], 7); assert.sameValue(typedArray[0], 7);
assert.sameValue(typedArray[1], 42); assert.sameValue(typedArray[1], 42);
assert.sameValue(typedArray.constructor, TA);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
}); });

View File

@ -27,11 +27,12 @@ var obj = {
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var typedArray = new TA(obj); var typedArray = new TA(obj);
assert.sameValue(typedArray.length, 4); assert.sameValue(typedArray.length, 5);
assert.sameValue(typedArray[0], 0); assert.sameValue(typedArray[0], 0);
assert.sameValue(typedArray[2], 42); assert.sameValue(typedArray[2], 42);
assert.sameValue(typedArray[3], 7); assert.sameValue(typedArray[3], 7);
assert.sameValue(typedArray[5], undefined); assert.sameValue(typedArray[5], undefined);
assert.sameValue(typedArray.constructor, TA);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype); assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
if (TA === Float32Array || TA === Float64Array) { if (TA === Float32Array || TA === Float64Array) {

View File

@ -42,5 +42,6 @@ newTarget.prototype = proto;
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [], newTarget); var ta = Reflect.construct(TA, [], newTarget);
assert.sameValue(ta.constructor, Object);
assert.sameValue(Object.getPrototypeOf(ta), proto); assert.sameValue(Object.getPrototypeOf(ta), proto);
}); });

View File

@ -41,5 +41,6 @@ var o = [];
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [o], newTarget); var ta = Reflect.construct(TA, [o], newTarget);
assert.sameValue(ta.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
}); });

View File

@ -30,7 +30,7 @@ testWithTypedArrayConstructors(function(TA) {
var sample = new (TA === Int8Array ? sample2 : sample1); var sample = new (TA === Int8Array ? sample2 : sample1);
Object.defineProperty(sample.buffer, "constructor", { Object.defineProperty(sample.buffer, "constructor", {
get: function() { get() {
throw new Test262Error(); throw new Test262Error();
} }
}); });

View File

@ -46,7 +46,7 @@ testWithTypedArrayConstructors(function(TA) {
ctor[Symbol.species].prototype = custom; ctor[Symbol.species].prototype = custom;
var tarray = new TA(sample); var typedArray = new TA(sample);
assert.sameValue(Object.getPrototypeOf(tarray.buffer), custom); assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom);
assert.sameValue(called, 0); assert.sameValue(called, 0);
}); });

View File

@ -54,7 +54,7 @@ testWithTypedArrayConstructors(function(TA) {
ctor[Symbol.species].prototype = custom; ctor[Symbol.species].prototype = custom;
var tarray = new TA(sample); var typedArray = new TA(sample);
assert.sameValue(Object.getPrototypeOf(tarray.buffer), custom); assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom);
assert.sameValue(called, 0); assert.sameValue(called, 0);
}); });

View File

@ -37,11 +37,11 @@ features: [Symbol.species]
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var sample = new TA(); var sample = new TA();
var ctor = {}; var ctor = {};
var o = { m() {} }; var m = { m() {} };
sample.buffer.constructor = ctor; sample.buffer.constructor = ctor;
ctor[Symbol.species] = o.m; ctor[Symbol.species] = m;
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
new TA(sample); new TA(sample);

View File

@ -51,7 +51,7 @@ testWithTypedArrayConstructors(function(TA) {
ctor[Symbol.species] = function(){}.bind(null); ctor[Symbol.species] = function(){}.bind(null);
Object.defineProperty(ctor[Symbol.species], "prototype", { Object.defineProperty(ctor[Symbol.species], "prototype", {
get: function() { get() {
throw new Test262Error(); throw new Test262Error();
} }
}); });

View File

@ -38,7 +38,7 @@ testWithTypedArrayConstructors(function(TA) {
sample.buffer.constructor = ctor; sample.buffer.constructor = ctor;
Object.defineProperty(ctor, Symbol.species, { Object.defineProperty(ctor, Symbol.species, {
get: function() { get() {
throw new Test262Error(); throw new Test262Error();
} }
}); });

View File

@ -40,9 +40,9 @@ testWithTypedArrayConstructors(function(TA) {
sample.buffer.constructor = ctor; sample.buffer.constructor = ctor;
ctor[Symbol.species] = undefined; ctor[Symbol.species] = undefined;
var a = new TA(sample); var typedArray = new TA(sample);
assert.sameValue( assert.sameValue(
Object.getPrototypeOf(a.buffer), Object.getPrototypeOf(typedArray.buffer),
ArrayBuffer.prototype, ArrayBuffer.prototype,
"buffer ctor is not called when species is undefined" "buffer ctor is not called when species is undefined"
); );

View File

@ -36,58 +36,29 @@ features: [Symbol]
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var sample = new TA(); var sample = new TA();
Object.defineProperty(sample.buffer, "constructor", {
get: function() {
return 1;
},
configurable: true
});
sample.buffer.constructor = 1;
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
new TA(sample); new TA(sample);
}); });
Object.defineProperty(sample.buffer, "constructor", { sample.buffer.constructor = true;
get: function() {
return true;
},
configurable: true
});
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
new TA(sample); new TA(sample);
}); });
Object.defineProperty(sample.buffer, "constructor", { sample.buffer.constructor = '';
get: function() {
return '';
},
configurable: true
});
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
new TA(sample); new TA(sample);
}); });
Object.defineProperty(sample.buffer, "constructor", { sample.buffer.constructor = null;
get: function() {
return null;
},
configurable: true
});
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
new TA(sample); new TA(sample);
}); });
var s = Symbol('1'); var s = Symbol('1');
Object.defineProperty(sample.buffer, "constructor", { sample.buffer.constructor = s;
get: function() {
return s;
},
configurable: true
});
assert.throws(TypeError, function() { assert.throws(TypeError, function() {
new TA(sample); new TA(sample);
}); });

View File

@ -43,5 +43,6 @@ var sample = new Int8Array(8);
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [sample], newTarget); var ta = Reflect.construct(TA, [sample], newTarget);
assert.sameValue(ta.constructor, Object);
assert.sameValue(Object.getPrototypeOf(ta), proto); assert.sameValue(Object.getPrototypeOf(ta), proto);
}); });

View File

@ -41,5 +41,6 @@ var sample = new Int8Array(8);
testWithTypedArrayConstructors(function(TA) { testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [sample], newTarget); var ta = Reflect.construct(TA, [sample], newTarget);
assert.sameValue(ta.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
}); });