Skip to content

Commit c576af2

Browse files
committed
[GR-63022] Make source phase imports stable.
PullRequest: js/3542
2 parents 7d361dd + c6846f8 commit c576af2

File tree

6 files changed

+60
-8
lines changed

6 files changed

+60
-8
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ See [release calendar](https://www.graalvm.org/release-calendar/) for release da
1212
* Made option `js.text-encoding` stable and allowed in `SandboxPolicy.CONSTRAINED`.
1313
* Implemented the [`import defer`](https://github.com/tc39/proposal-defer-import-eval) proposal. It is available in ECMAScript staging mode (`--js.ecmascript-version=staging`).
1414
* Implemented the [`Upsert`](https://github.com/tc39/proposal-upsert) proposal. It is available in ECMAScript staging mode (`--js.ecmascript-version=staging`).
15+
* Enabled source phase imports from WebAssembly modules (`import source mod from "./mod.wasm"`) by default if the `js.webassembly` option is enabled and the `js.source-phase-imports` option is not explicitly set to `false`.
1516

1617
## Version 24.2.0
1718
* Updated Node.js to version 22.13.1.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
/**
9+
* Tests that source phase imports are enabled by default if js.webassembly=true.
10+
*
11+
* @option webassembly=true
12+
* @option unhandled-rejections=throw
13+
*/
14+
15+
import "./source-phase-import.mjs";
16+
import "./source-phase-import-dynamic.mjs";
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
6+
*/
7+
8+
/**
9+
* Tests that source phase imports can be disabled explicitly.
10+
*
11+
* @option webassembly=true
12+
* @option source-phase-imports=false
13+
* @option unhandled-rejections=throw
14+
*/
15+
16+
try {
17+
await import("./source-phase-import.mjs");
18+
throw new Error("should have thrown a SyntaxError");
19+
} catch (e) {
20+
if (!(e instanceof SyntaxError)) {
21+
throw e;
22+
}
23+
}
24+
try {
25+
await import("./source-phase-import-dynamic.mjs");
26+
throw new Error("should have thrown a SyntaxError");
27+
} catch (e) {
28+
if (!(e instanceof SyntaxError)) {
29+
throw e;
30+
}
31+
}

graal-js/src/com.oracle.truffle.js.test/wasm/source-phase-import-dynamic.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
@@ -8,8 +8,9 @@
88
/**
99
* Test source phase imports.
1010
*
11-
* @option webassembly
12-
* @option source-phase-imports
11+
* @option webassembly=true
12+
* @option source-phase-imports=true
13+
* @option unhandled-rejections=throw
1314
*/
1415

1516
const wasmModule = await import.source("./source-phase-import.wasm");

graal-js/src/com.oracle.truffle.js.test/wasm/source-phase-import.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* Licensed under the Universal Permissive License v 1.0 as shown at http://oss.oracle.com/licenses/upl.
@@ -8,8 +8,8 @@
88
/**
99
* Test source phase imports.
1010
*
11-
* @option webassembly
12-
* @option source-phase-imports
11+
* @option webassembly=true
12+
* @option source-phase-imports=true
1313
*/
1414

1515
import source wasmModule from "./source-phase-import.wasm";

graal-js/src/com.oracle.truffle.js/src/com/oracle/truffle/js/runtime/JSContextOptions.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,10 @@ public String toString() {
664664
@CompilationFinal private boolean jsonModules;
665665

666666
public static final String SOURCE_PHASE_IMPORTS_NAME = JS_OPTION_PREFIX + "source-phase-imports";
667-
@Option(name = SOURCE_PHASE_IMPORTS_NAME, category = OptionCategory.USER, help = "Enable source phase imports proposal") //
667+
@Option(name = SOURCE_PHASE_IMPORTS_NAME, category = OptionCategory.USER, help = "" +
668+
"Enable source phase imports (`import source` and `import.source()`). " +
669+
"If this option is not set and " + WEBASSEMBLY_NAME + "=true, " +
670+
"source phase imports from WebAssembly modules are enabled by default.") //
668671
public static final OptionKey<Boolean> SOURCE_PHASE_IMPORTS = new OptionKey<>(false);
669672
@CompilationFinal private boolean sourcePhaseImports;
670673

@@ -821,7 +824,7 @@ private void cacheOptions(SandboxPolicy sandboxPolicy) {
821824
this.importAttributes = readBooleanOption(IMPORT_ATTRIBUTES, JSConfig.ECMAScript2025);
822825
this.importAssertions = readBooleanOption(IMPORT_ASSERTIONS);
823826
this.jsonModules = readBooleanOption(JSON_MODULES, JSConfig.ECMAScript2025);
824-
this.sourcePhaseImports = readBooleanOption(SOURCE_PHASE_IMPORTS);
827+
this.sourcePhaseImports = SOURCE_PHASE_IMPORTS.hasBeenSet(optionValues) ? readBooleanOption(SOURCE_PHASE_IMPORTS) : webAssembly;
825828
this.wasmBigInt = readBooleanOption(WASM_BIG_INT);
826829
this.esmEvalReturnsExports = readBooleanOption(ESM_EVAL_RETURNS_EXPORTS);
827830
this.printNoNewline = readBooleanOption(PRINT_NO_NEWLINE);

0 commit comments

Comments
 (0)