Example #1
0
        public Engine Execute(Program program)
        {
            ResetStatementsCount();
            ResetTimeoutTicks();
            ResetLastStatement();
            ResetCallStack();

            var scope = PoolStrictMode.Get();

            scope.Setup(Options._IsStrict || program.Strict);

            DeclarationBindingInstantiation(DeclarationBindingType.GlobalCode, program.FunctionDeclarations, program.VariableDeclarations, null, null);

            var result = _statements.ExecuteProgram(program);

            if (result.Type == Completion.Throw)
            {
                var exception = new JavaScriptException(result.GetValueOrDefault())
                                .SetCallstack(this, result.Location);

                scope.Teardown();
                PoolStrictMode.Put(scope);

                throw exception;
            }

            _completionValue = result.GetValueOrDefault();

            scope.Teardown();
            PoolStrictMode.Put(scope);

            return(this);
        }
Example #2
0
        public Engine Execute(Program program)
        {
            ResetStatementsCount();
            ResetTimeoutTicks();
            ResetLastStatement();
            ResetCallStack();

            using (new StrictModeScope(Options.IsStrict() || program.Strict))
            {
                DeclarationBindingInstantiation(DeclarationBindingType.GlobalCode, program.FunctionDeclarations, program.VariableDeclarations, null, null);

                var result = _statements.ExecuteProgram(program);
                if (result.Type == Completion.Throw)
                {
                    throw new JavaScriptException(result.GetValueOrDefault())
                          {
                              Location = result.Location
                          };
                }

                _completionValue = result.GetValueOrDefault();
            }

            return(this);
        }
Example #3
0
        public Engine Execute(Program program)
        {
            try
            {
                ResetStatementsCount();
                ResetTimeoutTicks();
                ResetLastStatement();
                ResetCallStack();

                using (new StrictModeScope(Options._IsStrict || program.Strict))
                {
                    DeclarationBindingInstantiation(DeclarationBindingType.GlobalCode, program.FunctionDeclarations, program.VariableDeclarations, null, null);

                    var result = _statements.ExecuteProgram(program);
                    if (result.Type == Completion.Throw)
                    {
                        throw new JavaScriptException(result.GetValueOrDefault())
                              {
                                  Location = result.Location
                              };
                    }

                    _completionValue = result.GetValueOrDefault();
                }

                return(this);
            }
            catch (Exception ex)
            {
                Location location      = null;
                var      isJsError     = ex is JavaScriptException;
                var      isDotnetError = ex is DotnetOnJavaScriptException;
                if (isJsError)
                {
                    location = (ex as JavaScriptException).Location;
                }
                if (isDotnetError)
                {
                    location = (ex as DotnetOnJavaScriptException).Location;
                }

                if (location != null)
                {
                    var error = "JavaScript error on line" + location.Start.Line.ToString() + ", cloumn: " + location.Start.Column.ToString() + " " + ex.Message;
                    throw new Exception(error, ex.InnerException);
                }

                throw;
            }
        }
Example #4
0
        public Engine Execute(Program program, JintCallStack callStack)
        {
            JintCallStack oldCallStack = null;

            if (callStack != null)
            {
                oldCallStack = CallStack;
                CallStack    = callStack;
            }

            try
            {
                using (new StrictModeScope(Options._IsStrict || program.Strict))
                {
                    DeclarationBindingInstantiation(DeclarationBindingType.GlobalCode, program.FunctionDeclarations, program.VariableDeclarations, null, null);

                    var result = _statements.ExecuteProgram(program);
                    if (result.Type == Completion.Throw)
                    {
                        throw result.Exception ?? new JavaScriptException(result.GetValueOrDefault())
                              .SetCallstack(this, result.Location);
                    }

                    _completionValue = result.GetValueOrDefault();
                }
            }
            finally
            {
                if (oldCallStack != null)
                {
                    CallStack = oldCallStack;
                }
            }

            return(this);
        }
Example #5
0
        public Engine Execute(Program program)
        {
            ResetStatementsCount();

            if (_memoryLimit > 0)
            {
                ResetMemoryUsage();
            }

            ResetTimeoutTicks();
            ResetLastStatement();
            ResetCallStack();

            using (new StrictModeScope(_isStrict || program.Strict))
            {
                DeclarationBindingInstantiation(DeclarationBindingType.GlobalCode, program.HoistingScope.FunctionDeclarations, program.HoistingScope.VariableDeclarations, null, null);

                _statements.ExecuteProgram(program);
            }

            return(this);
        }