author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 41145 | nashorn/test/script/basic/es6/computed-property-method.js@b9a1cb9ed1d3 |
permissions | -rw-r--r-- |
41145
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
1 |
/* |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
2 |
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
4 |
* |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
8 |
* |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
13 |
* accompanied this code). |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
14 |
* |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
18 |
* |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
21 |
* questions. |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
22 |
*/ |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
23 |
|
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
24 |
/** |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
25 |
* JDK-8164467: ES6 computed properties are implemented wrongly |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
26 |
* |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
27 |
* @test |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
28 |
* @run |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
29 |
* @option --language=es6 |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
30 |
*/ |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
31 |
|
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
32 |
function f(x) { |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
33 |
return x; |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
34 |
} |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
35 |
|
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
36 |
var d = 'd'; |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
37 |
var n = 3; |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
38 |
var s1 = Symbol(); |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
39 |
var s2 = Symbol(); |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
40 |
|
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
41 |
var object = { |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
42 |
a() { return 'a' }, |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
43 |
['b']() { return 'b' }, |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
44 |
[f('c')]() { return 'c' }, |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
45 |
[d]() { return d }, |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
46 |
[1]() { return 1 }, |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
47 |
[f(2)]() { return 2 }, |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
48 |
[n]() { return 3 }, |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
49 |
[s1]() { return s1 }, |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
50 |
[f(s2)]() { return s2 } |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
51 |
}; |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
52 |
|
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
53 |
|
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
54 |
Assert.assertEquals(object.a(), 'a'); |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
55 |
Assert.assertEquals(object.b(), 'b'); |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
56 |
Assert.assertEquals(object.c(), 'c'); |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
57 |
Assert.assertEquals(object.d(), 'd'); |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
58 |
Assert.assertEquals(object[1](), 1); |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
59 |
Assert.assertEquals(object[2](), 2); |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
60 |
Assert.assertEquals(object[3](), 3); |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
61 |
Assert.assertEquals(object[s1](), s1); |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
62 |
Assert.assertEquals(object[s2](), s2); |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
63 |
|
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
64 |
for (var s of ['a', 'b', 'c', 'd', 1, 2, 3, s1, s2]) { |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
65 |
Assert.assertEquals(object[s](), s); |
b9a1cb9ed1d3
8164467: ES6 computed properties are implemented wrongly
hannesw
parents:
diff
changeset
|
66 |
} |