summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/length/define-own-prop-length-coercion-order-set.js
blob: bb3acea2e2d9ded12c81423cd4be329345dfb4c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);