Example #1
0
  private Object applyOrCall(
      boolean isApply, Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
    String methodName = isApply ? "apply" : "call";
    if (!(thisObj instanceof XMLList) || ((XMLList) thisObj).targetProperty == null)
      throw ScriptRuntime.typeError1("msg.isnt.function", methodName);

    return ScriptRuntime.applyOrCall(isApply, cx, scope, thisObj, args);
  }
Example #2
0
  public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
    // This XMLList is being called as a Function.
    // Let's find the real Function object.
    if (targetProperty == null) throw ScriptRuntime.notFunctionError(this);

    String methodName = targetProperty.getLocalName();

    boolean isApply = methodName.equals("apply");
    if (isApply || methodName.equals("call")) return applyOrCall(isApply, cx, scope, thisObj, args);

    if (!(thisObj instanceof XMLObject)) {
      throw ScriptRuntime.typeError1("msg.incompat.call", methodName);
    }
    Object func = null;
    Scriptable sobj = thisObj;

    while (sobj instanceof XMLObject) {
      XMLObject xmlObject = (XMLObject) sobj;
      func = xmlObject.getFunctionProperty(cx, methodName);
      if (func != Scriptable.NOT_FOUND) {
        break;
      }
      sobj = xmlObject.getExtraMethodSource(cx);
      if (sobj != null) {
        thisObj = sobj;
        if (!(sobj instanceof XMLObject)) {
          func = ScriptableObject.getProperty(sobj, methodName);
        }
      }
    }

    if (!(func instanceof Callable)) {
      throw ScriptRuntime.notFunctionError(thisObj, func, methodName);
    }
    return ((Callable) func).call(cx, scope, thisObj, args);
  }
Example #3
0
 public Scriptable construct(Context cx, Scriptable scope, Object[] args) {
   throw ScriptRuntime.typeError1("msg.not.ctor", "XMLList");
 }