ECMA-262-3 in-depth analysis. Chapter 1. Execution Context

Source: Internet
Author: User
Tags types of functions

Introduction
This article mainly discusses the ECMAScript execution context and related ECMAScript executable code.

Definition
Each time the controller is transferred to ECMAScript executable code, it enters an execution context.

Execution context (-EC) is an abstract concept, which is used by ECMA-262 standards to distinguish it from executable code.

The standard specification does not accurately define the EC type and structure from the perspective of technical implementation; this should be an issue to be considered when implementing the ECMAScript engine.

The execution context of the activity is logically grouped into a stack. The bottom of the stack is always a global context, and the top of the stack is the current (active) Execution context. The stack is modified when a variable of the EC type (varous kingds of EC) is pushed or popped up.

Executable code
The concept of executable code is relative to that of abstract execution context. At some point in time, executable code is equivalent to the execution context.

For example, we can define an array to simulate the execution context Stack:

ECStack = [];

This stack is pushed every time you enter a function (even if the function is recursively called or used as a constructor) or when the built-in eval function works.

Global Code
This type of code is processed at the "program" level: for example, loading external js files or local code within the <script> </script> label. The Global Code does not include any code in the function body.

In the initialization (Program startup) phase, ECStack is like this:

ECStack = [

GlobalContext

];

Function Code
When function code (all types of Functions) is entered, ECStack is pushed into new elements. Note that the specific function code does not include the inner functions code. As shown in the following figure, let the function call its own method for recursion:

(Function foo (bar ){

If (bar ){

Return;

}

Foo (true );

})();

Then, ECStack is changed as follows:

// First activation of foo

ECStack = [

<Foo> functionContext

GlobalContext

];

// Recursive activation of foo

ECStack = [

<Foo> functionContext-recursively

<Foo> functionContext

GlobalContext

];

Each time an existing execution context is returned and the corresponding execution context pops up on the ECStack, the stack pointer automatically moves the location. This is a typical stack implementation method. One thrown but not intercepted exception also has one or more execution contexts. After the relevant code segment is executed, until the entire application ends, ECStack only includes the global context ).

ECMA-262-3 in detail. Chapter 1. Execution Contexts

Author: Justin
Source: http://justinw.cnblogs.com/

  • 2 pages in total:
  • Previous Page
  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.