-
Notifications
You must be signed in to change notification settings - Fork 863
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
ReferenceError: "importPackage" is not defined. #657
Comments
I fixed my own problem by searching the source code for importPackage and finding ImporterTopLevel thus
But this required far too much effort, there should be a default inifStandardObjectsWithLiveConnect method under context. |
importClass & importPackage are enabled by default in the Shell. If you're embedding Rhino, its up to you to decide what to init. If you want importClass and importPackage, you have 2 options:
|
Hello, How can Using previous versions up to 1.7.13 along with the Version 1.7.14 seems now to be incompatible with the above JSR-223 adapter. And using the new Here is my test code: ScriptEngineManager manager = new ScriptEngineManager();
ScriptEngine engine = manager.getEngineByName("rhino");
ScriptContext ctx = new SimpleScriptContext();
Bindings bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE);
bindings.put("who", "David");
System.out.println(engine.eval("(function() { return 'Hello ' + who; })();", bindings)); // Success
System.out.println(engine.eval("importPackage(Packages.org.json);"
+ "(function() { return new JSONObject().put('hello', who).toString(); })();", bindings)); // Exception and the corresponding <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>test</groupId>
<artifactId>rhino</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>1.7.14</version>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino-engine</artifactId>
<version>1.7.14</version>
</dependency>
<!-- Just here to test importing an additonal package -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20211205</version>
</dependency>
</dependencies>
</project> Thank you for your help or advice. |
See #1043 |
这类文档是在哪里查看的呢? |
Rhino Version: rhino-1.7.12.jar
Exception: org.mozilla.javascript.EcmaError: ReferenceError: "importPackage" is not defined.
Stack trace:
Reproducing code:
Source javascript at line 1:
importPackage(Packages.main.data);
The script argument is previously generated by
ctx.compileReader(fileReader, name, 0, null);
.To my understanding, importPackage is part of LiveConnect, and that gets lazy loaded into scopes at some point. It seems to not get lazy loaded in my case.
The text was updated successfully, but these errors were encountered: