internal JSValue Call(JSContext Scope, JSValue ThisObj, JSValue fncObject, JSArgs Args) { JSFunctionContext ctx = new JSFunctionContext(ThisObj, Args, this.ParameterList, Scope, ((JSFunctionObject) fncObject).Scope); ctx.Source = this.Source; if (this.Name != "[function]") { ctx.LexicalEnv.CreateMutableBinding(this.Name); ctx.LexicalEnv.SetMutableBinding(this.Name, fncObject); } return this._delegate(ctx); }
internal JSValue Call(JSContext Scope, JSValue ThisObj, JSValue fncObject, JSArgs Args) { JSFunctionContext ctx = new JSFunctionContext(ThisObj, Args, this.ParameterList, Scope, ((JSFunctionObject)fncObject).Scope); ctx.Source = this.Source; if (this.Name != "[function]") { ctx.LexicalEnv.CreateMutableBinding(this.Name); ctx.LexicalEnv.SetMutableBinding(this.Name, fncObject); } return(this._delegate(ctx)); }
public override JSValue Call(JSContext Scope, JSValue ThisObj, JSArgs Args) { if (ThisObj.CheckCoercible()) { ThisObj = ThisObj.ToJSObject(); } else { ThisObj = JSContext.CurrentGlobalContext.Global; } return this.FunctionDef.Call(Scope, ThisObj, this, Args); }
public override JSValue Call(JSContext Scope, JSValue ThisObj, JSArgs Args) { if (ThisObj.CheckCoercible()) { ThisObj = ThisObj.ToJSObject(); } else { ThisObj = JSContext.CurrentGlobalContext.Global; } JSFunctionContext ctx = new JSFunctionContext(ThisObj, Args, new ParameterList(this.def.param_names), Scope, this.Scope); return this.def.del(ctx); }
public JSFunctionContext(JSValue ThisObj, JSArgs Args, ParameterList parameterList, JSContext context, JSEnvRec Scope) : base(context) { if (!((ThisObj is JSNull) || (ThisObj is JSUndefined))) { this.ThisObj = ThisObj; } this.Args = Args; this.parameterList = parameterList; base.LexicalEnv = new JSDeclScope(Scope); base.VariableEnv = base.LexicalEnv; base.CreateMutableBinding("arguments"); base.SetMutableBinding("arguments", Args); int m = parameterList.Names.Length; for (int i = 0; i < m; i++) { base.CreateMutableBinding(parameterList.Names[i]); base.SetMutableBinding(parameterList.Names[i], Args[i]); } }
private void AddFunction() { this.FunctionCtor = new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor) { string argNames; string sBody; if (args.Count > 1) { string[] ar = new string[args.Count - 1]; for (int i = 0; i < (args.Count - 1); i++) { ar[i] = args[i].StringValue(); } argNames = string.Join(",", ar); } else { argNames = ""; } if (args.Count == 0) { sBody = ""; } else { sBody = args[args.Count - 1].StringValue(); } JSFunctionObject r = CompiledScript.Compile("(function (" + argNames + ") {" + sBody + "})", false).Run() as JSFunctionObject; r.Scope = JSContext.CurrentGlobalContext.LexicalEnv; return r; }, 1); this.FunctionPrototype = new JSFunctionBase(); this.FunctionPrototype.SetDataProp("constructor", this.FunctionCtor, true, false, true); this.FunctionPrototype.SetDataProp("call", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor) { JSArgs newArgs; if (AsConstructor) { throw new JSRuntimeException("TypeError", "Function.call called as constructor"); } JSFunctionBase fnc = InternalUtilities.JSFunctionCast(ThisObj); if (args.Count == 0) { newArgs = args; } else { JSValue[] newAr = new JSValue[args.Count - 1]; Array.Copy(args.ArgValues, 1, newAr, 0, args.Count - 1); newArgs = new JSArgs(ThisObj, newAr); } return fnc.Call(Scope, args[0], newArgs); }, 1), true, false, true); this.FunctionPrototype.SetDataProp("apply", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor) { if (AsConstructor) { throw new JSRuntimeException("TypeError", "Function.apply called as constructor"); } JSFunctionBase fnc = InternalUtilities.JSFunctionCast(ThisObj); JSValue argArray = args[1]; if ((argArray is JSUndefined) || (argArray is JSNull)) { return fnc.Call(Scope, args[0], new JSArgs(ThisObj, new JSValue[0])); } if (!(argArray is JSObject)) { throw new JSRuntimeException("TypeError", "Invalid argument to Function.apply"); } JSValue olen = argArray["length"]; if (!olen.CheckCoercible()) { throw new JSRuntimeException("TypeError", "Invalid argument to Function.apply"); } double nlen = olen.NumberValue(); uint len = nlen.JSToUInt32(); if (len != nlen) { throw new JSRuntimeException("TypeError", "Invalid argument to Function.apply"); } JSValue[] newAr = new JSValue[len]; for (int i = 0; i < len; i++) { newAr[i] = argArray[i.ToString()]; } return fnc.Call(Scope, args[0], new JSArgs(ThisObj, newAr)); }, 2), true, false, true); this.FunctionPrototype.SetDataProp("toString", new JSDelegateWrapper(delegate(JSContext Scope, JSValue ThisObj, JSArgs args, bool AsConstructor) { return InternalUtilities.JSFunctionCast(ThisObj).GenerateString(); }), true, false, true); this.FunctionPrototype.SetDataProp("length", 0.0, true, false, true); this.FunctionCtor.SetDataProp("prototype", this.FunctionPrototype, false, false, false); }
public override JSValue Construct(JSContext Scope, JSArgs Args) { return this._delegate(Scope, this, Args, true); }
public override JSValue Call(JSContext Scope, JSValue ThisObj, JSArgs Args) { if (ThisObj.CheckCoercible()) { ThisObj = ThisObj.ToJSObject(); } else { ThisObj = JSContext.CurrentGlobalContext.Global; } return this._delegate(Scope, ThisObj, Args, false); }
internal JSFunctionCall(string functionName, JSValue arg) { this.args = new JSArgs() { arg }; this._functionName = functionName; }
internal JSFunctionCall(string functionName, JSArgs args) { this.args = args; this._functionName = functionName; }
internal JSFunctionCall(JSFunction f, JSArgs args) { this.f = f; this.args = args; }
internal JSFunctionCall(JSFunction f) { this.f = f; this.args = new JSArgs(); }
public JSFunctionCall Call(JSArgs args) { return RegisterFunctionCall(new JSFunctionCall(this, args)); }
public virtual JSValue Construct(JSContext Scope, JSArgs Args) { JSObject o = new JSObject(this["prototype"], this); JSValue r = this.Call(Scope, o, Args); if (r is JSObject) { return r; } return o; }
public virtual JSValue Call(JSContext Scope, JSValue ThisObj, JSArgs Args) { return JSUndefined.Instance; }
internal static JSValue _Eval(JSContext Scope, JSArgs args, bool AsConstructor) { if (AsConstructor) { throw new JSRuntimeException("TypeError", "eval called as constructor"); } JSValue arg = args[0]; if (!(arg is JSString)) { return arg; } JSContext EvalContext = new JSContext(Scope); JSContext.PushContext(EvalContext); try { return CompiledScript.Compile(arg.StringValue(), false).Run(); } finally { JSContext.PopContext(); } }
internal static JSValue DirectEvalCall(JSFunctionBase fnc, JSContext Scope, JSValue ThisObj, JSArgs Args) { if (fnc == JSContext.CurrentGlobalContext.GlobalEval) { return _Eval(Scope, Args, false); } return fnc.Call(JSContext.CurrentGlobalContext, ThisObj, Args); }