Skip to content

Instantly share code, notes, and snippets.

@snowmantw
Created December 7, 2018 11:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save snowmantw/20cc68b6487bcc7b142ad0120fa9c996 to your computer and use it in GitHub Desktop.
Save snowmantw/20cc68b6487bcc7b142ad0120fa9c996 to your computer and use it in GitHub Desktop.
dis
js> function f() { var bar = 1; bar == (bar = bar + 1) }
js> dis(f)
flags: CONSTRUCTOR
loc op
----- --
main:
00000: one
00001: setlocal 0
00005: pop
00006: getlocal 0
00010: getlocal 0
00014: one
00015: add
00016: setlocal 0
00020: eq
00021: pop
00022: retrval
@snowmantw
Copy link
Author

snowmantw commented Dec 7, 2018

js> function f() { var bar = 9; bar == (bar = bar + 1) }
js> dis(f)
flags: CONSTRUCTOR
loc     op
-----   --
main:
00000:  int8 9                   ;(now: [9]), push 9 onto stack
00001:  setlocal 0               ;(now: [9], #0 = 9), stores the top stack value (9) to the given local (#0)
00005:  pop                      ;(now: []), pop 9 out of the stack                                                         
00006:  getlocal 0               ;(now: [9]), pushes the value of local variable (#0:1) onto the stack
00010:  getlocal 0               ;(now: [9, 9]),pushes the value of local variable (#0:1) onto the stack
00014:  one                      ;(now: [1, 9, 9]), push 1 onto stack                                                               
00015:  add                      ;(now: [10, 9]), pops the top two values lval and rval from the stack,
                                 ;             then pushes the result of lval + rval                                  
00016:  setlocal 0               ;(now: [10, 9], #0 = 10), stores the top stack value (10) to the given local (#0)
00020:  eq                       ;(now: [false, 10, 9], #0 = 10) pops the top two values from the stack and
                                 ;             pushes the result of comparing them.                               
00021:  pop                      ; pop `false` out 
00022:  retrval                  ; <set rval of caller to the result>



ref1: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Hacking_Tips
ref2: https://developer.mozilla.org/en-US/docs/Mozilla/Projects/SpiderMonkey/Internals/Bytecode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment