Exemplo n.º 1
0
    void OnConnectToServer(int id)
    {
        Debug.Log("Connected to server as client " + id);
        timeConnected = renderTime;
        context.Activate();

        for (int i = 0; i < MaxClients; ++i)
        {
            context.HideAvatar(i);
        }

        isConnected = true;
    }
Exemplo n.º 2
0
    void OnConnectToServer(int clientIndex)
    {
        Debug.Log("Connected to server as client " + clientIndex);

        timeConnected = renderTime;

        context.Activate();

        for (int i = 0; i < Constants.MaxClients; ++i)
        {
            context.HideRemoteAvatar(i);
        }

        successfullyConnected = true;
    }
Exemplo n.º 3
0
        private JSValue run(Context internalContext)
        {
            internalContext.Activate();
            JSValue result = null;

            try
            {
                result = evaluateBody(internalContext);
            }
            finally
            {
                internalContext.Deactivate();
            }

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Run the script
        /// </summary>
        public void Run()
        {
            if (Code == "")
            {
                return;
            }

            try
            {
                Context.Activate();
                _root.Evaluate(Context);
            }
            finally
            {
                Context.Deactivate();
            }
        }
Exemplo n.º 5
0
        public IIteratorResult next(Arguments args)
        {
            if (_generatorContext == null)
            {
                initContext();
            }
            else
            {
                switch (_generatorContext._executionMode)
                {
                case ExecutionMode.Suspend:
                {
                    _generatorContext._executionMode = ExecutionMode.Resume;
                    break;
                }

                case ExecutionMode.ResumeThrow:
                {
                    break;
                }

                default:
                    return(new GeneratorResult(JSValue.undefined, true));
                }
                ;

                _generatorContext._executionInfo = args != null ? args[0] : JSValue.undefined;
            }

            _generatorContext.Activate();
            JSValue result;

            try
            {
                result = _generator.evaluateBody(_generatorContext);
            }
            finally
            {
                _generatorContext.Deactivate();
            }

            return(new GeneratorResult(result, _generatorContext._executionMode != ExecutionMode.Suspend));
        }
Exemplo n.º 6
0
        /// <summary>
        ///   Way 1: preloading all the data into memory and returning it inside this scope.
        /// </summary>
        private IEnumerator <Tuple> GetGreedyEnumerator()
        {
            using (var cs = Context.BeginEnumeration()) {
                List <Tuple> items;

                using (Context.Activate())
                    items = Source.ToList();

                foreach (var tuple in items)
                {
                    yield return(tuple);
                }

                if (cs != null)
                {
                    cs.Complete();
                }
            }
        }
Exemplo n.º 7
0
        private JSValue run(Context internalContext)
        {
            internalContext.Activate();
            JSValue result = null;

            try
            {
                result = evaluateBody(internalContext);
            }
            catch (JSException ex)
            {
                throw ex;
            }
            finally
            {
                internalContext.Deactivate();
            }

            return(result);
        }
Exemplo n.º 8
0
        public JSValue Evaluate(Context context)
        {
            if (Code == "")
            {
                return(JSValue.Undefined);
            }

            try
            {
                context.Activate();
                return(Root.Evaluate(context) ?? context._lastResult ?? JSValue.notExists);
            }
            finally
            {
                for (var i = 0; i < Root._variables.Length; i++)
                {
                    Root._variables[i].cacheContext = null;
                }
                context.Deactivate();
            }
        }
Exemplo n.º 9
0
        /// <summary>
        ///   Way 2: batched enumeration with periodical context activation
        /// </summary>
        private IEnumerator <Tuple> GetBatchedEnumerator()
        {
            EnumerationScope currentScope = null;
            var batched = Source.Batch(2).ApplyBeforeAndAfter(
                () => currentScope = Context.Activate(),
                () => currentScope.DisposeSafely());

            using (var cs = Context.BeginEnumeration()) {
                foreach (var batch in batched)
                {
                    foreach (var tuple in batch)
                    {
                        yield return(tuple);
                    }
                }
                if (cs != null)
                {
                    cs.Complete();
                }
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Way 1: asynchroniously preloading all the data into memory and returning it inside this scope.
        /// </summary>
        private async Task <IEnumerator <Tuple> > GetGreedyEnumeratorAsync(CancellationToken token)
        {
            var             cs = Context.BeginEnumeration();
            List <Tuple>    items;
            Action <object> afterEnumrationAction =
                o => {
                if (o == null)
                {
                    return;
                }
                var completableScope = (ICompletableScope)o;
                completableScope.Complete();
                completableScope.Dispose();
            };

            using (Context.Activate()) {
                var enumerator = await Source.GetEnumeratorAsync(Context, token).ConfigureAwait(false);

                items = enumerator.ToEnumerable().ToList();
            }

            return(items.ToEnumerator(afterEnumrationAction, cs));
        }
Exemplo n.º 11
0
        private void evaluateWithScope(Context context, int i, bool clearSuspendData)
        {
            var activated = _suppressScopeIsolation != SuppressScopeIsolationMode.Suppress && context.Activate();

            try
            {
                evaluateLines(context, i, clearSuspendData);
            }
            finally
            {
                if (_suppressScopeIsolation != SuppressScopeIsolationMode.Suppress)
                {
                    if (activated)
                    {
                        context.Deactivate();
                    }
                    context._parent._lastResult    = context._lastResult;
                    context._parent._executionInfo = context._executionInfo;
                    context._parent._executionMode = context._executionMode;
                    if (_variables.Length != 0)
                    {
                        clearVariablesCache();
                    }
                }
            }
        }
Exemplo n.º 12
0
        protected internal virtual JSValue Invoke(bool construct, JSValue targetObject, Arguments arguments)
        {
            JSValue result;
            var     body = FunctionDefinition.Body;

            if (body._lines.Length == 0)
            {
                notExists._valueType = JSValueType.NotExists;
                return(notExists);
            }

            var ceocw = FunctionDefinition.FunctionInfo.ContainsEval || FunctionDefinition.FunctionInfo.ContainsWith || FunctionDefinition.FunctionInfo.NeedDecompose;

            if (FunctionDefinition.recursionDepth > FunctionDefinition.parametersStored) // рекурсивный вызов.
            {
                if (!ceocw)
                {
                    storeParameters();
                }
                FunctionDefinition.parametersStored = FunctionDefinition.recursionDepth;
            }

            if (arguments == null)
            {
                arguments = new Arguments(Context.CurrentContext);
            }

            for (;;) // tail recursion catcher
            {
                var internalContext = new Context(Context, ceocw, this)
                {
                    _definedVariables = body._variables
                };
                internalContext.Activate();

                try
                {
                    initContext(targetObject, arguments, ceocw, internalContext);
                    initParameters(arguments, internalContext);
                    FunctionDefinition.recursionDepth++;
                    result = evaluateBody(internalContext);
                }
                finally
                {
                    FunctionDefinition.recursionDepth--;
                    if (FunctionDefinition.parametersStored > FunctionDefinition.recursionDepth)
                    {
                        FunctionDefinition.parametersStored = FunctionDefinition.recursionDepth;
                    }

                    exit(internalContext);
                }

                if (result != null) // tail recursion
                {
                    break;
                }

                arguments    = internalContext._executionInfo as Arguments;
                targetObject = correctTargetObject(internalContext._objectSource, body._strict);
            }

            return(result);
        }
Exemplo n.º 13
0
        private JSValue fastInvoke(JSValue targetObject, Expression[] arguments, Context initiator)
        {
#if DEBUG && !(PORTABLE || NETCORE)
            if (_functionDefinition.trace)
            {
                System.Console.WriteLine("DEBUG: Run \"" + _functionDefinition.Reference.Name + "\"");
            }
#endif
            var body = _functionDefinition._body;
            targetObject = correctTargetObject(targetObject, body._strict);
            if (_functionDefinition.recursionDepth > _functionDefinition.parametersStored) // рекурсивный вызов.
            {
                storeParameters();
                _functionDefinition.parametersStored++;
            }

            JSValue   res      = null;
            Arguments args     = null;
            bool      tailCall = false;
            for (; ;)
            {
                var internalContext = new Context(_initialContext, false, this);
                internalContext._callDepth = (Context.CurrentContext?._callDepth ?? 0) + 1;

                if (_functionDefinition.kind == FunctionKind.Arrow)
                {
                    internalContext._thisBind = _initialContext._thisBind;
                }
                else
                {
                    internalContext._thisBind = targetObject;
                }

                if (tailCall)
                {
                    initParameters(
                        args,
                        _functionDefinition._functionInfo.ContainsEval ||
                        _functionDefinition._functionInfo.ContainsWith ||
                        _functionDefinition._functionInfo.ContainsDebugger ||
                        _functionDefinition._functionInfo.NeedDecompose ||
                        (internalContext?._debugging ?? false),
                        internalContext);
                }
                else
                {
                    initParametersFast(arguments, initiator, internalContext);
                }

                // Эта строка обязательно должна находиться после инициализации параметров
                _functionDefinition.recursionDepth++;

                initCachedReference(internalContext);

                internalContext._strict |= body._strict;
                internalContext.Activate();

                try
                {
                    res = evaluateBody(internalContext);
                    if (internalContext._executionMode == ExecutionMode.TailRecursion)
                    {
                        tailCall = true;
                        args     = internalContext._executionInfo as Arguments;
                    }
                    else
                    {
                        tailCall = false;
                    }
                }
                finally
                {
#if DEBUG && !(PORTABLE || NETCORE)
                    if (_functionDefinition.trace)
                    {
                        System.Console.WriteLine("DEBUG: Exit \"" + _functionDefinition.Reference.Name + "\"");
                    }
#endif
                    _functionDefinition.recursionDepth--;
                    if (_functionDefinition.parametersStored > _functionDefinition.recursionDepth)
                    {
                        _functionDefinition.parametersStored--;
                    }
                    exit(internalContext);
                }

                if (!tailCall)
                {
                    break;
                }

                targetObject = correctTargetObject(internalContext._objectSource, body._strict);
            }
            return(res);
        }
Exemplo n.º 14
0
        private JSValue fastInvoke(JSValue targetObject, Expression[] arguments, Context initiator)
        {
            var body = FunctionDefinition.Body;

            targetObject = correctTargetObject(targetObject, body._strict);
            if (FunctionDefinition.recursionDepth > FunctionDefinition.parametersStored) // рекурсивный вызов.
            {
                storeParameters();
                FunctionDefinition.parametersStored++;
            }

            JSValue   res      = null;
            Arguments args     = null;
            bool      tailCall = false;

            for (;;)
            {
                var internalContext = new Context(Context, false, this)
                {
                    _thisBind = FunctionDefinition.Kind == FunctionKind.Arrow
                        ? Context._thisBind
                        : targetObject
                };


                if (tailCall)
                {
                    initParameters(args, internalContext);
                }
                else
                {
                    initParametersFast(arguments, initiator, internalContext);
                }

                // Эта строка обязательно должна находиться после инициализации параметров
                FunctionDefinition.recursionDepth++;

                if (FunctionDefinition.Reference._descriptor != null && FunctionDefinition.Reference._descriptor.cacheRes == null)
                {
                    FunctionDefinition.Reference._descriptor.cacheContext = internalContext._parent;
                    FunctionDefinition.Reference._descriptor.cacheRes     = this;
                }

                internalContext._strict |= body._strict;
                internalContext.Activate();

                try
                {
                    res = evaluateBody(internalContext);
                    if (internalContext._executionMode == ExecutionMode.TailRecursion)
                    {
                        tailCall = true;
                        args     = internalContext._executionInfo as Arguments;
                    }
                    else
                    {
                        tailCall = false;
                    }
                }
                finally
                {
                    FunctionDefinition.recursionDepth--;
                    if (FunctionDefinition.parametersStored > FunctionDefinition.recursionDepth)
                    {
                        FunctionDefinition.parametersStored--;
                    }
                    exit(internalContext);
                }

                if (!tailCall)
                {
                    break;
                }

                targetObject = correctTargetObject(internalContext._objectSource, body._strict);
            }
            return(res);
        }