Skip to content

Instantly share code, notes, and snippets.

@ehzawad
Created July 24, 2023 08:10
Show Gist options
  • Select an option

  • Save ehzawad/76e36a4e899c9035a7fdbfe7ef53bd11 to your computer and use it in GitHub Desktop.

Select an option

Save ehzawad/76e36a4e899c9035a7fdbfe7ef53bd11 to your computer and use it in GitHub Desktop.
const fs = require('fs');
console.log(1);
console.log(2);
setTimeout(() => {
console.log('setTimeout');
}, 0);
console.log(3);
setImmediate(() => {
console.log('setImmediate');
});
console.log(4);
process.nextTick(() => {
console.log('nextTick');
});
const f1 = () => {
console.log('f1')
setTimeout(() => {
console.log('Hello from f1');
}, 2000);
}
const f2 = () => {
setTimeout(() => {
console.log('Hello from f2');
}, 1000);
console.log('f2')
}
console.log(5);
fs.readFile(__filename, () => {
console.log('readFile callback');
});
console.log(6);
console.log(7);
Promise.resolve().then(() => {
console.log('promise');
});
console.log(8);
f2()
f1()
@ehzawad

ehzawad commented Jul 26, 2023

Copy link
Copy Markdown
Author
Bytecode File Information:
  Bytecode version number: 95
  Source hash: 4f8d38c30eb5a157aff37725af7b6be502ad35b1
  Function count: 10
  String count: 21
  BigInt count: 0
  String Kind Entry count: 2
  RegExp count: 0
  Segment ID: 0
  CommonJS module count: 0
  CommonJS module count (static): 0
  Function source count: 0
  Bytecode options:
    staticBuiltins: 0
    cjsModulesStaticallyResolved: 0

Global String Table:
s0[ASCII, 0..-1]: 
s1[ASCII, 0..12]: Hello from f1
s2[ASCII, 11..12]: f1
s3[ASCII, 13..25]: Hello from f2
s4[ASCII, 24..25]: f2
s5[ASCII, 26..27]: fs
s6[ASCII, 30..35]: global
s7[ASCII, 36..42]: promise
s8[ASCII, 58..74]: readFile callback
i9[ASCII, 28..30] #1C35E808: log
i10[ASCII, 41..52] #83DE3FFC: setImmediate
i11[ASCII, 53..59] #EB75CA32: require
i12[ASCII, 58..65] #5FAD29E0: readFile
i13[ASCII, 75..81] #9D007186: Promise
i14[ASCII, 80..89] #500B50F7: setTimeout
i15[ASCII, 89..92] #3F9C8812: then
i16[ASCII, 92..99] #48DF9F7F: nextTick
i17[ASCII, 100..109] #1E7D2120: __filename
i18[ASCII, 110..116] #629A2BFD: console
i19[ASCII, 117..123] #59476AD7: process
i20[ASCII, 124..130] #B2A44401: resolve

