• jsdoor: VAROBJFIX makes require() fail in non-global scopes

    From Rob Swindell@1:103/705 to GitLab issue in main/sbbs on Fri Nov 20 14:39:12 2026
    open https://gitlab.synchro.net/main/sbbs/-/work_items/1372

    jsdoor is the only Synchronet JS host that sets `JSOPTION_VAROBJFIX` (`src/sbbs3/jsexec.cpp`, the `#ifdef JSDOOR` `js_opts`), enabled as an experiment in 96f3df2d0c (yellow-3-trades, 2021-03-07). jsexec and the servers use `JAVASCRIPT_OPTIONS` (0x10, COMPILE_N_GO only).

    One consequence: `require()` fails inside any non-global scope under jsdoor. With VAROBJFIX, a loaded file's top-level `function`/`var` declarations bind to the global object. But `js_require()` (`src/sbbs3/js_global.cpp`) checks for the symbol with `JS_HasProperty()` on `JS_GetScopeChain(cx)` only, which inside `js.exec(file, scope, obj)` or `load(scope, file)` is the scope object, not the global. So under jsdoor:

    - `require(path, "sym")` loads the file and then fails with `symbol 'sym' not defined by script '...'`, although `typeof sym` is `"function"` right afterwards.
    - `require()` never sees a symbol that was already loaded, so it always searches for the file again.

    a563651f4e (graduation-38-grab, 2019-08-29) turned VAROBJFIX off for this very reason ("it causes variables to be created in the global scope when a scope is passed to load(), require() or js.exec()"). 96f3df2d0c turned it back on for jsdoor only.

    ### How it showed up

    The `jsdoor-testsuite` CI jobs have failed on every platform since pipeline 13032: `exec/tests/listfiles/lib.js` fails with `listfiles_lib.js line 8 Error: can't open attr_option.js`. `exec/tests/test.js` runs each test with `js.exec(testscript, location, new function(){})`, so the library's bare `require("attr_option.js", "attr_option")` runs in a non-global scope. jsdoor also has no configured exec dir (its `scfg` is never loaded), so the bare filename can't be resolved against `exec/load/` either. Loading `attr_option.js` by path in the test first does not help, for the reason above.

    The test works around it for now by copying the function onto its own scope object (`this.attr_option = attr_option`) before loading the library.

    ### Repro (jsdoor built from master, run from a tree with `ctrl/` and `exec/`)

    `exec/tests/zprobe/p.js`:

    ```js
    require(js.exec_dir + "../../load/attr_option.js", "attr_option"); log("typeof=" + typeof attr_option);
    ```

    ```
    SBBSCTRL=./ctrl jsdoor -S -f exec/tests/test.js zprobe
    p.js line 1 Error: symbol 'attr_option' not defined by script '.../exec/load/attr_option.js'
    ```

    The same probe passes under jsexec. The same `require()` at a script's top level (global scope) passes under jsdoor too.

    ### Question

    Is VAROBJFIX still wanted in jsdoor? If yes, `js_require()` probably needs to look the symbol up where VAROBJFIX puts it (the global object, or along the scope chain), both before and after the load. If not, removing it brings jsdoor back in line with jsexec.

    Separately: should jsdoor resolve bare `load()`/`require()` names against an exec dir (e.g. one next to the script, or one named on the command line), so that libraries in `exec/load/` that `require()` other libraries work under jsdoor?

    -- *Authored by Claude (Claude Code), on behalf of @rswindell*
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Deucе@1:103/705 to GitLab note in main/sbbs on Fri Nov 20 14:54:43 2026
    https://gitlab.synchro.net/main/sbbs/-/work_items/1372#note_11104

    The standards distinction here is between ordinary global script execution and Synchronet's extension for executing a script against a supplied scope object.

    For ordinary script execution, **the declaration-placement behaviour with `JSOPTION_VAROBJFIX` enabled matches ECMAScript**:

    * [ECMA-262 Edition 3, §10.2.1](https://ecma-international.org/wp-content/uploads/ECMA-262_3rd_edition_december_1999.pdf) specifies that global code uses the global object as its variable object.
    * [ECMA-262 Edition 5.1, §10.4.1.1](https://262.ecma-international.org/5.1/#sec-10.4.1.1) sets the variable and lexical environments to the global environment. [§10.5](https://262.ecma-international.org/5.1/#sec-10.5) places variable and function declaration bindings in that variable environment.

    Calling a file loader from inside a function does not, by itself, make the loaded source part of that function's code or scope. Direct `eval()` has separate rules ([§10.4.2](https://262.ecma-international.org/5.1/#sec-10.4.2)); a host file loader is not automatically a direct eval.

    SpiderMonkey 1.8.5's own `jsapi.h` comments (in the bundled `3rdp/dist/libmozjs.tgz`, immediately before the script compilation/execution API declarations) explicitly call the flag-off behaviour "confusing and non-ECMA explicit vs. implicit variable creation" and recommend enabling `JSOPTION_VAROBJFIX`. The discrepancy is that, with no existing binding, `x = 1` creates a global property while `var x = 1` creates a property on the supplied scope object. See also [the original Mozilla bug introducing the option](https://bugzilla.mozilla.org/show_bug.cgi?id=65553).

    **However, `load(scope, file)`, Synchronet's `require()`, and `js.exec()` are host extensions whose contracts are not specified by ECMAScript.** Synchronet may deliberately provide scoped execution where declarations populate the supplied object. Offering that extension does not inherently make the host nonconformant. Conversely, enabling `VAROBJFIX` only addresses declaration placement; it does not turn every aspect of execution against an arbitrary scope object into standard global-code execution.

    Thus, jsdoor follows the standard global-code declaration-placement rule, while jsexec preserves Synchronet's custom scoped-loading behaviour. The reported `require()` failure is an inconsistency between the host API's property check and the declaration destination. ECMAScript does not decide which scoped-loading contract Synchronet should promise, but loading and symbol checking need to agree on that contract. Bare-filename search paths are also a host API policy, outside ECMAScript.
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Deucе@1:103/705 to GitLab note in main/sbbs on Fri Nov 20 15:37:23 2026
    https://gitlab.synchro.net/main/sbbs/-/work_items/1372#note_11111

    On the separate exec-directory question: jsdoor already has a directory lookup policy. The statement that its exec directory is unset because it does not load `scfg` is incorrect for the current source.

    The `#ifdef JSDOOR` initialization sets `scfg.exec_dir` and `scfg.mods_dir` (along with the other directory fields) from the startup working directory. See [jsexec.cpp](https://gitlab.synchro.net/main/sbbs/-/blob/867e3a6d3ea1be98082c3faea737bda8c4c4609e/src/sbbs3/jsexec.cpp#L1373).

    `load()` and `require()` then use the existing shared loader: it checks the executing script's `js.exec_dir` first, searches `js.load_path_list`, and falls back through the configured directory roots. The default load-path entry is `load`; relative entries are rooted at those directory settings, while absolute entries are searched directly. The `-i<path_list>` command-line option supplies the initial comma-separated load search path. See [the loader](https://gitlab.synchro.net/main/sbbs/-/blob/867e3a6d3ea1be98082c3faea737bda8c4c4609e/src/sbbs3/js_global.cpp#L580) and [the command-line option](https://gitlab.synchro.net/main/sbbs/-/blob/867e3a6d3ea1be98082c3faea737bda8c4c4609e/src/sbbs3/jsexec.cpp#L1438).

    For example, starting jsdoor in the repository's `exec/` directory makes the default `load` entry resolve to `exec/load/`; starting in the repository root can use `-iexec/load`. Setting `SBBSCTRL` alone does not select an installed Synchronet exec directory for jsdoor.

    Commit 867e3a6d3e fixes the scoped-declaration defect while keeping `VAROBJFIX` enabled and retaining this directory policy. There is no outstanding directory-policy change needed to close this defect.
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Deucе@1:103/705 to GitLab note in main/sbbs on Fri Nov 20 15:38:31 2026
    https://gitlab.synchro.net/main/sbbs/-/work_items/1372#note_11111

    On the separate exec-directory question: jsdoor already has a directory lookup policy. The statement that its exec directory is unset because it does not load `scfg` is incorrect for the current source.

    The `#ifdef JSDOOR` initialization sets `scfg.exec_dir` and `scfg.mods_dir` (along with the other directory fields) from the startup working directory. See [jsexec.cpp](https://gitlab.synchro.net/main/sbbs/-/blob/92e457aa3fc801296a4edb8e3f53f1cbd4a81cb4/src/sbbs3/jsexec.cpp#L1373).

    `load()` and `require()` then use the existing shared loader: it checks the executing script's `js.exec_dir` first, searches `js.load_path_list`, and falls back through the configured directory roots. The default load-path entry is `load`; relative entries are rooted at those directory settings, while absolute entries are searched directly. The `-i<path_list>` command-line option supplies the initial comma-separated load search path. See [the loader](https://gitlab.synchro.net/main/sbbs/-/blob/92e457aa3fc801296a4edb8e3f53f1cbd4a81cb4/src/sbbs3/js_global.cpp#L580) and [the command-line option](https://gitlab.synchro.net/main/sbbs/-/blob/92e457aa3fc801296a4edb8e3f53f1cbd4a81cb4/src/sbbs3/jsexec.cpp#L1438).

    For example, starting jsdoor in the repository's `exec/` directory makes the default `load` entry resolve to `exec/load/`; starting in the repository root can use `-iexec/load`. Setting `SBBSCTRL` alone does not select an installed Synchronet exec directory for jsdoor.

    Commit 92e457aa3f fixes the scoped-declaration defect while keeping `VAROBJFIX` enabled and retaining this directory policy. There is no outstanding directory-policy change needed to close this defect.
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)
  • From Deucе@1:103/705 to GitLab issue in main/sbbs on Fri Nov 20 15:38:36 2026
    close https://gitlab.synchro.net/main/sbbs/-/work_items/1372
    --- SBBSecho 3.38-Linux
    * Origin: Vertrauen - [vert/cvs/bbs].synchro.net (1:103/705)