Debian Codegraph @

rhino/testsrc/jstests/harmony/method-definition.js

raw symbols SCIP
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4
5 load("testsrc/assert.js");
6
7 var obj;
8
9 obj = {
10 a() {
11 return 123;
12 }
13 };
14 assertEquals(123, obj.a());
15 // assertEquals("a", obj.a.name);
16
17 assertEquals("abcefg", {
18 abc() {
19 return "abc";
20 },
21 efg() {
22 return this.abc() + "efg";
23 }
24 }.efg());
25
26 obj = {
27 get() {
28 return 123;
29 }
30 };
31 assertEquals(123, obj.get());
32 // assertEquals("get", obj.get.name);
33
34 obj = {
35 set() {
36 return 123;
37 }
38 };
39 assertEquals(123, obj.set());
40 // assertEquals("set", obj.set.name);
41
42 assertEquals("\n" +
43 "function () {\n" +
44 " +{f() {\n" +
45 " print(1);\n" +
46 " }};\n" +
47 "}\n", (function() { +{ f() { print(1); }}; }).toString());
48
49 // Allow reserved word
50 assertEquals(123, {
51 if() {
52 return 123;
53 }
54 }.if());
55
56 // Allow NumericLiteral
57 assertEquals(123, {
58 123() {
59 return 123;
60 }
61 }[123]());
62
63 // Allow StringLiteral
64 assertEquals(123, {
65 'abc'() {
66 return 123;
67 }
68 }.abc());
69
70 // Method is the kind of function, that is non-constructor.
71 // assertThrows('new (({ a() {} }).a)', TypeError);
72
73 var desc = Object.getOwnPropertyDescriptor({
74 a() {
75 return 123;
76 }
77 }, 'a');
78 assertEquals(true, desc.writable);
79 assertEquals(true, desc.enumerable);
80 assertEquals(true, desc.configurable);
81
82 "success";