Add tests for internal methods of typedArray instances

Test specific behaviour for Integer Indexed exotic objects, WRT the
following internal methods:

- [[GetOwnProperty]]
- [[HasProperty]]
- [[DefineOwnProperty]]
- [[Get]]
- [[Set]]
- [[OwnPropertyKeys]]
This commit is contained in:
Leonardo Balter 2016-03-07 12:44:20 -05:00 committed by Mike Pennisi
parent 887b379421
commit 3cb20b9df5
68 changed files with 2895 additions and 0 deletions

View File

@ -0,0 +1,39 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: |
Return abrupt from the evaluation of ToNumber(desc.value)
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
xi. If Desc has a [[Value]] field, then
1. Let value be Desc.[[Value]].
2. Return ? IntegerIndexedElementSet(O, intIndex, value).
...
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
...
3. Let numValue be ? ToNumber(value).
...
includes: [testTypedArray.js]
---*/
var obj = {
valueOf: function() {
throw new Test262Error();
}
};
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42]);
assert.throws(Test262Error, function() {
Object.defineProperty(sample, "0", {value: obj});
});
});

View File

@ -0,0 +1,134 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: |
Throws a TypeError if object has valid numeric index and a detached buffer
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
xi. If Desc has a [[Value]] field, then
1. Let value be Desc.[[Value]].
2. Return ? IntegerIndexedElementSet(O, intIndex, value).
...
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
...
4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
...
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [Reflect]
---*/
var desc = {
value: 0,
configurable: false,
enumerable: true,
writable: true
};
var obj = {
valueOf: function() {
throw new Test262Error();
}
}
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(42);
$DETACHBUFFER(sample.buffer);
assert.throws(TypeError, function() {
Reflect.defineProperty(sample, "0", desc);
}, "Throws TypeError on valid numeric index if instance has a detached buffer");
assert.sameValue(
Reflect.defineProperty(sample, "-1", desc),
false,
"Return false before Detached Buffer check when value is a negative number"
);
assert.sameValue(
Reflect.defineProperty(sample, "1.1", desc),
false,
"Return false before Detached Buffer check when value is not an integer"
);
assert.sameValue(
Reflect.defineProperty(sample, "-0", desc),
false,
"Return false before Detached Buffer check when value is -0"
);
assert.sameValue(
Reflect.defineProperty(sample, "2", {
configurable: true,
enumerable: true,
writable: true,
value: obj
}),
false,
"Return false before Detached Buffer check when desc configurable is true"
);
assert.sameValue(
Reflect.defineProperty(sample, "3", {
configurable: false,
enumerable: false,
writable: true,
value: obj
}),
false,
"Return false before Detached Buffer check when desc enumerable is false"
);
assert.sameValue(
Reflect.defineProperty(sample, "4", {
writable: false,
configurable: false,
enumerable: true,
value: obj
}),
false,
"Return false before Detached Buffer check when desc writable is false"
);
assert.sameValue(
Reflect.defineProperty(sample, "42", desc),
false,
"Return false before Detached Buffer check when key == [[ArrayLength]]"
);
assert.sameValue(
Reflect.defineProperty(sample, "43", desc),
false,
"Return false before Detached Buffer check when key > [[ArrayLength]]"
);
assert.sameValue(
Reflect.defineProperty(sample, "5", {
get: function() {}
}),
false,
"Return false before Detached Buffer check with accessor descriptor"
);
assert.sameValue(
Reflect.defineProperty(sample, "6", {
configurable: false,
enumerable: true,
writable: true
}),
true,
"Return true before Detached Buffer check when desc value is not present"
);
assert.throws(Test262Error, function() {
Reflect.defineProperty(sample, "7", {value: obj});
}, "Return Abrupt before Detached Buffer check from ToNumber(desc.value)");
});

View File

@ -0,0 +1,47 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: >
Returns false if numericIndex is >= [[ArrayLength]]
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
ii. Let intIndex be numericIndex.
...
v. Let length be the value of O's [[ArrayLength]] internal slot.
vi. If intIndex length, return false.
...
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
assert.sameValue(
Reflect.defineProperty(sample, "2", {
value: 42,
configurable: false,
enumerable: true,
writable: true
}),
false,
"numericIndex == length"
);
assert.sameValue(
Reflect.defineProperty(sample, "3", {
value: 42,
configurable: false,
enumerable: true,
writable: true
}),
false,
"numericIndex > length"
);
});

View File

@ -0,0 +1,34 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: >
Returns false if numericIndex is < 0
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
ii. Let intIndex be numericIndex.
iv. If intIndex < 0, return false.
...
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
assert.sameValue(
Reflect.defineProperty(sample, "-1", {
value: 42,
configurable: true,
enumerable: true,
writable: true
}),
false,
"-1"
);
});

View File

@ -0,0 +1,36 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: >
Returns false if numericIndex is "-0"
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. If IsInteger(numericIndex) is false, return false.
ii. Let intIndex be numericIndex.
iii. If intIndex = -0, return false.
...
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(2);
assert.sameValue(
Reflect.defineProperty(sample, "-0", {
value: 42,
configurable: false,
enumerable: true,
writable: true
}),
false,
"defineProperty returns false"
);
assert.sameValue(sample[0], 0, "does not change the value for [0]");
assert.sameValue(sample["-0"], undefined, "does define a value for ['-0']");
});

View File

@ -0,0 +1,98 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: |
Sets an ordinary property value if numeric key is not a CanonicalNumericIndex
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return OrdinaryDefineOwnProperty(O, P, Desc).
...
includes: [testTypedArray.js, propertyHelper.js]
features: [Reflect]
---*/
var keys = [
"1.0",
"+1",
"1000000000000000000000",
"0.0000001"
];
var dataDesc = {
value: 42,
writable: true,
configurable: true
};
var fnset = function() {};
var fnget = function() {};
var acDesc = {
get: fnget,
set: fnset,
enumerable: true,
configurable: false
};
testWithTypedArrayConstructors(function(TA) {
keys.forEach(function(key) {
var sample1 = new TA();
assert.sameValue(
Reflect.defineProperty(sample1, key, dataDesc),
true,
"return true after defining data property [" + key + "]"
);
assert.sameValue(sample1[key], 42, "value is set to [" + key + "]");
verifyNotEnumerable(sample1, key);
verifyWritable(sample1, key);
verifyConfigurable(sample1, key);
assert.sameValue(sample1[0], undefined, "no value is set on sample1[0]");
assert.sameValue(sample1.length, 0, "length is still 0");
var sample2 = new TA();
assert.sameValue(
Reflect.defineProperty(sample2, key, acDesc),
true,
"return true after defining accessors property [" + key + "]"
);
var desc = Object.getOwnPropertyDescriptor(sample2, key);
verifyEnumerable(sample2, key);
assert.sameValue(desc.get, fnget, "accessor's get [" + key + "]");
assert.sameValue(desc.set, fnset, "accessor's set [" + key + "]");
verifyNotConfigurable(sample2, key);
assert.sameValue(sample2[0], undefined,"no value is set on sample2[0]");
assert.sameValue(sample2.length, 0, "length is still 0");
var sample3 = new TA();
Object.preventExtensions(sample3);
assert.sameValue(
Reflect.defineProperty(sample3, key, dataDesc),
false,
"return false defining property on a non-extensible sample"
);
assert.sameValue(Object.getOwnPropertyDescriptor(sample3, key), undefined);
var sample4 = new TA();
Object.preventExtensions(sample4);
assert.sameValue(
Reflect.defineProperty(sample4, key, acDesc),
false,
"return false defining property on a non-extensible sample"
);
assert.sameValue(Object.getOwnPropertyDescriptor(sample4, key), undefined);
});
});

