张平:JavaScript引擎实现

  • 13,442 views
Uploaded on

 

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
No Downloads

Views

Total Views
13,442
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
84
Comments
1
Likes
8

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

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