-
Notifications
You must be signed in to change notification settings - Fork 864
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
ES5 Object not accessible when used in commonjs module #95
Comments
p-bakker
added
the
CommonJS
Issues related to the CommonJS implementation in Rhino
label
Jun 29, 2021
Works for me: import java.io.StringReader;
import java.net.URI;
import java.net.URISyntaxException;
import org.mozilla.javascript.Context;
import org.mozilla.javascript.Scriptable;
import org.mozilla.javascript.commonjs.module.Require;
import org.mozilla.javascript.commonjs.module.RequireBuilder;
import org.mozilla.javascript.commonjs.module.provider.ModuleSource;
import org.mozilla.javascript.commonjs.module.provider.ModuleSourceProvider;
import org.mozilla.javascript.commonjs.module.provider.StrongCachingModuleScriptProvider;
public class Main2 {
public static void main(String[] args) {
try(Context cx = Context.enter()) {
cx.setOptimizationLevel(-1);
Scriptable scope = cx.initStandardObjects();
Require r = new RequireBuilder()
.setModuleScriptProvider(new StrongCachingModuleScriptProvider(
new ModuleSourceProvider() {
@Override public ModuleSource loadSource(String moduleId, Scriptable paths,
Object validator) throws URISyntaxException {
var base = new URI("http://localhost/");
return loadSource(base.resolve(moduleId), base, validator);
}
@Override
public ModuleSource loadSource(URI uri, URI baseUri, Object validator) {
return new ModuleSource(
new StringReader(
"var obj={}; Object.defineProperties(obj, {\n"
+ "\"property1\": { value: true, writable: true },\n"
+ "\"property2\": { value: \"Hello\", writable: false}\n"
+ "});"), null, uri, baseUri, validator);
}
})
)
.createRequire(cx, scope);
r.install(scope);
cx.evaluateString(scope, "require('whatever.js')", "", 1, null);
}
}
} This programs exits without errors. Try to introduce a typo in "definePropertes" and you'll see it fails (so it does work without the typo.) |
Closing as cannot be reproduced. Feel free to reopen with a reproducible example |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code:
Object.defineProperties(obj, {
"property1": { value: true, writable: true },
"property2": { value: "Hello", writable: false}
});
will fail with the following exception:
org.mozilla.javascript.EcmaError: ReferenceError: "Object" is not defined.
The text was updated successfully, but these errors were encountered: