/** * {@inheritDoc} */ @Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { final String s = (String) super.call(cx, scope, thisObj, args); if (thisObj instanceof BaseFunction && s.indexOf("[native code]") > -1) { final String functionName = ((BaseFunction) thisObj).getFunctionName(); return "\nfunction " + functionName + "() {\n [native code]\n}\n"; } return s; }
/** * {@inheritDoc} */ @Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { final String s = (String) super.call(cx, scope, thisObj, args); if (thisObj instanceof BaseFunction && s.indexOf("[native code]") > -1) { final String functionName = ((BaseFunction) thisObj).getFunctionName(); return "function " + functionName + "() { [native code] }"; } return s.replace("function anonymous() {", "function anonymous(\n) {"); } }
/** * {@inheritDoc} */ @Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { final String s = (String) super.call(cx, scope, thisObj, args); if (thisObj instanceof BaseFunction && s.indexOf("[native code]") > -1) { final String functionName = ((BaseFunction) thisObj).getFunctionName(); return "function " + functionName + "() { [native code] }"; } return s.replace("function anonymous() {", "function anonymous(\n) {"); } }
/** * {@inheritDoc} */ @Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { final String s = (String) super.call(cx, scope, thisObj, args); if (thisObj instanceof BaseFunction && s.indexOf("[native code]") > -1) { final String functionName = ((BaseFunction) thisObj).getFunctionName(); return "\nfunction " + functionName + "() {\n [native code]\n}\n"; } return s; }
/** * Decompile the source information associated with this js * function/script back into a string. * * @param indent How much to indent the decompiled result. * * @param flags Flags specifying format of decompilation output. */ 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("() {\n\t"); } sb.append("[native code, arity="); sb.append(getArity()); sb.append("]\n"); if (!justbody) { sb.append("}\n"); } return sb.toString(); }
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> * Register a snippet of JavaScript code as an event handler. The JavaScript code will * be wrapped inside a unique function declaration which provides one argument named * "event" * @param eventName Name of event such as "onclick" or "onblur", etc * @param jsSnippet executable JavaScript code */ public final void setEventHandler(final String eventName, final String jsSnippet) { final BaseFunction function = new EventHandler(this, eventName, jsSnippet); setEventHandler(eventName, function); if (LOG.isDebugEnabled()) { LOG.debug("Created event handler " + function.getFunctionName() + " for " + eventName + " on " + this); } }
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> * Register a snippet of JavaScript code as an event handler. The JavaScript code will * be wrapped inside a unique function declaration which provides one argument named * "event" * @param eventName Name of event such as "onclick" or "onblur", etc * @param jsSnippet executable JavaScript code */ public final void setEventHandler(final String eventName, final String jsSnippet) { final BaseFunction function = new EventHandler(this, eventName, jsSnippet); setEventHandler(eventName, function); if (LOG.isDebugEnabled()) { LOG.debug("Created event handler " + function.getFunctionName() + " for " + eventName + " on " + this); } }
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br/> * Register a snippet of JavaScript code as an event handler. The JavaScript code will * be wrapped inside a unique function declaration which provides one argument named * "event" * @param eventName Name of event such as "onclick" or "onblur", etc * @param jsSnippet executable JavaScript code */ public final void setEventHandler(final String eventName, final String jsSnippet) { final BaseFunction function = new EventHandler(this, eventName, jsSnippet); setEventHandler(eventName, function); if (LOG.isDebugEnabled()) { LOG.debug("Created event handler " + function.getFunctionName() + " for " + eventName + " on " + this); } }
sb.append(((BaseFunction) val).getFunctionName()); sb.append("() {[native code]}");
sb.append(((BaseFunction) val).getFunctionName()); sb.append("() {[native code]}");
private static String formatToString(final Object o) { if (o == null) { return "null"; } else if (o instanceof NativeFunction) { return ((NativeFunction) o).toString(); } else if (o instanceof BaseFunction) { return "function " + ((BaseFunction) o).getFunctionName() + "\n" + " [native code]\n" + "}"; } else if (o instanceof NativeArray) { // If an array is embedded inside another array, just return // "[object Object]" return "[object Object]"; } else if (o instanceof Delegator) { return "[object " + ((Delegator) o).getDelegee().getClassName() + "]"; } else if (o instanceof NativeObject) { return "[object " + ((NativeObject) o).getClassName() + "]"; } else if (o instanceof SimpleScriptable) { return "[object " + ((SimpleScriptable) o).getClassName() + "]"; } else { return o.toString(); } }
sb.append(id + ": function " + ((BaseFunction) value).getFunctionName() + "()\n");
private static String formatToString(final Object o) { if (o == null) { return "null"; } else if (o instanceof NativeFunction) { return ((NativeFunction) o).toString(); } else if (o instanceof BaseFunction) { return "function " + ((BaseFunction) o).getFunctionName() + "\n" + " [native code]\n" + "}"; } else if (o instanceof NativeArray) { // If an array is embedded inside another array, just return // "[object Object]" return "[object Object]"; } else if (o instanceof Delegator) { return "[object " + ((Delegator) o).getDelegee().getClassName() + "]"; } else if (o instanceof NativeObject) { return "[object " + ((NativeObject) o).getClassName() + "]"; } else if (o instanceof SimpleScriptable) { return "[object " + ((SimpleScriptable) o).getClassName() + "]"; } else { return o.toString(); } }
sb.append(id + ": function " + ((BaseFunction) value).getFunctionName() + "()\n");
/** * Implements the instanceof operator for JavaScript Function objects. * <p> * <code> * foo = new Foo();<br> * foo instanceof Foo; // true<br> * </code> * * @param instance The value that appeared on the LHS of the instanceof * operator * @return true if the "prototype" property of "this" appears in * value's prototype chain * */ @Override public boolean hasInstance(Scriptable instance) { Object protoProp = ScriptableObject.getProperty(this, "prototype"); if (protoProp instanceof Scriptable) { return ScriptRuntime.jsDelegatesTo(instance, (Scriptable)protoProp); } throw ScriptRuntime.typeError1("msg.instanceof.bad.prototype", getFunctionName()); }
public Scriptable construct(Context cx, Scriptable scope, Object[] args) { Scriptable result = createObject(cx, scope); if (result != null) { Object val = call(cx, scope, result, args); if (val instanceof Scriptable) { result = (Scriptable)val; } } else { Object val = call(cx, scope, null, args); if (!(val instanceof Scriptable)) { // It is program error not to return Scriptable from // the call method if createObject returns null. throw new IllegalStateException( "Bad implementaion of call as constructor, name=" +getFunctionName()+" in "+getClass().getName()); } result = (Scriptable)val; if (result.getPrototype() == null) { result.setPrototype(getClassPrototype()); } if (result.getParentScope() == null) { Scriptable parent = getParentScope(); if (result != parent) { result.setParentScope(parent); } } } return result; }
@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); }