0
Javascript引擎实现<br />Author:张平<br />Email:p.zhang.9.25@gmail.com<br />
Modules:<br />Interpreter<br />compiler:parse, tree-walker code generator<br />memory manager and garbage collector<br />s...
memory manager<br /><ul><li>Theoretical Basis:Fast Allocation and Deallocation of Memory Based on Object Lifetimes.  Autho...
Eliminate recursion:Automated Verification of the Deutsch-Schorr-Waite Tree-Traversal Algorithm。参考:http://www.cs.wisc.edu/w...
Prototype-based programming:<br /><ul><li>Class-base:class: structure, behaviorinstance: statefocus first on relationships...
Prototype-based:</li></ul>No class<br />Performed via process of clone objects(prototypes)<br />focus on behavior of objec...
JS prototype chain:<br /><ul><li>__proto__(object construction):Delegation pointer to prototype</li></ul>Donot clone proto...
JS Scope chain:<br /><ul><li>Scope:scope is an enclosing context where values and expressions are associated.
Dynamic scope:
Static(lexical scope):</li></li></ul><li>JS lexical scope chain:<br /><ul><li>__parent__: Delegation pointer to function’s...
<ul><li>How to generate closure:</li></ul>Function use nonlocal variables<br />Function will invoke again in another scope...
Closure:<br /><ul><li>Pseudo-code:function A(){var a = 1;   function B(){       return ++a;   }   return B}generate callA:...
张平:JavaScript引擎实现
张平:JavaScript引擎实现
Upcoming SlideShare
Loading in...5
×

张平:JavaScript引擎实现

13,545

Published on

Published in: Technology
1 Comment
9 Likes
Statistics
Notes
No Downloads
Views
Total Views
13,545
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
88
Comments
1
Likes
9
Embeds 0
No embeds

No notes for slide

Transcript of "张平:JavaScript引擎实现"

  1. 1. Javascript引擎实现<br />Author:张平<br />Email:p.zhang.9.25@gmail.com<br />
  2. 2. Modules:<br />Interpreter<br />compiler:parse, tree-walker code generator<br />memory manager and garbage collector<br />standard library:<br />debugger<br />JIT<br />
  3. 3. memory manager<br /><ul><li>Theoretical Basis:Fast Allocation and Deallocation of Memory Based on Object Lifetimes. Author : David Hanson.</li></li></ul><li>GC<br /><ul><li>Mark-Sweep
  4. 4. Eliminate recursion:Automated Verification of the Deutsch-Schorr-Waite Tree-Traversal Algorithm。参考:http://www.cs.wisc.edu/wpis/papers/sas06-dsw.pdf</li></li></ul><li>JS ObjectInternal:<br />__proto__prototype chain<br />__parent__scope chain<br />__class__record object constructor<br />
  5. 5. Prototype-based programming:<br /><ul><li>Class-base:class: structure, behaviorinstance: statefocus first on relationships between classes.
  6. 6. Prototype-based:</li></ul>No class<br />Performed via process of clone objects(prototypes)<br />focus on behavior of objects<br />
  7. 7. JS prototype chain:<br /><ul><li>__proto__(object construction):Delegation pointer to prototype</li></ul>Donot clone prototype<br />Propagate changes through the system.<br />
  8. 8. JS Scope chain:<br /><ul><li>Scope:scope is an enclosing context where values and expressions are associated.
  9. 9. Dynamic scope:
  10. 10. Static(lexical scope):</li></li></ul><li>JS lexical scope chain:<br /><ul><li>__parent__: Delegation pointer to function’s parent scope.function A{ function B{ print(c);}}A.__parent__ === globalB.__parent__ === A</li></li></ul><li>Call Object:<br /><ul><li>Special temporary object that exists while a function is active.</li></ul>Provide a pointer to Arguments object.<br />Administer the scope chain(closure).<br /><ul><li>Pseudo-code:before function f call:fScope = new CallObject()fScope.__parent__ = f.__parent__</li></li></ul><li>Find name:<br />fScope<br />No failed<br />hasProperty(c) <br />fScope = fScope.__parent__<br />
  11. 11. <ul><li>How to generate closure:</li></ul>Function use nonlocal variables<br />Function will invoke again in another scope.<br /><ul><li>Call object: add function’s parameters and local variables to scope chain and serve as closure’s context.</li></ul>Closure:<br />
  12. 12. Closure:<br /><ul><li>Pseudo-code:function A(){var a = 1; function B(){ return ++a; } return B}generate callA: callA.__parent__ === globalcloned function B as clonedB:clonedB.__proto__ === BclonedB.__parent__ === callAreturn clonedB</li></li></ul><li>Thanks!<br />
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×