Bug 255396 - Unexpected 'var' resolution in module
Summary: Unexpected 'var' resolution in module
Status: RESOLVED INVALID
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari 16
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2023-04-13 07:56 PDT by Tzvetelin Vassilev
Modified: 2023-04-20 10:50 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tzvetelin Vassilev 2023-04-13 07:56:39 PDT
Problem is observed with emscripten build. 

Generated Module looks in this way:

// Module.mjs
var Module = (() => {
	var _scriptDir = import.meta.url;

	return (
		async function(Module = {})  {
			console.log(Module) // result is null, expected value is data

			var Module = typeof Module != "undefined" ? Module : {};

			console.log(Module) // result is {}

			// emscripten stuff
		}
	);
})();

export default Module;

After import like this:

// index.mjs
let factory = (await import("Module.mjs")).default
await Module({/* data */})

Something is got wrong and Module value is lost.
Comment 1 Radar WebKit Bug Importer 2023-04-20 07:57:21 PDT
<rdar://problem/108318013>
Comment 2 Yusuke Suzuki 2023-04-20 09:23:26 PDT
That's correct behavior. module's global scope is Module lexical environment. Not global scope.