• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright JS Foundation and other contributors, http://js.foundation
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15function check_syntax_error (script)
16{
17  try
18  {
19    eval (script);
20    assert (false);
21  }
22  catch (e)
23  {
24    assert (e instanceof SyntaxError);
25  }
26}
27
28var
29  implements = 0,
30  private = 1,
31  public = 2,
32  interface = 3,
33  package = 4,
34  protected = 5,
35  let = 6,
36  yield = 7,
37  static = 8;
38
39check_syntax_error("'use strict'\nimplements")
40check_syntax_error("'use strict'\n\\u0069mplements")
41assert(eval("'use stric'\nimplements") === 0)
42assert(eval("'use stric'\n\\u0069mplements") === 0)
43
44check_syntax_error("'use strict'\nprivate")
45check_syntax_error("'use strict'\n\\u0070rivate")
46assert(eval("'use stric'\nprivate") === 1)
47assert(eval("'use stric'\n\\u0070rivate") === 1)
48
49check_syntax_error("'use strict'\npublic")
50check_syntax_error("'use strict'\n\\u0070ublic")
51assert(eval("'use stric'\npublic") === 2)
52assert(eval("'use stric'\n\\u0070ublic") === 2)
53
54check_syntax_error("'use strict'\ninterface")
55check_syntax_error("'use strict'\n\\u0069nterface")
56assert(eval("'use stric'\ninterface") === 3)
57assert(eval("'use stric'\n\\u0069nterface") === 3)
58
59check_syntax_error("'use strict'\npackage")
60check_syntax_error("'use strict'\n\\u0070ackage")
61assert(eval("'use stric'\npackage") === 4)
62assert(eval("'use stric'\n\\u0070ackage") === 4)
63
64check_syntax_error("'use strict'\nprotected")
65check_syntax_error("'use strict'\n\\u0070rotected")
66assert(eval("'use stric'\nprotected") === 5)
67assert(eval("'use stric'\n\\u0070rotected") === 5)
68
69check_syntax_error("'use strict'\nlet")
70check_syntax_error("'use strict'\n\\u006cet")
71assert(eval("'use stric'\nlet") === 6)
72assert(eval("'use stric'\n\\u006cet") === 6)
73
74check_syntax_error("'use strict'\nyield")
75check_syntax_error("'use strict'\n\\u0079ield")
76assert(eval("'use stric'\nyield") === 7)
77assert(eval("'use stric'\n\\u0079ield") === 7)
78
79check_syntax_error("'use strict'\nstatic")
80check_syntax_error("'use strict'\n\\u0073tatic")
81assert(eval("'use stric'\nstatic") === 8)
82assert(eval("'use stric'\n\\u0073tatic") === 8)
83