Skip to content

Commit

Permalink
Use globalThis rather than global in JS compiler. NFC
Browse files Browse the repository at this point in the history
Since we updated out min node version to 16 in emscripten-core#20551 we can now
assume that `globalThis` (the more standard name) is always available

See https://nodejs.org/api/globals.html#global
  • Loading branch information
sbc100 committed Dec 6, 2023
1 parent e574381 commit 69b3818
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 34 deletions.
16 changes: 8 additions & 8 deletions src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
// LLVM => JavaScript compiler, main entry point

const fs = require('fs');
global.vm = require('vm');
global.assert = require('assert');
global.nodePath = require('path');
globalThis.vm = require('vm');
globalThis.assert = require('assert');
globalThis.nodePath = require('path');

global.print = (x) => {
globalThis.print = (x) => {
process.stdout.write(x + '\n');
};

global.printErr = (x) => {
globalThis.printErr = (x) => {
process.stderr.write(x + '\n');
};

Expand All @@ -32,7 +32,7 @@ function find(filename) {
return filename;
}

global.read = (filename) => {
globalThis.read = (filename) => {
assert(filename);
const absolute = find(filename);
return fs.readFileSync(absolute).toString();
Expand Down Expand Up @@ -62,7 +62,7 @@ assert(settingsFile);
const settings = JSON.parse(read(settingsFile));
Object.assign(global, settings);

global.symbolsOnly = symbolsOnlyArg != -1;
globalThis.symbolsOnly = symbolsOnlyArg != -1;

// In case compiler.js is run directly (as in gen_sig_info)
// ALL_INCOMING_MODULE_JS_API might not be populated yet.
Expand All @@ -81,7 +81,7 @@ if (symbolsOnly) {
}

// Side modules are pure wasm and have no JS
assert(!SIDE_MODULE || (ASYNCIFY && global.symbolsOnly), 'JS compiler should only run on side modules if asyncify is used.');
assert(!SIDE_MODULE || (ASYNCIFY && globalThis.symbolsOnly), 'JS compiler should only run on side modules if asyncify is used.');

// Load compiler code

Expand Down
6 changes: 3 additions & 3 deletions src/jsifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
// Convert analyzed data to javascript. Everything has already been calculated
// before this stage, which just does the final conversion to JavaScript.

global.addedLibraryItems = {};
globalThis.addedLibraryItems = {};

global.extraLibraryFuncs = [];
globalThis.extraLibraryFuncs = [];

// Some JS-implemented library functions are proxied to be called on the main
// browser thread, if the Emscripten runtime is executing in a Web Worker.
// Each such proxied function is identified via an ordinal number (this is not
// the same namespace as function pointers in general).
global.proxiedFunctionTable = [];
globalThis.proxiedFunctionTable = [];

// Mangles the given C/JS side function name to assembly level function name (adds an underscore)
function mangleCSymbolName(f) {
Expand Down
2 changes: 1 addition & 1 deletion src/library_html5_webgpu.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{{
// Helper functions for code generation
global.html5_gpu = {
globalThis.html5_gpu = {
makeImportExport: (snake_case, CamelCase) => {
return `
LibraryHTML5WebGPU.emscripten_webgpu_import_${snake_case}__deps = ['$WebGPU', '$JsValStore'];
Expand Down
4 changes: 2 additions & 2 deletions src/library_int53.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ addToLibrary({
});

#if WASM_BIGINT
global.i53ConversionDeps = ['$bigintToI53Checked'];
globalThis.i53ConversionDeps = ['$bigintToI53Checked'];
#else
global.i53ConversionDeps = ['$convertI32PairToI53Checked'];
globalThis.i53ConversionDeps = ['$convertI32PairToI53Checked'];
#endif
6 changes: 3 additions & 3 deletions src/library_wasm_worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#if WASM_WORKERS == 2
// Helpers for _wasmWorkerBlobUrl used in WASM_WORKERS == 2 mode
{{{
global.captureModuleArg = () => MODULARIZE ? '' : 'self.Module=d;';
global.instantiateModule = () => MODULARIZE ? `${EXPORT_NAME}(d);` : '';
global.instantiateWasm = () => MINIMAL_RUNTIME ? '' : 'd[`instantiateWasm`]=(i,r)=>{var n=new WebAssembly.Instance(d[`wasm`],i);return r(n,d[`wasm`]);};';
globalThis.captureModuleArg = () => MODULARIZE ? '' : 'self.Module=d;';
globalThis.instantiateModule = () => MODULARIZE ? `${EXPORT_NAME}(d);` : '';
globalThis.instantiateWasm = () => MINIMAL_RUNTIME ? '' : 'd[`instantiateWasm`]=(i,r)=>{var n=new WebAssembly.Instance(d[`wasm`],i);return r(n,d[`wasm`]);};';
null;
}}}
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/library_webgl.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
{{{ GL_POOL_TEMP_BUFFERS_SIZE = 2*9*16 }}} // = 288

{{{
global.isCurrentContextWebGL2 = () => {
globalThis.isCurrentContextWebGL2 = () => {
if (MIN_WEBGL_VERSION >= 2) return 'true';
if (MAX_WEBGL_VERSION <= 1) return 'false';
return 'GL.currentContext.version >= 2';
Expand Down
2 changes: 1 addition & 1 deletion src/library_webgpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

{{{
// Helper functions for code generation
global.gpu = {
globalThis.gpu = {
makeInitManager: function(type) {
var mgr = `WebGPU.mgr${type}`;
return `${mgr} = ${mgr} || new Manager();`;
Expand Down
4 changes: 2 additions & 2 deletions src/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ function genArgSequence(n) {
}

// List of symbols that were added from the library.
global.librarySymbols = [];
globalThis.librarySymbols = [];

global.LibraryManager = {
globalThis.LibraryManager = {
library: {},
structs: {},
loaded: false,
Expand Down
10 changes: 5 additions & 5 deletions src/parseTools.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* Tests live in test/other/test_parseTools.js.
*/

global.FOUR_GB = 4 * 1024 * 1024 * 1024;
globalThis.FOUR_GB = 4 * 1024 * 1024 * 1024;
const FLOAT_TYPES = new Set(['float', 'double']);

// Does simple 'macro' substitution, using Django-like syntax,
Expand Down Expand Up @@ -175,8 +175,8 @@ function needsQuoting(ident) {
return true;
}

global.POINTER_SIZE = MEMORY64 ? 8 : 4;
global.STACK_ALIGN = 16;
globalThis.POINTER_SIZE = MEMORY64 ? 8 : 4;
globalThis.STACK_ALIGN = 16;
const POINTER_BITS = POINTER_SIZE * 8;
const POINTER_TYPE = `u${POINTER_BITS}`;
const POINTER_JS_TYPE = MEMORY64 ? "'bigint'" : "'number'";
Expand Down Expand Up @@ -645,13 +645,13 @@ function makeEval(code) {
return ret;
}

global.ATINITS = [];
globalThis.ATINITS = [];

function addAtInit(code) {
ATINITS.push(code);
}

global.ATEXITS = [];
globalThis.ATEXITS = [];

function addAtExit(code) {
if (EXIT_RUNTIME) {
Expand Down
4 changes: 2 additions & 2 deletions src/parseTools_legacy.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,14 @@ function getNativeFieldSize(type) {
return Math.max(getNativeTypeSize(type), POINTER_SIZE);
}

global.Runtime = {
globalThis.Runtime = {
getNativeTypeSize,
getNativeFieldSize,
POINTER_SIZE,
QUANTUM_SIZE: POINTER_SIZE,
};

global.ATMAINS = [];
globalThis.ATMAINS = [];

function addAtMain(code) {
warn('use of legacy parseTools function: addAtMain');
Expand Down
4 changes: 2 additions & 2 deletions src/preamble_minimal.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
{{{
// Helper function to export a symbol on the module object
// if requested.
global.maybeExport = (x) => MODULARIZE && EXPORT_ALL ? `Module['${x}'] = ` : '';
globalThis.maybeExport = (x) => MODULARIZE && EXPORT_ALL ? `Module['${x}'] = ` : '';
// Export to the AudioWorkletGlobalScope the needed variables to access
// the heap. AudioWorkletGlobalScope is unable to access global JS vars
// in the compiled main JS file.
global.maybeExportIfAudioWorklet = (x) => (MODULARIZE && EXPORT_ALL) || AUDIO_WORKLET ? `Module['${x}'] = ` : '';
globalThis.maybeExportIfAudioWorklet = (x) => (MODULARIZE && EXPORT_ALL) || AUDIO_WORKLET ? `Module['${x}'] = ` : '';
null;
}}}

Expand Down
8 changes: 4 additions & 4 deletions src/utility.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ function dump(item) {
}
}

global.warnings = false;
global.currentFile = null;
globalThis.warnings = false;
globalThis.currentFile = null;

function errorPrefix() {
if (currentFile) {
Expand All @@ -48,7 +48,7 @@ function errorPrefix() {
}

function warn(a, msg) {
global.warnings = true;
globalThis.warnings = true;
if (!msg) {
msg = a;
a = false;
Expand All @@ -71,7 +71,7 @@ function warnOnce(a, msg) {
}
}

global.abortExecution = false;
globalThis.abortExecution = false;

function error(msg) {
abortExecution = true;
Expand Down

0 comments on commit 69b3818

Please sign in to comment.