View File

@ -0,0 +1,124 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: >
Returns false if numericIndex is not an integer
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. If IsInteger(numericIndex) is false, return false.
...
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(2);
assert.sameValue(
Reflect.defineProperty(sample, "0.1", {
value: 42,
configurable: false,
enumerable: true,
writable: true
}),
false,
"0.1"
);
assert.sameValue(sample[0], 0, "'0.1' - does not change the value for [0]");
assert.sameValue(
sample["0.1"],
undefined,
"'0.1' - does not define a value for ['0.1']"
);
assert.sameValue(
Reflect.defineProperty(sample, "0.000001", {
value: 42,
configurable: false,
enumerable: true,
writable: true
}),
false,
"0.000001"
);
assert.sameValue(
sample[0], 0,
"'0.000001' - does not change the value for [0]"
);
assert.sameValue(
sample["0.000001"],
undefined,
"'0.000001' - does not define a value for ['0.000001']"
);
assert.sameValue(
Reflect.defineProperty(sample, "1.1", {
value: 42,
configurable: false,
enumerable: true,
writable: true
}),
false,
"1.1"
);
assert.sameValue(sample[1], 0, "'1.1' - does not change the value for [1]");
assert.sameValue(
sample["1.1"],
undefined,
"'1.1' - does not define a value for ['1.1']"
);
assert.sameValue(
Reflect.defineProperty(sample, "Infinity", {
value: 42,
configurable: false,
enumerable: true,
writable: true
}),
false,
"Infinity"
);
assert.sameValue(
sample[0], 0,
"'Infinity' - does not change the value for [0]"
);
assert.sameValue(
sample[1], 0,
"'Infinity' - does not change the value for [1]"
);
assert.sameValue(
sample["Infinity"],
undefined,
"'Infinity' - does not define a value for ['Infinity']"
);
assert.sameValue(
Reflect.defineProperty(sample, "-Infinity", {
value: 42,
configurable: false,
enumerable: true,
writable: true
}),
false,
"-Infinity"
);
assert.sameValue(
sample[0], 0,
"'-Infinity' - does not change the value for [0]"
);
assert.sameValue(
sample[1], 0,
"'-Infinity' - does not change the value for [1]"
);
assert.sameValue(
sample["-Infinity"],
undefined,
"'-Infinity' - does not define a value for ['-Infinity']"
);
});

View File

@ -0,0 +1,52 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: >
Returns an ordinary property value if key is not a CanonicalNumericIndex
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return OrdinaryDefineOwnProperty(O, P, Desc).
...
includes: [testTypedArray.js, propertyHelper.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
assert.sameValue(
Reflect.defineProperty(sample, "foo", {value:42}),
true,
"return true after defining property"
);
assert.sameValue(sample.foo, 42);
verifyNotWritable(sample, "foo");
verifyNotConfigurable(sample, "foo");
verifyNotEnumerable(sample, "foo");
var fnset = function() {};
var fnget = function() {};
assert.sameValue(
Reflect.defineProperty(sample, "bar", {
get: fnget,
set: fnset,
enumerable: false,
configurable: true
}),
true,
"return true after defining property"
);
var desc = Object.getOwnPropertyDescriptor(sample, "bar");
assert.sameValue(desc.get, fnget, "accessor's get");
assert.sameValue(desc.set, fnset, "accessor's set");
verifyNotEnumerable(sample, "bar");
verifyConfigurable(sample, "bar");
});

View File

@ -0,0 +1,58 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: |
Returns false if key is a numeric index and Descriptor is an
AccessorDescriptor
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
vii. If IsAccessorDescriptor(Desc) is true, return false.
...
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(2);
assert.sameValue(
Reflect.defineProperty(sample, "0", {
get: function() {
return 42;
},
enumerable: true
}),
false,
"get accessor"
);
assert.sameValue(sample[0], 0, "get accessor - side effect check");
assert.sameValue(
Reflect.defineProperty(sample, "0", {
set: function() {},
enumerable: true
}),
false,
"set accessor"
);
assert.sameValue(sample[0], 0, "set accessor - side effect check");
assert.sameValue(
Reflect.defineProperty(sample, "0", {
set: function() {},
get: function() {
return 42;
},
enumerable: true
}),
false,
"get and set accessors"
);
assert.sameValue(sample[0], 0, "get and set accessors - side effect check");
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: |
Returns false if key is a numeric index and Desc.[[Configurable]] is true
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
viii. If Desc has a [[Configurable]] field and if Desc.[[Configurable]] is
true, return false.
...
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(2);
assert.sameValue(
Reflect.defineProperty(sample, "0", {
value: 42,
configurable: true,
enumerable: true,
writable: true
}),
false,
"defineProperty's result"
);
assert.sameValue(sample[0], 0, "side effect check");
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: |
Returns false if key is a numeric index and Desc.[[Enumerable]] is false
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
ix. If Desc has an [[Enumerable]] field and if Desc.[[Enumerable]] is
false, return false.
...
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(2);
assert.sameValue(
Reflect.defineProperty(sample, "0", {
value: 42,
configurable: false,
enumerable: false,
writable: true
}),
false,
"defineProperty's result"
);
assert.sameValue(sample[0], 0, "side effect check");
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: |
Returns false if key is a numeric index and Desc.[[Writable]] is false
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
x. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false,
return false.
...
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(2);
assert.sameValue(
Reflect.defineProperty(sample, "0", {
value: 42,
configurable: false,
enumerable: true,
writable: false
}),
false,
"defineProperty's result"
);
assert.sameValue(sample[0], 0, "side effect check");
});

View File

@ -0,0 +1,42 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: |
Returns true after setting a valid numeric index key
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
x. If Desc has a [[Writable]] field and if Desc.[[Writable]] is false,
return false.
...
includes: [testTypedArray.js, propertyHelper.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 42]);
assert.sameValue(
Reflect.defineProperty(sample, "0", {
value: 8,
configurable: false,
enumerable: true,
writable: true
}),
true
);
assert.sameValue(sample[0], 8, "property value was set");
var desc = Object.getOwnPropertyDescriptor(sample, "0");
assert.sameValue(desc.value, 8, "desc.value");
assert.sameValue(desc.writable, true, "property is writable");
verifyEnumerable(sample, "0");
verifyNotConfigurable(sample, "0");
});

