• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Js in js
 

Js in js

on

  • 7,608 views

 

Statistics

Views

Total Views
7,608
Views on SlideShare
2,719
Embed Views
4,889

Actions

Likes
5
Downloads
42
Comments
0

7 Embeds 4,889

http://ued.alipay.com 4869
http://xianguo.com 6
http://cache.baidu.com 6
http://static.slideshare.net 4
http://arale.alipay.net 2
http://zhuaxia.com 1
http://reader.youdao.com 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Js in js Js in js Presentation Transcript

    • JS  in  JS { The  Narcissus  Project / /aimingoo h8p://blog.csdn.net/aimingoo aiming@gmail.com
    • Ñ  new Ñ  with Ñ  function Ñ  object Ñ  eval
    • js.jsjsdefs.js jsparse.js jsexec.js h8ps://github.com/mozilla/narcissus/ h8p://lxr.mozilla.org/mozilla/source/js/narcissus
    • Ñ  Script Ñ  Statements   Ñ  Statement Ñ  Expression Ñ  functionparse
    • jsdefs.jsl l l l l 
    • jsparse.jsl l 
    • jsparse.js  -­‐‑   (1) function  Statements  (t,  x)  {        var  n  =  new  Node(t,  BLOCK);            while  (!t.done  && Statements                t.peek()  !=  RIGHT_CURLY)                n.push(Statement(t,  x));          ... Function } function  Script(t,  x)  {        var  n  =  Statements(t,  x);        n.type  =  SCRIPT; Script        ... } function  parse(s,  f,  l)  {        var  t  =  new  Tokenizer(s,  f,  l);        var  x  =  new  CompilerContext(false);        var  n  =  Script(t,  x);
    • jsparse.js  -­‐‑   (2) function  Statement(t,  x)  {        var  i,  label,  n,  n2,  ss,  8  =  t.get(); Statement          switch  (8)  { Statements            case  FUNCTION:  ...            case  LEFT_CURLY:  ...            case  IF:                n  =  new  Node(t);                n.condition  =  ParenExpression(t,  x);                n.thenPart  =  Statement(t,  x);                n.elsePart  =  ...            default:                if  (8  ==  IDENTIFIER)  ... .... function  Statements  (t,  x)  {        var  n  =  new  Node(t,  BLOCK);          while  (!t.done  &&                t.peek()  !=  RIGHT_CURLY)                n.push(Statement(t,  x));        ... }
    • jsparse.js  -­‐‑   (3) function  ParenExpression(t,  x)  { Expression        t.mustMatch(LEFT_PAREN);        var  n  =  Expression(t,  x);          t.mu(RIGHT_PAREN); Statement        return  n; } function  Statement(t,  x)  {    ...    n.condition  =  ParenExpression(t,  x);    //  switch    n.discriminant  =      n2.caseLabel  =      //  for/for..in    n.object  =    n.setup  = if  (condition)  ....    //  try..catch    n2.guard  = return  x    //  other  ...    n.expression  =  Expression(t,  x); }
    • jsparse.js  –   (1) Var  
    • Script(t,  x) Variables(t,  x)Statements(t,  x) Expression(t,  x,  COMMA) Statement  (t,  x) Expression(t,  x,  COMMA)type:SCRIPT type:IDENTIFIER[0] value: a type:VAR value: var [0] [1] type:IDENTIFIER [2] value: i initializer: type:NUMBER type:IDENTIFIER value: 100 value: v initializer: type:+ value: + type:IDENTIFIER [0] value: i [1] type:NUMBER value: 100
    • jsparse.js  –   (2) ; ; , 1 2
    • Script(t,  x)Statements(t,  x) Expression(t,  x,  COMMA) Statement  (t,  x)type:SCRIPT[0] type:SEMICOLON value: a expression: type:IDENTIFIER value: a type:COMMA value: , [0] type:ASSIGN [1] value: = type:IDENTIFIER [2] [0] value: i [1] type:NUMBER value: 100 type:ASSIGN value: = type:IDENTIFIERfunction  Expression(t,  x,  stop)   [0] value: ‘v    … [1] type:+  while  (operators.length) value: + type:IDENTIFIER value: i [0]        reduce(); [1]    return  operands.pop(); type:NUMBER value: 100}
    • jsparse.js  -­‐‑   (4) function  Variables(t,  x)  {    x.varDecls.push(n2); … function  FunctionDefinition(t,  x,  …) Declared    var  x2  =  new  CompilerContext(true);      f.body  =  Script(t,  x2); Function …    x.funDecls.push(f); … function  Script(t,  x)  { /        var  n  =  Statements(t,  x);        n.type  =  SCRIPT;        n.funDecls  =  x.funDecls;        n.varDecls  =  x.varDecls;        return  n; } function  parse(s,  f,  l)  {        var  t  =  new  Tokenizer(s,  f,  l);        var  x  =  new  CompilerContext(false);        var  n  =  Script(t,  x);
    • jsparse.js  –   (3) type:SCRIPT - x.funDecls[0] type:IDENTIFIER - x.varDecls:[] value: a type:FUNCTION type:IDENTIFIER name:”t” value: i params:[‘x’, ‘y’] initializer: body: type:IDENTIFIER functionForm: value: v initializer: type:SCRIPT - x2.funDecls[0] - x2.varDecls:[] type:FUNCTION name:”m” params:[] body: functionForm: type:SCRIPT - x2.funDecls[0] - x2.varDecls:[]
    • jsparse.js  –  functionForm var DECLARED_FORM = 0, EXPRESSED_FORM = 1, STATEMENT_FORM = 2;
    • Ñ  Script Ñ  Statements   Ñ  Statement Ñ  Expression Ñ  functionexec
    • -­‐‑type:SCRIPTfunDecls[0]varDecls:[][0][1][2][3]... type:VAR value: var [0] [1] [2] type:SCRIPT type:SCRIPT type:FUNCTION name:”m” params:[] ... body: functionForm: type:IF/FOR/ TRY... value: condition: type:+ type:IDENTIFIER ... value: + value: i [0] type:... [1] value:... type:NUMBER expression: value: 100 ...
    • -­‐‑ function  evaluate(s,  f,  l)  { …        var  x  =  ExecutionContext.current;        var  x2  =  new  ExecutionContext(GLOBAL_CODE);        ExecutionContext.current  =  x2;        execute(parse(s,  f,  l),  x2); … var      GLOBAL_CODE  =  0,      EVAL_CODE  =  1, function  ExecutionContext(type)  {      FUNCTION_CODE  =  2;        this.type  =  type; } var  XCp  =  ExecutionContext.prototype; ExecutionContext.current  =  XCp.caller  =  XCp.callee  =  null; var  global  =  {        //  Value  properties. XCp.scope  =  {object:  global,  parent:  null};        NaN:  NaN,  Infinity:    …, XCp.thisObject  =  global;        //  Function  properties. XCp.result  =  undefined;        eval:    function  eval(s)  {  … XCp.target  =  null;        Function  :  …        Array  :  … XCp.ecmaStrictMode  =  false;        String:  …
    • jsexec.js  –  execute()
    • jsexec.js  –  
    • jsexec.js  –  new
    • jsexec.js  –  with
    • jsexec.js  –  Object/Func.
    • jsexec.js  –  Function.
    • jsexec.js  –  eval
    • { END.