本文整理汇总了Java中org.mozilla.javascript.JavaScriptException类的典型用法代码示例。如果您正苦于以下问题:Java JavaScriptException类的具体用法?Java JavaScriptException怎么用?Java JavaScriptException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JavaScriptException类属于org.mozilla.javascript包,在下文中一共展示了JavaScriptException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeSimpleHandlerCore
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
protected void executeSimpleHandlerCore(String handlerType, org.mozilla.javascript.Context myJavascriptContext) throws EcmaError, EvaluatorException, JavaScriptException, EngineException {
handlerName = "on" + handlerType;
Engine.logBeans.trace("(Transaction) Searching the " + handlerType + " handler (" + handlerName + ")");
Object object = scope.get(handlerName, scope);
Engine.logBeans.trace("(Transaction) Rhino returned: [" + object.getClass().getName() + "] " + object.toString());
if (!(object instanceof Function)) {
Engine.logBeans.debug("(Transaction) No " + handlerType + " handler (" + handlerName + ") found");
return;
}
else {
Engine.logBeans.debug("(Transaction) Execution of the " + handlerType + " handler (" + handlerName + ") for the transaction '" + getName() + "'");
}
function = (Function) object;
Object returnedValue = function.call(myJavascriptContext, scope, scope, null);
if (returnedValue instanceof org.mozilla.javascript.Undefined) {
handlerResult = "";
}
else {
handlerResult = returnedValue.toString();
}
}
示例2: load
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
/**
* load
* @param response
*/
public void load( WebResponse response ) {
Function onLoadEvent=null;
try {
Context context = Context.enter();
context.initStandardObjects( null );
HTMLDocument htmlDocument = ((DomWindow) response.getScriptingHandler()).getDocument();
if (!(htmlDocument instanceof HTMLDocumentImpl)) return;
HTMLBodyElementImpl body = (HTMLBodyElementImpl) htmlDocument.getBody();
if (body == null) return;
onLoadEvent = body.getOnloadEvent();
if (onLoadEvent == null) return;
onLoadEvent.call( context, body, body, new Object[0] );
} catch (JavaScriptException e) {
ScriptingEngineImpl.handleScriptException(e, onLoadEvent.toString());
// HttpUnitUtils.handleException(e);
} catch (EcmaError ee) {
//throw ee;
ScriptingEngineImpl.handleScriptException(ee, onLoadEvent.toString());
} finally {
Context.exit();
}
}
示例3: runWithExpectedStackTrace
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
private void runWithExpectedStackTrace(final String _source, final String _expectedStackTrace)
{
final ContextAction action = new ContextAction() {
public Object run(Context cx) {
final Scriptable scope = cx.initStandardObjects();
try {
cx.evaluateString(scope, _source, "test.js", 0, null);
}
catch (final JavaScriptException e)
{
assertEquals(_expectedStackTrace, e.getScriptStackTrace());
return null;
}
throw new RuntimeException("Exception expected!");
}
};
Utils.runWithOptimizationLevel(action, -1);
}
示例4: throwWrappedScriptException
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
/**
* Wraps given exception and throws it as ScriptException.
*
* @param ex Exception to be wrapped.
* @throws ScriptException Thrown always by this method.
*/
public static void throwWrappedScriptException(Exception ex) throws ScriptException {
if ( ex instanceof RhinoException) {
RhinoException rhinoException = (RhinoException)ex;
int line = rhinoException.lineNumber();
int column = rhinoException.columnNumber();
String message;
if (ex instanceof JavaScriptException) {
message = String.valueOf(((JavaScriptException)ex).getValue());
} else {
message = ex.toString();
}
ScriptException scriptException = new ScriptException(message, rhinoException.sourceName(), line, column);
scriptException.initCause(ex);
throw scriptException;
} else {
throw new ScriptException(ex);
}
}
示例5: eval
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
/**
* Executes an arbitrary expression.<br>
* It fails if the expression throws a JsAssertException.<br>
* It fails if the expression throws a RhinoException.<br>
*
* Code from JsTester (http://jstester.sf.net/)
*/
public Object eval(String expr) {
Object value = null;
try {
value = context.evaluateString(globalScope, expr, "", 1, null);
} catch (JavaScriptException jse) {
Scriptable jsAssertException = (Scriptable) globalScope.get(
"currentException", globalScope);
jse.printStackTrace();
String message = (String) jsAssertException.get("message",
jsAssertException);
if (message != null) {
fail(message);
}
} catch (RhinoException re) {
fail(re.getMessage());
}
return value;
}
示例6: put
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
/**
* Support setting parameter value by following methods:
*/
public void put( String name, Scriptable start, Object value )
{
PageVariable variable = variables.get( name );
if ( variable != null )
{
if ( value instanceof Wrapper )
{
value = ( (Wrapper) value ).unwrap( );
}
variable.setValue( value );
return;
}
String errorMessage = "Report variable\"" + name + "\" does not exist";
throw new JavaScriptException( errorMessage, "<unknown>", -1 );
}
示例7: compile
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
/**
* After having setup a compiler by (1) registering it and (2) passing in its arguments
* @param lineno The starting line number of the source code to be compiled (used for debugging)
* @param securityDomain
* @return
* @throws IOException
* @throws RhinoEvaluatorException
*/
public String compile (int lineno, Object securityDomain) throws IOException, JavaScriptException {
Context context = Context.enter();
Reader reader = new InputStreamReader(program);
Object ret = context.evaluateReader(instanceScope,
reader,
programName,
lineno,
securityDomain);
if (ret instanceof org.mozilla.javascript.Undefined) {
// This is really 'void'. Perhaps a separate 'compile' method
// should be used that has 'void' as its return type, and that
// get used by the likes of the RjsConfigCompiler
return "";
} else {
return (String) ret;
}
}
示例8: testAddTestCaseNoOutput
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
@Test(expected = JavaScriptException.class)
public void testAddTestCaseNoOutput() throws IOException {
String configJS = "ci.addTestCase({\n" +
" name: \"wordcount test case 1\",\n" +
" sampleTimeStart: \"2013-11-20T11:00Z\",\n" +
" sampleTimeEnd: \"2013-11-20T18:00Z\",\n" +
" inputs: [\n" +
" ci.hdfsInput(ci.fixDirFromResource(\"src/test/celos-ci/test-1/input/plain/input/wordcount1\"), \"input/wordcount1\"),\n" +
" ci.hdfsInput(ci.fixDirFromResource(\"src/test/celos-ci/test-1/input/plain/input/wordcount11\"), \"input/wordcount11\")\n" +
" ]\n" +
"})\n";
TestConfigurationParser parser = new TestConfigurationParser();
parser.evaluateTestConfig(new StringReader(configJS), "string");
}
示例9: testAddTestCaseNoInput
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
@Test(expected = JavaScriptException.class)
public void testAddTestCaseNoInput() throws IOException {
String configJS = "ci.addTestCase({\n" +
" name: \"wordcount test case 1\",\n" +
" sampleTimeStart: \"2013-11-20T11:00Z\",\n" +
" sampleTimeEnd: \"2013-11-20T18:00Z\",\n" +
" outputs: [\n" +
" ci.plainCompare(ci.fixDirFromResource(\"src/test/celos-ci/test-1/output/plain/output/wordcount1\"), \"output/wordcount1\")\n" +
" ]\n" +
"})\n";
TestConfigurationParser parser = new TestConfigurationParser();
parser.evaluateTestConfig(new StringReader(configJS), "string");
}
示例10: testAddTestCaseNoSampleTimeStart
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
@Test(expected = JavaScriptException.class)
public void testAddTestCaseNoSampleTimeStart() throws IOException {
String configJS = "ci.addTestCase({\n" +
" name: \"wordcount test case 1\",\n" +
" sampleTimeEnd: \"2013-11-20T18:00Z\",\n" +
" inputs: [\n" +
" ci.hdfsInput(ci.fixDirFromResource(\"src/test/celos-ci/test-1/input/plain/input/wordcount1\"), \"input/wordcount1\"),\n" +
" ci.hdfsInput(ci.fixDirFromResource(\"src/test/celos-ci/test-1/input/plain/input/wordcount11\"), \"input/wordcount11\")\n" +
" ],\n" +
" outputs: [\n" +
" ci.plainCompare(ci.fixDirFromResource(\"src/test/celos-ci/test-1/output/plain/output/wordcount1\"), \"output/wordcount1\")\n" +
" ]\n" +
"})\n";
TestConfigurationParser parser = new TestConfigurationParser();
parser.evaluateTestConfig(new StringReader(configJS), "string");
}
示例11: testAddTestCaseNoSampleTimeEnd
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
@Test(expected = JavaScriptException.class)
public void testAddTestCaseNoSampleTimeEnd() throws IOException {
String configJS = "ci.addTestCase({\n" +
" name: \"wordcount test case 1\",\n" +
" sampleTimeStart: \"2013-11-20T18:00Z\",\n" +
" inputs: [\n" +
" ci.hdfsInput(ci.fixDirFromResource(\"src/test/celos-ci/test-1/input/plain/input/wordcount1\"), \"input/wordcount1\"),\n" +
" ci.hdfsInput(ci.fixDirFromResource(\"src/test/celos-ci/test-1/input/plain/input/wordcount11\"), \"input/wordcount11\")\n" +
" ],\n" +
" outputs: [\n" +
" ci.plainCompare(ci.fixDirFromResource(\"src/test/celos-ci/test-1/output/plain/output/wordcount1\"), \"output/wordcount1\")\n" +
" ]\n" +
"})\n";
TestConfigurationParser parser = new TestConfigurationParser();
parser.evaluateTestConfig(new StringReader(configJS), "string");
}
示例12: eval
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
public Object eval(ScriptContext context) throws ScriptException {
Object result = null;
Context cx = RhinoScriptEngine.enterContext();
try {
Scriptable scope = engine.getRuntimeScope(context);
Object ret = script.exec(cx, scope);
result = engine.unwrapReturnValue(ret);
} catch (RhinoException re) {
int line = (line = re.lineNumber()) == 0 ? -1 : line;
String msg;
if (re instanceof JavaScriptException) {
msg = String.valueOf(((JavaScriptException)re).getValue());
} else {
msg = re.toString();
}
ScriptException se = new ScriptException(msg, re.sourceName(), line);
se.initCause(re);
throw se;
} finally {
Context.exit();
}
return result;
}
示例13: compile
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
private String compile(Scriptable rootScope, final String source, final String sourceName) {
return childScope(rootScope, new DefaultScopeOperation<String>() {
public String action(Scriptable compileScope, Context context) {
compileScope.put("coffeeScriptSource", compileScope, source);
try {
return (String) context.evaluateString(compileScope, "CoffeeScript.compile(coffeeScriptSource, {});", sourceName, 0, null);
} catch (JavaScriptException jse) {
throw new SourceTransformationException(String.format("Failed to compile coffeescript file: %s", sourceName), jse);
}
}
});
}
示例14: executeSimpleHandlerCore
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
@Override
protected void executeSimpleHandlerCore(String handlerType, Context myJavascriptContext) throws EcmaError, EvaluatorException, JavaScriptException, EngineException {
handlerName = "on" + handlerType;
Engine.logBeans.trace("(HtmlTransaction) Searching the " + handlerType + " handler (" + handlerName + ")");
HandlerStatement handlerStatement = getHandlerStatement(handlerName);
handlerResult = "";
if (handlerStatement != null) {
if (!handlerStatement.isEnabled())
return;
Engine.logBeans.debug("(HtmlTransaction) Execution of the " + handlerType + " handler (" + handlerName + ") for the transaction '" + getName() + "'");
handlerStatement.execute(myJavascriptContext, scope);
Object returnedValue = handlerStatement.getReturnedValue();
if (returnedValue instanceof org.mozilla.javascript.Undefined) {
handlerResult = "";
}
else {
handlerResult = returnedValue.toString();
}
}
else {
Engine.logBeans.debug("(HtmlTransaction) No " + handlerType + " handler (" + handlerName + ") found");
}
}
示例15: executeHandlerCore
import org.mozilla.javascript.JavaScriptException; //导入依赖的package包/类
@Override
protected void executeHandlerCore(String handlerType, org.mozilla.javascript.Context javascriptContext) throws EcmaError, EvaluatorException, JavaScriptException, EngineException {
if (!AbstractHttpTransaction.EVENT_DATA_RETRIEVED.equals(handlerType)) {
super.executeHandlerCore(handlerType, javascriptContext);
return;
}
executeSimpleHandlerCore(handlerType, javascriptContext);
}