private IEnumerable <Expression> GetParametersForSwitchCase(int pArgsLength) { int k = 0; for (int i = 0, length = parameters.Length - (tailArray ? 1 : 0); i < length; i++) { if (i == posNew) { yield return(EcmaValueUtility.ConvertFromEcmaValueExpression(pNewTarget, parameters[i].ParameterType)); } else if (i == posThis) { yield return(EcmaValueUtility.ConvertFromEcmaValueExpression(pThisArg, parameters[i].ParameterType)); } else if (k >= pArgsLength) { yield return(GetDefaultExpression(parameters[i].ParameterType)); } else { yield return(GetArgumentFromArray(k++, i)); } } if (tailArray) { if (k >= pArgsLength) { yield return(Expression.MakeMemberAccess(null, typeof(EcmaValue).GetField("EmptyArray", BindingFlags.Static | BindingFlags.Public))); } else { yield return(GetTailArray(k)); } } }
private IEnumerable <Expression> GetParametersForSwitchDefault() { int k = 0; for (int i = 0, length = parameters.Length - (tailArray ? 1 : 0); i < length; i++) { if (i == posNew) { yield return(EcmaValueUtility.ConvertFromEcmaValueExpression(pNewTarget, parameters[i].ParameterType)); } else if (i == posThis) { yield return(EcmaValueUtility.ConvertFromEcmaValueExpression(pThisArg, parameters[i].ParameterType)); } else { yield return(Expression.Condition( Expression.GreaterThan(Expression.Property(pArgs, "Length"), Expression.Constant(i)), EcmaValueUtility.ConvertFromEcmaValueExpression(Expression.ArrayIndex(pArgs, Expression.Constant(k++)), parameters[i].ParameterType), GetDefaultExpression(parameters[i].ParameterType))); } } if (tailArray) { yield return(GetTailArray(k)); } }
public static RuntimeFunctionDelegate Compile(MethodInfo method) { NativeRuntimeFunctionCompiler compiler = new NativeRuntimeFunctionCompiler(method); Expression <RuntimeFunctionDelegate> lambda = Expression.Lambda <RuntimeFunctionDelegate>( EcmaValueUtility.ConvertToEcmaValueExpression(compiler.GetExpression()), pRecord, pArgs, pTarget); return(lambda.Compile()); }
public override EcmaValue Get(EcmaPropertyKey propertyKey, RuntimeObject receiver) { if (EcmaValueUtility.TryIndexByPropertyKey(this.Target, propertyKey, out EcmaValue value)) { return(value); } if (propertyKey == WellKnownProperty.Length) { return(Target.Count); } return(base.Get(propertyKey, receiver)); }
public override bool TryGet(string target, EcmaPropertyKey name, out EcmaValue value) { if (name.IsArrayIndex) { return(EcmaValueUtility.TryIndexByPropertyKey(target, name, out value)); } if (name.Name == "length") { value = target.Length; return(true); } return(base.TryGet(target, name, out value)); }
public override EcmaPropertyDescriptor GetOwnProperty(EcmaPropertyKey propertyKey) { if (value.Type == EcmaValueType.String) { string str = value.ToString(); if (EcmaValueUtility.TryIndexByPropertyKey(str, propertyKey, out EcmaValue ch)) { return(new EcmaPropertyDescriptor(ch, EcmaPropertyAttributes.Enumerable)); } if (propertyKey == WellKnownProperty.Length) { return(new EcmaPropertyDescriptor(str.Length, EcmaPropertyAttributes.None)); } } return(base.GetOwnProperty(propertyKey)); }
public bool SetException(Exception ex) { if (state == State.Finally) { throw ex; } if (state == State.Try && catchBlock != null) { afterYield = false; state = State.Catch; iterator.Dispose(); iterator = catchBlock(EcmaValueUtility.GetValueFromException(ex)).GetEnumerator(); return(true); } exception = ex; return(SetFinally()); }
public static EcmaValue Race([This] EcmaValue thisValue, EcmaValue iterable) { Guard.ArgumentIsObject(thisValue); PromiseCapability capability = PromiseCapability.CreateFromConstructor(thisValue.ToObject()); try { using (EcmaIteratorEnumerator iterator = iterable.ForOf()) { EcmaValue resolve = thisValue[WellKnownProperty.Resolve]; while (MoveNextSafe(iterator)) { EcmaValue thenable = resolve.Call(thisValue, iterator.Current); thenable.Invoke(WellKnownProperty.Then, capability.ResolveCallback, capability.RejectCallback); } } } catch (Exception ex) { capability.Reject(EcmaValueUtility.GetValueFromException(ex)); } return(capability.Promise); }
public static EcmaValue All([This] EcmaValue thisValue, EcmaValue iterable) { Guard.ArgumentIsObject(thisValue); PromiseCapability capability = PromiseCapability.CreateFromConstructor(thisValue.ToObject()); PromiseAggregator aggregator = new AllFulfilledAggregator(capability); try { using (EcmaIteratorEnumerator iterator = iterable.ForOf()) { EcmaValue resolve = thisValue[WellKnownProperty.Resolve]; while (MoveNextSafe(iterator)) { EcmaValue thenable = resolve.Call(thisValue, iterator.Current); thenable.Invoke(WellKnownProperty.Then, (PromiseResolver)aggregator.CreateHandler().ResolveHandler, capability.RejectCallback); } } aggregator.ResolveIfConditionMet(); } catch (Exception ex) { capability.Reject(EcmaValueUtility.GetValueFromException(ex)); } return(capability.Promise); }
public static void SendUnhandledException(Exception ex) { Guard.ArgumentNotNull(ex, "ex"); RuntimeExecution current = EnsureInstance(); current.UnhandledException?.Invoke(null, new RuntimeUnhandledExceptionEventArgs(ex, EcmaValueUtility.GetValueFromException(ex))); }
public override double ToDouble(string value) { return(EcmaValueUtility.ParseStringNumericLiteral(value).ToDouble()); }
public override int ToInt32(string value) { return(EcmaValueUtility.ParseStringNumericLiteral(value).ToInt32()); }
private Expression GetArgumentFromArray(int argsIndex, int nativeParameterIndex) { return(EcmaValueUtility.ConvertFromEcmaValueExpression(Expression.ArrayIndex(pArgs, Expression.Constant(argsIndex)), parameters[nativeParameterIndex].ParameterType)); }
public override long ToInt64(string value) { return(EcmaValueUtility.ParseStringNumericLiteral(value).ToInt64()); }
protected override bool Matches(object actual) { EcmaValue value = EcmaValueUtility.GetValueFromException((Exception)actual); return(value.InstanceOf(fn)); }
public static EcmaValue Apply([This] EcmaValue thisValue, EcmaValue thisArg, EcmaValue args) { Guard.ArgumentIsCallable(thisValue); return(thisValue.Call(thisArg, EcmaValueUtility.CreateListFromArrayLike(args))); }
public override EcmaValue ToNumber(string value) { return(EcmaValueUtility.ParseStringNumericLiteral(value)); }