Skip to content

Commit

Permalink
fixup! rename test files + review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
leobalter committed Feb 5, 2016
1 parent d033b16 commit 0a30413
Show file tree
Hide file tree
Showing 76 changed files with 86 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@ testWithTypedArrayConstructors(function(TA) {
var ta1 = new TA(buffer, offset, 2);
assert.sameValue(ta1.length, 2, "ta1.length");
assert.sameValue(ta1.buffer, buffer, "ta1.buffer");
assert.sameValue(
Object.getPrototypeOf(ta1), TA.prototype,
"Object.getPrototypeOf(ta1)"
);
assert.sameValue(ta1.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);

var ta2 = new TA(buffer, offset, 0);
assert.sameValue(ta2.length, 0, "ta2.length");
assert.sameValue(ta2.buffer, buffer, "ta2.buffer");
assert.sameValue(
Object.getPrototypeOf(ta2), TA.prototype,
"Object.getPrototypeOf(ta2)"
);
assert.sameValue(ta2.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,12 @@ testWithTypedArrayConstructors(function(TA) {
var ta1 = new TA(buffer, 0, length);
assert.sameValue(ta1.length, length);
assert.sameValue(ta1.buffer, buffer);
assert.sameValue(ta1.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);

var ta2 = new TA(buffer, 0, 0);
assert.sameValue(ta2.length, 0);
assert.sameValue(ta2.buffer, buffer);
assert.sameValue(ta2.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
});
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,29 @@ includes: [testTypedArray.js]

testWithTypedArrayConstructors(function(TA) {
var bpe = TA.BYTES_PER_ELEMENT;
var length = 4;
var buffer = new ArrayBuffer(bpe * length * 4);
var buffer = new ArrayBuffer(bpe * 2);

var ta1 = new TA(buffer, 0, -1);
assert.sameValue(ta1.length, 0);
assert.sameValue(ta1.buffer, buffer);
assert.sameValue(ta1.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);

var ta2 = new TA(buffer, 0, -Infinity);
assert.sameValue(ta2.length, 0);
assert.sameValue(ta2.buffer, buffer);
assert.sameValue(ta2.constructor, TA);
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.buffer, buffer);
assert.sameValue(ta3.constructor, TA);
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.buffer, buffer);
assert.sameValue(ta4.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta4), TA.prototype);
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ testWithTypedArrayConstructors(function(TA) {
var ta1 = new TA(buffer, bpe * 2);
assert.sameValue(ta1.length, 2);
assert.sameValue(ta1.buffer, buffer);
assert.sameValue(ta1.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);

var ta2 = new TA(buffer, 0);
assert.sameValue(ta2.length, 4);
assert.sameValue(ta2.buffer, buffer);
assert.sameValue(ta2.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ info: >
includes: [testTypedArray.js]
---*/

var buffer = new ArrayBuffer(8);

testWithTypedArrayConstructors(function(TA) {
var bpe = TA.BYTES_PER_ELEMENT;
var buffer = new ArrayBuffer(bpe);

assert.throws(RangeError, function() {
new TA(buffer, 0, 16);
new TA(buffer, 0, bpe * 2);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ info: >
includes: [testTypedArray.js]
---*/

var buffer = new ArrayBuffer(8);

testWithTypedArrayConstructors(function(TA) {
var bpe = TA.BYTES_PER_ELEMENT;
var buffer = new ArrayBuffer(bpe);

assert.throws(RangeError, function() {
new TA(buffer, 16);
new TA(buffer, bpe * 2);
});

assert.throws(RangeError, function() {
new TA(buffer, 16, undefined);
new TA(buffer, bpe * 2, undefined);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*---
id: sec-typedarray-buffer-byteoffset-length
description: >
Return new typedArray from undefined defined offset
Return new typedArray from undefined offset and length
info: >
22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] )
Expand All @@ -20,11 +20,13 @@ testWithTypedArrayConstructors(function(TA) {
var ta1 = new TA(buffer1);
assert.sameValue(ta1.length, 4);
assert.sameValue(ta1.buffer, buffer1);
assert.sameValue(ta1.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype);

var buffer2 = new ArrayBuffer(0);
var ta2 = new TA(buffer2);
assert.sameValue(ta2.length, 0);
assert.sameValue(ta2.buffer, buffer2);
assert.sameValue(ta2.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype);
});
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,6 @@ newTarget.prototype = proto;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [buffer], newTarget);

assert.sameValue(ta.constructor, Object);
assert.sameValue(Object.getPrototypeOf(ta), proto);
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ newTarget.prototype = null;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [buffer], newTarget);

assert.sameValue(ta.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
});
28 changes: 28 additions & 0 deletions test/built-ins/TypedArrays/length-arg-minus-signal-zero.js
Original file line number Diff line number Diff line change
@@ -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);
});
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,5 @@ testWithTypedArrayConstructors(function(TA) {

assert.sameValue(length, 4, "length");
assert.sameValue(typedArray.constructor, TA);
assert.sameValue(
Object.getPrototypeOf(typedArray), TA.prototype,
"Object.getPrototypeOf(typedArray)"
);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ newTarget.prototype = proto;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [1], newTarget);

assert.sameValue(ta.constructor, Object);
assert.sameValue(Object.getPrototypeOf(ta), proto);
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ newTarget.prototype = null;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [1], newTarget);

assert.sameValue(ta.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
});
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ newTarget.prototype = proto;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [], newTarget);

assert.sameValue(ta.constructor, Object);
assert.sameValue(Object.getPrototypeOf(ta), proto);
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,6 @@ newTarget.prototype = null;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [], newTarget);

assert.sameValue(ta.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ testWithTypedArrayConstructors(function(TA) {
assert.sameValue(typedArray.length, 2);
assert.sameValue(typedArray[0], 7);
assert.sameValue(typedArray[1], 42);
assert.sameValue(typedArray.constructor, TA);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
});
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ testWithTypedArrayConstructors(function(TA) {
assert.sameValue(typedArray.length, 2);
assert.sameValue(typedArray[0], 7);
assert.sameValue(typedArray[1], 42);
assert.sameValue(typedArray.constructor, TA);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);
});
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ var obj = {

testWithTypedArrayConstructors(function(TA) {
var typedArray = new TA(obj);
assert.sameValue(typedArray.length, 4);
assert.sameValue(typedArray.length, 5);
assert.sameValue(typedArray[0], 0);
assert.sameValue(typedArray[2], 42);
assert.sameValue(typedArray[3], 7);
assert.sameValue(typedArray[5], undefined);
assert.sameValue(typedArray.constructor, TA);
assert.sameValue(Object.getPrototypeOf(typedArray), TA.prototype);

if (TA === Float32Array || TA === Float64Array) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,6 @@ newTarget.prototype = proto;
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [], newTarget);

assert.sameValue(ta.constructor, Object);
assert.sameValue(Object.getPrototypeOf(ta), proto);
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ var o = [];
testWithTypedArrayConstructors(function(TA) {
var ta = Reflect.construct(TA, [o], newTarget);

assert.sameValue(ta.constructor, TA);
assert.sameValue(Object.getPrototypeOf(ta), TA.prototype);
});
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ testWithTypedArrayConstructors(function(TA) {
var sample = new (TA === Int8Array ? sample2 : sample1);

Object.defineProperty(sample.buffer, "constructor", {
get: function() {
get() {
throw new Test262Error();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ testWithTypedArrayConstructors(function(TA) {

ctor[Symbol.species].prototype = custom;

var tarray = new TA(sample);
assert.sameValue(Object.getPrototypeOf(tarray.buffer), custom);
var typedArray = new TA(sample);
assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom);
assert.sameValue(called, 0);
});
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ testWithTypedArrayConstructors(function(TA) {

ctor[Symbol.species].prototype = custom;

var tarray = new TA(sample);
assert.sameValue(Object.getPrototypeOf(tarray.buffer), custom);
var typedArray = new TA(sample);
assert.sameValue(Object.getPrototypeOf(typedArray.buffer), custom);
assert.sameValue(called, 0);
});
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ features: [Symbol.species]
testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
var ctor = {};
var o = { m() {} };
var m = { m() {} };

sample.buffer.constructor = ctor;

ctor[Symbol.species] = o.m;
ctor[Symbol.species] = m;

assert.throws(TypeError, function() {
new TA(sample);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ testWithTypedArrayConstructors(function(TA) {

ctor[Symbol.species] = function(){}.bind(null);
Object.defineProperty(ctor[Symbol.species], "prototype", {
get: function() {
get() {
throw new Test262Error();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ testWithTypedArrayConstructors(function(TA) {

sample.buffer.constructor = ctor;
Object.defineProperty(ctor, Symbol.species, {
get: function() {
get() {
throw new Test262Error();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ testWithTypedArrayConstructors(function(TA) {
sample.buffer.constructor = ctor;

ctor[Symbol.species] = undefined;
var a = new TA(sample);
var typedArray = new TA(sample);
assert.sameValue(
Object.getPrototypeOf(a.buffer),
Object.getPrototypeOf(typedArray.buffer),
ArrayBuffer.prototype,
"buffer ctor is not called when species is undefined"
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,58 +36,29 @@ features: [Symbol]

testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
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
});

sample.buffer.constructor = s;
assert.throws(TypeError, function() {
new TA(sample);
});
Expand Down
Loading

0 comments on commit 0a30413

Please sign in to comment.