View File

@ -0,0 +1,54 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: >
Define an ordinary property value if key is a Symbol
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
...
4. Return OrdinaryDefineOwnProperty(O, P, Desc).
...
includes: [testTypedArray.js, propertyHelper.js]
features: [Reflect, Symbol]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
var s1 = Symbol("foo");
assert.sameValue(
Reflect.defineProperty(sample, s1, {
value: 42,
configurable: true
}),
true,
"return true after defining property"
);
assert.sameValue(sample[s1], 42);
verifyNotWritable(sample, s1);
verifyNotEnumerable(sample, s1);
verifyConfigurable(sample, s1);
var s2 = Symbol("bar");
var fnset = function() {};
var fnget = function() {};
assert.sameValue(
Reflect.defineProperty(sample, s2, {
get: fnget,
set: fnset,
enumerable: true
}),
true,
"return true after defining property"
);
var desc = Object.getOwnPropertyDescriptor(sample, s2);
assert.sameValue(desc.get, fnget, "accessor's get");
assert.sameValue(desc.set, fnset, "accessor's set");
assert.sameValue(desc.enumerable, true);
verifyNotConfigurable(sample, s2);
});

View File

@ -0,0 +1,44 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: >
Can't define a new non-numerical key on a non-extensible instance
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return OrdinaryDefineOwnProperty(O, P, Desc).
...
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
Object.preventExtensions(sample);
assert.sameValue(
Reflect.defineProperty(sample, "foo", {value:42}),
false,
"return false on a non-extensible object - data descriptor"
);
assert.sameValue(Object.getOwnPropertyDescriptor(sample, "foo"), undefined);
assert.sameValue(
Reflect.defineProperty(sample, "bar", {
get: function() {},
set: function() {},
enumerable: false,
configurable: true
}),
false,
"return false on a non-extensible object - accessor descriptor"
);
assert.sameValue(Object.getOwnPropertyDescriptor(sample, "bar"), undefined);
});

View File

@ -0,0 +1,57 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: >
Redefine a non-numerical key on a non-extensible instance
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return OrdinaryDefineOwnProperty(O, P, Desc).
...
includes: [testTypedArray.js, propertyHelper.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
sample.foo = true;
sample.bar = true;
Object.preventExtensions(sample);
assert.sameValue(
Reflect.defineProperty(sample, "foo", {value:42}),
true,
"data descriptor"
);
assert.sameValue(sample.foo, 42);
verifyEnumerable(sample, "foo");
verifyWritable(sample, "foo");
verifyConfigurable(sample, "foo");
var fnget = function() {};
var fnset = function() {};
assert.sameValue(
Reflect.defineProperty(sample, "bar", {
get: fnget,
set: fnset,
enumerable: false,
configurable: false
}),
true,
"accessor descriptor"
);
var desc = Object.getOwnPropertyDescriptor(sample, "bar");
assert.sameValue(desc.get, fnget, "accessor's get");
assert.sameValue(desc.set, fnset, "accessor's set");
verifyNotEnumerable(sample, "bar");
verifyNotConfigurable(sample, "bar");
});

View File

@ -0,0 +1,45 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: |
Set the value and return true
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
xi. If Desc has a [[Value]] field, then
1. Let value be Desc.[[Value]].
2. Return ? IntegerIndexedElementSet(O, intIndex, value).
...
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
...
15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue).
16. Return true.
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([0, 0]);
assert.sameValue(
Reflect.defineProperty(sample, "0", {value: 1}),
true,
"set value for sample[0] returns true"
);
assert.sameValue(
Reflect.defineProperty(sample, "1", {value: 2}),
true,
"set value for sample[1] returns true"
);
assert.sameValue(sample[0], 1, "sample[0]");
assert.sameValue(sample[1], 2, "sample[1]");
});

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
description: >
Returns false for non-numeric index property value if `this` is not extensible
info: >
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return OrdinaryDefineOwnProperty(O, P, Desc).
...
includes: [testTypedArray.js]
features: [Reflect, Symbol]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
Object.preventExtensions(sample);
assert.sameValue(Reflect.defineProperty(sample, "foo", {value:42}), false);
assert.sameValue(Reflect.getOwnPropertyDescriptor(sample, "foo"), undefined);
var s = Symbol("1");
assert.sameValue(Reflect.defineProperty(sample, s, {value:42}), false);
assert.sameValue(Reflect.getOwnPropertyDescriptor(sample, s), undefined);
});

View File

@ -0,0 +1,27 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-get-p-receiver
description: >
Does not throw on an instance with a detached buffer if key is not a number
info: >
9.4.5.4 [[Get]] (P, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
3. Return ? OrdinaryGet(O, P, Receiver
includes: [testTypedArray.js, detachArrayBuffer.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
sample.foo = "test262";
$DETACHBUFFER(sample.buffer);
assert.sameValue(sample.undef, undefined);
assert.sameValue(sample.foo, "test262");
});

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.
/*---
esid: sec-integer-indexed-exotic-objects-get-p-receiver
description: >
Does not throw on an instance with a detached buffer if key is a Symbol
info: >
9.4.5.4 [[Get]] (P, Receiver)
...
2. If Type(P) is String, then
...
3. Return ? OrdinaryGet(O, P, Receiver).
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [Symbol]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
$DETACHBUFFER(sample.buffer);
var s = Symbol("1");
assert.sameValue(sample[s], undefined);
sample[s] = "test262";
assert.sameValue(sample[s], "test262");
});

View File

@ -0,0 +1,46 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-get-p-receiver
description: >
Throws a TypeError if key has a numeric index and object has a detached buffer
info: >
9.4.5.4 [[Get]] (P, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Return ? IntegerIndexedElementGet(O, numericIndex).
...
includes: [testTypedArray.js, detachArrayBuffer.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42]);
$DETACHBUFFER(sample.buffer);
assert.throws(TypeError, function() {
sample[0];
}, "valid numeric index");
assert.throws(TypeError, function() {
sample["1.1"];
}, "detach buffer runs before checking for 1.1");
assert.throws(TypeError, function() {
sample["-0"];
}, "detach buffer runs before checking for -0");
assert.throws(TypeError, function() {
sample["-1"];
}, "detach buffer runs before checking for -1");
assert.throws(TypeError, function() {
sample["1"];
}, "detach buffer runs before checking for key == length");
assert.throws(TypeError, function() {
sample["2"];
}, "detach buffer runs before checking for key > length");
});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-get-p-receiver
description: >
Return value from valid numeric index
info: >
9.4.5.4 [[Get]] (P, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Return ? IntegerIndexedElementGet(O, numericIndex).
...
includes: [testTypedArray.js]
---*/
var proto = TypedArray.prototype;
var throwDesc = {
get: function() {
throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c");
}
};
Object.defineProperty(proto, "0", throwDesc);
Object.defineProperty(proto, "1", throwDesc);
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 1]);
assert.sameValue(sample["0"], 42);
assert.sameValue(sample["1"], 1);
});

