Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Anatomy of js_2014_execution_context
1. The anatomy of ECMA 262-3 #1
Execution Context
김훈민
프론트엔드개발팀 / UIT 개발실
2014.01.16
2. #1 Execution Context
10. Execution context
“When control is transferred to ECMAScript executable code, control is entering
an execution context. Active execution contexts logically form a stack. The top
execution context on this logical stack is the running execution context”
…
ECMA-262-3
제어가 실행 코드를 만나면 실행 콘텍스트로 들어간다.
여러 개의 실행 콘텍스트는 논리적으로 스택의 형태를 구성한다.
3. #1 Execution Context
10.2 Entering An Execution context
“When control enters an execution context, the scope chain is created and
initialised, variable instantiation is performed, and the this value is determined.
The initialization of the scope chain, variable instantiation, and the determination
of the this value depend on the type of code being entered.”
ECMA-262-3
실행 콘텍스트로 제어가 이동 하면 스코프 체인 생성, 변수 초기화를 하고 this
값을 결정한다. 세부 과정은 실행 콘텍스트에 전달한 코드의 종류에 따라서 다
르다.
4. #1 Execution Context
10.1.2 Types of Executable code
•
Global code is source text that is treated as an ECMAScript Program. …(생
•
Eval code is the source text supplied to the built-in eval function. More
•
략)
precisely, if the parameter to the built-in eval function is a string, it is treated
as an ECMAScript Program. …(생략)
Function code is source text that is parsed as part of a FunctionBody. The
function code of a particular FunctionBody does not include any source text
that is parsed as part of a nested FunctionBody. …(생략)
ECMA-262-3
전역 코드(Global code), Eval 코드(Eval Code), 함수 코드(Function Code)가
있다.
5. #1 Execution Context
Execution context…?
실행 콘텍스트, 실행 문맥이라고도 함.
ECMAScript에 정의된 추상적인 개념으로 코드가 실행되는 환경을 의미.
“모든 Javascript 코드는 실행 콘텍스트 안에서 돌아간다.”
7. #1 Execution Context
생성한 실행 콘텍스트는 논리적으로 스택의 형태를 구성한다.
Execution context stack
작동중인 실행 문맥 - 3
(Execution context)
실행 문맥 - 2
(Execution context)
실행 문맥 - 1
(Execution context)
8. #1 Execution Context
실행 콘텍스트는 스코프 체인 생성, 변수 초기화, this 값을 결정한다.
ExecutionContext = {
실행 콘텍스트
(Execution context)
}
초기화 과정은 실행 코드의 종류에 따라서 다르다.
변수, 함수, 매개변수 생성
스코프 체인 생성,
this 바인딩,
…
9. #1 Execution Context
Executable Code…?
하나의 실행 콘텍스트에서 처리되는 JavaScript 코드의 단위.
ECMA-262는 실행 코드를 3가지로 분류.
•
전역 코드( Global code)
ECMAScript 프로그램이 최초에 실행하는 소스 텍스트
•
함수 코드( Function code)
함수 몸체의 부분으로 해석할 수 있는 소스 텍스트
•
Eval 코드( Eval code)
내장 eval 함수에 넘겨진 소스 텍스트
10. #1 Execution Context
전역 코드(Global code)
• 전역 코드는 프로그램 수준에서 실행
• Js 파일을 로딩하거나 지역 인라인 코드를 만났을 때 Javascript 엔진이 최초로 읽어 들이는
코드
• 처음 시작 시, 실행 콘텍스트 스택(ECSTack)에는 오직 전역 콘텍스트만 존재
Control
Execution context stack
전역 콘텍스트
(Global context)
12. #1 Execution Context
함수 코드(Function code)
함수 실행 코드를 만나면 새로운 실행 콘텍스트를 생성하여 ECStack에 넣는다.
Execution
context stack
person 함수 실행 콘텍스트
(Function execution context)
전역 콘텍스트
(Global context)
Control
14. #1 Execution Context
함수 코드(Function code)
Execution
context stack
getFirstName 함수 실행 콘텍스트
(Function execution context)
person 함수 실행 콘텍스트
(Function execution context)
전역 콘텍스트
(Global context)
Control
16. #1 Execution Context
Execution context stack
Execution context stack
작동중인 실행 문맥
(Eval context)
실행 문맥 - 2
(Function execution context)
실행 문맥 - 1
(Function execution context)
전역 실행 문맥
(Global context)
17. #1 Execution Context
더 자세한 내용은…
•
원문 : http://dmitrysoshnikov.com/ecmascript/chapter-1-execution-contexts/
•
번역 : http://huns.me/%EB%B2%88%EC%97%AD-ecma-262-3-in-detailchapter-1-execution-contexts/