summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/object-keys.js
blob: 29eb85d6aa7bac7072a7109432c3698ea0d1f9e2 (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
// Copyright 2017 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax

// Ensure that mutation of the Object.keys result doesn't affect the
// enumeration cache for fast-mode objects.
(function() {
  const a = {x:1, y:2};
  let k = Object.keys(a);
  %HeapObjectVerify(k);
  assertEquals(2, k.length);
  assertEquals("x", k[0]);
  assertEquals("y", k[1]);
  k[0] = "y";
  k[1] = "x";
  k = Object.keys(a);
  assertEquals(2, k.length);
  assertEquals("x", k[0]);
  assertEquals("y", k[1]);
})();

// Ensure that the copy-on-write keys are handled properly, even in
// the presence of Symbols.
(function() {
  const s = Symbol();
  const a = {[s]: 1};
  let k = Object.keys(a);
  %HeapObjectVerify(k);
  assertEquals(0, k.length);
  k.shift();
  assertEquals(0, k.length);
})();