anatomy of js_2014_execution_context

18
The anatomy of ECMA 262-3 #1 김김김 김김김김김김김김 / UIT 김김김 2014.01.16 Execution Context

Upload: kim-hunmin

Post on 10-May-2015

143 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Anatomy of js_2014_execution_context

The anatomy of ECMA 262-3 #1

김훈민

프론트엔드개발팀 / UIT 개발실

2014.01.16

Execution Context

Page 2: Anatomy of js_2014_execution_context

#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

제어가 실행 코드를 만나면 실행 콘텍스트로 들어간다 .

여러 개의 실행 콘텍스트는 논리적으로 스택의 형태를 구성한다 .

Page 3: Anatomy of js_2014_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 de-termination of the this value depend on the type of code being en-tered.”

ECMA-262-3

실행 콘텍스트로 제어가 이동 하면 스코프 체인 생성 , 변수 초기화를 하고

this 값을 결정한다 . 세부 과정은 실행 콘텍스트에 전달한 코드의 종류에

따라서 다르다 .

#1 Execution Context

Page 4: Anatomy of js_2014_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

#1 Execution Context

전역 코드 (Global code), Eval 코드 (Eval Code), 함수 코드 (Function

Code) 가 있다 .

Page 5: Anatomy of js_2014_execution_context

실행 콘텍스트 , 실행 문맥이라고도 함 .

ECMAScript 에 정의된 추상적인 개념으로 코드가 실행되는 환경을 의미 .

Execution context…?

“ 모든 Javascript 코드는 실행 콘텍스트 안에서 돌아간다 .”

#1 Execution Context

Page 6: Anatomy of js_2014_execution_context

제어가 ECMAScript 코드를 만나면 실행 콘텍스트를 생성한다 .

실행 콘텍스트(Execution context)

Control

#1 Execution Context

Page 7: Anatomy of js_2014_execution_context

생성한 실행 콘텍스트는 논리적으로 스택의 형태를 구성한다 .

작동중인 실행 문맥 - 3(Execution context)

실행 문맥 - 1(Execution context)

실행 문맥 - 2(Execution context)

#1 Execution Context

Execution context stack

Page 8: Anatomy of js_2014_execution_context

실행 콘텍스트는 스코프 체인 생성 , 변수 초기화 , this 값을 결정한다 .

ExecutionContext = {

변수 , 함수 , 매개변수 생성스코프 체인 생성 ,this 바인딩 ,…

}

초기화 과정은 실행 코드의 종류에 따라서 다르다 .

실행 콘텍스트(Execution context)

#1 Execution Context

Page 9: Anatomy of js_2014_execution_context

Executable Code…?

하나의 실행 콘텍스트에서 처리되는 JavaScript 코드의 단위 .

ECMA-262 는 실행 코드를 3 가지로 분류 .

• 전역 코드 ( Global code)

ECMAScript 프로그램이 최초에 실행하는 소스 텍스트

• 함수 코드 ( Function code)

함수 몸체의 부분으로 해석할 수 있는 소스 텍스트

• Eval 코드 ( Eval code)

내장 eval 함수에 넘겨진 소스 텍스트

#1 Execution Context

Page 10: Anatomy of js_2014_execution_context

• 전역 코드는 프로그램 수준에서 실행

• Js 파일을 로딩하거나 지역 인라인 코드를 만났을 때 Javascript 엔진이 최초로 읽어

들이는 코드

• 처음 시작 시 , 실행 콘텍스트 스택 (ECSTack) 에는 오직 전역 콘텍스트만 존재

전역 코드 (Global code)

Execution context stack

전역 콘텍스트(Global context)

Control

#1 Execution Context

Page 11: Anatomy of js_2014_execution_context

전역 코드 (Global code) 의 범위

함수 몸체 안의 코드는 전역 코드에 포함되지 않는다 .

#1 Execution Context

Page 12: Anatomy of js_2014_execution_context

함수 코드 (Function code)

함수 실행 코드를 만나면 새로운 실행 콘텍스트를 생성하여 ECStack 에 넣는다 .

Execution context stack

전역 콘텍스트(Global context)

person 함수 실행 콘텍스트(Function execution con-

text)

#1 Execution Context

Control

Page 13: Anatomy of js_2014_execution_context

역시 함수 내부 중첩 함수의 코드는 함수 코드에 포함되지 않는다 .

함수 코드 (Function code)

#1 Execution Context

Page 14: Anatomy of js_2014_execution_context

함수 코드 (Function code)

Execution context stack

전역 콘텍스트(Global context)

person 함수 실행 콘텍스트(Function execution context)

getFirstName 함수 실행 콘텍스트(Function execution context)

Control

#1 Execution Context

Page 15: Anatomy of js_2014_execution_context

eval 코드 (eval code)

eval 코드에는 호출 콘텍스트 (calling context) 라는 개념이 존재

#1 Execution Context

Page 16: Anatomy of js_2014_execution_context

#1 Execution Context

작동중인 실행 문맥(Eval context)

전역 실행 문맥 (Global context)

실행 문맥 - 1(Function execution context)

Execution context stack

실행 문맥 - 2(Function execution context)

Execution context stack

Page 17: Anatomy of js_2014_execution_context

#1 Execution Context

더 자세한 내용은…

• 원문 : http://dmitrysoshnikov.com/ecmascript/chapter-1-execution-contexts/

• 번역 : http://huns.me/%EB%B2%88%EC%97%AD-ecma-262-3-in-de-tail-chapter-1-execution-contexts/

Page 18: Anatomy of js_2014_execution_context

Thank you.