diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/test262/built-ins/Array/length/define-own-prop-length-coercion-order-set.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Array/length/define-own-prop-length-coercion-order-set.js')
-rw-r--r-- | js/src/tests/test262/built-ins/Array/length/define-own-prop-length-coercion-order-set.js | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Array/length/define-own-prop-length-coercion-order-set.js b/js/src/tests/test262/built-ins/Array/length/define-own-prop-length-coercion-order-set.js new file mode 100644 index 0000000000..bb3acea2e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Array/length/define-own-prop-length-coercion-order-set.js @@ -0,0 +1,48 @@ +// Copyright (C) 2020 Alexey Shvayka. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +author: André Bargull +esid: sec-arraysetlength +description: > + [[Value]] is coerced to number before current descriptor's [[Writable]] check. +info: | + ArraySetLength ( A, Desc ) + + [...] + 3. Let newLen be ? ToUint32(Desc.[[Value]]). + 4. Let numberLen be ? ToNumber(Desc.[[Value]]). + [...] + 7. Let oldLenDesc be OrdinaryGetOwnProperty(A, "length"). + [...] + 12. If oldLenDesc.[[Writable]] is false, return false. +features: [Symbol, Symbol.toPrimitive, Reflect, Reflect.set] +includes: [compareArray.js] +---*/ + +var array = [1, 2, 3]; +var hints = []; +var length = {}; +length[Symbol.toPrimitive] = function(hint) { + hints.push(hint); + Object.defineProperty(array, "length", {writable: false}); + return 0; +}; + +assert.throws(TypeError, function() { + "use strict"; + array.length = length; +}, '`"use strict"; array.length = length` throws a TypeError exception'); +assert.compareArray(hints, ["number", "number"], 'The value of hints is expected to be ["number", "number"]'); + + +array = [1, 2, 3]; +hints = []; + +assert( + !Reflect.set(array, "length", length), + 'The value of !Reflect.set(array, "length", length) is expected to be true' +); +assert.compareArray(hints, ["number", "number"], 'The value of hints is expected to be ["number", "number"]'); + +reportCompare(0, 0); |