public virtual IDynamic Call(IEnvironment environment, IDynamic thisBinding, IArgs args) { var oldContext = environment.Context; var newEnvironment = Scope.NewDeclarativeEnvironment(); using (var newContext = environment.EnterContext()) { newContext.LexicalEnviroment = newEnvironment; newContext.VariableEnviroment = newEnvironment; newContext.Strict = ExecutableCode.Strict; if (ExecutableCode.Strict) { newContext.ThisBinding = thisBinding; } else { switch (thisBinding.TypeCode) { case LanguageTypeCode.Undefined: case LanguageTypeCode.Null: newContext.ThisBinding = Environment.GlobalObject; break; default: newContext.ThisBinding = thisBinding.ConvertToObject(); break; } } BindFormalParameters(args); Environment.BindFunctionDeclarations(ExecutableCode.FunctionDeclarations, ExecutableCode.Strict, true); BindArgumentsObject(args); Environment.BindVariableDeclarations(ExecutableCode.VariableDeclarations, ExecutableCode.Strict, true); return ExecutableCode.Code(environment, args); } }
public bool CombineGeneratorWithIterator(Generator generator, IDynamic other) { var iterable = other.ConvertToObject(); var createIterator = iterable.Get("createIterator") as ICallable; if (createIterator == null) { throw CreateTypeError(""); } var iterator = createIterator.Call(this, iterable, EmptyArgs).ConvertToObject(); if (!iterator.HasProperty("current")) { throw CreateTypeError(""); } var next = iterator.Get("next") as ICallable; if (next == null) { throw CreateTypeError(""); } GeneratorStep step = null; step = (_e, _g) => { if (!next.Call(this, Undefined, EmptyArgs).ConvertToBoolean().BaseValue) { return(false); } generator.Current = iterator.Get("current"); generator.Steps.Enqueue(step); return(true); }; return(step(this, generator)); }
public virtual IDynamic Op_In(IDynamic other) { if (other.TypeCode != LanguageTypeCode.Object) { throw Environment.CreateTypeError(""); } var obj = other.ConvertToObject(); var prop = this.ConvertToString().BaseValue; return(Environment.CreateBoolean(obj.HasProperty(prop))); }
public Iterator(IEnvironment environment, IDynamic iterable) { _environment = environment; var o = iterable.ConvertToObject(); var createIterator = o.Get("createIterator") as ICallable; if (createIterator == null) throw environment.CreateTypeError("The object supplied does not contain a callable property named 'createIterator'."); _iterator = createIterator.Call(environment, iterable, environment.EmptyArgs).ConvertToObject(); if (!_iterator.HasProperty("current")) throw environment.CreateTypeError("The object returned from the iterable supplied does not have a property named 'current'."); _next = _iterator.Get("next") as ICallable; if (_next == null) throw environment.CreateTypeError("The object returned from the iterable supplied does not have a callable property named 'next'."); }
public Iterator(IEnvironment environment, IDynamic iterable) { _environment = environment; var o = iterable.ConvertToObject(); var createIterator = o.Get("createIterator") as ICallable; if (createIterator == null) { throw environment.CreateTypeError("The object supplied does not contain a callable property named 'createIterator'."); } _iterator = createIterator.Call(environment, iterable, environment.EmptyArgs).ConvertToObject(); if (!_iterator.HasProperty("current")) { throw environment.CreateTypeError("The object returned from the iterable supplied does not have a property named 'current'."); } _next = _iterator.Get("next") as ICallable; if (_next == null) { throw environment.CreateTypeError("The object returned from the iterable supplied does not have a callable property named 'next'."); } }
public virtual IDynamic Call(IEnvironment environment, IDynamic thisBinding, IArgs args) { var oldContext = environment.Context; var newEnvironment = Scope.NewDeclarativeEnvironment(); using (var newContext = environment.EnterContext()) { newContext.LexicalEnviroment = newEnvironment; newContext.VariableEnviroment = newEnvironment; newContext.Strict = ExecutableCode.Strict; if (ExecutableCode.Strict) { newContext.ThisBinding = thisBinding; } else { switch (thisBinding.TypeCode) { case LanguageTypeCode.Undefined: case LanguageTypeCode.Null: newContext.ThisBinding = Environment.GlobalObject; break; default: newContext.ThisBinding = thisBinding.ConvertToObject(); break; } } BindFormalParameters(args); Environment.BindFunctionDeclarations(ExecutableCode.FunctionDeclarations, ExecutableCode.Strict, true); BindArgumentsObject(args); Environment.BindVariableDeclarations(ExecutableCode.VariableDeclarations, ExecutableCode.Strict, true); return(ExecutableCode.Code(environment, args)); } }
public bool CombineGeneratorWithIterator(Generator generator, IDynamic other) { var iterable = other.ConvertToObject(); var createIterator = iterable.Get("createIterator") as ICallable; if (createIterator == null) throw CreateTypeError(""); var iterator = createIterator.Call(this, iterable, EmptyArgs).ConvertToObject(); if (!iterator.HasProperty("current")) throw CreateTypeError(""); var next = iterator.Get("next") as ICallable; if (next == null) throw CreateTypeError(""); GeneratorStep step = null; step = (_e, _g) => { if (!next.Call(this, Undefined, EmptyArgs).ConvertToBoolean().BaseValue) return false; generator.Current = iterator.Get("current"); generator.Steps.Enqueue(step); return true; }; return step(this, generator); }
public virtual IDynamic Op_In(IDynamic other) { if (other.TypeCode != LanguageTypeCode.Object) { throw Environment.CreateTypeError(""); } var obj = other.ConvertToObject(); var prop = this.ConvertToString().BaseValue; return Environment.CreateBoolean(obj.HasProperty(prop)); }