View File

@ -0,0 +1,60 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-get-p-receiver
description: >
Use OrginaryGet if numeric key is not a CanonicalNumericIndex
info: >
9.4.5.4 [[Get]] (P, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
3. Return ? OrdinaryGet(O, P, Receiver).
includes: [testTypedArray.js]
---*/
var keys = [
"1.0",
"+1",
"1000000000000000000000",
"0.0000001"
];
testWithTypedArrayConstructors(function(TA) {
keys.forEach(function(key) {
var sample = new TA();
assert.sameValue(
sample[key], undefined,
"return undefined for inexistent properties [" + key + "]"
);
TypedArray.prototype[key] = "test262";
assert.sameValue(
sample[key],
"test262",
"return value from inherited key [" + key + "]"
);
sample[key] = "bar";
assert.sameValue(
sample[key], "bar",
"return value from own key [" + key + "]"
);
Object.defineProperty(sample, key, {
get: function() { return "baz"; }
});
assert.sameValue(
sample[key], "baz",
"return value from get accessor [" + key + "]"
);
delete TypedArray.prototype[key];
});
});

View File

@ -0,0 +1,36 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-get-p-receiver
description: >
Return undefined if key is numeric index is not an integer.
info: >
9.4.5.4 [[Get]] (P, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Return ? IntegerIndexedElementGet(O, numericIndex).
...
9.4.5.8 IntegerIndexedElementGet ( O, index )
...
5. If IsInteger(index) is false, return undefined.
...
includes: [testTypedArray.js]
---*/
var proto = TypedArray.prototype;
Object.defineProperty(proto, "1.1", {
get: function() {
throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c");
}
});
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
assert.sameValue(sample["1.1"], undefined);
});

View File

@ -0,0 +1,36 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-get-p-receiver
description: >
Return undefined if key is numeric index is -0.
info: >
9.4.5.4 [[Get]] (P, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Return ? IntegerIndexedElementGet(O, numericIndex).
...
9.4.5.8 IntegerIndexedElementGet ( O, index )
...
6. If index = -0, return undefined.
...
includes: [testTypedArray.js]
---*/
var proto = TypedArray.prototype;
Object.defineProperty(proto, "-0", {
get: function() {
throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c");
}
});
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
assert.sameValue(sample["-0"], undefined);
});

View File

@ -0,0 +1,37 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-get-p-receiver
description: >
Returns abrupt from OrginaryGet when key is not a numeric index
info: >
9.4.5.4 [[Get]] (P, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
3. Return ? OrdinaryGet(O, P, Receiver).
9.1.8.1 OrdinaryGet (O, P, Receiver)
...
8. Return ? Call(getter, Receiver).
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
Object.defineProperty(sample, "test262", {
get: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
sample.test262;
});
});

View File

@ -0,0 +1,38 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-get-p-receiver
description: >
Use OrginaryGet if key is not a CanonicalNumericIndex
info: >
9.4.5.4 [[Get]] (P, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
3. Return ? OrdinaryGet(O, P, Receiver).
includes: [testTypedArray.js]
---*/
TypedArray.prototype.baz = "test262";
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
assert.sameValue(
sample.foo, undefined,
"return undefined for inexistent properties"
);
sample.foo = "bar";
assert.sameValue(sample.foo, "bar", "return value");
Object.defineProperty(sample, "bar", {
get: function() { return "baz"; }
});
assert.sameValue(sample.bar, "baz", "return value from get accessor");
assert.sameValue(sample.baz, "test262", "return value from inherited key");
});

View File

@ -0,0 +1,42 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-get-p-receiver
description: >
Return undefined if key is numeric index < 0 or index [[ArrayLength]].
info: >
9.4.5.4 [[Get]] (P, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Return ? IntegerIndexedElementGet(O, numericIndex).
...
9.4.5.8 IntegerIndexedElementGet ( O, index )
...
7. Let length be the value of O's [[ArrayLength]] internal slot.
8. If index < 0 or index length, return undefined.
...
includes: [testTypedArray.js]
---*/
var proto = TypedArray.prototype;
var throwDesc = {
get: function() {
throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c");
}
};
Object.defineProperty(proto, "-1", throwDesc);
Object.defineProperty(proto, "2", throwDesc);
Object.defineProperty(proto, "3", throwDesc);
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
assert.sameValue(sample["-1"], undefined);
assert.sameValue(sample["2"], undefined);
assert.sameValue(sample["3"], undefined);
});

View File

@ -0,0 +1,40 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-get-p-receiver
description: >
Use OrginaryGet if key is a Symbol
info: >
9.4.5.4 [[Get]] (P, Receiver)
...
2. If Type(P) is String, then
...
3. Return ? OrdinaryGet(O, P, Receiver).
includes: [testTypedArray.js]
features: [Symbol]
---*/
var parentKey = Symbol("2");
TypedArray.prototype[parentKey] = "test262";
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42]);
var s1 = Symbol("1");
assert.sameValue(
sample[s1], undefined,
"return undefined if not property is present"
);
sample[s1] = "foo";
assert.sameValue(sample[s1], "foo", "return value");
Object.defineProperty(sample, s1, {
get: function() { return "bar"; }
});
assert.sameValue(sample[s1], "bar", "return value from get accessor");
assert.sameValue(sample[parentKey], "test262", "value from parent key");
});

View File

@ -0,0 +1,37 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-getownproperty-p
description: >
Does not throw on an instance with a detached buffer if key is not a number
info: >
9.4.5.1 [[GetOwnProperty]] ( P )
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return OrdinaryGetOwnProperty(O, P).
includes: [testTypedArray.js, detachArrayBuffer.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
$DETACHBUFFER(sample.buffer);
assert.sameValue(
Object.getOwnPropertyDescriptor(sample, "undef"),
undefined,
"undefined property"
);
// Tests for the property descriptor are defined on the tests for
// [[DefineOwnProperty]] calls
Object.defineProperty(sample, "foo", { value: "bar" });
assert.sameValue(
Object.getOwnPropertyDescriptor(sample, "foo").value,
"bar",
"return value from a String key"
);
});

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-getownproperty-p
description: >
Does not throw on an instance with a detached buffer if key is a Symbol
info: >
9.4.5.1 [[GetOwnProperty]] ( P )
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return OrdinaryGetOwnProperty(O, P).
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [Symbol]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
$DETACHBUFFER(sample.buffer);
var s = Symbol("foo");
Object.defineProperty(sample, s, { value: "baz" });
assert.sameValue(
Object.getOwnPropertyDescriptor(sample, s).value,
"baz",
"return value from a Symbol key"
);
});

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-getownproperty-p
description: Throws a TypeError if this has a detached buffer
info: >
9.4.5.1 [[GetOwnProperty]] ( P )
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Let value be ? IntegerIndexedElementGet(O, numericIndex).
...
9.4.5.8 IntegerIndexedElementGet ( O, index )
...
3. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
4. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
...
includes: [testTypedArray.js, detachArrayBuffer.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
$DETACHBUFFER(sample.buffer);
assert.throws(TypeError, function() {
Object.getOwnPropertyDescriptor(sample, 0);
});
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-getownproperty-p
description: >
Returns a descriptor object from an index property
info: >
9.4.5.1 [[GetOwnProperty]] ( P )
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
iii. Return a PropertyDescriptor{[[Value]]: value, [[Writable]]: true,
[[Enumerable]]: true, [[Configurable]]: false}.
...
includes: [testTypedArray.js, propertyHelper.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
var desc0 = Object.getOwnPropertyDescriptor(sample, 0);
assert.sameValue(desc0.value, 42, "value", "desc0.value === 42");
assert.sameValue(desc0.writable, true, "index descriptor is writable [0]");
verifyEnumerable(sample, "0", "index descriptor is enumerable [0]");
verifyNotConfigurable(sample, "0", "index descriptor is not configurable [0]");
var desc1 = Object.getOwnPropertyDescriptor(sample, 1);
assert.sameValue(desc1.value, 43, "value", "desc1.value === 43");
assert.sameValue(desc1.writable, true, "index descriptor is writable [1]");
verifyEnumerable(sample, "1", "index descriptor is enumerable [1]");
verifyNotConfigurable(sample, "1", "index descriptor is not configurable [1]");
});

