regress-4825.js 3.3 KB
Newer Older
1 2 3 4
// Copyright 2016 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.

5 6
// Flags: --allow-natives-syntax

7 8 9 10 11 12 13 14
function enumerate(o) {
  var keys = [];
  for (var key in o) keys.push(key);
  return keys;
}

(function testSlowSloppyArgumentsElements()  {
  function slowSloppyArguments(a, b, c) {
15
    %HeapObjectVerify(arguments);
16 17 18 19 20
    arguments[10000] = "last";
    arguments[4000] = "first";
    arguments[6000] = "second";
    arguments[5999] = "x";
    arguments[3999] = "y";
21
    %HeapObjectVerify(arguments);
22 23 24 25 26 27 28 29 30 31 32 33 34 35
    return arguments;
  }
  assertEquals(["0", "1", "2", "3999", "4000", "5999", "6000", "10000"],
               Object.keys(slowSloppyArguments(1, 2, 3)));

  assertEquals(["0", "1", "2", "3999", "4000", "5999", "6000", "10000"],
               enumerate(slowSloppyArguments(1,2,3)));
})();

(function testSlowSloppyArgumentsElementsNotEnumerable() {
  function slowSloppyArguments(a, b, c) {
    Object.defineProperty(arguments, 10000, {
      enumerable: false, configurable: false, value: "NOPE"
    });
36
    %HeapObjectVerify(arguments);
37 38 39 40
    arguments[4000] = "first";
    arguments[6000] = "second";
    arguments[5999] = "x";
    arguments[3999] = "y";
41
    %HeapObjectVerify(arguments);
42 43 44 45 46 47 48 49 50 51
    return arguments;
  }

  assertEquals(["0", "1", "2", "3999", "4000", "5999", "6000"],
               Object.keys(slowSloppyArguments(1, 2, 3)));

  assertEquals(["0", "1", "2", "3999", "4000", "5999", "6000"],
                enumerate(slowSloppyArguments(1,2,3)));
})();

52

53 54 55 56 57
(function testFastSloppyArgumentsElements()  {
  function fastSloppyArguments(a, b, c) {
    arguments[5] = 1;
    arguments[7] = 0;
    arguments[3] = 2;
58
    %HeapObjectVerify(arguments);
59 60 61 62 63 64 65 66 67 68
    return arguments;
  }
  assertEquals(["0", "1", "2", "3", "5", "7"],
               Object.keys(fastSloppyArguments(1, 2, 3)));

  assertEquals(
      ["0", "1", "2", "3", "5", "7"], enumerate(fastSloppyArguments(1, 2, 3)));

  function fastSloppyArguments2(a, b, c) {
    delete arguments[0];
69 70
    %DebugPrint(arguments);
    %HeapObjectVerify(arguments);
71
    arguments[0] = "test";
72 73
    %DebugPrint(arguments);
    %HeapObjectVerify(arguments);
74 75 76 77 78 79 80 81 82 83 84 85
    return arguments;
  }

  assertEquals(["0", "1", "2"], Object.keys(fastSloppyArguments2(1, 2, 3)));
  assertEquals(["0", "1", "2"], enumerate(fastSloppyArguments2(1, 2, 3)));
})();

(function testFastSloppyArgumentsElementsNotEnumerable() {
  function fastSloppyArguments(a, b, c) {
    Object.defineProperty(arguments, 5, {
      enumerable: false, configurable: false, value: "NOPE"
    });
86
    %HeapObjectVerify(arguments);
87 88
    arguments[7] = 0;
    arguments[3] = 2;
89
    %HeapObjectVerify(arguments);
90 91 92 93 94 95 96 97 98 99
    return arguments;
  }
  assertEquals(
      ["0", "1", "2", "3", "7"], Object.keys(fastSloppyArguments(1, 2, 3)));

  assertEquals(
      ["0", "1", "2", "3", "7"], enumerate(fastSloppyArguments(1,2,3)));

  function fastSloppyArguments2(a, b, c) {
    delete arguments[0];
100
    %HeapObjectVerify(arguments);
101 102 103 104
    Object.defineProperty(arguments, 1, {
      enumerable: false, configurable: false, value: "NOPE"
    });
    arguments[0] = "test";
105
    %HeapObjectVerify(arguments);
106 107 108 109 110 111
    return arguments;
  }

  assertEquals(["0", "2"], Object.keys(fastSloppyArguments2(1, 2, 3)));
  assertEquals(["0", "2"], enumerate(fastSloppyArguments2(1, 2, 3)));
})();