我正在尝试获取我编写的JavaScript函数的返回值。我可以使用涉及监听器的非常复杂的方法来实现它,但我想使用Eclipse的Browser.evaluate方法。Browser.evaluate
作为一个玩具问题,我在Java文件中有以下代码:
在扩展
Object result = this.browser.evaluate("new String(\"Hello World\")");
在扩展
org.eclipse.ui.part.EditorPart
类并重写createPartControl
函数内,创建了属性this.browser
:public void createPartControl(Composite parent) {
// Create the browser instance and have it
this.browser = new Browser(parent, SWT.NONE);
this.browser.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
SomeEditor.this.getSite().getPage().activate(SomeEditor.this);
}
});
new ErrorReporter(this.browser);
this.browser.setUrl(Activator.getResourceURL("html/java-shim.html").toString());
...more stuff snipped...
}
然而,与其说 result
是一个包含内容为“Hello World”的Java字符串,不如说它是 null
。我是在错误地使用这个方法吗,还是它本身就有问题?