diff options
author | Leonardo Balter <leonardo.balter@gmail.com> | 2016-03-07 12:44:20 -0500 |
---|---|---|
committer | Mike Pennisi <mike@mikepennisi.com> | 2016-03-28 10:38:24 -0400 |
commit | 3cb20b9df59daeb850588bffcfa0c2c880395e10 (patch) | |
tree | b4715e3bec2cb7f7c11e276fac9535b75e83adf8 /test/built-ins/TypedArrays/internals/HasProperty | |
parent | 887b3794217f7e4ea2f6c93769740712744d6974 (diff) | |
download | qtdeclarative-testsuites-3cb20b9df59daeb850588bffcfa0c2c880395e10.tar.gz |
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]]
Diffstat (limited to 'test/built-ins/TypedArrays/internals/HasProperty')
13 files changed, 449 insertions, 0 deletions
diff --git a/test/built-ins/TypedArrays/internals/HasProperty/abrupt-from-ordinary-has-parent-hasproperty.js b/test/built-ins/TypedArrays/internals/HasProperty/abrupt-from-ordinary-has-parent-hasproperty.js new file mode 100644 index 000000000..ca1bcb436 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/abrupt-from-ordinary-has-parent-hasproperty.js @@ -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" + ); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-not-number.js b/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-not-number.js new file mode 100644 index 000000000..693de351a --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-not-number.js @@ -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); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-symbol.js b/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-symbol.js new file mode 100644 index 000000000..00e45f46d --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer-key-is-symbol.js @@ -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); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer.js b/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer.js new file mode 100644 index 000000000..ed9bed956 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/detached-buffer.js @@ -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"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/indexed-value.js b/test/built-ins/TypedArrays/internals/HasProperty/indexed-value.js new file mode 100644 index 000000000..3cd5c3992 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/indexed-value.js @@ -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); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/inherited-property.js b/test/built-ins/TypedArrays/internals/HasProperty/inherited-property.js new file mode 100644 index 000000000..ceba758ab --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/inherited-property.js @@ -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"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/key-is-greater-than-last-index.js b/test/built-ins/TypedArrays/internals/HasProperty/key-is-greater-than-last-index.js new file mode 100644 index 000000000..20adc0355 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/key-is-greater-than-last-index.js @@ -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"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/key-is-lower-than-zero.js b/test/built-ins/TypedArrays/internals/HasProperty/key-is-lower-than-zero.js new file mode 100644 index 000000000..efb5b379d --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/key-is-lower-than-zero.js @@ -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"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/key-is-minus-zero.js b/test/built-ins/TypedArrays/internals/HasProperty/key-is-minus-zero.js new file mode 100644 index 000000000..6c6ec59bb --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/key-is-minus-zero.js @@ -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"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-canonical-index.js b/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-canonical-index.js new file mode 100644 index 000000000..3ededcf06 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-canonical-index.js @@ -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 + "]" + ); + }); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-integer.js b/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-integer.js new file mode 100644 index 000000000..742069389 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-integer.js @@ -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"); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-numeric-index.js b/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-numeric-index.js new file mode 100644 index 000000000..8e3bfec37 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/key-is-not-numeric-index.js @@ -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); +}); diff --git a/test/built-ins/TypedArrays/internals/HasProperty/key-is-symbol.js b/test/built-ins/TypedArrays/internals/HasProperty/key-is-symbol.js new file mode 100644 index 000000000..8c1d9ad17 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/HasProperty/key-is-symbol.js @@ -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); +}); |