Skip to content

Use the correct CLI option to enable TDZ in Hermes #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 8, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion lib/agents/hermes.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,29 @@ class HermesAgent extends ConsoleAgent {
this.args.unshift('-non-strict');
}

this.args.unshift('-Xintl', '-enable-eval', '-fenable-tdz');
// Early Hermes CLI versions had `-fenable-tdz`.
// In version 0.10.0, it was replaced with `-Xenable-tdz`.
// In version 0.13.0 (release version: 0.12.0, bytecode version: 96), it was removed.
// https://github.com/facebook/hermes/commit/f811a0e75f19ab0da7dcf969a61db894fbb3cc35
// https://github.com/facebook/hermes/commit/5e2ddd5ed1c1f9af9b5b51c3ac67857a1477cb56
try {
const cp = await this.createChildProcess(['-version']);
let stdout = '';
cp.stdout.on('data', str => { stdout += str; });
await new Promise(resolve => { cp.on('close', resolve); });
// https://github.com/facebook/hermes/blob/66d3f87a8fd0436634be8a1049a1db9d3aa6e9c0/lib/CompilerDriver/CompilerDriver.cpp#L2164
const [_, releaseVersion] = /Hermes release version: (.*)/.exec(stdout);
const [__, bytecodeVersion] = /HBC bytecode version: (.*)/.exec(stdout);
if (/^0[.][0-9][.]/.test(releaseVersion)) {
this.args.unshift('-fenable-tdz');
} else if (/^0[.]1[012][.]/.test(releaseVersion) && !(+bytecodeVersion >= 96)) {
this.args.unshift('-Xenable-tdz');
}
} catch (error) {
// suppressed
}

this.args.unshift('-Xintl', '-enable-eval');

// There is currently no flag for supporting modules in Hermes
// if (options.module && this.args[0] !== '-m') {
Expand Down