Skip to content

Commit f242ab9

Browse files
[GR-31586] [GR-31839] Prepare 21.2 release branch & Default to ECMASCript Version 5 in nashorn-compat mode.
PullRequest: js/2042
2 parents bea1ff9 + 8e74352 commit f242ab9

File tree

10 files changed

+243
-126
lines changed

10 files changed

+243
-126
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The main focus is on user-observable behavior of the engine.
99
* Implemented the [New Set Methods](https://github.com/tc39/proposal-set-methods) proposal. It is available behind an experimental flag (`--js.new-set-methods`).
1010
* Implemented experimental operator overloading support. Use the experimental option `--js.operator-overloading` to enable it and consult [the documentation](docs/user/OperatorOverloading.md).
1111
* Updated RegExp Match Indices proposal with opt-in using the `d` flag. Available in ECMAScript 2022 (`--js.ecmascript-version=2022`). Deprecated `--js.regexp-match-indices` option.
12+
* Nashorn compatibility mode now defaults to compatiblity with ECMAScript version 5, unless another version is explicitly selected.
1213

1314
## Version 21.1.0
1415
* Updated Node.js to version 14.16.1.

common.jsonnet

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ local common_json = (import "common.json");
2222
deploy: {targets+: ['deploy']},
2323
gate: {targets+: ['gate']},
2424
postMerge: {targets+: ['post-merge']},
25-
bench: {targets+: ['bench', 'post-merge']},
25+
bench: {targets+: ['bench']},
2626
dailyBench: {targets+: ['bench', 'daily']},
2727
weeklyBench: {targets+: ['bench', 'weekly']},
2828
manualBench: {targets+: ['bench']},
@@ -37,6 +37,7 @@ local common_json = (import "common.json");
3737

3838
local common = python3 + {
3939
packages+: {
40+
'mx': '5.302.2',
4041
'pip:pylint': '==1.9.3',
4142
'pip:ninja_syntax': '==1.7.2',
4243
},

docs/user/NashornMigrationGuide.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ This is the case for Nashorn-specific extensions that GraalVM JavaScript does no
3535
Note that you have to enable [experimental options](Options.md#stable-and-experimental-options) to use this flag.
3636
Further note that setting this flag defeats the [secure by default](#secure-by-default) approach of GraalVM JavaScript in some cases, e.g., when operating on a legacy `ScriptEngine`.
3737

38+
When you use the Nashorn compatibility mode, by default, ECMAScript 5 is set as compatibility level.
39+
You can specify a different ECMAScript version using the `js.ecmascript-version` flag; note that this might conflict with full Nashorn compatibilty.
40+
A code example how to set the flag is given near the end of this section.
41+
3842
The `js.nashorn-compat` option can be set:
3943
1. by using a command line option:
4044
```shell
@@ -55,7 +59,7 @@ try (Context context = Context.newBuilder().allowExperimentalOptions(true).optio
5559
java -Dpolyglot.js.nashorn-compat=true MyApplication
5660
```
5761

58-
Functionality only available under this flag includes:
62+
Functionality only available under the `nashorn-compat` flag includes:
5963
* `Java.isJavaFunction`, `Java.isJavaMethod`, `Java.isScriptObject`, `Java.isScriptFunction`
6064
* `new Interface|AbstractClass(fn|obj)`
6165
* `JavaImporter`
@@ -64,6 +68,13 @@ Functionality only available under this flag includes:
6468
* `load("nashorn:parser.js")`, `load("nashorn:mozilla_compat.js")`
6569
* `exit`, `quit`
6670

71+
The `js.ecmascript-version` option can be set in similar fashion.
72+
As this is a supported option, there is no need to provide the `experimental-options` flag just for setting the `ecmascript-version`:
73+
1. by using a command line option:
74+
```shell
75+
js --js.ecmascript-version=2020
76+
```
77+
6778
## Nashorn Syntax Extensions
6879

6980
[Nashorn syntax extensions](https://wiki.openjdk.java.net/display/Nashorn/Nashorn+extensions) can be enabled using the `js.syntax-extensions` experimental option.

docs/user/Options.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The following options are currently available:
3939
* `--js.annex-b`: enable ECMAScript Annex B web compatibility features. Boolean value, default is `true`.
4040
* `--js.array-sort-inherited`: define whether `Array.protoype.sort` should sort inherited keys (implementation-defined behavior). Boolean value, default is `true`.
4141
* `--js.atomics`: enable *ES2017 Atomics*. Boolean value, default is `true`.
42-
* `--js.ecmascript-version`: emulate a specific ECMAScript version. Integer value (`5`-`9`), default is the latest version.
42+
* `--js.ecmascript-version`: emulate a specific ECMAScript version. Integer value (`5`-`13`, or `2015`-`2022`), default is the latest stable version.
4343
* `--js.foreign-object-prototype`: provide JavaScript's default prototype to foreign objects that mimic JavaScript's own types (foreign Arrays, Objects and Functions). Boolean value, default is `false`.
4444
* `--js.intl-402`: enable ECMAScript Internationalization API. Boolean value, default is `false`.
4545
* `--js.regexp-static-result`: provide static `RegExp` properties containing the results of the last successful match, e.g., `RegExp.$1` (legacy). Boolean value, default is `true`.
@@ -72,8 +72,7 @@ See [ScriptEngine Implementation](ScriptEngine.md) on how to use experimental op
7272

7373
This option provides compatibility to a specific version of the ECMAScript specification.
7474
It expects an integer value, where both the counting version numbers (`5` to `11`) and the publication years (starting from `2015`) are supported.
75-
The default in the development version of GraalVM is the current draft of the specification, currently the [`ECMAScript 2021 draft specification`](https://tc39.es/ecma262/).
76-
Thus, starting with GraalVM 21.0.0, the default will move to the draft ECMAScript 2021 specification.
75+
The default in the development version of GraalVM is the [`ECMAScript 2021 specification`](https://tc39.es/ecma262/).
7776
GraalVM JavaScript implements some features of the future draft specification and of open proposals, if you explicitly select that version and/or enable specific experimental flags.
7877
For production settings, it is recommended to set the `ecmascript-version` to an existing, finalized version of the specification.
7978

@@ -84,10 +83,12 @@ Available versions are:
8483
* `8` or `2017` for ECMAScript 2017
8584
* `9` or `2018` for ECMAScript 2018
8685
* `10` or `2019` for ECMAScript 2019
87-
* `11` or `2020` for ECMAScript 2020 (latest finalized version of the specification)
88-
* `12` or `2021` for ECMAScript 2021 (**default**, currently in draft stage)
86+
* `11` or `2020` for ECMAScript 2020
87+
* `12` or `2021` for ECMAScript 2021 (**default**, latest finalized version of the specification)
8988
* `13` or `2022` for ECMAScript 2022 (future changes and proposals)
9089

90+
As of GraalVM 21.2, the flag can also be set to `latest` or `staging`, to use the latest stable version (which is the default), or the staging version including experimental functionality under development.
91+
9192
## intl-402
9293

9394
This option enables ECMAScript's [Internationalization API](https://tc39.github.io/ecma402/).

docs/user/ScriptEngine.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ These options are:
2222
* `polyglot.js.allowHostClassLookup <boolean or Predicate<String>>`
2323
* `polyglot.js.allowHostClassLoading <boolean>`
2424
* `polyglot.js.allowAllAccess <boolean>`
25+
* `polyglot.js.nashorn-compat <boolean>`
26+
* `polyglot.js.ecmascript-version <String>`
2527

2628
These options control the sandboxing rules applied to evaluated JavaScript code and are set to `false` by default, unless the application was started in the Nashorn compatibility mode (`--js.nashorn-compat=true`).
2729

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2021, 2021, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.truffle.js.scriptengine.test;
42+
43+
import javax.script.Bindings;
44+
import javax.script.ScriptContext;
45+
import javax.script.ScriptEngine;
46+
import javax.script.ScriptEngineManager;
47+
import javax.script.ScriptException;
48+
49+
import org.junit.Assert;
50+
import org.junit.Test;
51+
52+
import com.oracle.truffle.js.runtime.JSConfig;
53+
54+
public class TestNashornCompatECMAScriptVersion {
55+
56+
@Test
57+
public void testNashornDefaultsToES5() throws ScriptException {
58+
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
59+
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
60+
bindings.put("polyglot.js.nashorn-compat", true);
61+
Assert.assertEquals(5, engine.eval("Graal.versionECMAScript"));
62+
}
63+
64+
@Test
65+
public void testNashornAllowsNewer() throws ScriptException {
66+
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
67+
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
68+
bindings.put("polyglot.js.nashorn-compat", true);
69+
bindings.put("polyglot.js.ecmascript-version", 2021);
70+
Assert.assertEquals(2021, engine.eval("Graal.versionECMAScript"));
71+
}
72+
73+
@Test
74+
public void testLatestECMAScriptVersion() throws ScriptException {
75+
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
76+
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
77+
bindings.put("polyglot.js.ecmascript-version", "latest");
78+
Assert.assertEquals(JSConfig.CurrentECMAScriptVersion + JSConfig.ECMAScriptNumberYearDelta, engine.eval("Graal.versionECMAScript"));
79+
}
80+
81+
@Test
82+
public void testStagingECMAScriptVersion() throws ScriptException {
83+
ScriptEngine engine = new ScriptEngineManager().getEngineByName("JavaScript");
84+
Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE);
85+
bindings.put("polyglot.js.ecmascript-version", "staging");
86+
Assert.assertEquals(JSConfig.MaxECMAScriptVersion + JSConfig.ECMAScriptNumberYearDelta, engine.eval("Graal.versionECMAScript"));
87+
}
88+
89+
}

0 commit comments

Comments
 (0)