@Override String decompile(int indent, int flags) { StringBuffer sb = new StringBuffer(); boolean justbody = (0 != (flags & Decompiler.ONLY_BODY_FLAG)); if (!justbody) { sb.append("function "); sb.append(getFunctionName()); sb.append("() { "); } sb.append("[native code for "); if (idcall instanceof Scriptable) { Scriptable sobj = (Scriptable)idcall; sb.append(sobj.getClassName()); sb.append('.'); } sb.append(getFunctionName()); sb.append(", arity="); sb.append(getArity()); sb.append(justbody ? "]\n" : "] }\n"); return sb.toString(); }
/** * Utility method to construct type error to indicate incompatible call * when converting script thisObj to a particular type is not possible. * Possible usage would be to have a private function like realThis: * <pre> * private static NativeSomething realThis(Scriptable thisObj, * IdFunctionObject f) * { * if (!(thisObj instanceof NativeSomething)) * throw incompatibleCallError(f); * return (NativeSomething)thisObj; * } * </pre> * Note that although such function can be implemented universally via * java.lang.Class.isInstance(), it would be much more slower. * @param f function that is attempting to convert 'this' * object. * @return Scriptable object suitable for a check by the instanceof * operator. * @throws RuntimeException if no more instanceof target can be found */ protected static EcmaError incompatibleCallError(IdFunctionObject f) { throw ScriptRuntime.typeError1("msg.incompat.call", f.getFunctionName()); }
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()); }
private static String stringValue(final Object arg) { if (arg instanceof NativeFunction) { // Don't return the string value of the function, because it's usually // multiple lines of content and messes up the log. final String name = StringUtils.defaultIfEmpty(((NativeFunction) arg).getFunctionName(), "anonymous"); return "[function " + name + "]"; } else if (arg instanceof IdFunctionObject) { return "[function " + ((IdFunctionObject) arg).getFunctionName() + "]"; } else if (arg instanceof Function) { return "[function anonymous]"; } String asString = null; try { // try to get the js representation asString = Context.toString(arg); if (arg instanceof Event) { asString += "<" + ((Event) arg).getType() + ">"; } } catch (final Throwable e) { // seems to be a bug (many bugs) in rhino (TODO: investigate it) asString = String.valueOf(arg); } return asString; }
private static String stringValue(final Object arg) { if (arg instanceof NativeFunction) { // Don't return the string value of the function, because it's usually // multiple lines of content and messes up the log. final String name = StringUtils.defaultIfEmpty(((NativeFunction) arg).getFunctionName(), "anonymous"); return "[function " + name + "]"; } else if (arg instanceof IdFunctionObject) { return "[function " + ((IdFunctionObject) arg).getFunctionName() + "]"; } else if (arg instanceof Function) { return "[function anonymous]"; } String asString = null; try { // try to get the js representation asString = Context.toString(arg); if (arg instanceof Event) { asString += "<" + ((Event) arg).getType() + ">"; } } catch (final Throwable e) { // seems to be a bug (many bugs) in rhino (TODO: investigate it) asString = String.valueOf(arg); } return asString; }
private String stringValue(final Object arg) { if (arg instanceof NativeFunction) { // Don't return the string value of the function, because it's usually // multiple lines of content and messes up the log. final String name = StringUtils.defaultIfEmpty(((NativeFunction) arg).getFunctionName(), "anonymous"); return "[function " + name + "]"; } else if (arg instanceof IdFunctionObject) { return "[function " + ((IdFunctionObject) arg).getFunctionName() + "]"; } else if (arg instanceof Function) { return "[function anonymous]"; } String asString = null; try { // try to get the js representation asString = Context.toString(arg); if (arg instanceof Event) { asString += "<" + ((Event) arg).jsxGet_type() + ">"; } } catch (final Throwable e) { // seems to be a bug (many bugs) in rhino (TODO: investigate it) asString = String.valueOf(arg); } return asString; }
private String stringValue(final Object arg) { if (arg instanceof NativeFunction) { // Don't return the string value of the function, because it's usually // multiple lines of content and messes up the log. final String name = StringUtils.defaultIfEmpty(((NativeFunction) arg).getFunctionName(), "anonymous"); return "[function " + name + "]"; } else if (arg instanceof IdFunctionObject) { return "[function " + ((IdFunctionObject) arg).getFunctionName() + "]"; } else if (arg instanceof Function) { return "[function anonymous]"; } String asString = null; try { // try to get the js representation asString = Context.toString(arg); if (arg instanceof Event) { asString += "<" + ((Event) arg).jsxGet_type() + ">"; } } catch (final Throwable e) { // seems to be a bug (many bugs) in rhino (TODO: investigate it) asString = String.valueOf(arg); } return asString; }
private String stringValue(final Object arg) { if (arg instanceof NativeFunction) { // Don't return the string value of the function, because it's usually // multiple lines of content and messes up the log. final String name = StringUtils.defaultIfEmpty(((NativeFunction) arg).getFunctionName(), "anonymous"); return "[function " + name + "]"; } else if (arg instanceof IdFunctionObject) { return "[function " + ((IdFunctionObject) arg).getFunctionName() + "]"; } else if (arg instanceof Function) { return "[function anonymous]"; } String asString = null; try { // try to get the js representation asString = Context.toString(arg); if (arg instanceof Event) { asString += "<" + ((Event) arg).jsxGet_type() + ">"; } } catch (final Throwable e) { // seems to be a bug (many bugs) in rhino (TODO: investigate it) asString = String.valueOf(arg); } return asString; }