本文整理汇总了Java中netscape.javascript.JSException类的典型用法代码示例。如果您正苦于以下问题:Java JSException类的具体用法?Java JSException怎么用?Java JSException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSException类属于netscape.javascript包,在下文中一共展示了JSException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadResults
import netscape.javascript.JSException; //导入依赖的package包/类
public void loadResults() {
try {
JSObject windowObj = (JSObject)webEngine.executeScript("window");
ObjectMapper mapper = new ObjectMapper();
String json = mapper.writeValueAsString(testResult);
windowObj.setMember("result", json);
try {
webEngine.executeScript("refreshResult()");
} catch (JSException js) {
Logger.error(js, "error updating result");
}
} catch (JsonProcessingException e) {
return;
}
}
示例2: testMethodCallNoParam
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* This test checks what happens when a call to a method is made
* while parameter is lacking. JS ignores lacking parameter, so
* we just check that nothing bad happens (and undefined result is returned).
*/
@Test(timeout=10000)
public void testMethodCallNoParam() {
final String ILLEGAL_ARGUMENT_EXCEPTION_MSG = "java.lang.IllegalArgumentException: wrong number of arguments";
testObject = new HelperObject();
resultObject = null;
Platform.runLater(new Runnable() {
public void run() {
initWebEngineAndWindow();
window.setMember("testObject", testObject);
try {
engine.executeScript("testObject.doParamImportant();");
} catch (JSException e) {
resultObject = e;
System.out.println("exceptionCaught.getMessage(): " + ((JSException)resultObject).getMessage());
}
}
});
doWait(new Tester() {
public boolean isPassed() {
return (resultObject != null);
}
});
Assert.assertEquals(ILLEGAL_ARGUMENT_EXCEPTION_MSG, ((JSException)resultObject).getMessage());
}
示例3: testMethodCallException
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* This test checks what happens when a method throws an exception.
*/
@Test(timeout=10000)
public void testMethodCallException() {
testObject = new HelperObject();
resultObject = null;
Platform.runLater(new Runnable() {
public void run() {
initWebEngineAndWindow();
window.setMember("testObject", testObject);
try {
resultObject = engine.executeScript("testObject.iThrowException();");
} catch (JSException e) {
resultObject = e;
}
}
});
doWait(new Tester() {
public boolean isPassed() {
return resultObject != null;
}
});
Assert.assertEquals(((HelperObject)testObject).e, ((JSException)resultObject).getCause());
}
示例4: testMethodCallException2
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* This test checks what happens when a method throws an exception.
*/
@Test(timeout=10000)
public void testMethodCallException2() {
testObject = new HelperObject();
resultObject = null;
Platform.runLater(new Runnable() {
public void run() {
initWebEngineAndWindow();
window.setMember("testObject", testObject);
try {
resultObject = engine.executeScript("testObject.iThrowException2();");
} catch (JSException e) {
resultObject = e;
}
}
});
doWait(new Tester() {
public boolean isPassed() {
return resultObject != null;
}
});
Assert.assertEquals(((HelperObject)testObject).e2, ((JSException)resultObject).getCause());
}
示例5: testPublicStaticMethod
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* Test for accessing a public static method.
* Checks that public method of a bound object is accessible from JavaScript.
* http://javafx-jira.kenai.com/browse/RT-19099
*/
@Test(timeout=10000)
public void testPublicStaticMethod() {
testObject = new HelperObject();
resultObject = null;
Platform.runLater(new Runnable() {
public void run() {
initWebEngineAndWindow();
window.setMember("testObject", testObject);
try {
engine.executeScript("testObject.doSomethingStatic();");
} catch (JSException e) {
resultObject = e;
System.out.println(e.getMessage());
}
}
});
doWait(new Tester() {
public boolean isPassed() {
return (resultObject != null);
}
});
Assert.assertTrue(resultObject instanceof JSException);
Assert.assertTrue(((JSException) resultObject).getMessage().equals(STATIC_MEMBER_MSG));
}
示例6: testAccessAbsentMethod
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* This test checks that the situation when JS is trying to access an absent
* method of an exposed object is handled properly.
*/
@Test(timeout=10000)
public void testAccessAbsentMethod() {
final String UNDEFINED_FUNCTION_ABSENT_MSG = "TypeError: 'undefined' is not a function (evaluating 'testObject.absent()')";
testObject = new Object();
resultObject = null;
Platform.runLater(new Runnable() {
public void run() {
initWebEngineAndWindow();
window.setMember("testObject", testObject);
try {
resultObject = engine.executeScript("testObject.absent();");
} catch (JSException e) {
resultObject = e;
System.out.println(e.getMessage());
}
}
});
doWait(new Tester() {
public boolean isPassed() {
return (resultObject != null);
}
});
Assert.assertTrue(resultObject instanceof JSException);
Assert.assertTrue(((JSException) resultObject).getMessage().equals(UNDEFINED_FUNCTION_ABSENT_MSG));
}
示例7: testProtectedMethod
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* Test for accessing a protected method.
* Checks that protected method of a bound object is not accessible from JavaScript.
*/
@Test(timeout=10000)
public void testProtectedMethod() {
final String UNDEFINED_FUNCTION_PROTECTED_MSG = "TypeError: 'undefined' is not a function (evaluating 'testObject.protectedMethod()')";
testObject = new HelperObject();
resultObject = null;
Platform.runLater(new Runnable() {
public void run() {
initWebEngineAndWindow();
window.setMember("testObject", testObject);
try {
resultObject = engine.executeScript("testObject.protectedMethod();");
} catch (JSException e) {
resultObject = e;
System.out.println(e.getMessage());
}
}
});
doWait(new Tester() {
public boolean isPassed() {
return (resultObject != null);
}
});
Assert.assertTrue(resultObject instanceof JSException);
Assert.assertTrue(((JSException) resultObject).getMessage().equals(UNDEFINED_FUNCTION_PROTECTED_MSG));
}
示例8: testPrivateMethod
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* Test for accessing a private method.
* Checks that private method of a bound object is not accessible from JavaScript.
*/
@Test(timeout=10000)
public void testPrivateMethod() {
final String UNDEFINED_FUNCTION_PRIVATE_MSG = "TypeError: 'undefined' is not a function (evaluating 'testObject.privateMethod()')";
testObject = new HelperObject();
resultObject = null;
Platform.runLater(new Runnable() {
public void run() {
initWebEngineAndWindow();
window.setMember("testObject", testObject);
try {
resultObject = engine.executeScript("testObject.privateMethod();");
} catch (JSException e) {
resultObject = e;
System.out.println(e.getMessage());
}
}
});
doWait(new Tester() {
public boolean isPassed() {
return (resultObject != null);
}
});
Assert.assertTrue(resultObject instanceof JSException);
Assert.assertTrue(((JSException) resultObject).getMessage().equals(UNDEFINED_FUNCTION_PRIVATE_MSG));
}
示例9: testAddJavaScriptBindingDotName
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* Simple test for WebEngine.addJavaScriptBinding call.
* Checks that a situation with malformed binding name is handled nicely
* and using this malformed name in JS conforms to JS syntax.
*/
@Test(timeout=10000)
public void testAddJavaScriptBindingDotName() {
testObject = new Object();
resultObject = null;
Platform.runLater(new Runnable() {
public void run() {
initWebEngineAndWindow();
window.setMember("test.Object", testObject);
try {
resultObject = engine.executeScript("test.Object;");
} catch (JSException e) {
resultObject = e;
System.out.println(e.getMessage());
}
}
});
doWait(new Tester() {
public boolean isPassed() {
return (resultObject != null);
}
});
Assert.assertTrue(resultObject instanceof JSException);
Assert.assertTrue(((JSException) resultObject).getMessage().equals(NO_VARIABLE_MSG2));
}
示例10: testAddJavaScriptBindingHashName
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* Simple test for WebEngine.addJavaScriptBinding call.
* Checks that a situation with malformed binding name is handled nicely
* and using this malformed name in JS conforms to JS syntax.
*/
@Test(timeout=10000)
public void testAddJavaScriptBindingHashName() {
testObject = new Object();
resultObject = null;
Platform.runLater(new Runnable() {
public void run() {
initWebEngineAndWindow();
window.setMember("test#Object", testObject);
try {
resultObject = engine.executeScript("test#Object;");
} catch (JSException e) {
resultObject = e;
System.out.println(e.getMessage());
}
}
});
doWait(new Tester() {
public boolean isPassed() {
return (resultObject != null);
}
});
Assert.assertTrue(resultObject instanceof JSException);
Assert.assertTrue(((JSException) resultObject).getMessage().equals(INVALID_CHARACTER_MSG));
}
示例11: testAddJavaScriptBindingDashName
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* Simple test for WebEngine.addJavaScriptBinding call.
* Checks that a situation with malformed binding name is handled nicely.
* and using this malformed name in JS conforms to JS syntax.
*/
@Test(timeout=10000)
public void testAddJavaScriptBindingDashName() {
testObject = new Object();
resultObject = null;
Platform.runLater(new Runnable() {
public void run() {
initWebEngineAndWindow();
window.setMember("test-Object", testObject);
try {
resultObject = engine.executeScript("test-Object;");
} catch (JSException e) {
resultObject = e;
System.out.println(e.getMessage());
}
}
});
doWait(new Tester() {
public boolean isPassed() {
return (resultObject != null);
}
});
Assert.assertTrue(resultObject instanceof JSException);
Assert.assertTrue(((JSException) resultObject).getMessage().equals(NO_VARIABLE_MSG2));
}
示例12: testAddJavaScriptBindingQuoteName
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* Simple test for WebEngine.addJavaScriptBinding call.
* Checks that a situation with malformed binding name is handled nicely.
* and using this malformed name in JS conforms to JS syntax.
*/
@Test(timeout=10000)
public void testAddJavaScriptBindingQuoteName() {
testObject = new Object();
resultObject = null;
Platform.runLater(new Runnable() {
public void run() {
initWebEngineAndWindow();
window.setMember("test\"Object", testObject);
try {
resultObject = engine.executeScript("test\"Object;");
} catch (JSException e) {
resultObject = e;
System.out.println(e.getMessage());
}
}
});
doWait(new Tester() {
public boolean isPassed() {
return (resultObject != null);
}
});
Assert.assertTrue(resultObject instanceof JSException);
Assert.assertTrue(((JSException) resultObject).getMessage().equals(UNEXPECTED_EOF_MSG));
}
示例13: testEvalWrongCode
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* Test for JSObject.eval call with an argument which cannot be evaluated.
*/
@Test(timeout=10000)
public void testEvalWrongCode(){
Platform.runLater(new Runnable() {
public void run() {
initWebEngine();
JSObject winO = getWindow(engine);
try {
winO.eval("asdf");
} catch (JSException e) {
resultObject = Boolean.TRUE;
}
}
});
doWait(new Tester() {
public boolean isPassed() {
return (resultObject != null);
}
});
}
示例14: enableDebug
import netscape.javascript.JSException; //导入依赖的package包/类
public void enableDebug() {
try {
webEngine.executeScript("if (!document.getElementById('FirebugLite')) {\n" +
" E = document['createElement' + 'NS'] && document.documentElement.namespaceURI;\n" +
" E = E ? document['createElement' + 'NS'](E, 'script') : document['createElement']('script');\n" +
" E['setAttribute']('id', 'FirebugLite');\n" +
" E['setAttribute']('src', 'https://getfirebug.com/' + 'firebug-lite.js' + '#startOpened');\n" +
//" E['setAttribute']('src', '" + fireBugJS + "');\n" +
" E['setAttribute']('FirebugLite', '4');\n" +
" (document['getElementsByTagName']('head')[0] || document['getElementsByTagName']('body')[0]).appendChild(E);\n" +
" E = new Image;\n" +
" E['setAttribute']('src', 'https://getfirebug.com/' + '#startOpened');\n" +
"}\n");
} catch (JSException ex) {
String error = ex.toString();
logger.info("[" + instance + "] " + "JSException on script", ex);
}
}
示例15: getTypeString
import netscape.javascript.JSException; //导入依赖的package包/类
/**
* 指定された JSObject のメンバの型を文字列として取得します。
*
* @param object 対象となる JSObject。
* @param name 対象のメンバ名。
* @return JavaScriptでの型名。メンバが存在しない、何らかの理由で取得に失敗した場合は undefined。
*/
public static String getTypeString(JSObject object, String name) {
if (object == null)
return "undefined";
if (name == null)
return "undefined";
try {
if (hasMember(object, name))
return (String) object.eval("typeof this." + name);
} catch (JSException e) {
//
}
return "undefined";
}