blob: 5ad096f3ed6a86d634019091a24602f049d6e4a0 [file] [log] [blame]
Ben Murdochda12d292016-06-02 14:46:10 +01001// Copyright 2016 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5function enumerate(o) {
6 var keys = [];
7 for (var key in o) keys.push(key);
8 return keys;
9}
10
11(function testSlowSloppyArgumentsElements() {
12 function slowSloppyArguments(a, b, c) {
13 arguments[10000] = "last";
14 arguments[4000] = "first";
15 arguments[6000] = "second";
16 arguments[5999] = "x";
17 arguments[3999] = "y";
18 return arguments;
19 }
20 assertEquals(["0", "1", "2", "3999", "4000", "5999", "6000", "10000"],
21 Object.keys(slowSloppyArguments(1, 2, 3)));
22
23 assertEquals(["0", "1", "2", "3999", "4000", "5999", "6000", "10000"],
24 enumerate(slowSloppyArguments(1,2,3)));
25})();
26
27(function testSlowSloppyArgumentsElementsNotEnumerable() {
28 function slowSloppyArguments(a, b, c) {
29 Object.defineProperty(arguments, 10000, {
30 enumerable: false, configurable: false, value: "NOPE"
31 });
32 arguments[4000] = "first";
33 arguments[6000] = "second";
34 arguments[5999] = "x";
35 arguments[3999] = "y";
36 return arguments;
37 }
38
39 assertEquals(["0", "1", "2", "3999", "4000", "5999", "6000"],
40 Object.keys(slowSloppyArguments(1, 2, 3)));
41
42 assertEquals(["0", "1", "2", "3999", "4000", "5999", "6000"],
43 enumerate(slowSloppyArguments(1,2,3)));
44})();
45
46(function testFastSloppyArgumentsElements() {
47 function fastSloppyArguments(a, b, c) {
48 arguments[5] = 1;
49 arguments[7] = 0;
50 arguments[3] = 2;
51 return arguments;
52 }
53 assertEquals(["0", "1", "2", "3", "5", "7"],
54 Object.keys(fastSloppyArguments(1, 2, 3)));
55
56 assertEquals(
57 ["0", "1", "2", "3", "5", "7"], enumerate(fastSloppyArguments(1, 2, 3)));
58
59 function fastSloppyArguments2(a, b, c) {
60 delete arguments[0];
61 arguments[0] = "test";
62 return arguments;
63 }
64
65 assertEquals(["0", "1", "2"], Object.keys(fastSloppyArguments2(1, 2, 3)));
66 assertEquals(["0", "1", "2"], enumerate(fastSloppyArguments2(1, 2, 3)));
67})();
68
69(function testFastSloppyArgumentsElementsNotEnumerable() {
70 function fastSloppyArguments(a, b, c) {
71 Object.defineProperty(arguments, 5, {
72 enumerable: false, configurable: false, value: "NOPE"
73 });
74 arguments[7] = 0;
75 arguments[3] = 2;
76 return arguments;
77 }
78 assertEquals(
79 ["0", "1", "2", "3", "7"], Object.keys(fastSloppyArguments(1, 2, 3)));
80
81 assertEquals(
82 ["0", "1", "2", "3", "7"], enumerate(fastSloppyArguments(1,2,3)));
83
84 function fastSloppyArguments2(a, b, c) {
85 delete arguments[0];
86 Object.defineProperty(arguments, 1, {
87 enumerable: false, configurable: false, value: "NOPE"
88 });
89 arguments[0] = "test";
90 return arguments;
91 }
92
93 assertEquals(["0", "2"], Object.keys(fastSloppyArguments2(1, 2, 3)));
94 assertEquals(["0", "2"], enumerate(fastSloppyArguments2(1, 2, 3)));
95})();