本文整理汇总了Java中org.mozilla.javascript.EcmaError类的典型用法代码示例。如果您正苦于以下问题:Java EcmaError类的具体用法?Java EcmaError怎么用?Java EcmaError使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EcmaError类属于org.mozilla.javascript包,在下文中一共展示了EcmaError类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeSimpleHandlerCore
import org.mozilla.javascript.EcmaError; //导入依赖的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.EcmaError; //导入依赖的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: invokeFunction
import org.mozilla.javascript.EcmaError; //导入依赖的package包/类
public void invokeFunction(String name, Object... parameters) {
Function func = (Function) globalScope.get(name, globalScope);
if(func != null) {
Context.enter();
try {
func.call(context, globalScope, globalScope, parameters);
} catch (EcmaError err) {
KakaoManager.getInstance().receiveError(err);
}
String params = "";
int i = 0;
for(Object p : parameters) {
i++;
params += " -> " + String.valueOf(p);
if(i != parameters.length) {
params += "\n";
}
}
Logger.Log log = new Logger.Log();
log.type = Logger.Type.APP;
log.title = "call \"" + name + "\"";
log.index = "parameters\n" + params;
Logger.getInstance().add(log);
}
}
示例4: receiveError
import org.mozilla.javascript.EcmaError; //导入依赖的package包/类
public void receiveError(final EcmaError err) {
if(isForeground) {
MainActivity.UIThread(new Runnable() {
@Override
public void run() {
MainActivity.settingPower.setChecked(false);
Toast.makeText(ctx, "Error: " + err.getName() + " (" + err.lineNumber() + ", " + err.columnNumber() + ")\n" + err.getErrorMessage(), Toast.LENGTH_SHORT).show();
}
});
}
Logger.Log log = new Logger.Log();
log.type = Logger.Type.ERROR;
log.title = err.getName();
log.index = "at (" + err.lineNumber() + ", " + err.columnNumber() + ")\n" + err.getErrorMessage();
Logger.getInstance().add(log);
}
示例5: executeSimpleHandlerCore
import org.mozilla.javascript.EcmaError; //导入依赖的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");
}
}
示例6: executeHandlerCore
import org.mozilla.javascript.EcmaError; //导入依赖的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);
}
示例7: executeHandlerCore
import org.mozilla.javascript.EcmaError; //导入依赖的package包/类
protected void executeHandlerCore(String handlerType, org.mozilla.javascript.Context myJavascriptContext) throws EcmaError, EvaluatorException, JavaScriptException, EngineException {
if ((!Transaction.EVENT_XML_GENERATED.equals(handlerType)) &&
(!Transaction.EVENT_TRANSACTION_STARTED.equals(handlerType))) {
throw new IllegalArgumentException("Unknown handler type: " + handlerType);
}
executeSimpleHandlerCore(handlerType, myJavascriptContext);
}
示例8: testWriteReadOnly_throws
import org.mozilla.javascript.EcmaError; //导入依赖的package包/类
/**
* @throws Exception if the test fails
*/
@Test
public void testWriteReadOnly_throws() throws Exception {
try {
testWriteReadOnly(false);
Assert.fail();
}
catch (EcmaError e) {
Assert.assertTrue(e.getMessage(), e.getMessage().contains("Cannot set property myProp that has only a getter"));
}
}
示例9: eval
import org.mozilla.javascript.EcmaError; //导入依赖的package包/类
public void eval(String content) {
try {
this.context.evaluateString(this.scope, content, this.getAbsoluteName(), 1, null);
} catch(EcmaError e) {
KnuddelsServer.getDefaultLogger().error(e.getMessage());
}
}
示例10: jsEval
import org.mozilla.javascript.EcmaError; //导入依赖的package包/类
/**
* evaluate a javascript String
* @param name the name of the script (for error messages)
* @param script the content of the script
* @return the result
*/
public Object jsEval(String name, String script) {
try {
return getContext().evaluateString(scope, script, name, 1, null);
} catch (EcmaError e) {
throw new RuntimeException("can't evaluate "+name+": "+script,e);
}
}
示例11: getFunction
import org.mozilla.javascript.EcmaError; //导入依赖的package包/类
private Function getFunction(String name, Scriptable scope, Context ctx) {
Object fun;
try {
fun = ctx.compileString(name, null, 1, null).exec(ctx, scope);
} catch (EcmaError ee) {
throw new RuntimeException ("Function '" + name + "()' not found.");
}
if (!(fun instanceof Function)) {
throw new RuntimeException("'" + name + "' is not a function");
} else {
return (Function) fun;
}
}
示例12: executeInternal
import org.mozilla.javascript.EcmaError; //导入依赖的package包/类
private Object executeInternal(final String script, final String scriptName, final ScriptContext context,
final boolean function, final Class<?> expectedResultClass) throws ScriptException
{
// never ever execute an empty script, it's just a waste of time
if( !Check.isEmpty(script) )
{
// In most cases apart from calls from birt, we can expect that
// there'll be no current context, thus one will be generated by
// this call into the ContextFactory
return ContextFactory.getGlobal().call(new ContextAction()
{
@Override
public Object run(Context cx)
{
Logger errorLogger = context.getLogger();
if( errorLogger == null )
{
errorLogger = logger;
}
Scriptable userScriptScope = ((DefaultScriptContext) context).getUserScriptScope(cx);
ScriptableModuleSourceProvider sourceProvider = new ScriptableModuleSourceProvider(userScriptScope);
ModuleScriptProvider scriptProvider = new SoftCachingModuleScriptProvider(sourceProvider);
cx.initStandardObjects();
Scriptable scope = ((DefaultScriptContext) context).getScope(cx);
RequireBuilder builder = new RequireBuilder();
// The "uri" property must not exist in a sandbox
builder.setSandboxed(false);
builder.setModuleScriptProvider(scriptProvider);
Require require = builder.createRequire(cx, scope);
cx.setOptimizationLevel(-1);
cx.setErrorReporter(new ScriptErrorReporter(errorLogger));
final String execScript = (function ? "function runScript() {\n" + script + "\n}\n runScript();"
: script);
final String execScriptName = (scriptName != null ? scriptName : "script");
try
{
context.scriptEnter();
require.install(scope);
Object result = cx.evaluateString(scope, execScript, execScriptName, 1, null);
context.scriptExit();
if( expectedResultClass == String.class )
{
return result.toString();
}
return result;
}
catch( JavaScriptException js )
{
throw new ScriptException(js);
}
catch( EcmaError ec )
{
throw new ScriptException(ec);
}
catch( EvaluatorException ev )
{
throw new ScriptException(ev);
}
}
});
}
return Boolean.TRUE;
}
示例13: testS15_10_2_15_A1_T4
import org.mozilla.javascript.EcmaError; //导入依赖的package包/类
@Test(expected = EcmaError.class)
public void testS15_10_2_15_A1_T4() {
String source = "(new RegExp('[\\\\Db-G]').exec('a'))";
String sourceName = "Conformance/15_Native/15.10_RegExp_Objects/15.10.2_Pattern_Semantics/15.10.2.15_NonemptyClassRanges/S15.10.2.15_A1_T4.js";
cx.evaluateString(scope, source, sourceName, 0, null);
}
示例14: testS15_10_2_15_A1_T5
import org.mozilla.javascript.EcmaError; //导入依赖的package包/类
@Test(expected = EcmaError.class)
public void testS15_10_2_15_A1_T5() {
String source = "(new RegExp('[\\\\sb-G]').exec('a'))";
String sourceName = "Conformance/15_Native/15.10_RegExp_Objects/15.10.2_Pattern_Semantics/15.10.2.15_NonemptyClassRanges/S15.10.2.15_A1_T5.js";
cx.evaluateString(scope, source, sourceName, 0, null);
}
示例15: testS15_10_2_15_A1_T6
import org.mozilla.javascript.EcmaError; //导入依赖的package包/类
@Test(expected = EcmaError.class)
public void testS15_10_2_15_A1_T6() {
String source = "(new RegExp('[\\\\Sb-G]').exec('a'))";
String sourceName = "Conformance/15_Native/15.10_RegExp_Objects/15.10.2_Pattern_Semantics/15.10.2.15_NonemptyClassRanges/S15.10.2.15_A1_T6.js";
cx.evaluateString(scope, source, sourceName, 0, null);
}