Stage
: Returns a new stage object to work with after being instantiated.
stages
: An object which contains references to all running stages.
parse
: A reference to acorn.parse
to turn source code into an AST.
generate
: A reference to astring.generate
to turn an AST back into source code.
key
: The stage's unique key.
input
: The original submitted code.
script
: The patched version of the submitted code.
nodes
: An object which contains references to all AST nodes in the code, indexed by their relative hash
code.
symbols
: An object which contains references to all functions, indexed by the given function's name.
addListener
: Takes an numeric listener type as it's first parameter and returns an RuntimeListener
object.
getFunctionNodeByName
: Returns the raw AST node related to the passed in function name.
Each RuntimeListener
event has an RuntimeEvent
argument which contains various event specific properties.
Example:
let listener = stage.addListener(Iroh.ALLOC);
listener.on("fire", (e) => console.log(e.value));
Iroh.ALLOC
has only one event called fire
. This means the listener just fires as soon as the related code get's executed. In this case fire
triggers when an object or array gets created. The event's property value
contains a reference to the allocated object. Since fire
gets triggered before the actual code gets executed, we can even modify the passed in data!
All listener events provide you the following fixed options:
All RuntimeEvents
come with the following fixed properties:
hash
: Unique numeric hash which is also a link to the original AST node. The hash is only used once for the specific code location.
indent
: Numeric indentation level which can be used to model the code's flow. Increases when entering a branch (e.g. Iroh.IF.enter
) and decreases after leaving a branch (e.g. Iroh.IF.leave
).
All RuntimeEvents
come with the following fixed methods:
getASTNode
: Returns the original AST node
getPosition
: Returns an object with the original source position (start
, end
)
getLocation
: Returns an object with the original source location, which is better formated than getPosition
. The object contains: (start.line
, start.column
), (end.line
, end.column
).
getSource
: Returns the original (non-patched) relative source code
This list gives you an overview, which events a listener supports and which properties come along with it.
Iroh.IF
:
test
hash
: Unique hashvalue
: The if's condition valueindent
: Indent level
enter
hash
: Unique hashvalue
: The if's condition valueindent
: Indent level
leave
hash
: Unique hashindent
: Indent level
Iroh.ELSE
:
enter
hash
: Unique hashindent
: Indent level
leave
hash
: Unique hashindent
: Indent level
Iroh.LOOP
:
test
hash
: Unique hashindent
: Indent levelvalue
: The loop's condition valuekind
: Indicates the loop kind e.g.WhileStatement
enter
hash
: Unique hashindent
: Indent levelkind
: Indicates the loop kind e.g.DoWhileStatement
leave
hash
: Unique hashindent
: Indent levelkind
: Indicates the loop kind e.g.ForStatement
Iroh.BREAK
:
fire
hash
: Unique hashvalue
: Do break or notindent
: Indent level
Iroh.CONTINUE
:
fire
hash
: Unique hashvalue
: Do continue or notindent
: Indent level
Iroh.SWITCH
:
test
hash
: Unique hashvalue
: The switch's tested valueindent
: Indent level
enter
hash
: Unique hashindent
: Indent level
leave
hash
: Unique hashindent
: Indent level
Iroh.CASE
:
test
hash
: Unique hashvalue
: The case's tested valueindent
: Indent level
enter
hash
: Unique hashindent
: Indent leveldefault
: Default case or not
leave
hash
: Unique hashindent
: Indent leveldefault
: Default case or not
Iroh.CALL
:
before
hash
: Unique hashindent
: Indent levelarguments
: The call's argumentscontext
: The context the call is performed inobject
: The call's objectcall
: Called function if object is nullcallee
: String version of the called function nameexternal
: E.g.Array.map
andeval
are external calls
after
hash
: Unique hashindent
: Indent levelarguments
: The call's argumentsreturn
: The returned value after the call is performedcontext
: The context the call is performed inobject
: The call's objectcall
: Called function if object is nullcallee
: String version of the called function nameexternal
: E.g.Array.map
andeval
are external calls
Iroh.FUNCTION
:
enter
hash
: Unique hashindent
: Indent levelscope
: The function's inner scopesloppy
: Got called from outsidearguments
: The function's argumentsname
: The function's name
leave
hash
: Unique hashindent
: Indent levelsloppy
: Got called from outsidename
: The function's name
return
hash
: Unique hashindent
: Indent levelsloppy
: Got called from outsidereturn
: The return statement's valuename
: The function's name
Iroh.VAR
:
before
hash
: Unique hashindent
: Indent levelname
: The variable's name
after
hash
: Unique hashindent
: Indent levelname
: The variable's namevalue
: The variable's value
Iroh.NEW
:
before
hash
: Unique hashindent
: Indent levelctor
: The passed constructorname
: Auto-generated constructor namearguments
: The passed constructor arguments
after
hash
: Unique hashindent
: Indent levelreturn
: The new's returned value
Iroh.TRY
:
enter
hash
: Unique hashindent
: Indent level
leave
hash
: Unique hashindent
: Indent level
Iroh.CATCH
:
enter
hash
: Unique hashindent
: Indent level
leave
hash
: Unique hashindent
: Indent level
Iroh.FINALLY
:
enter
hash
: Unique hashindent
: Indent level
leave
hash
: Unique hashindent
: Indent level
Iroh.ALLOC
:
fire
hash
: Unique hashindent
: Indent levelvalue
: The passed value (object
orarray
)
Iroh.MEMBER
:
fire
hash
: Unique hashindent
: Indent levelobject
: The member expression's objectproperty
: The member expression's property
Iroh.THIS
:
fire
hash
: Unique hashindent
: Indent levelcontext
: The context
Iroh.LITERAL
:
fire
hash
: Unique hashindent
: Indent levelvalue
: The literal's value
Iroh.ASSIGN
:
fire
hash
: Unique hashindent
: Indent levelop
: The used operatorobject
: The left valueproperty
: The right value,null
ifobject
is an identifiervalue
: The value to assign with
Iroh.TERNARY
:
fire
hash
: Unique hashindent
: Indent leveltest
: The tested conditiontruthy
: The truth triggerfalsy
: The falsy triggerresult
: The returned value
Iroh.LOGICAL
:
fire
hash
: Unique hashindent
: Indent levelop
: The used operatorleft
: The left valueright
: The right valueresult
: The result
Iroh.BINARY
:
fire
hash
: Unique hashindent
: Indent levelop
: The used operatorleft
: The left valueright
: The right valueresult
: The result
Iroh.UNARY
:
fire
hash
: Unique hashindent
: Indent levelop
: The used operatorvalue
: The unary's valueresult
: The result
Iroh.UPDATE
:
fire
hash
: Unique hashindent
: Indent levelop
: The used operatorprefix
: Prefix or postfix indicatorresult
: The result
Iroh.PROGRAM
:
enter
hash
: Unique hashindent
: Indent level
leave
hash
: Unique hashindent
: Indent levelreturn
: The program's returned frame value
Iroh provides the following listeners types, which can be used to listen for specific code types.
Iroh.IF
if () {}
else if () {}
Iroh.ELSE
else {}
Iroh.LOOP
while () {}
do {} while ()
for () {}
for (a in b) {}
for (a of b) {}
Iroh.BREAK
break
Iroh.CONTINUE
continue
Iroh.SWITCH
switch () {}
Iroh.CASE
case :
default :
Iroh.CALL
object()
Iroh.FUNCTION
function() {}
Iroh.VAR
let
var
const
Iroh.OP_NEW
new object()
Iroh.TRY
try {}
Iroh.CATCH
catch(e) {}
Iroh.FINALLY
finally() {}
Iroh.ALLOC
{},
[]
Iroh.MEMBER
a.b
a[b]
Iroh.THIS
this
Iroh.LITERAL
""
1
true
..
Iroh.ASSIGN
a = 2
a += 2
..
Iroh.TERNARY
true ? 1 : 0
Iroh.LOGICAL
&&,
||
Iroh.BINARY
+,
-,
*
..
Iroh.UNARY
+0,
-0,
!true
typeof a
..
Iroh.UPDATE
++object
--object
object++
object--
..
Iroh.PROGRAM
Code enter,
Code exit