|
1 // Any copyright is dedicated to the Public Domain. |
|
2 // http://creativecommons.org/licenses/publicdomain/ |
|
3 |
|
4 var gTestfile = 'destructure-accessor.js'; |
|
5 //----------------------------------------------------------------------------- |
|
6 var BUGNUMBER = 536472; |
|
7 var summary = |
|
8 'ES5: { get x(v) { } } and { set x(v, v2) { } } should be syntax errors'; |
|
9 |
|
10 print(BUGNUMBER + ": " + summary); |
|
11 |
|
12 //----------------------------------------------------------------------------- |
|
13 |
|
14 function expectOk(s) |
|
15 { |
|
16 try |
|
17 { |
|
18 eval(s); |
|
19 return; |
|
20 } |
|
21 catch (e) |
|
22 { |
|
23 assertEq(true, false, |
|
24 "expected no error parsing '" + "', got : " + e); |
|
25 } |
|
26 } |
|
27 |
|
28 function expectSyntaxError(s) |
|
29 { |
|
30 try |
|
31 { |
|
32 eval(s); |
|
33 throw new Error("no error thrown"); |
|
34 } |
|
35 catch (e) |
|
36 { |
|
37 assertEq(e instanceof SyntaxError, true, |
|
38 "expected syntax error parsing '" + s + "', got: " + e); |
|
39 } |
|
40 } |
|
41 |
|
42 expectSyntaxError("({ get x([]) { } })"); |
|
43 expectSyntaxError("({ get x({}) { } })"); |
|
44 expectSyntaxError("({ get x(a, []) { } })"); |
|
45 expectSyntaxError("({ get x(a, {}) { } })"); |
|
46 expectSyntaxError("({ get x([], a) { } })"); |
|
47 expectSyntaxError("({ get x({}, a) { } })"); |
|
48 expectSyntaxError("({ get x([], a, []) { } })"); |
|
49 expectSyntaxError("({ get x([], a, {}) { } })"); |
|
50 expectSyntaxError("({ get x({}, a, []) { } })"); |
|
51 expectSyntaxError("({ get x({}, a, {}) { } })"); |
|
52 |
|
53 expectOk("({ get x() { } })"); |
|
54 |
|
55 |
|
56 expectSyntaxError("({ set x() { } })"); |
|
57 expectSyntaxError("({ set x(a, []) { } })"); |
|
58 expectSyntaxError("({ set x(a, b, c) { } })"); |
|
59 |
|
60 expectOk("({ set x([]) { } })"); |
|
61 expectOk("({ set x({}) { } })"); |
|
62 expectOk("({ set x([a]) { } })"); |
|
63 expectOk("({ set x([a, b]) { } })"); |
|
64 expectOk("({ set x([a,]) { } })"); |
|
65 expectOk("({ set x([a, b,]) { } })"); |
|
66 expectOk("({ set x([, b]) { } })"); |
|
67 expectOk("({ set x([, b,]) { } })"); |
|
68 expectOk("({ set x([, b, c]) { } })"); |
|
69 expectOk("({ set x([, b, c,]) { } })"); |
|
70 expectOk("({ set x({ a: a }) { } })"); |
|
71 expectOk("({ set x({ a: a, b: b }) { } })"); |
|
72 |
|
73 //----------------------------------------------------------------------------- |
|
74 |
|
75 reportCompare(true, true); |