Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ ENVIRONMENT_MAY_BE_SHELL = !ENVIRONMENT || ENVIRONMENTS.indexOf('shell') >= 0;
// The worker case also includes Node.js workers when pthreads are
// enabled and Node.js is one of the supported environments for the build to
// run on. Node.js workers are detected as a combination of
// ENVIRONMENT_IS_WORKER and ENVIRONMENT_HAS_NODE.
// ENVIRONMENT_IS_WORKER and ENVIRONMENT_IS_NODE.
ENVIRONMENT_MAY_BE_WORKER = !ENVIRONMENT || ENVIRONMENTS.indexOf('worker') >= 0 ||
(ENVIRONMENT_MAY_BE_NODE && USE_PTHREADS);

Expand Down
4 changes: 2 additions & 2 deletions src/library_nodefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

mergeInto(LibraryManager.library, {
$NODEFS__deps: ['$FS', '$PATH', '$ERRNO_CODES'],
$NODEFS__postset: 'if (ENVIRONMENT_HAS_NODE) { var fs = require("fs"); var NODEJS_PATH = require("path"); NODEFS.staticInit(); }',
$NODEFS__postset: 'if (ENVIRONMENT_IS_NODE) { var fs = require("fs"); var NODEJS_PATH = require("path"); NODEFS.staticInit(); }',
$NODEFS: {
isWindows: false,
staticInit: function() {
Expand Down Expand Up @@ -38,7 +38,7 @@ mergeInto(LibraryManager.library, {
return ERRNO_CODES[code];
},
mount: function (mount) {
assert(ENVIRONMENT_HAS_NODE);
assert(ENVIRONMENT_IS_NODE);
return NODEFS.createNode(null, '/', NODEFS.getMode(mount.opts.root), 0);
},
createNode: function (parent, name, mode, dev) {
Expand Down
2 changes: 1 addition & 1 deletion src/library_noderawfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

mergeInto(LibraryManager.library, {
$NODERAWFS__deps: ['$ERRNO_CODES', '$FS', '$NODEFS'],
$NODERAWFS__postset: 'if (ENVIRONMENT_HAS_NODE) {' +
$NODERAWFS__postset: 'if (ENVIRONMENT_IS_NODE) {' +
'var _wrapNodeError = function(func) { return function() { try { return func.apply(this, arguments) } catch (e) { if (!e.code) throw e; throw new FS.ErrnoError(ERRNO_CODES[e.code]); } } };' +
'var VFS = Object.assign({}, FS);' +
'for (var _key in NODERAWFS) FS[_key] = _wrapNodeError(NODERAWFS[_key]);' +
Expand Down
4 changes: 2 additions & 2 deletions src/library_pthread.js
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ var LibraryPThread = {
};

#if ENVIRONMENT_MAY_BE_NODE
if (ENVIRONMENT_HAS_NODE) {
if (ENVIRONMENT_IS_NODE) {
worker.on('message', function(data) {
worker.onmessage({ data: data });
});
Expand Down Expand Up @@ -910,7 +910,7 @@ var LibraryPThread = {
else PThread.threadExit(status);
#if WASM_BACKEND
// pthread_exit is marked noReturn, so we must not return from it.
if (ENVIRONMENT_HAS_NODE) {
if (ENVIRONMENT_IS_NODE) {
// exit the pthread properly on node, as a normal JS exception will halt
// the entire application.
process.exit(status);
Expand Down
4 changes: 2 additions & 2 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ function createWasm() {
try {
binary = getBinary();
#if NODE_CODE_CACHING
if (ENVIRONMENT_HAS_NODE) {
if (ENVIRONMENT_IS_NODE) {
var v8 = require('v8');
// Include the V8 version in the cache name, so that we don't try to
// load cached code from another version, which fails silently (it seems
Expand All @@ -1062,7 +1062,7 @@ err(module);
if (!module) {
module = new WebAssembly.Module(binary);
}
if (ENVIRONMENT_HAS_NODE) {
if (ENVIRONMENT_IS_NODE) {
if (!hasCached) {
#if RUNTIME_LOGGING
err('NODE_CODE_CACHING: saving module');
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_init_memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ if (ENVIRONMENT_IS_PTHREAD) {
#if USE_PTHREADS
if (!(wasmMemory.buffer instanceof SharedArrayBuffer)) {
err('requested a shared WebAssembly.Memory but the returned buffer is not a SharedArrayBuffer, indicating that while the browser has SharedArrayBuffer it does not have WebAssembly threads support - you may need to set a flag');
if (ENVIRONMENT_HAS_NODE) {
if (ENVIRONMENT_IS_NODE) {
console.log('(on node you may need: --experimental-wasm-threads --experimental-wasm-bulk-memory and also use a recent version)');
}
throw Error('bad memory');
Expand Down
30 changes: 14 additions & 16 deletions src/shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,17 @@ var quit_ = function(status, toThrow) {
var ENVIRONMENT_IS_WEB = {{{ ENVIRONMENT === 'web' }}};
var ENVIRONMENT_IS_WORKER = {{{ ENVIRONMENT === 'worker' }}};
var ENVIRONMENT_IS_NODE = {{{ ENVIRONMENT === 'node' }}};
var ENVIRONMENT_HAS_NODE = ENVIRONMENT_IS_NODE;
var ENVIRONMENT_IS_SHELL = {{{ ENVIRONMENT === 'shell' }}};
#else // ENVIRONMENT
var ENVIRONMENT_IS_WEB = false;
var ENVIRONMENT_IS_WORKER = false;
var ENVIRONMENT_IS_NODE = false;
var ENVIRONMENT_HAS_NODE = false;
var ENVIRONMENT_IS_SHELL = false;
ENVIRONMENT_IS_WEB = typeof window === 'object';
ENVIRONMENT_IS_WORKER = typeof importScripts === 'function';
// A web environment like Electron.js can have Node enabled, so we must
// distinguish between Node-enabled environments and Node environments per se.
// This will allow the former to do things like mount NODEFS.
// Extended check using process.versions fixes issue #8816.
// (Also makes redundant the original check that 'require' is a function.)
ENVIRONMENT_HAS_NODE = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string';
ENVIRONMENT_IS_NODE = ENVIRONMENT_HAS_NODE && !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_WORKER;
// N.b. Electron.js environment is simultaneously a NODE-environment, but
// also a web environment.
ENVIRONMENT_IS_NODE = typeof process === 'object' && typeof process.versions === 'object' && typeof process.versions.node === 'string';
ENVIRONMENT_IS_SHELL = !ENVIRONMENT_IS_WEB && !ENVIRONMENT_IS_NODE && !ENVIRONMENT_IS_WORKER;
#endif // ENVIRONMENT

Expand All @@ -98,10 +92,10 @@ var _scriptDir = import.meta.url;
#else
var _scriptDir = (typeof document !== 'undefined' && document.currentScript) ? document.currentScript.src : undefined;

if (ENVIRONMENT_IS_NODE) {
_scriptDir = __filename;
} else if (ENVIRONMENT_IS_WORKER) {
if (ENVIRONMENT_IS_WORKER) {
_scriptDir = self.location.href;
} else if (ENVIRONMENT_IS_NODE) {
_scriptDir = __filename;
}
#endif
#endif
Expand Down Expand Up @@ -133,7 +127,11 @@ if (ENVIRONMENT_IS_NODE) {
if (!(typeof process === 'object' && typeof require === 'function')) throw new Error('not compiled for this environment (did you build to HTML and try to run it not on the web, or set ENVIRONMENT to something - like node - and run it someplace else - like on the web?)');
#endif
#endif
scriptDirectory = __dirname + '/';
if (ENVIRONMENT_IS_WORKER) {
scriptDirectory = require('path').dirname(scriptDirectory) + '/';
} else {
scriptDirectory = __dirname + '/';
}

#include "node_shell_read.js"

Expand Down Expand Up @@ -259,7 +257,7 @@ if (ENVIRONMENT_IS_SHELL) {

// Note that this includes Node.js workers when relevant (pthreads is enabled).
// Node.js workers are detected as a combination of ENVIRONMENT_IS_WORKER and
// ENVIRONMENT_HAS_NODE.
// ENVIRONMENT_IS_NODE.
#if ENVIRONMENT_MAY_BE_WEB || ENVIRONMENT_MAY_BE_WORKER
if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
if (ENVIRONMENT_IS_WORKER) { // Check worker, not web, since window could be polyfilled
Expand Down Expand Up @@ -293,7 +291,7 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
// Differentiate the Web Worker from the Node Worker case, as reading must
// be done differently.
#if USE_PTHREADS
if (ENVIRONMENT_HAS_NODE) {
if (ENVIRONMENT_IS_NODE) {

#include "node_shell_read.js"

Expand All @@ -315,7 +313,7 @@ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
}

#if ENVIRONMENT_MAY_BE_NODE && USE_PTHREADS
if (ENVIRONMENT_HAS_NODE) {
if (ENVIRONMENT_IS_NODE) {
// Polyfill the performance object, which emscripten pthreads support
// depends on for good timing.
if (typeof performance === 'undefined') {
Expand Down