Skip to content

Commit 9bc3ffa

Browse files
authored
Flip some negated #if checks. NFC (#25487)
This helps with readability IMHO since you don't need to do a double negative when considering the `#else` block.
1 parent 3b22cd6 commit 9bc3ffa

File tree

5 files changed

+47
-47
lines changed

5 files changed

+47
-47
lines changed

src/jsifier.mjs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -601,15 +601,7 @@ function(${args}) {
601601
warn('To build in STANDALONE_WASM mode without a main(), use emcc --no-entry');
602602
}
603603
}
604-
if (!RELOCATABLE) {
605-
// emit a stub that will fail at runtime
606-
LibraryManager.library[symbol] = new Function(`abort('missing function: ${symbol}');`);
607-
// We have already warned/errored about this function, so for the purposes of Closure use, mute all type checks
608-
// regarding this function, marking ot a variadic function that can take in anything and return anything.
609-
// (not useful to warn/error multiple times)
610-
LibraryManager.library[symbol + '__docs'] = '/** @type {function(...*):?} */';
611-
isStub = true;
612-
} else {
604+
if (RELOCATABLE) {
613605
// Create a stub for this symbol which can later be replaced by the
614606
// dynamic linker. If this stub is called before the symbol is
615607
// resolved assert in debug builds or trap in release builds.
@@ -626,6 +618,14 @@ function(${args}) {
626618
const functionBody = assertion + `return ${target}(...args);`;
627619
LibraryManager.library[symbol] = new Function('...args', functionBody);
628620
isStub = true;
621+
} else {
622+
// emit a stub that will fail at runtime
623+
LibraryManager.library[symbol] = new Function(`abort('missing function: ${symbol}');`);
624+
// We have already warned/errored about this function, so for the purposes of Closure use, mute all type checks
625+
// regarding this function, marking ot a variadic function that can take in anything and return anything.
626+
// (not useful to warn/error multiple times)
627+
LibraryManager.library[symbol + '__docs'] = '/** @type {function(...*):?} */';
628+
isStub = true;
629629
}
630630
}
631631

src/lib/libcore.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,10 +2556,10 @@ function wrapSyscallFunction(x, library, isWasi) {
25562556
}
25572557

25582558
var isVariadic = !isWasi && t.includes(', varargs');
2559-
#if SYSCALLS_REQUIRE_FILESYSTEM == 0
2560-
var canThrow = false;
2561-
#else
2559+
#if SYSCALLS_REQUIRE_FILESYSTEM
25622560
var canThrow = library[x + '__nothrow'] !== true;
2561+
#else
2562+
var canThrow = false;
25632563
#endif
25642564

25652565
library[x + '__deps'] ??= [];

src/lib/libemval.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -279,33 +279,7 @@ var LibraryEmVal = {
279279
var argFromPtr = argTypes.map(type => type.readValueFromPointer.bind(type));
280280
argCount--; // remove the extracted return type
281281
282-
#if !DYNAMIC_EXECUTION
283-
var argN = new Array(argCount);
284-
var invokerFunction = (handle, methodName, destructorsRef, args) => {
285-
var offset = 0;
286-
for (var i = 0; i < argCount; ++i) {
287-
argN[i] = argFromPtr[i](args + offset);
288-
offset += GenericWireTypeSize;
289-
}
290-
var rv;
291-
switch (kind) {
292-
case {{{ cDefs['internal::EM_INVOKER_KIND::FUNCTION'] }}}:
293-
rv = Emval.toValue(handle).apply(null, argN);
294-
break;
295-
case {{{ cDefs['internal::EM_INVOKER_KIND::CONSTRUCTOR'] }}}:
296-
rv = Reflect.construct(Emval.toValue(handle), argN);
297-
break;
298-
case {{{ cDefs['internal::EM_INVOKER_KIND::CAST'] }}}:
299-
// no-op, just return the argument
300-
rv = argN[0];
301-
break;
302-
case {{{ cDefs['internal::EM_INVOKER_KIND::METHOD'] }}}:
303-
rv = Emval.toValue(handle)[getStringOrSymbol(methodName)](...argN);
304-
break;
305-
}
306-
return emval_returnValue(toReturnWire, destructorsRef, rv);
307-
};
308-
#else
282+
#if DYNAMIC_EXECUTION
309283
var captures = {'toValue': Emval.toValue};
310284
var args = argFromPtr.map((argFromPtr, i) => {
311285
var captureName = `argFromPtr${i}`;
@@ -339,6 +313,32 @@ ${functionBody}
339313
}`;
340314
341315
var invokerFunction = new Function(Object.keys(captures), functionBody)(...Object.values(captures));
316+
#else
317+
var argN = new Array(argCount);
318+
var invokerFunction = (handle, methodName, destructorsRef, args) => {
319+
var offset = 0;
320+
for (var i = 0; i < argCount; ++i) {
321+
argN[i] = argFromPtr[i](args + offset);
322+
offset += GenericWireTypeSize;
323+
}
324+
var rv;
325+
switch (kind) {
326+
case {{{ cDefs['internal::EM_INVOKER_KIND::FUNCTION'] }}}:
327+
rv = Emval.toValue(handle).apply(null, argN);
328+
break;
329+
case {{{ cDefs['internal::EM_INVOKER_KIND::CONSTRUCTOR'] }}}:
330+
rv = Reflect.construct(Emval.toValue(handle), argN);
331+
break;
332+
case {{{ cDefs['internal::EM_INVOKER_KIND::CAST'] }}}:
333+
// no-op, just return the argument
334+
rv = argN[0];
335+
break;
336+
case {{{ cDefs['internal::EM_INVOKER_KIND::METHOD'] }}}:
337+
rv = Emval.toValue(handle)[getStringOrSymbol(methodName)](...argN);
338+
break;
339+
}
340+
return emval_returnValue(toReturnWire, destructorsRef, rv);
341+
};
342342
#endif
343343
var functionName = `methodCaller<(${argTypes.map(t => t.name)}) => ${retType.name}>`;
344344
return emval_addMethodCaller(createNamedFunction(functionName, invokerFunction));

src/lib/libsdl.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1743,17 +1743,17 @@ var LibrarySDL = {
17431743
// We actually do the whole screen in Unlock...
17441744
},
17451745

1746-
#if !ASYNCIFY
1746+
#if ASYNCIFY
1747+
SDL_Delay__deps: ['emscripten_sleep'],
1748+
SDL_Delay__async: true,
1749+
SDL_Delay: (delay) => _emscripten_sleep(delay),
1750+
#else
17471751
SDL_Delay: (delay) => {
17481752
if (!ENVIRONMENT_IS_WORKER) abort('SDL_Delay called on the main thread! Potential infinite loop, quitting. (consider building with async support like ASYNCIFY)');
17491753
// horrible busy-wait, but in a worker it at least does not block rendering
17501754
var now = Date.now();
17511755
while (Date.now() - now < delay) {}
17521756
},
1753-
#else
1754-
SDL_Delay__deps: ['emscripten_sleep'],
1755-
SDL_Delay__async: true,
1756-
SDL_Delay: (delay) => _emscripten_sleep(delay),
17571757
#endif
17581758

17591759
SDL_WM_SetCaption__proxy: 'sync',

src/postamble_minimal.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ WebAssembly.instantiate(Module['wasm'], imports).then(/** @suppress {missingProp
258258
wasmExports = applySignatureConversions(wasmExports);
259259
#endif
260260

261-
#if !DECLARE_ASM_MODULE_EXPORTS
262-
exportWasmSymbols(wasmExports);
263-
#else
261+
#if DECLARE_ASM_MODULE_EXPORTS
264262
assignWasmExports(wasmExports);
263+
#else
264+
exportWasmSymbols(wasmExports);
265265
#endif
266266

267267
#if !IMPORTED_MEMORY

0 commit comments

Comments
 (0)