/** * {@inheritDoc} */ @Override public Object get(final String name, final Scriptable start) { // quick and dirty if ("toString".equals(name)) { return new BaseFunction() { @Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { return jsSnippet_; } }; } return super.get(name, start); }
/** * {@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; }
/** * Gets the value returned by calling the typeof operator on this object. * @see net.sourceforge.htmlunit.corejs.javascript.ScriptableObject#getTypeOf() * @return "function" or "undefined" if {@link #avoidObjectDetection()} returns <code>true</code> */ @Override public String getTypeOf() { return avoidObjectDetection() ? "undefined" : "function"; }
static void init(Scriptable scope, boolean sealed) { BaseFunction obj = new BaseFunction(); // Function.prototype attributes: see ECMA 15.3.3.1 obj.prototypePropertyAttributes = DONTENUM | READONLY | PERMANENT; obj.exportAsJSClass(MAX_PROTOTYPE_ID, scope, sealed); }
@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); }
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; }
var parent = new BaseFunction();
/** * 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(); }
final Object obj = ((BaseFunction) iterator).call(context, thisObj.getParentScope(), scriptable, new Object[0]); .call(context, thisObj.getParentScope(), scriptableIterator, new Object[0]); .call(context, thisObj.getParentScope(), scriptableIterator, new Object[0]); done = (boolean) next.get(ES6Iterator.DONE_PROPERTY); value = next.get(ES6Iterator.VALUE_PROPERTY);
final Object obj = ((BaseFunction) iterator).call(context, thisObj.getParentScope(), scriptable, new Object[0]); .call(context, thisObj.getParentScope(), scriptableIterator, new Object[0]); .call(context, thisObj.getParentScope(), scriptableIterator, new Object[0]); done = (boolean) next.get(ES6Iterator.DONE_PROPERTY); value = next.get(ES6Iterator.VALUE_PROPERTY);
/** * {@inheritDoc} */ @Override public Object get(final String name, final Scriptable start) { // quick and dirty if ("toString".equals(name)) { return new BaseFunction() { @Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { return jsSnippet_; } }; } return super.get(name, start); }
/** * {@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 get(final String name, final Scriptable start) { // quick and dirty if ("toString".equals(name)) { return new BaseFunction() { private static final long serialVersionUID = 3761409724511435061L; @Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { return jsSnippet_; } }; } return super.get(name, start); }
/** * {@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 get(final String name, final Scriptable start) { // quick and dirty if ("toString".equals(name)) { return new BaseFunction() { private static final long serialVersionUID = 3761409724511435061L; @Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { return jsSnippet_; } }; } return super.get(name, start); }
/** * {@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 get(final String name, final Scriptable start) { // quick and dirty if ("toString".equals(name)) { return new BaseFunction() { private static final long serialVersionUID = 3761409724511435061L; @Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, final Object[] args) { return jsSnippet_; } }; } return super.get(name, start); }
/** * <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); } }