Download Game! Currently 62 players and visitors. Last logged in:SuzukiShutatMahjongFloppy

Blitzer's Blog >> 71997

Back to blogs index
Posted: 04 Sep 2026 09:35 [ permalink ]
Run node harness.js tests/inheriter.c. You should see inherited_str after
::create(): 42 successfully printed directly from the shared closure scope!

==

user@elli:~/Downloads/Remote/LPC/GEM$ node harness.js tests/inheriter.c
[+] Compiling tests/inheriter.c into VM Memory...

[+] Launching Javascript V8 Native Environment...


--- BOOTING VM ---
inherited_str before ::create():

[CRASH] TypeError: _this.create_overload__1 is not a function
    at _this.create (eval at runVM (/home/user/Downloads/Remote/LPC/GEM/harness
.js:642:26), <anonymous>:60:9)
    at Object.clone_object (eval at runVM (/home/user/Downloads/Remote/LPC/GEM/
harness.js:642:26), <anonymous>:8:27)
    at eval (eval at runVM (/home/user/Downloads/Remote/LPC/GEM/harness.js:642:
26), <anonymous>:68:4)
    at runVM (/home/user/Downloads/Remote/LPC/GEM/harness.js:643:9)
    at Object.<anonymous> (/home/user/Downloads/Remote/LPC/GEM/harness.js:651:1
)
    at Module._compile (node:internal/modules/cjs/loader:1871:14)
    at Object..js (node:internal/modules/cjs/loader:2002:10)
    at Module.load (node:internal/modules/cjs/loader:1594:32)
    at Module._load (node:internal/modules/cjs/loader:1396:12)
    at wrapModuleLoad (node:internal/modules/cjs/loader:255:19)
user@elli:~/Downloads/Remote/LPC/GEM$

==

This is the exact reason we test! You successfully uncovered an off-by-one
arithmetic error in the AST's method-overloading loop.
If you look closely at the crash, V8 attempted to call _this.create_overload__1
(). But if we look at what the parser generated, it actually renamed the
parent's create method to create_overload__2 instead of 1!
Why did it skip 1?
When transpiling method overloading, the JS GDCompiler tracks how many times a
function is declared. The parent file declares create() (count = 1). The child
file declares create() (count = 2).
When the child parsed, the loop executed:
let to = funcName + "_overload__" + (c + 1);
Because c was 1, it replaced create directly with create_overload__2,
completely bypassing 1. So when the child file called ::create(), it looked
for _overload__1 and exploded.
The Fix
We simply need to correct the indexing math so that create is renamed to
_overload__1, _overload__1 is renamed to _overload__2, and so on. This ensures
the prototype chain stacks perfectly.

==

user@elli:~/Downloads/Remote/LPC/GEM$ node harness.js tests/inheriter.c       
                                                   [+] Compiling
tests/inheriter.c into VM Memory...                                           
                                     [+] Launching Javascript V8 Native
Environment...                                                                
                                                                              
  --- BOOTING VM ---                                              
inherited_str before ::create():                                 inherited_str
after ::create(): 42                               
user@elli:~/Downloads/Remote/LPC/GEM$ node harness.js tests/inheriter.c       
                                                   [+] Compiling
tests/inheriter.c into VM Memory...                                           
                                     [+] Launching Javascript V8 Native
Environment...                                                                
                                                                              
  --- BOOTING VM ---                                              
inherited_str before ::create():                                 inherited_str
after ::create(): 42                                [VM HALTED CLEANLY]       
                                   user@elli:~/Downloads/Remote/LPC/GEM$