Skip to content

Commit

Permalink
[GR-60802] Execution result of some modules was not stored.
Browse files Browse the repository at this point in the history
PullRequest: js/3374
  • Loading branch information
iamstolis committed Jan 3, 2025
2 parents 0206e9f + 67b3c82 commit 24ad4e4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down Expand Up @@ -970,7 +970,8 @@ public int compare(CyclicModuleRecord o1, CyclicModuleRecord o2) {
moduleAsyncExecution(realm, m);
} else {
try {
m.executeModule(realm, (PromiseCapabilityRecord) null);
Object result = m.executeModule(realm, (PromiseCapabilityRecord) null);
m.setExecutionResult(result);
m.setAsyncEvaluation(false);
m.setStatus(Status.Evaluated);
if (m.getTopLevelCapability() != null) {
Expand Down
21 changes: 21 additions & 0 deletions graal-nodejs/test/graal/unit/vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
*/

var assert = require('assert');
var { spawnSync } = require('child_process');
var vm = require('vm');

describe('vm', function () {
Expand Down Expand Up @@ -154,4 +155,24 @@ describe('vm', function () {
it('should handle globalThis.hasOwnProperty(symbol)', function () {
assert.ok(!vm.runInNewContext("globalThis.hasOwnProperty(Symbol())"));
});
it('should store module execution result', function () {
this.timeout(40000);
var code = `
var first = new vm.SourceTextModule('import mid from "mid"; mid;');
var mid = new vm.SourceTextModule('import last from "last"; export default last');
var last = new vm.SourceTextModule('if (false) await import(""); export default 42;');
first.link(function(name) { return (name === "mid") ? mid : last; })
.then(() => first.evaluate())
.then(() => mid.evaluate()) // checks the execution result of mid again
.then(() => console.log('OK'));`;

var result = spawnSync(process.execPath, [
'--experimental-vm-modules',
'--no-warnings=ExperimentalWarning',
'-e', code],
{ env: { ...process.env, NODE_JVM_OPTIONS: (process.env.NODE_JVM_OPTIONS || '') + ' -ea' }});
assert.strictEqual(result.stderr.toString(), '');
assert.strictEqual(result.stdout.toString().trim(), 'OK');
assert.strictEqual(result.status, 0);
});
});

0 comments on commit 24ad4e4

Please sign in to comment.