Function<global>(1 params, 16 registers, 0 symbols):
Offset in debug table: source 0x0000, scope 0x0000, textified callees 0x0000
    CreateEnvironment r1
    GetGlobalObject   r2
    TryGetById        r4, r2, 1, "require"
    LoadConstUndefined r0
    LoadConstString   r3, "fs"
    Call2             r6, r4, r0, r3
    TryGetById        r5, r2, 2, "console"
    GetByIdShort      r4, r5, 3, "log"
    LoadConstUInt8    r3, 1
    Call2             r3, r4, r5, r3
    TryGetById        r5, r2, 2, "console"
    GetByIdShort      r4, r5, 3, "log"
    LoadConstUInt8    r3, 2
    Call2             r3, r4, r5, r3
    TryGetById        r5, r2, 4, "setTimeout"
    CreateClosure     r4, r1, NCFunction<>
    LoadConstZero     r3
    Call3             r3, r5, r0, r4, r3
    TryGetById        r5, r2, 2, "console"
    GetByIdShort      r4, r5, 3, "log"
    LoadConstUInt8    r3, 3
    Call2             r3, r4, r5, r3
    TryGetById        r4, r2, 5, "setImmediate"
    CreateClosure     r3, r1, NCFunction<>
    Call2             r3, r4, r0, r3
    TryGetById        r5, r2, 2, "console"
    GetByIdShort      r4, r5, 3, "log"
    LoadConstUInt8    r3, 4
    Call2             r3, r4, r5, r3
    TryGetById        r5, r2, 6, "process"
    GetByIdShort      r4, r5, 7, "nextTick"
    CreateClosure     r3, r1, NCFunction<>
    Call2             r3, r4, r5, r3
    TryGetById        r5, r2, 2, "console"
    GetByIdShort      r4, r5, 3, "log"
    LoadConstUInt8    r3, 5
    Call2             r3, r4, r5, r3
    GetByIdShort      r5, r6, 8, "readFile"
    TryGetById        r4, r2, 9, "__filename"
    CreateClosure     r3, r1, NCFunction<>
    Call3             r3, r5, r6, r4, r3
    TryGetById        r5, r2, 2, "console"
    GetByIdShort      r4, r5, 3, "log"
    LoadConstUInt8    r3, 6
    Call2             r3, r4, r5, r3
    TryGetById        r5, r2, 2, "console"
    GetByIdShort      r4, r5, 3, "log"
    LoadConstUInt8    r3, 7
    Call2             r3, r4, r5, r3
    TryGetById        r4, r2, 10, "Promise"
    GetByIdShort      r3, r4, 11, "resolve"
    Call1             r5, r3, r4
    GetByIdShort      r4, r5, 12, "then"
    CreateClosure     r3, r1, NCFunction<>
    Call2             r3, r4, r5, r3
    TryGetById        r4, r2, 2, "console"
    GetByIdShort      r3, r4, 3, "log"
    LoadConstUInt8    r2, 8
    Call2             r2, r3, r4, r2
    CreateClosure     r2, r1, NCFunction<f2>
    Call1             r2, r2, r0
    CreateClosure     r1, r1, NCFunction<f1>
    Call1             r1, r1, r0
    Ret               r0

NCFunction<>(1 params, 11 registers, 0 symbols):
Offset in debug table: source 0x00db, scope 0x0000, textified callees 0x0000
    GetGlobalObject   r0
    TryGetById        r2, r0, 1, "console"
    GetByIdShort      r1, r2, 2, "log"
    LoadConstString   r0, "setTimeout"
    Call2             r0, r1, r2, r0
    LoadConstUndefined r0
    Ret               r0

NCFunction<>(1 params, 11 registers, 0 symbols):
Offset in debug table: source 0x00fa, scope 0x0000, textified callees 0x0000
    GetGlobalObject   r0
    TryGetById        r2, r0, 1, "console"
    GetByIdShort      r1, r2, 2, "log"
    LoadConstString   r0, "setImmediate"
    Call2             r0, r1, r2, r0
    LoadConstUndefined r0
    Ret               r0

NCFunction<>(1 params, 11 registers, 0 symbols):
Offset in debug table: source 0x0119, scope 0x0000, textified callees 0x0000
    GetGlobalObject   r0
    TryGetById        r2, r0, 1, "console"
    GetByIdShort      r1, r2, 2, "log"
    LoadConstString   r0, "nextTick"
    Call2             r0, r1, r2, r0
    LoadConstUndefined r0
    Ret               r0

NCFunction<f1>(1 params, 13 registers, 0 symbols):
Offset in debug table: source 0x0138, scope 0x0000, textified callees 0x0000
    GetGlobalObject   r0
    TryGetById        r3, r0, 1, "console"
    GetByIdShort      r2, r3, 2, "log"
    LoadConstString   r1, "f1"
    Call2             r1, r2, r3, r1
    TryGetById        r3, r0, 3, "setTimeout"
    LoadConstUndefined r0
    CreateEnvironment r1
    CreateClosure     r2, r1, NCFunction<>
    LoadConstInt      r1, 2000
    Call3             r1, r3, r0, r2, r1
    Ret               r0

NCFunction<>(1 params, 11 registers, 0 symbols):
Offset in debug table: source 0x0155, scope 0x0000, textified callees 0x0000
    GetGlobalObject   r0
    TryGetById        r2, r0, 1, "console"
    GetByIdShort      r1, r2, 2, "log"
    LoadConstString   r0, "Hello from f1"
    Call2             r0, r1, r2, r0
    LoadConstUndefined r0
    Ret               r0

