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); }
public Scriptable createObject(Context cx, Scriptable scope) { return delegate.createObject(cx, scope); }
public Object execIdCall(IdFunctionObject f, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) { return delegate.execIdCall(f, cx, scope, thisObj, args); }
public static void setFunctionProtoAndParent(BaseFunction fn, Scriptable scope) { fn.setParentScope(scope); fn.setPrototype(ScriptableObject.getFunctionPrototype(scope)); }
@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; }
/** * 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(); }
/** * Creates new script object. * The default implementation of {@link #construct} uses the method to * to get the value for <tt>thisObj</tt> argument when invoking * {@link #call}. * The methos is allowed to return <tt>null</tt> to indicate that * {@link #call} will create a new object itself. In this case * {@link #construct} will set scope and prototype on the result * {@link #call} unless they are already set. */ public Scriptable createObject(Context cx, Scriptable scope) { Scriptable newInstance = new NativeObject(); newInstance.setPrototype(getClassPrototype()); newInstance.setParentScope(getParentScope()); return newInstance; }
@Override public Object call(final Context cx, final Scriptable scope, final Scriptable thisObj, Object[] args) { final Function callback = (Function) args[0]; if (callback != null ) { asyncCallbacksQueue.add(new BaseFunction() { @Override public Object call(Context cx2, Scriptable scope2, Scriptable thisObj2, Object[] args2) { return callback.call(cx, scope, thisObj, new Object[] {}); } }); } return Undefined.instance; } }
@Override public Scriptable getPrototype() { return delegate.getPrototype(); }
public String getFunctionName() { return delegate.getFunctionName(); }
public int getLength() { return delegate.getLength(); }
@Override public void setParentScope(Scriptable m) { delegate.setParentScope(m); }
@Override public Scriptable getParentScope() { return delegate.getParentScope(); }
public int getArity() { return delegate.getArity(); }
return delegate.call(cx, scope, thisObj, params);
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; Object val = call(cx, scope, null, args); if (!(val instanceof Scriptable)) { +getFunctionName()+" in "+getClass().getName()); Scriptable proto = getClassPrototype(); if (result != proto) { result.setPrototype(proto); Scriptable parent = getParentScope(); if (result != parent) { result.setParentScope(parent);
@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 static void setFunctionProtoAndParent(BaseFunction fn, Scriptable scope) { fn.setParentScope(scope); fn.setPrototype(ScriptableObject.getFunctionPrototype(scope)); }
/** * 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) { StringBuilder sb = new StringBuilder(); 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(); }