摘要:堆棧結構的底部是全局執(zhí)行上下文,頂部是當前執(zhí)行上下文。不同的執(zhí)行上下文切換時堆棧會發(fā)生改變譯論及代碼類型時,在某些時候可能也意味著執(zhí)行上下文。函數(shù)體中代碼執(zhí)行完后,只剩全局上下文直到程序結束譯代碼更有意思。
第一次翻譯,希望各位多多包涵,有錯誤處還望指出,歡迎提出建議。
Chapter 1.Execution ContextsIntroduction (介紹)
Definitions (定義)
Types of excutable code (可執(zhí)行代碼的類型)
Global code(全局代碼)
Funcion code(函數(shù)代碼)
Eval code(eval代碼)
Conclusion(結論)
Additional literature (文獻參考)
IntroductionIn this note we will metion execution contexts of ECMAScript and types of executable code related with them.
譯:在這篇筆記中,我們將討論執(zhí)行環(huán)境和相關的可執(zhí)行代碼類型。
DefinitionsEvery time when control is transferred to ECMAScript executable code, control is entered an execution context.
譯:當控制流即將執(zhí)行代碼時,總是先進入執(zhí)行上下文
Execution context( abbreviated from - EC) is the abstract concept used by ECMA-262 specification for typification and differentation of an executable code.
譯:執(zhí)行上下文(縮寫為EC)是ECMA-262使用的抽象概念,通常用來表示可執(zhí)行代碼的類型和區(qū)別。
The standard does not define accurate structure and kind of EC from the technical implementation viewpoint; it is a question of the ECMAScript-engines implementing the standard.
譯:官方標準沒有定義EC的確切結構和技術實現(xiàn),按照規(guī)范來實現(xiàn)依然ECMAScript引擎的問題
Logically, set of active execution contexts forms a stack. The bottom of this stack is always a global context, the top - a current (active) execution context. The stack is modified (pushed/popped) during the entering and exiting various kinds of EC.
譯:從邏輯上來看,許多激活的執(zhí)行上下文會形成一個堆棧結構。堆棧結構的底部是全局執(zhí)行上下文,頂部是當前執(zhí)行上下文。不同的執(zhí)行上下文切換時堆棧會發(fā)生改變
Types of executable codeWith abstract concept of an execution context, the concept of type of an executable code is related. Speaking about code type, it is possible in the certain moments to mean an execution context.
譯:論及代碼類型時,在某些時候可能也意味著執(zhí)行上下文??蓤?zhí)行上下文的抽象概念和其類型是分不開的
For examples, we define the stack of execution contexts as an array:
譯:例如,我們將執(zhí)行上下文的堆棧定義為數(shù)組
ECStack = [];
The stack is pushed every time on entering a function (even if the function is called recursively or as the constructor), and also at built-in eval function work.
譯:控制流每次進入函數(shù)(即使該函數(shù)是遞歸調用或作為構造器)時,入棧就會發(fā)生,同樣內(nèi)嵌在該函數(shù)中的eval函數(shù)也會引發(fā)入棧行為。
Global codeThis type of code is processed at level Program: i.e. the loaded external .js -file or the local inline-code (inside the tags). The global code does not include any parts of a code which are in bodies of functions.
譯:這種類型的代碼是以程序級別處理的:比如說額外的js文件或者局部的內(nèi)連代碼(在標簽中的)。全局代碼不包括任何函數(shù)體內(nèi)的代碼
At initialization(program start), ECStack looks like:
Function codeECStack = [ globalContext ];
On entering the function code (all kinds of functions), ECStack is pushed with new elements. It is necessary to notice that the code of concrete function does not include codes of the inner functions.
譯:一旦進入函數(shù)代碼,ECStack就會加入新元素。該函數(shù)代碼并不包括其內(nèi)部函數(shù)的代碼。
For example, let"s take the function which calls itself recursively once:
(function foo(flag) { if (flag) { return; } foo(true); })(false);
Then, ECStack is modified as follows:
//first activation of foo ECStack = [functionContext globalContext ]; //recursive activation of foo ECStack = [ functionContext - recursively functionContext globalContext ];
Every return from a function exits the current execution context and ECStack poped accordingly - consecutively and upside-down - quite natural implementation of a stack. After the work of this code is finished, ECStack again contains only globalContext- until the program end.
譯:函數(shù)的每次返回都代表了當前執(zhí)行上下文的結束,ECStack會有序的推出該函數(shù)。函數(shù)體中代碼執(zhí)行完后,ECStack只剩全局上下文直到程序結束
A thrown but not caught exception may also exit one or more execution contexts:
Eval code(function foo() { (function bar() { throw "Exit from bar and foo contexts"; })(); })();
Things are more interesting with eval code. In this case, there is a concept of a calling context, i.e. a context from which eval function is called.
譯:eval代碼更有意思。在該情況下,有個調用上下文的新概念,其本質是上下文,只不過是當eval函數(shù)被調用時的上下文
The actions made by eval, such as variable or function definition, influence exactly the calling context:
//influence global context eval("var x = 10"); (function foo() { // and here, variable "y" is // created in the local context // of "foo" function eval("var y = 20"); })(); alert(x); // 10 alert(y); // "y" is no defined
Note, in the strict-mode of ES5,eval already does not influence the calling context, but instead evaluates the code in the local sandbox.
For the example above we hav the following ECStack modifications:
ECStack = [ globalContext ]; // eval("var x = 10"); ECStack.push({ context: evalContext, callingContext: globalContext }); //eval extied context ECStack.pop(); //foo function call ECStack.push(functionContext); //eval("var y = 20"); ECStack.push({ context:evalContext, callingContext: functionContext }); //return from eval ECStack.pop(); //return from foo ECStack.pop();
I.e. quite casual and logical call-stack.
譯
ConclusionIn old SpiderMonkey implementations(Firefox), up to version 1.7, it was possible to pass a calling context as a second argument for eval function. Thus, if the context still exists, it is possible to influence private variables:
function foo() { var x = 1; return function() {alert(x);}; }; var bar = foo(); bar(); // 1 eval("x = 2", bar); //pass context, influence internal var "x" bar(); // 2However, due to security reasons in modern engines it was fixed and is not significant anymore.
This theoretical minimum is required the further analysis of details related with execution contexts, such as variable object or scope chain, which descriptions can be found in the appropriate chapters.
譯:這片理論最低要求是掌握執(zhí)行環(huán)境的細節(jié)分析,比如說變量對象或作用域,有關細節(jié)描述可以在相關章節(jié)中查閱到。
Additional literatureCorresponding section ECMA-262-3 specification - 10. Execution Contexts.
譯:該內(nèi)容截選自ECMA-262-3說明第十章執(zhí)行上下文。
文章版權歸作者所有,未經(jīng)允許請勿轉載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。
轉載請注明本文地址:http://systransis.cn/yun/78650.html
摘要:簡介年由公司發(fā)布的一門面向對象的程序設計語言虛擬機。兩個主要組件編譯器源程序轉成字節(jié)碼運行編譯后的程序后綴運行時環(huán)境。 Lecture1 Java簡介 1995年由Sun公司發(fā)布的一門面向對象的程序設計語言 JVM(Java Virtual Machine):Java虛擬機。是實現(xiàn)Java平臺無關性的關鍵Java程序的執(zhí)行流程:解釋執(zhí)行的過程由JVM來完成,即JVM把字節(jié)碼文件解釋...
摘要:執(zhí)行環(huán)境在很多方面都有其獨特之處全局變量和函數(shù)便是其中之一事實上的初始執(zhí)行環(huán)境是由多種多樣的全局變量所定義的這寫全局變量在腳本環(huán)境創(chuàng)建之初就已經(jīng)存在了我們說這些都是掛載在全局對象上的全局對象是一個神秘的對象它表示了腳本最外層上下文在瀏覽器中 JavaScript執(zhí)行環(huán)境在很多方面都有其獨特之處. 全局變量和函數(shù)便是其中之一. 事實上, js的初始執(zhí)行環(huán)境是由多種多樣的全局變量所定義的,...
摘要:由于本人更習慣使用所以后續(xù)案例都是基于與,同時這里是基于最新的編寫的哦創(chuàng)建項目初次接觸,我們先來看看如何創(chuàng)建一個項目,這里以為例,其他的工具小伙伴們自行搜索創(chuàng)建方式。創(chuàng)建完項目后,各位小伙伴請認真細心的對比下與傳統(tǒng)的工程有何區(qū)別如目錄結構。 SpringBoot 是為了簡化 Spring 應用的創(chuàng)建、運行、調試、部署等一系列問題而誕生的產(chǎn)物,自動裝配的特性讓我們可以更好的關注業(yè)務本身...
摘要:大數(shù)據(jù)時代第三次信息化浪潮年前后,以云計算大數(shù)據(jù)物聯(lián)網(wǎng)的首發(fā)為標志迎來第三次信息化浪潮。大數(shù)據(jù)的發(fā)展歷程大數(shù)據(jù)的概念和影響大數(shù)據(jù)的特性特性指。處理大規(guī)模圖結構數(shù)據(jù)。物聯(lián)網(wǎng)應用大數(shù)據(jù)云計算物聯(lián)網(wǎng)的關系三者相輔相成,既有聯(lián)系又有區(qū)別。 ...
摘要:在傳輸層前者提供面向連接的服務后者提供面向無連接或無連接的傳輸服務。共同點均實現(xiàn)異構網(wǎng)絡互聯(lián),不同廠家數(shù)據(jù)通信網(wǎng)絡傳輸過程用戶自然語言通信數(shù)據(jù)應用層封裝分段數(shù)據(jù)單元協(xié)議控制信息網(wǎng)絡傳輸解封裝通信數(shù)據(jù)自然語言應用層用戶 ...
閱讀 3558·2021-09-22 15:50
閱讀 3248·2019-08-30 15:54
閱讀 2766·2019-08-30 14:12
閱讀 3069·2019-08-30 11:22
閱讀 2093·2019-08-29 11:16
閱讀 3588·2019-08-26 13:43
閱讀 1200·2019-08-23 18:33
閱讀 931·2019-08-23 18:32