NCFunction<f2>(1 params, 14 registers, 0 symbols):
Offset in debug table: source 0x0174, scope 0x0000, textified callees 0x0000
    GetGlobalObject   r1
    TryGetById        r4, r1, 1, "setTimeout"
    LoadConstUndefined r0
    CreateEnvironment r2
    CreateClosure     r3, r2, NCFunction<>
    LoadConstInt      r2, 1000
    Call3             r2, r4, r0, r3, r2
    TryGetById        r3, r1, 2, "console"
    GetByIdShort      r2, r3, 3, "log"
    LoadConstString   r1, "f2"
    Call2             r1, r2, r3, r1
    Ret               r0

NCFunction<>(1 params, 11 registers, 0 symbols):
Offset in debug table: source 0x0191, scope 0x0000, textified callees 0x0000
    GetGlobalObject   r0
    TryGetById        r2, r0, 1, "console"
    GetByIdShort      r1, r2, 2, "log"
    LoadConstString   r0, "Hello from f2"
    Call2             r0, r1, r2, r0
    LoadConstUndefined r0
    Ret               r0

NCFunction<>(1 params, 11 registers, 0 symbols):
Offset in debug table: source 0x01b0, scope 0x0000, textified callees 0x0000
    GetGlobalObject   r0
    TryGetById        r2, r0, 1, "console"
    GetByIdShort      r1, r2, 2, "log"
    LoadConstString   r0, "readFile callback"
    Call2             r0, r1, r2, r0
    LoadConstUndefined r0
    Ret               r0

NCFunction<>(1 params, 11 registers, 0 symbols):
Offset in debug table: source 0x01cf, scope 0x0000, textified callees 0x0000
    GetGlobalObject   r0
    TryGetById        r2, r0, 1, "console"
    GetByIdShort      r1, r2, 2, "log"
    LoadConstString   r0, "promise"
    Call2             r0, r1, r2, r0
    LoadConstUndefined r0
    Ret               r0

Debug filename table:
  0: /tmp/hermes-input.js

Debug file table:
  source table offset 0x0000: filename id 0

