The ugly macro JS_THIS_OBJECT and the JS::CallReceiver have been removed in SpiderMonkey 61 and 49 respectively:
Remove JS::CallReceiver
Firefox 49
https://bugzilla.mozilla.org/show_bug.cgi?id=1270977
Remove JS_THIS_OBJECT
Firefox 61
https://bugzilla.mozilla.org/show_bug.cgi?id=1255800
Gotchas / Pitfalls:
- Test-for-object:
One can control the this argument from JS functions. The macro alwas behaved correctly, even if this was a number, null, or empty object.
If one uses JS::CallArgs without testing for non-objects, one will get segfaults / null-deref.
- Return Callstack:
Instead of passing nullptr, one can pass the CallArgs to JS_GetInstancePrivate, and thus obtain a nicer JS callstack:
ERROR: JavaScript error: gui/pregame/mainmenu.js line 20
TypeError: GUIObject.prototype.toString called on incompatible Object
init@gui/pregame/mainmenu.js:20:7
These three lines were not printed in the previous verison, when calling Engine.GetGUIObjectByName("submenu").toString.call({}); in the main menu`
Patch prehistory:
The patch was created by wraitii early 2018 in
https://github.com/wraitii/0ad/commit/9b5e783e47a2b060463b1ca3a305bfaac5d416ed
https://github.com/0ad/0ad/commit/f231c1d0412d903b9accb7fde8ebfee7ab248fa1
I tried my luck in december 2018 in D1699, but got sidetracked by unrelated cleanup.
In march 2019, rP22134 added one CallReceiverFromVp in preference of avoiding JS_THIS_OBJECT, copied from the wrong place.
In august 2019, in D2142 I attempted again to remove the macros and got sidetracked again by deduplication.
In august 2019, rP22596 removed CallArgs, since they were redundant with the consistent CallReceiver use.
rP7259 added the TODO for JS_GetInstancePrivate and GetClass.