summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Array/pop-no-has-trap.js
blob: 11bb93ddd0eb815b4ee85119ceaeda4a921e627b (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
49
50
51
52
53
54
55
56
57
58
// Test that Array.prototype.pop doesn't call the [[HasProperty]] internal
// method of objects when retrieving the element at the last index.

var log = [];
var array = [];
var proxy = new Proxy(array, new Proxy({}, {
    get(t, trap, r) {
      return (t, pk, ...more) => {
        log.push(`${trap}:${String(pk)}`);
        return Reflect[trap](t, pk, ...more);
      };
    }
}));

var result;

result = Array.prototype.pop.call(proxy);
assertEqArray(log, [
  "get:length",
  "set:length", "getOwnPropertyDescriptor:length", "defineProperty:length"
]);
assertEq(result, undefined);

log.length = 0;
array.push(1);

result = Array.prototype.pop.call(proxy);
assertEqArray(log, [
  "get:length",
  "get:0", "deleteProperty:0",
  "set:length", "getOwnPropertyDescriptor:length", "defineProperty:length"
]);
assertEq(result, 1);

log.length = 0;
array.push(2, 3);

result = Array.prototype.pop.call(proxy);
assertEqArray(log, [
  "get:length",
  "get:1", "deleteProperty:1",
  "set:length", "getOwnPropertyDescriptor:length", "defineProperty:length"
]);
assertEq(result, 3);

log.length = 0;
array.push(4, 5);

result = Array.prototype.pop.call(proxy);
assertEqArray(log, [
  "get:length",
  "get:2", "deleteProperty:2",
  "set:length", "getOwnPropertyDescriptor:length", "defineProperty:length"
]);
assertEq(result, 5);

if (typeof reportCompare === "function")
  reportCompare(true, true);