author | hannesw |
Thu, 27 Nov 2014 16:42:53 +0100 | |
changeset 27817 | 56f6161c3e55 |
parent 27814 | 96427359f4fe |
permissions | -rw-r--r-- |
26377
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
1 |
/* |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
2 |
* Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved. |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
4 |
* |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
8 |
* |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
13 |
* accompanied this code). |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
14 |
* |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
18 |
* |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
21 |
* questions. |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
22 |
*/ |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
23 |
|
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
24 |
/** |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
25 |
* JDK-8051889: Implement block scoping in symbol assignment and scope computation |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
26 |
* |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
27 |
* @test |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
28 |
* @run |
27814
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
26377
diff
changeset
|
29 |
* @option --language=es6 |
96427359f4fe
8057691: Nashorn: let & const declarations are not shared between scripts
hannesw
parents:
26377
diff
changeset
|
30 |
*/ |
26377
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
31 |
|
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
32 |
"use strict"; |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
33 |
|
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
34 |
load(__DIR__ + "let-load-lib.js"); |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
35 |
|
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
36 |
{ |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
37 |
let a = 20; |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
38 |
const c = 30; |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
39 |
print("print local defs: " + a, c); |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
40 |
} |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
41 |
|
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
42 |
print("imported var: " + a); |
27817
56f6161c3e55
8057980: let & const: remaining issues with lexical scoping
hannesw
parents:
27814
diff
changeset
|
43 |
print("imported let: " + b); |
56f6161c3e55
8057980: let & const: remaining issues with lexical scoping
hannesw
parents:
27814
diff
changeset
|
44 |
print("imported const: " + c); |
26377
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
45 |
|
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
46 |
top(); |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
47 |
|
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
48 |
try { |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
49 |
block(); |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
50 |
} catch (e) { |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
51 |
print(e); |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
52 |
} |
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
53 |
|
27817
56f6161c3e55
8057980: let & const: remaining issues with lexical scoping
hannesw
parents:
27814
diff
changeset
|
54 |
try { |
56f6161c3e55
8057980: let & const: remaining issues with lexical scoping
hannesw
parents:
27814
diff
changeset
|
55 |
c = "foo"; |
56f6161c3e55
8057980: let & const: remaining issues with lexical scoping
hannesw
parents:
27814
diff
changeset
|
56 |
} catch (e) { |
56f6161c3e55
8057980: let & const: remaining issues with lexical scoping
hannesw
parents:
27814
diff
changeset
|
57 |
print(e); |
56f6161c3e55
8057980: let & const: remaining issues with lexical scoping
hannesw
parents:
27814
diff
changeset
|
58 |
} |
26377
028dad61662f
8051889: Implement block scoping in symbol assignment and scope computation
hannesw
parents:
diff
changeset
|
59 |
|
27817
56f6161c3e55
8057980: let & const: remaining issues with lexical scoping
hannesw
parents:
27814
diff
changeset
|
60 |