eval.js revision 605:7cc5ff16380f
1255577Sdes/*
2255577Sdes * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved.
3255577Sdes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4255577Sdes *
5255577Sdes * This code is free software; you can redistribute it and/or modify it
6255577Sdes * under the terms of the GNU General Public License version 2 only, as
7255577Sdes * published by the Free Software Foundation.
8255577Sdes *
9255577Sdes * This code is distributed in the hope that it will be useful, but WITHOUT
10255577Sdes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11255577Sdes * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12255577Sdes * version 2 for more details (a copy is included in the LICENSE file that
13255577Sdes * accompanied this code).
14255577Sdes *
15255577Sdes * You should have received a copy of the GNU General Public License version
16255577Sdes * 2 along with this work; if not, write to the Free Software Foundation,
17255577Sdes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18255577Sdes *
19255577Sdes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20255577Sdes * or visit www.oracle.com if you need additional information or have any
21255577Sdes * questions.
22255577Sdes */
23255577Sdes
24255577Sdes/**
25255577Sdes * eval test.
26255577Sdes *
27255779Sdes * @test
28255577Sdes * @run
29255577Sdes */
30255577Sdes
31255577Sdesprint("eval.length " + eval.length);
32255577Sdes
33255577Sdesfunction test1() {
34255589Sdes    var x = 200;
35255577Sdes    y = x + 2000;
36255577Sdes
37255577Sdes    print(x);
38255577Sdes    print(y);
39255577Sdes}
40255577Sdes
41255589Sdesfunction test2() {
42255577Sdes    eval("var x = 300;");
43255577Sdes    eval("y = x + 3000;");
44255577Sdes
45255577Sdes    print(x);
46255577Sdes    print(y);
47255577Sdes}
48255577Sdes
49255577Sdes
50255577Sdeseval("var x = 100;");
51255577Sdeseval("y = x + 1000;");
52255577Sdes
53255577Sdesprint(x);
54285206Sdesprint(y);
55285206Sdes
56285206Sdestest1();
57285206Sdes
58285206Sdesprint(x);
59255577Sdesprint(y);
60255577Sdes
61255577Sdestest2();
62255577Sdes
63255577Sdesprint(x);
64255577Sdesprint(y);
65255577Sdes
66255577Sdes// evaluate with syntax error and catch error
67255577Sdestry {
68255577Sdes    // missing end quote
69255577Sdes    eval("print('hello)");
70255577Sdes} catch (e) {
71255577Sdes    print("is syntax error? " + (e instanceof SyntaxError));
72255577Sdes    printError(e);
73255577Sdes}
74255577Sdes