Repository navigation
Conversation
This is the warning step from the deprecation checklist in emscripten-core#28081. Module['ctx'] keeps working, and release builds don't change. The runtime's own reads go through readModuleCtx so that they don't warn. They stay on Module['ctx'] because code such as Defold deletes it to reset the context cached by Browser.createContext. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Code Review
This pull request deprecates the undocumented Module['ctx'] property, triggering a warning in ASSERTIONS builds when read by user code while keeping it functional. It introduces internal helpers and hooks to distinguish between user-space and runtime reads of the context, and adds corresponding tests. The feedback recommends explicitly declaring $hookModuleCtx as a dependency of $readModuleCtx to ensure correct dependency resolution by the compiler.
| $readModuleCtx__internal: true, | ||
| $readModuleCtx: () => { |
There was a problem hiding this comment.
To ensure robust dependency resolution and prevent potential issues with the compiler's automatic dependency scanner, it is highly recommended to explicitly declare $hookModuleCtx as a dependency of $readModuleCtx using __deps.
$readModuleCtx__deps: ['$hookModuleCtx'],
$readModuleCtx__internal: true,
$readModuleCtx: () => {
This is the nudge discussed in #28081, and the warning step on that issue's deprecation checklist.
Module['ctx']keeps working, but reading it from user code now warns once inASSERTIONSbuilds:It removes nothing, so it can land before #28079 or instead of it. If #28081 goes ahead with the removal, #28079 can follow once the deprecation period is over. It uses the getter/setter suggested in the survey on #28081.
Questions for @sbc100 and @kripken:
Module['ctx']property #28079?Module['ctx']#28081 hasn't settled on removal. Is "deprecated" the right word for the warning, or should it be softer until that's decided?Module['ctx']property #28079). If you want those bytes back sooner, emcc already scansEM_ASM,EM_JS,--pre-jsand JS libraries at link time, so it could keep the write only for programs that mentionModule.ctx. JS on the page itself wouldn't be seen, so those programs would getundefinedin release builds. Is that worth adding, or is it too much compiler logic for so few bytes? I haven't built it, but I can as a follow-up.ASSERTIONS..jsand.wasmare byte-identical to main for GL, GLFW, SDL1 and main loop builds at-O2, and with--closure 1,-sMODULARIZE,-pthreadand-sMINIMAL_RUNTIMEon the GL build (--closure 1on GLFW too).Browser.createContext,glfwCreateWindowand the main loop'srequestAnimationFramecheck read it throughreadModuleCtx.Module['ctx']: Remove undocumentedModule['ctx']property #28079 moves them toBrowser.ctx, but Defold'sdelete Module.ctxrelies on resetting the context cached inBrowser.createContext. A private field breaks that, and the new test fails if I add one.Browser: other builds pay only for the main loop check.-O2 -sASSERTIONS.jsbytes / gzip.jsbytes / gzip.jsbytes / gzipLimits:
Module.ctx, such as the 2D context orAudioContextusers in the survey, also gets the warning if it links GL orBrowser. The setter can't tell who wrote the value.delete Module.ctxremoves the hook, so later reads don't warn. That includes the runtime's own delete inglfwDestroyWindowandglutDestroyWindow.src/cpuprofiler.jsstill readsModule['ctx']as a fallback whenGLctxdoesn't exist, so a--cpuprofilerbuild withBrowserbut no GL can warn once. Remove undocumentedModule['ctx']property #28079 removes that fallback.Tests: the new
browser.test_module_ctx_deprecatedruns with and without Closure on Chrome 151 headless, and it fails on main. It checks that creating a GLFW window doesn't warn, that a read warns once and returns the live context, thatGLctxworks fromEM_ASM, and that deleting the property still resets the context.I ran 185 browser tests (GLFW, GLUT, WebGL, SDL, OpenAL, main loop) on the same Chrome: 175 passed, 9 skipped, and
test_html5_webgl_apifailed on itsdesynchronizedassertion, as it does on main. 42othertests covering code size, JS libraries and assertions passed, with no codesize changes needed. I also checked-pthreadand a context proxied fromPROXY_TO_PTHREADin Chrome, and that the main loop'srequestAnimationFramewarning still fires.Not run: the full test suite, Firefox, Safari, and
-sMINIMAL_RUNTIMEin a browser (the test harness fails there on main too, so that build only ran under Node with a fake context).AI-generated with Claude, reviewed by me before posting.