emscripten-core / emscripten-core/emscripten
RFE: _name_ the function created by -sMODULARIZE
- Dominant language
- C++
- Stars
- 27.6k
- Forks
- 3.6k
- Avg merge
- 1d 6h
- Merged PRs (30d)
- 109
Description
i have a conundrum...
`-sMODULARIZE=foo` lets me name my module init function `foo()`, but the current implementation has two shortcomings:
1) It reuses that name for 2 distinct purposes in the generated code:
```js
var sqlite3InitModule = (() => {
var _scriptDir = typeof document !== 'undefined' && document.currentScript ? document.currentScript.src : undefined;
return (
function(sqlite3InitModule) {
sqlite3InitModule = sqlite3InitModule || {};
...
```
Note that `sqlite3InitModule` is a distinctly different object in the inner function than in the outer declaration.
2) it provides no way for `--extern-post-js`-injected code to attach state to that function in such a way that `--pre-js`-injected code can access it.
What i'm trying to do is, in my `--extern-post-js`, attach some state to `sqlite3InitModule` so that i can reach it from my customized `Module['locateFile']` (which is injected via `--pre-js`). The problem is that the `Module['locateFile']` impl cannot access the outer `sqlite3InitModule` object. The state in question is only available when the script is loaded, not when the module init function is called, so it has to be stashed via `--extern-post-js` in either the global scope (boo!!!) or as a property of the init function itself (yeah!!!).
My request is that the the inner function get a well-defined name:
```js
return (
function HERE(sqlite3InitModule) {
sqlite3InitModule = sqlite3InitModule || {};
```
so that `--pre-js`-injected code can access the outer `-sMODULARIZE`-defined symbol via that name. Whatever that name is is unimportant to me.
Note that we cannot work around this using:
```js
return (
function (sqlite3InitModule) {
sqlite3InitModule = sqlite3InitModule || {};
// --pre-js-injected code:
const myfunc = arguments.callee;
```
To quote [the MDN docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments/callee) with emphasis added:
> Warning: Accessing arguments.callee in [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) will throw a [TypeError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypeError). ***If a function must reference itself, either give the function expression a name or use a function declaration.***
That name is precisely what i'm asking for.
Please?
Contributor guide
Assessment
This issue has not been assessed yet.