Skip to content

sourceType: "module" does not run code as strict mode #137

@arjunbhatt670

Description

@arjunbhatt670

Summary

With sourceType: "module", ECMAScript treats module code as strict mode code. In Sval, a minimal strict-mode check still behaves as if the code were not strict.

Reproduction

import Sval from "sval";
const interpreter = new Sval({
ecmaVer: 11,
sandBox: true,
sourceType: "module",
});
interpreter.run(`
var isStrict = (function () { return !this; })();
export { isStrict };
`);
console.log(interpreter.exports.isStrict);

Expected

In a real ES module, plain function calls have this === undefined, so !this is true. The variable should reflect strict behavior (isStrict === true).

Actual

interpreter.exports.isStrict is false, which matches sloppy mode (this is the global object).

Environment

  • sval: (e.g. 0.6.9)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions