blob: 85ae3692d8df2c849b663d71a98ab23ba6e209b1 [file] [log] [blame]
Ben Murdoch4a90d5f2016-03-22 12:00:34 +00001// Copyright 2014 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
5// Flags: --allow-natives-syntax
6
7Object.prototype["10"] = "unreachable";
8Object.prototype["7"] = "unreachable";
9Object.prototype["-1"] = "unreachable";
10Object.prototype["-0"] = "unreachable";
11Object.prototype["4294967295"] = "unreachable";
12
13var array = new Int32Array(10);
14
15function check() {
16 for (var i = 0; i < 4; i++) {
17 assertEquals(undefined, array["-1"]);
18 assertEquals(undefined, array["-0"]);
19 assertEquals(undefined, array["10"]);
20 assertEquals(undefined, array["4294967295"]);
21 }
22 assertEquals("unreachable", array.__proto__["-1"]);
23 assertEquals("unreachable", array.__proto__["-0"]);
24 assertEquals("unreachable", array.__proto__["10"]);
25 assertEquals("unreachable", array.__proto__["4294967295"]);
26}
27
28check();
29
30array["-1"] = "unreachable";
31array["-0"] = "unreachable";
32array["10"] = "unreachable";
33array["4294967295"] = "unreachable";
34
35check();
36
37delete array["-0"];
38delete array["-1"];
39delete array["10"];
40delete array["4294967295"];
41
42assertEquals(undefined, Object.getOwnPropertyDescriptor(array, "-1"));
43assertEquals(undefined, Object.getOwnPropertyDescriptor(array, "-0"));
44assertEquals(undefined, Object.getOwnPropertyDescriptor(array, "10"));
45assertEquals(undefined, Object.getOwnPropertyDescriptor(array, "4294967295"));
46assertEquals(10, Object.keys(array).length);
47
48check();
49
50function f() { return array["-1"]; }
51
52for (var i = 0; i < 3; i++) {
53 assertEquals(undefined, f());
54}
55%OptimizeFunctionOnNextCall(f);
56assertEquals(undefined, f());
57
58assertThrows('Object.defineProperty(new Int32Array(100), -1, {value: 1})');
59// -0 gets converted to the string "0", so use "-0" instead.
60assertThrows('Object.defineProperty(new Int32Array(100), "-0", {value: 1})');
61assertThrows('Object.defineProperty(new Int32Array(100), -10, {value: 1})');
62assertThrows('Object.defineProperty(new Int32Array(), 4294967295, {value: 1})');
63
64check();