/// <summary> Note that this method does not get forwarded to the delegee if /// the <code>hint</code> parameter is null, /// <code>typeof(Scriptable)</code> or /// <code>typeof(Function)</code>. Instead the object /// itself is returned. /// /// </summary> /// <param name="hint">the type hint /// </param> /// <returns> the default value /// /// </returns> public virtual object GetDefaultValue(Type hint) { return((hint == null || hint == typeof(IScriptable) || hint == typeof(IFunction)) ? this : obj.GetDefaultValue(hint)); }
private BaseFunction RealFunction(IScriptable thisObj, IdFunctionObject f) { object x = thisObj.GetDefaultValue(typeof(IFunction)); if (x is BaseFunction) { return((BaseFunction)x); } throw ScriptRuntime.TypeErrorById("msg.incompat.call", f.FunctionName); }
internal static object ToPrimitive (object val) { if (!(val is IScriptable)) { return val; } IScriptable s = (IScriptable)val; object result = s.GetDefaultValue (null); if (result is IScriptable) throw ScriptRuntime.TypeErrorById ("msg.bad.default.value"); return result; }
/// <summary> Function.prototype.apply and Function.prototype.call /// /// See Ecma 15.3.4.[34] /// </summary> public static object applyOrCall(bool isApply, Context cx, IScriptable scope, IScriptable thisObj, object [] args) { int L = args.Length; ICallable function; if (thisObj is ICallable) { function = (ICallable)thisObj; } else { object value = thisObj.GetDefaultValue (typeof (IFunction)); if (!(value is ICallable)) { throw ScriptRuntime.NotFunctionError (value, thisObj); } function = (ICallable)value; } IScriptable callThis = null; if (L != 0) { callThis = ScriptConvert.ToObjectOrNull (cx, args [0]); } if (callThis == null) { // This covers the case of args[0] == (null|undefined) as well. callThis = getTopCallScope (cx); } object [] callArgs; if (isApply) { // Follow Ecma 15.3.4.3 if (L <= 1) { callArgs = ScriptRuntime.EmptyArgs; } else { object arg1 = args [1]; if (arg1 == null || arg1 == Undefined.Value) { callArgs = ScriptRuntime.EmptyArgs; } else if (arg1 is BuiltinArray || arg1 is Arguments) { callArgs = cx.GetElements ((IScriptable)arg1); } else { throw ScriptRuntime.TypeErrorById ("msg.arg.isnt.array"); } } } else { // Follow Ecma 15.3.4.4 if (L <= 1) { callArgs = ScriptRuntime.EmptyArgs; } else { callArgs = new object [L - 1]; Array.Copy (args, 1, callArgs, 0, L - 1); } } return function.Call (cx, scope, callThis, callArgs); }
private BaseFunction RealFunction(IScriptable thisObj, IdFunctionObject f) { object x = thisObj.GetDefaultValue (typeof (IFunction)); if (x is BaseFunction) { return (BaseFunction)x; } throw ScriptRuntime.TypeErrorById ("msg.incompat.call", f.FunctionName); }