コード例 #1
0
ファイル: NFunction.cs プロジェクト: ChaosPandion/Machete
        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);
            }
        }
コード例 #2
0
ファイル: Environment.cs プロジェクト: bittercoder/Machete
        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));
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
ファイル: Iterator.cs プロジェクト: ChaosPandion/Machete
        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'.");
        }
コード例 #5
0
        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'.");
            }
        }
コード例 #6
0
        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));
            }
        }
コード例 #7
0
ファイル: Environment.cs プロジェクト: ChaosPandion/Machete
 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);
 }
コード例 #8
0
ファイル: LType.cs プロジェクト: ChaosPandion/Machete
 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));
 }