View File

@ -0,0 +1,36 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-getownproperty-p
description: Returns undefined when P is -0.
info: >
9.4.5.1 [[GetOwnProperty]] ( P )
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Let value be ? IntegerIndexedElementGet(O, numericIndex).
ii. If value is undefined, return undefined.
...
7.1.16 CanonicalNumericIndexString ( argument )
...
2. If argument is "-0", return -0.
...
9.4.5.8 IntegerIndexedElementGet ( O, index )
...
6. If index = -0, return undefined.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42]);
// -0 as a number value is converted to "0" before calling [[GetOwnProperty]]
assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-0"), undefined);
});

View File

@ -0,0 +1,47 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-getownproperty-p
description: |
Returns an ordinary property value if numeric key is not a
CanonicalNumericIndex
info: >
9.4.5.1 [[GetOwnProperty]] ( P )
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return OrdinaryGetOwnProperty(O, P).
...
includes: [testTypedArray.js]
---*/
var keys = [
"1.0",
"+1",
"1000000000000000000000",
"0.0000001"
];
testWithTypedArrayConstructors(function(TA) {
keys.forEach(function(key) {
var sample = new TA([42, 43]);
assert.sameValue(
Object.getOwnPropertyDescriptor(sample, key),
undefined,
"undefined property [" + key + "]"
);
// Tests for the property descriptor are defined on the tests for
// [[DefineOwnProperty]] calls
Object.defineProperty(sample, key, {value: "bar"});
assert.sameValue(
Object.getOwnPropertyDescriptor(sample, key).value,
"bar",
"return value from a ordinary property key [" + key + "]"
);
});
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-getownproperty-p
description: Returns undefined when P is not an integer.
info: >
9.4.5.1 [[GetOwnProperty]] ( P )
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Let value be ? IntegerIndexedElementGet(O, numericIndex).
ii. If value is undefined, return undefined.
...
9.4.5.8 IntegerIndexedElementGet ( O, index )
...
5. If IsInteger(index) is false, return undefined.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
assert.sameValue(Object.getOwnPropertyDescriptor(sample, "1.1"), undefined);
assert.sameValue(Object.getOwnPropertyDescriptor(sample, "0.1"), undefined);
});

View File

@ -0,0 +1,37 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-getownproperty-p
description: >
Returns an ordinary property value if key is not a CanonicalNumericIndex
info: >
9.4.5.1 [[GetOwnProperty]] ( P )
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return OrdinaryGetOwnProperty(O, P).
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
assert.sameValue(
Object.getOwnPropertyDescriptor(sample, "undef"),
undefined,
"undefined property"
);
// Tests for the property descriptor are defined on the tests for
// [[DefineOwnProperty]] calls
Object.defineProperty(sample, "foo", { value: "bar" });
assert.sameValue(
Object.getOwnPropertyDescriptor(sample, "foo").value,
"bar",
"return value from a String key"
);
});

View File

@ -0,0 +1,33 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-getownproperty-p
description: Returns undefined when P is not a valid index number.
info: >
9.4.5.1 [[GetOwnProperty]] ( P )
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Let value be ? IntegerIndexedElementGet(O, numericIndex).
ii. If value is undefined, return undefined.
...
9.4.5.8 IntegerIndexedElementGet ( O, index )
...
7. Let length be the value of O's [[ArrayLength]] internal slot.
8. If index < 0 or index length, return undefined.
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42]);
assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-1"), undefined);
assert.sameValue(Object.getOwnPropertyDescriptor(sample, "-42"), undefined);
assert.sameValue(Object.getOwnPropertyDescriptor(sample, "1"), undefined);
assert.sameValue(Object.getOwnPropertyDescriptor(sample, "42"), undefined);
});

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-getownproperty-p
description: >
Returns an ordinary property value if key is a Symbol
info: >
9.4.5.1 [[GetOwnProperty]] ( P )
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return OrdinaryGetOwnProperty(O, P).
...
includes: [testTypedArray.js]
features: [Symbol]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
var s = Symbol("foo");
Object.defineProperty(sample, s, { value: "baz" });
assert.sameValue(
Object.getOwnPropertyDescriptor(sample, s).value,
"baz",
"return value from a Symbol key"
);
});

View File

@ -0,0 +1,63 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-hasproperty-p
description: Return abrupt from OrdinaryHasProperty parent's [[HasProperty]]
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
...
9.1.7.1 OrdinaryHasProperty (O, P)
...
2. Let hasOwn be ? O.[[GetOwnProperty]](P).
3. If hasOwn is not undefined, return true.
4. Let parent be ? O.[[GetPrototypeOf]]().
5. If parent is not null, then
a. Return ? parent.[[HasProperty]](P).
6. Return false.
features: [Reflect, Proxy]
includes: [testTypedArray.js, detachArrayBuffer.js]
---*/
var handler = {
has: function() {
throw new Test262Error();
}
};
var proxy = new Proxy(TypedArray.prototype, handler);
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
Object.setPrototypeOf(sample, proxy);
assert.sameValue(
Reflect.has(sample, 0), true,
"OrdinaryHasProperty does not affect numericIndex properties [0]"
);
assert.sameValue(
Reflect.has(sample, 1), false,
"OrdinaryHasProperty does not affect numericIndex properties [1]"
);
assert.throws(Test262Error, function() {
Reflect.has(sample, "foo");
}, "Return abrupt from parent's [[HasProperty]] 'foo'");
Object.defineProperty(sample, "foo", { value: 42 });
assert.sameValue(
Reflect.has(sample, "foo"),
true,
"trap is not triggered if [[GetOwnProperty]] returns a defined value"
);
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-getproperty-p
description: |
Does not throw on an instance with a detached buffer if key is not a
CanonicalNumericIndexString
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return ? OrdinaryHasProperty(O, P).
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
Object.defineProperty(sample, "bar", { value: 42 });
$DETACHBUFFER(sample.buffer);
assert.sameValue(Reflect.has(sample, "foo"), false);
assert.sameValue(Reflect.has(sample, "bar"), true);
});

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-hasproperty-p
description: >
Does not throw on an instance with a detached buffer if key is a Symbol
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return ? OrdinaryHasProperty(O, P).
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [Reflect, Symbol]
---*/
var s1 = Symbol("foo");
var s2 = Symbol("bar");
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
Object.defineProperty(sample, s1, { value: "baz" });
$DETACHBUFFER(sample.buffer);
assert.sameValue(Reflect.has(sample, s1), true);
assert.sameValue(Reflect.has(sample, s2), false);
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-hasproperty-p
description: Throws a TypeError if this has a detached buffer
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
...
features: [Reflect]
includes: [testTypedArray.js, detachArrayBuffer.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
$DETACHBUFFER(sample.buffer);
assert.throws(TypeError, function() {
Reflect.has(sample, "0");
}, "0");
assert.throws(TypeError, function() {
Reflect.has(sample, "-0");
}, "-0");
assert.throws(TypeError, function() {
Reflect.has(sample, "1.1");
}, "1.1");
});

View File

@ -0,0 +1,32 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-hasproperty-p
description: >
Return true for indexed properties
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
ii. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
iii. If IsInteger(numericIndex) is false, return false.
iv. If numericIndex = -0, return false.
v. If numericIndex < 0, return false.
vi. If numericIndex the value of O's [[ArrayLength]] internal slot,
return false.
vii. Return true.
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
assert.sameValue(Reflect.has(sample, 0), true);
assert.sameValue(Reflect.has(sample, 1), true);
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-hasproperty-p
description: >
Find inherited properties if property is not a CanonicalNumericIndexString
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return ? OrdinaryHasProperty(O, P).
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
TypedArray.prototype.foo = 42;
TypedArray.prototype[42] = true;
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
TA.prototype.bar = 42;
assert.sameValue(Reflect.has(sample, "subarray"), true, "subarray");
assert.sameValue(Reflect.has(sample, "foo"), true, "foo");
assert.sameValue(Reflect.has(sample, "bar"), true, "bar");
assert.sameValue(Reflect.has(sample, "baz"), false, "baz");
assert.sameValue(Reflect.has(sample, "42"), false, "42");
});

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.
/*---
esid: sec-integer-indexed-exotic-objects-hasproperty-p
description: Return false if P's value is >= this's [[ArrayLength]]
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
vi. If numericIndex the value of O's [[ArrayLength]] internal slot,
return false.
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
// Prevents false positives using OrdinaryHasProperty
TypedArray.prototype[1] = "test262";
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
assert.sameValue(Reflect.has(sample, "1"), false, "1");
});

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.
/*---
esid: sec-integer-indexed-exotic-objects-hasproperty-p
description: Return false if P's value is < 0
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
v. If numericIndex < 0, return false.
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
// Prevents false positives using OrdinaryHasProperty
TypedArray.prototype[-1] = "test262";
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
assert.sameValue(Reflect.has(sample, "-1"), false, "-1");
});

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.
/*---
esid: sec-integer-indexed-exotic-objects-hasproperty-p
description: Return false if P's value is "-0"
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
iv. If numericIndex = -0, return false.
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
// Prevents false positives using OrdinaryHasProperty
TypedArray.prototype["-0"] = "test262";
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
assert.sameValue(Reflect.has(sample, "-0"), false, "-0");
});

View File

@ -0,0 +1,53 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-hasproperty-p
description: >
Return boolean from numeric keys that are not a CanonicalNumericIndexString
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return ? OrdinaryHasProperty(O, P).
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
var keys = [
"1.0",
"+1",
"1000000000000000000000",
"0.0000001"
];
testWithTypedArrayConstructors(function(TA) {
keys.forEach(function(key) {
var sample = new TA(1);
assert.sameValue(
Reflect.has(sample, key), false,
"returns false without key [" + key + "]"
);
TypedArray.prototype[key] = 42;
assert.sameValue(
Reflect.has(sample, key), true,
"returns true with inherited key [" + key + "]"
);
delete TypedArray.prototype[key];
Object.defineProperty(sample, key, {value: 42});
assert.sameValue(
Reflect.has(sample, key), true,
"returns true with own key [" + key + "]"
);
});
});

View File

@ -0,0 +1,30 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-hasproperty-p
description: Return false if P's value is not an integer
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
iii. If IsInteger(numericIndex) is false, return false.
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
// Prevents false positives using OrdinaryHasProperty
TypedArray.prototype["1.1"] = "test262";
TypedArray.prototype["0.000001"] = "test262";
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
assert.sameValue(Reflect.has(sample, "1.1"), false, "1.1");
assert.sameValue(Reflect.has(sample, "0.000001"), false, "0.000001");
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-hasproperty-p
description: >
Return boolean from properties that are not a CanonicalNumericIndexString
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
4. Return ? OrdinaryHasProperty(O, P).
...
features: [Reflect]
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
assert.sameValue(Reflect.has(sample, "foo"), false);
Object.defineProperty(sample, "foo", { value: 42 });
assert.sameValue(Reflect.has(sample, "foo"), true);
});

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.
/*---
esid: sec-integer-indexed-exotic-objects-hasproperty-p
description: >
Return boolean from Symbol properties
info: >
9.4.5.2 [[HasProperty]](P)
...
3. If Type(P) is String, then
...
4. Return ? OrdinaryHasProperty(O, P).
features: [Reflect, Symbol]
includes: [testTypedArray.js]
---*/
var s = Symbol("foo");
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
assert.sameValue(Reflect.has(sample, s), false);
Object.defineProperty(sample, s, { value: 42 });
assert.sameValue(Reflect.has(sample, s), true);
});

View File

@ -0,0 +1,48 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-ownpropertykeys
description: >
Return integer index + non numeric string keys
info: >
9.4.5.6 [[OwnPropertyKeys]] ()
...
3. Let len be the value of O's [[ArrayLength]] internal slot.
4. For each integer i starting with 0 such that i < len, in ascending order,
a. Add ! ToString(i) as the last element of keys.
...
includes: [testTypedArray.js, compareArray.js]
features: [Reflect, Symbol]
---*/
var s1 = Symbol("1");
var s2 = Symbol("2");
TypedArray.prototype[3] = 42;
TypedArray.prototype.bar = 42;
testWithTypedArrayConstructors(function(TA) {
var sample1 = new TA([42, 42, 42]);
sample1[s1] = 42;
sample1[s2] = 42;
sample1.test262 = 42;
sample1.ecma262 = 42;
var result1 = Reflect.ownKeys(sample1);
assert(
compareArray(result1, ["0", "1", "2", "test262", "ecma262", s1, s2]),
"result1"
);
var sample2 = new TA(4).subarray(2);
sample2[s1] = 42;
sample2[s2] = 42;
sample2.test262 = 42;
sample2.ecma262 = 42;
var result2 = Reflect.ownKeys(sample2);
assert(
compareArray(result2, ["0", "1", "test262", "ecma262", s1, s2]),
"result2"
);
});

View File

@ -0,0 +1,41 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-ownpropertykeys
description: >
Return integer index + non numeric string keys
info: >
9.4.5.6 [[OwnPropertyKeys]] ()
...
3. Let len be the value of O's [[ArrayLength]] internal slot.
4. For each integer i starting with 0 such that i < len, in ascending order,
a. Add ! ToString(i) as the last element of keys.
...
includes: [testTypedArray.js, compareArray.js]
features: [Reflect]
---*/
TypedArray.prototype[3] = 42;
TypedArray.prototype.bar = 42;
testWithTypedArrayConstructors(function(TA) {
var sample1 = new TA([42, 42, 42]);
sample1.test262 = 42;
sample1.ecma262 = 42;
var result1 = Reflect.ownKeys(sample1);
assert(
compareArray(result1, ["0", "1", "2", "test262", "ecma262"]),
"result1"
);
var sample2 = new TA(4).subarray(2);
sample2.test262 = 42;
sample2.ecma262 = 42;
var result2 = Reflect.ownKeys(sample2);
assert(
compareArray(result2, ["0", "1", "test262", "ecma262"]),
"result2"
);
});

View File

@ -0,0 +1,36 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-ownpropertykeys
description: >
Return keys
info: >
9.4.5.6 [[OwnPropertyKeys]] ()
...
3. Let len be the value of O's [[ArrayLength]] internal slot.
4. For each integer i starting with 0 such that i < len, in ascending order,
a. Add ! ToString(i) as the last element of keys.
...
includes: [testTypedArray.js, compareArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample1 = new TA([42, 42, 42]);
var result1 = Reflect.ownKeys(sample1);
assert(compareArray(result1, ["0", "1", "2"]), "result1");
var sample2 = new TA(4);
var result2 = Reflect.ownKeys(sample2);
assert(compareArray(result2, ["0", "1", "2", "3"]), "result2");
var sample3 = new TA(4).subarray(2);
var result3 = Reflect.ownKeys(sample3);
assert(compareArray(result3, ["0", "1"]), "result3");
var sample4 = new TA();
var result4 = Reflect.ownKeys(sample4);
assert(compareArray(result4, []), "result4");
});

View File

@ -0,0 +1,35 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-ownpropertykeys
description: >
List not-enumerable own keys
info: >
9.4.5.6 [[OwnPropertyKeys]] ()
...
3. Let len be the value of O's [[ArrayLength]] internal slot.
4. For each integer i starting with 0 such that i < len, in ascending order,
a. Add ! ToString(i) as the last element of keys.
...
includes: [testTypedArray.js, compareArray.js]
features: [Reflect, Symbol]
---*/
var s = Symbol("1");
testWithTypedArrayConstructors(function(TA) {
var sample = new TA();
Object.defineProperty(sample, s, {
value: 42,
enumerable: false
});
Object.defineProperty(sample, "test262", {
value: 42,
enumerable: false
});
var result = Reflect.ownKeys(sample);
assert(compareArray(result, ["test262", s]));
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
description: >
Does not throw on an instance with a detached buffer if key is not a number
info: >
9.4.5.5 [[Set]] ( P, V, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
3. Return ? OrdinarySet(O, P, V, Receiver).
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
$DETACHBUFFER(sample.buffer);
assert.sameValue(Reflect.set(sample, "foo", "test262"), true);
assert.sameValue(sample["foo"], "test262");
});

View File

@ -0,0 +1,26 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
description: >
Does not throw on an instance with a detached buffer if key is a Symbol
info: >
9.4.5.5 [[Set]] ( P, V, Receiver)
...
2. If Type(P) is String, then
...
3. Return ? OrdinarySet(O, P, V, Receiver).
includes: [testTypedArray.js, detachArrayBuffer.js]
features: [Symbol, Reflect]
---*/
var s = Symbol("1");
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
$DETACHBUFFER(sample.buffer);
assert.sameValue(Reflect.set(sample, s, "test262"), true);
assert.sameValue(sample[s], "test262");
});

View File

@ -0,0 +1,64 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
description: >
Throws a TypeError if key has a numeric index and object has a detached buffer
info: >
9.4.5.5 [[Set]] ( P, V, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Return ? IntegerIndexedElementSet(O, numericIndex, V).
...
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
...
3. Let numValue be ? ToNumber(value).
4. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot.
5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
...
includes: [testTypedArray.js, detachArrayBuffer.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42]);
$DETACHBUFFER(sample.buffer);
assert.throws(TypeError, function() {
sample[0] = 1;
}, "valid numeric index");
assert.throws(TypeError, function() {
sample["1.1"] = 1;
}, "detach buffer runs before checking for 1.1");
assert.throws(TypeError, function() {
sample["-0"] = 1;
}, "detach buffer runs before checking for -0");
assert.throws(TypeError, function() {
sample["-1"] = 1;
}, "detach buffer runs before checking for -1");
assert.throws(TypeError, function() {
sample["1"] = 1;
}, "detach buffer runs before checking for key == length");
assert.throws(TypeError, function() {
sample["2"] = 1;
}, "detach buffer runs before checking for key > length");
var obj = {
valueOf: function() {
throw new Test262Error();
}
};
assert.throws(Test262Error, function() {
sample["0"] = obj;
}, "ToNumber(value) is called before detached buffer check");
});

View File

@ -0,0 +1,43 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
description: >
Returns true after setting value
info: >
9.4.5.5 [[Set]] ( P, V, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Return ? IntegerIndexedElementSet(O, numericIndex, V).
...
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
...
15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue).
16. Return true.
includes: [testTypedArray.js]
features: [Reflect]
---*/
var proto = TypedArray.prototype;
var throwDesc = {
set: function() {
throw new Test262Error("OrdinarySet was called! Ref: 9.1.9.1 3.b.i");
}
};
Object.defineProperty(proto, "0", throwDesc);
Object.defineProperty(proto, "1", throwDesc);
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42, 43]);
assert.sameValue(Reflect.set(sample, "0", 1), true, "sample[0]");
assert.sameValue(sample[0], 1, "sample[0] value is set");
assert.sameValue(Reflect.set(sample, "1", 42), true, "sample[1]");
assert.sameValue(sample[1], 42, "sample[1] value is set");
});

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
description: >
Returns false if index is -0
info: >
9.4.5.5 [[Set]] ( P, V, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Return ? IntegerIndexedElementSet(O, numericIndex, V).
...
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
...
7. If index = -0, return false.
...
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42]);
assert.sameValue(Reflect.set(sample, "-0", 1), false, "-0");
assert.sameValue(sample.hasOwnProperty("-0"), false, "has no property [-0]");
});

View File

@ -0,0 +1,58 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
description: >
Use OrginarySet if numeric key is not a CanonicalNumericIndex
info: >
9.4.5.5 [[Set]] ( P, V, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
3. Return ? OrdinarySet(O, P, V, Receiver).
includes: [testTypedArray.js]
features: [Reflect]
---*/
var keys = [
"1.0",
"+1",
"1000000000000000000000",
"0.0000001"
];
testWithTypedArrayConstructors(function(TA) {
keys.forEach(function(key) {
var sample = new TA([42]);
assert.sameValue(
Reflect.set(sample, key, "ecma262"),
true,
"Return true setting a new property [" + key + "]"
);
assert.sameValue(sample[key], "ecma262");
assert.sameValue(
Reflect.set(sample, key, "es3000"),
true,
"Return true setting a value to a writable property [" + key + "]"
);
assert.sameValue(sample[key], "es3000");
Object.defineProperty(sample, key, {
writable: false,
value: undefined
});
assert.sameValue(
Reflect.set(sample, key, 42),
false,
"Return false setting a value to a non-writable property [" + key + "]"
);
assert.sameValue(
sample[key], undefined, "non-writable [" + key + "] is preserved"
);
});
});

View File

@ -0,0 +1,38 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
description: >
Returns false if index is not integer
info: >
9.4.5.5 [[Set]] ( P, V, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Return ? IntegerIndexedElementSet(O, numericIndex, V).
...
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
...
6. If IsInteger(index) is false, return false.
...
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42]);
assert.sameValue(Reflect.set(sample, "1.1", 1), false, "1.1");
assert.sameValue(Reflect.set(sample, "0.0001", 1), false, "0.0001");
assert.sameValue(sample.hasOwnProperty("1.1"), false, "has no property [1.1]");
assert.sameValue(
sample.hasOwnProperty("0.0001"),
false,
"has no property [0.0001]"
);
});

View File

@ -0,0 +1,39 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
description: >
Returns abrupt from OrginarySet when key is not a numeric index
info: >
9.4.5.5 [[Set]] ( P, V, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
3. Return ? OrdinarySet(O, P, V, Receiver).
9.1.9.1 OrdinarySet (O, P, V, Receiver)
...
8. Perform ? Call(setter, Receiver, « V »).
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA(1);
Object.defineProperty(sample, "test262", {
set: function() {
throw new Test262Error();
}
});
assert.throws(Test262Error, function() {
sample.test262 = 1;
});
assert.sameValue(sample.test262, undefined);
});

View File

@ -0,0 +1,47 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
description: >
Use OrginarySet if key is not a CanonicalNumericIndex
info: >
9.4.5.5 [[Set]] ( P, V, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
...
3. Return ? OrdinarySet(O, P, V, Receiver).
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42]);
assert.sameValue(
Reflect.set(sample, "test262", "ecma262"),
true,
"Return true setting a new property"
);
assert.sameValue(sample.test262, "ecma262");
assert.sameValue(
Reflect.set(sample, "test262", "es3000"),
true,
"Return true setting a value to a writable property"
);
assert.sameValue(sample.test262, "es3000");
Object.defineProperty(sample, "foo", {
writable: false,
value: undefined
});
assert.sameValue(
Reflect.set(sample, "foo", 42),
false,
"Return false setting a value to a non-writable property"
);
assert.sameValue(sample.foo, undefined);
});

View File

@ -0,0 +1,37 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
description: >
Returns false if index is out of bounds
info: >
9.4.5.5 [[Set]] ( P, V, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Return ? IntegerIndexedElementSet(O, numericIndex, V).
...
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
...
8. Let length be the value of O's [[ArrayLength]] internal slot.
9. If index < 0 or index length, return false.
...
includes: [testTypedArray.js]
features: [Reflect]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42]);
assert.sameValue(Reflect.set(sample, "-1", 1), false, "-1");
assert.sameValue(Reflect.set(sample, "1", 1), false, "1");
assert.sameValue(Reflect.set(sample, "2", 1), false, "2");
assert.sameValue(sample.hasOwnProperty("-1"), false, "has no property [-1]");
assert.sameValue(sample.hasOwnProperty("1"), false, "has no property [1]");
assert.sameValue(sample.hasOwnProperty("2"), false, "has no property [2]");
});

View File

@ -0,0 +1,48 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
description: >
Use OrginarySet if key is a Symbol
info: >
9.4.5.5 [[Set]] ( P, V, Receiver)
...
2. If Type(P) is String, then
...
3. Return ? OrdinarySet(O, P, V, Receiver).
includes: [testTypedArray.js]
features: [Reflect, Symbol]
---*/
var s1 = Symbol("1");
var s2 = Symbol("2");
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42]);
assert.sameValue(
Reflect.set(sample, s1, "ecma262"),
true,
"Return true setting a new property"
);
assert.sameValue(sample[s1], "ecma262");
assert.sameValue(
Reflect.set(sample, s1, "es3000"),
true,
"Return true setting a value to a writable property"
);
assert.sameValue(sample[s1], "es3000");
Object.defineProperty(sample, s2, {
writable: false,
value: undefined
});
assert.sameValue(
Reflect.set(sample, s2, 42),
false,
"Return false setting a value to a non-writable property"
);
assert.sameValue(sample[s2], undefined);
});

View File

@ -0,0 +1,57 @@
// Copyright (C) 2016 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
description: >
Returns abrupt from ToNumber(value)
info: >
9.4.5.5 [[Set]] ( P, V, Receiver)
...
2. If Type(P) is String, then
a. Let numericIndex be ! CanonicalNumericIndexString(P).
b. If numericIndex is not undefined, then
i. Return ? IntegerIndexedElementSet(O, numericIndex, V).
...
9.4.5.9 IntegerIndexedElementSet ( O, index, value )
...
3. Let numValue be ? ToNumber(value).
...
includes: [testTypedArray.js]
---*/
testWithTypedArrayConstructors(function(TA) {
var sample = new TA([42]);
var obj = {
valueOf: function() {
throw new Test262Error();
}
};
assert.throws(Test262Error, function() {
sample["0"] = obj;
}, "ToNumber check with a valid index");
assert.throws(Test262Error, function() {
sample["1.1"] = obj;
}, "ToNumber runs before ToInteger(index)");
assert.throws(Test262Error, function() {
sample["-0"] = obj;
}, "ToNumber runs before -0 check");
assert.throws(Test262Error, function() {
sample["-1"] = obj;
}, "ToNumber runs before < 0 check");
assert.throws(Test262Error, function() {
sample["1"] = obj;
}, "ToNumber runs before index == length check");
assert.throws(Test262Error, function() {
sample["2"] = obj;
}, "ToNumber runs before index > length check");
});