Debug source table:
  0x0000  function idx 0, starts at line 1 col 1
    bc 4: line 1 col 12 scope offset 0x0000 env r4
    bc 16: line 1 col 19 scope offset 0x0000 env r6
    bc 21: line 2 col 1 scope offset 0x0000 env r5
    bc 27: line 2 col 12 scope offset 0x0000 env r4
    bc 35: line 2 col 12 scope offset 0x0000 env r3
    bc 40: line 3 col 1 scope offset 0x0000 env r5
    bc 46: line 3 col 12 scope offset 0x0000 env r4
    bc 54: line 3 col 12 scope offset 0x0000 env r3
    bc 59: line 5 col 1 scope offset 0x0000 env r5
    bc 72: line 5 col 11 scope offset 0x0000 env r3
    bc 78: line 9 col 1 scope offset 0x0000 env r5
    bc 84: line 9 col 12 scope offset 0x0000 env r4
    bc 92: line 9 col 12 scope offset 0x0000 env r3
    bc 97: line 11 col 1 scope offset 0x0000 env r4
    bc 108: line 11 col 13 scope offset 0x0000 env r3
    bc 113: line 15 col 1 scope offset 0x0000 env r5
    bc 119: line 15 col 12 scope offset 0x0000 env r4
    bc 127: line 15 col 12 scope offset 0x0000 env r3
    bc 132: line 17 col 1 scope offset 0x0000 env r5
    bc 138: line 17 col 17 scope offset 0x0000 env r4
    bc 148: line 17 col 17 scope offset 0x0000 env r3
    bc 153: line 35 col 1 scope offset 0x0000 env r5
    bc 159: line 35 col 12 scope offset 0x0000 env r4
    bc 167: line 35 col 12 scope offset 0x0000 env r3
    bc 172: line 37 col 12 scope offset 0x0000 env r5
    bc 177: line 37 col 13 scope offset 0x0000 env r4
    bc 188: line 37 col 12 scope offset 0x0000 env r3
    bc 194: line 41 col 1 scope offset 0x0000 env r5
    bc 200: line 41 col 12 scope offset 0x0000 env r4
    bc 208: line 41 col 12 scope offset 0x0000 env r3
    bc 213: line 43 col 1 scope offset 0x0000 env r5
    bc 219: line 43 col 12 scope offset 0x0000 env r4
    bc 227: line 43 col 12 scope offset 0x0000 env r3
    bc 232: line 45 col 1 scope offset 0x0000 env r4
    bc 238: line 45 col 16 scope offset 0x0000 env r3
    bc 243: line 45 col 16 scope offset 0x0000 env r5
    bc 247: line 45 col 23 scope offset 0x0000 env r4
    bc 257: line 45 col 23 scope offset 0x0000 env r3
    bc 262: line 49 col 1 scope offset 0x0000 env r4
    bc 268: line 49 col 12 scope offset 0x0000 env r3
    bc 276: line 49 col 12 scope offset 0x0000 env r2
    bc 286: line 50 col 3 scope offset 0x0000 env r2
    bc 295: line 51 col 3 scope offset 0x0000 env r1
  0x00db  function idx 1, starts at line 5 col 12
    bc 2: line 6 col 3 scope offset 0x0000 env none
    bc 8: line 6 col 14 scope offset 0x0000 env none
    bc 17: line 6 col 14 scope offset 0x0000 env none
  0x00fa  function idx 2, starts at line 11 col 14
    bc 2: line 12 col 3 scope offset 0x0000 env none
    bc 8: line 12 col 14 scope offset 0x0000 env none
    bc 17: line 12 col 14 scope offset 0x0000 env none
  0x0119  function idx 3, starts at line 17 col 18
    bc 2: line 18 col 3 scope offset 0x0000 env none
    bc 8: line 18 col 14 scope offset 0x0000 env none
    bc 17: line 18 col 14 scope offset 0x0000 env none
  0x0138  function idx 4, starts at line 21 col 12
    bc 2: line 22 col 3 scope offset 0x0000 env r3
    bc 8: line 22 col 14 scope offset 0x0000 env r2
    bc 17: line 22 col 14 scope offset 0x0000 env r1
    bc 22: line 23 col 3 scope offset 0x0000 env r3
    bc 43: line 23 col 13 scope offset 0x0000 env r1
  0x0155  function idx 5, starts at line 23 col 14
    bc 2: line 24 col 5 scope offset 0x0000 env none
    bc 8: line 24 col 16 scope offset 0x0000 env none
    bc 17: line 24 col 16 scope offset 0x0000 env none
  0x0174  function idx 6, starts at line 28 col 12
    bc 2: line 29 col 3 scope offset 0x0000 env r4
    bc 23: line 29 col 13 scope offset 0x0000 env r2
    bc 29: line 32 col 3 scope offset 0x0000 env r3
    bc 35: line 32 col 14 scope offset 0x0000 env r2
    bc 44: line 32 col 14 scope offset 0x0000 env r1
  0x0191  function idx 7, starts at line 29 col 14
    bc 2: line 30 col 5 scope offset 0x0000 env none
    bc 8: line 30 col 16 scope offset 0x0000 env none
    bc 17: line 30 col 16 scope offset 0x0000 env none
  0x01b0  function idx 8, starts at line 37 col 25
    bc 2: line 38 col 3 scope offset 0x0000 env none
    bc 8: line 38 col 14 scope offset 0x0000 env none
    bc 17: line 38 col 14 scope offset 0x0000 env none
  0x01cf  function idx 9, starts at line 45 col 24
    bc 2: line 46 col 3 scope offset 0x0000 env none
    bc 8: line 46 col 14 scope offset 0x0000 env none
    bc 17: line 46 col 14 scope offset 0x0000 env none
  0x01ee  end of debug source table

Debug scope descriptor table:
  0x0000  lexical parent:   none, flags:    , variable count: 0
  0x0003  end of debug scope descriptor table

Textified callees table:
  0x0000  entries: 0
  0x0001  end of textified callees table

Debug string table:
  0x0000  end of debug string table

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