@Override public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { String stack = args[0].toString(); return new NativeArray(resultParser.decodeStack(stack)); } };
return; String status = result.get("status", result).toString(); switch (status) { case "ok": break; case "exception": { String className = String.valueOf(result.get("className", result)); if (debugInformation != null) { String decodedName = debugInformation.getClassNameByJsName(className); String message = String.valueOf(result.get("message", result)); String stack = result.get("stack", result).toString(); StackTraceElement[] decodedStack = null; if (debugInformation != null) {
@Override public void runTest(TestRun run) throws IOException { if (++runs == 50) { runs = 0; cleanUp(); init(); } try { page.set(webClient.get().getPage("about:blank")); } catch (IOException e) { throw new RuntimeException(e); } HtmlPage pageRef = page.get(); pageRef.executeJavaScript(readFile(new File(run.getBaseDirectory(), run.getFileName()))); boolean decodeStack = Boolean.parseBoolean(System.getProperty(TeaVMTestRunner.JS_DECODE_STACK, "true")); File debugFile = decodeStack ? new File(run.getBaseDirectory(), run.getFileName() + ".teavmdbg") : null; RhinoResultParser resultParser = new RhinoResultParser(debugFile); AsyncResult asyncResult = new AsyncResult(); Function function = (Function) page.get().executeJavaScript(readResource("teavm-htmlunit-adapter.js")) .getJavaScriptResult(); Object[] args = new Object[] { decodeStack ? createStackDecoderFunction(resultParser) : null, new NativeJavaObject(function, asyncResult, AsyncResult.class) }; pageRef.executeJavaScriptFunction(function, function, args, page.get()); resultParser.parseResult((Scriptable) asyncResult.getResult(), run.getCallback()); }
public static Scriptable newObject(Context cx, Scriptable scope, String constructorName, Object[] args) { scope = ScriptableObject.getTopLevelScope(scope); Function ctor = getExistingCtor(cx, scope, constructorName); if (args == null) { args = ScriptRuntime.emptyArgs; } return ctor.construct(cx, scope, args); }
@Override protected Object getInstanceIdValue(int id) { switch (id) { case Id_length: return ScriptRuntime.wrapInt(getLength()); case Id_arity: return ScriptRuntime.wrapInt(getArity()); case Id_name: return getFunctionName(); case Id_prototype: return getPrototypeProperty(); case Id_arguments: return getArguments(); } return super.getInstanceIdValue(id); }
@Override public Object doRun(final Context cx) { if (ScriptRuntime.hasTopCall(cx)) { return function.call(cx, scope, thisObject, args); } return ScriptRuntime.doTopCall(function, cx, scope, thisObject, args, cx.isStrictMode()); } @Override
private Object js_eval(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { if (thisObj.getParentScope() == null) { // We allow indirect calls to eval as long as the script will execute in // the global scope. return ScriptRuntime.evalSpecial(cx, scope, thisObj, args, "eval code", 1); } String m = ScriptRuntime.getMessage1("msg.cant.call.indirect", "eval"); throw NativeGlobal.constructError(cx, "EvalError", m, scope); }
/** * This is set after the make method is called, so we can't do this eagerly. */ public Throwable getCause() { Object javaException = ScriptableObject.getProperty(NativeError.this, "javaException"); if (javaException instanceof NativeJavaObject) { NativeJavaObject njo = (NativeJavaObject) javaException; return (Throwable)njo.unwrap(); } return super.getCause(); } }
public final void initPrototypeMethod(Object tag, int id, String name, int arity) { Scriptable scope = ScriptableObject.getTopLevelScope(this); IdFunctionObject f = newIdFunction(tag, id, name, arity, scope); prototypeValues.initValue(id, name, f, DONTENUM); }
protected void addIdFunctionProperty(Scriptable obj, Object tag, int id, String name, int arity) { Scriptable scope = ScriptableObject.getTopLevelScope(obj); IdFunctionObject f = newIdFunction(tag, id, name, arity, scope); f.addAsProperty(obj); }
ScriptableObject getPropertyDescriptor(Context cx, Scriptable scope) { ScriptableObject desc = new NativeObject(); ScriptRuntime.setObjectProtoAndParent(desc, scope); if (value != null) desc.defineProperty("value", value, EMPTY); desc.defineProperty("writable", (attributes & READONLY) == 0, EMPTY); desc.defineProperty("enumerable", (attributes & DONTENUM) == 0, EMPTY); desc.defineProperty("configurable", (attributes & PERMANENT) == 0, EMPTY); return desc; }
Scriptable[] createRegExpWraps(Context cx, Scriptable scope) { if (idata.itsRegExpLiterals == null) Kit.codeBug(); RegExpProxy rep = ScriptRuntime.checkRegExpProxy(cx); int N = idata.itsRegExpLiterals.length; Scriptable[] array = new Scriptable[N]; for (int i = 0; i != N; ++i) { array[i] = rep.wrapRegExp(cx, scope, idata.itsRegExpLiterals[i]); } return array; }
void initAsConstructor(Scriptable scope, Scriptable prototype) { ScriptRuntime.setFunctionProtoAndParent(this, scope); setImmunePrototypeProperty(prototype); prototype.setParentScope(this); defineProperty(prototype, "constructor", this, ScriptableObject.DONTENUM | ScriptableObject.PERMANENT | ScriptableObject.READONLY); setParentScope(scope); }
private BaseFunction realFunction(Scriptable thisObj, IdFunctionObject f) { Object x = thisObj.getDefaultValue(ScriptRuntime.FunctionClass); if (x instanceof BaseFunction) { return (BaseFunction)x; } throw ScriptRuntime.typeError1("msg.incompat.call", f.getFunctionName()); }
static long getLengthProperty(Context cx, Scriptable obj) { // These will both give numeric lengths within Uint32 range. if (obj instanceof NativeString) { return ((NativeString)obj).getLength(); } else if (obj instanceof NativeArray) { return ((NativeArray)obj).getLength(); } return ScriptRuntime.toUint32( ScriptRuntime.getObjectProp(obj, "length", cx)); }
public void defineConst(String name, Scriptable start) { if (putImpl(name, 0, start, Undefined.instance, UNINITIALIZED_CONST)) return; if (start == this) throw Kit.codeBug(); if (start instanceof ConstProperties) ((ConstProperties)start).defineConst(name, start); } /**
private void addToken(int token) { if (!Icode.validTokenCode(token)) throw Kit.codeBug(); addUint8(token); }
private void addIcode(int icode) { if (!Icode.validIcode(icode)) throw Kit.codeBug(); // Write negative icode as uint8 bits addUint8(icode & 0xFF); }
void reportError(String messageId, int position, int length) { addError(messageId, position, length); if (!compilerEnv.recoverFromErrors()) { throw new ParserException(); } }
RhinoException() { Evaluator e = Context.createInterpreter(); if (e != null) e.captureStackInfo(this); overwriteStackTrace(this); }