Skip to content

Commit

Permalink
More use of JS method syntax. NFC (#19906)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Aug 1, 2023
1 parent 2817cd7 commit 0ac2d7d
Show file tree
Hide file tree
Showing 22 changed files with 245 additions and 247 deletions.
4 changes: 2 additions & 2 deletions src/library.js
Original file line number Diff line number Diff line change
Expand Up @@ -1755,7 +1755,7 @@ mergeInto(LibraryManager.library, {
names: {}
},

lookup_name: (name) => {
lookup_name(name) {
// If the name is already a valid ipv4 / ipv6 address, don't generate a fake one.
var res = inetPton4(name);
if (res !== null) {
Expand Down Expand Up @@ -1784,7 +1784,7 @@ mergeInto(LibraryManager.library, {
return addr;
},

lookup_addr: (addr) => {
lookup_addr(addr) {
if (DNS.address_map.names[addr]) {
return DNS.address_map.names[addr];
}
Expand Down
38 changes: 19 additions & 19 deletions src/library_async.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ mergeInto(LibraryManager.library, {
#if ASYNCIFY == 1 && MEMORY64
rewindArguments: {},
#endif
instrumentWasmImports: function(imports) {
instrumentWasmImports(imports) {
#if ASYNCIFY_DEBUG
dbg('asyncify instrumenting imports');
#endif
Expand Down Expand Up @@ -108,14 +108,14 @@ mergeInto(LibraryManager.library, {
}
},
#if ASYNCIFY == 1 && MEMORY64
saveOrRestoreRewindArguments: function(funcName, passedArguments) {
saveOrRestoreRewindArguments(funcName, passedArguments) {
if (passedArguments.length === 0) {
return Asyncify.rewindArguments[funcName] || []
}
return Asyncify.rewindArguments[funcName] = Array.from(passedArguments)
},
#endif
instrumentWasmExports: function(exports) {
instrumentWasmExports(exports) {
#if ASYNCIFY_DEBUG
dbg('asyncify instrumenting exports');
#endif
Expand Down Expand Up @@ -205,7 +205,7 @@ mergeInto(LibraryManager.library, {
asyncPromiseHandlers: null, // { resolve, reject } pair for when *all* asynchronicity is done
sleepCallbacks: [], // functions to call every time we sleep

getCallStackId: function(funcName) {
getCallStackId(funcName) {
var id = Asyncify.callStackNameToId[funcName];
if (id === undefined) {
id = Asyncify.callStackId++;
Expand All @@ -215,7 +215,7 @@ mergeInto(LibraryManager.library, {
return id;
},

maybeStopUnwind: function() {
maybeStopUnwind() {
#if ASYNCIFY_DEBUG
dbg('ASYNCIFY: maybe stop unwind', Asyncify.exportCallStack);
#endif
Expand All @@ -240,7 +240,7 @@ mergeInto(LibraryManager.library, {
}
},

whenDone: function() {
whenDone() {
#if ASSERTIONS
assert(Asyncify.currData, 'Tried to wait for an async operation when none is in progress.');
assert(!Asyncify.asyncPromiseHandlers, 'Cannot have multiple async operations in flight at once');
Expand All @@ -250,7 +250,7 @@ mergeInto(LibraryManager.library, {
});
},

allocateData: function() {
allocateData() {
// An asyncify data structure has three fields:
// 0 current stack pos
// 4 max stack pos
Expand All @@ -265,12 +265,12 @@ mergeInto(LibraryManager.library, {
return ptr;
},

setDataHeader: function(ptr, stack, stackSize) {
setDataHeader(ptr, stack, stackSize) {
{{{ makeSetValue('ptr', C_STRUCTS.asyncify_data_s.stack_ptr, 'stack', '*') }}};
{{{ makeSetValue('ptr', C_STRUCTS.asyncify_data_s.stack_limit, 'stack + stackSize', '*') }}};
},

setDataRewindFunc: function(ptr) {
setDataRewindFunc(ptr) {
var bottomOfCallStack = Asyncify.exportCallStack[0];
#if ASYNCIFY_DEBUG >= 2
dbg('ASYNCIFY: setDataRewindFunc('+ptr+'), bottomOfCallStack is', bottomOfCallStack, new Error().stack);
Expand All @@ -282,7 +282,7 @@ mergeInto(LibraryManager.library, {
#if RELOCATABLE
getDataRewindFunc__deps: [ '$resolveGlobalSymbol' ],
#endif
getDataRewindFunc: function(ptr) {
getDataRewindFunc(ptr) {
var id = {{{ makeGetValue('ptr', C_STRUCTS.asyncify_data_s.rewind_id, 'i32') }}};
var name = Asyncify.callStackIdToName[id];
var func = wasmExports[name];
Expand All @@ -296,7 +296,7 @@ mergeInto(LibraryManager.library, {
return func;
},

doRewind: function(ptr) {
doRewind(ptr) {
var start = Asyncify.getDataRewindFunc(ptr);
#if ASYNCIFY_DEBUG
dbg('ASYNCIFY: start:', start);
Expand All @@ -310,7 +310,7 @@ mergeInto(LibraryManager.library, {
// This receives a function to call to start the async operation, and
// handles everything else for the user of this API. See emscripten_sleep()
// and other async methods for simple examples of usage.
handleSleep: function(startAsync) {
handleSleep(startAsync) {
#if ASSERTIONS
assert(Asyncify.state !== Asyncify.State.Disabled, 'Asyncify cannot be done during or after the runtime exits');
#endif
Expand Down Expand Up @@ -424,7 +424,7 @@ mergeInto(LibraryManager.library, {
//
// This is particularly useful for native JS `async` functions where the
// returned value will "just work" and be passed back to C++.
handleAsync: function(startAsync) {
handleAsync(startAsync) {
return Asyncify.handleSleep((wakeUp) => {
// TODO: add error handling as a second param when handleSleep implements it.
startAsync().then(wakeUp);
Expand All @@ -439,10 +439,10 @@ mergeInto(LibraryManager.library, {
// Stores all the exported raw Wasm functions that are wrapped with async
// WebAssembly.Functions.
asyncExports: null,
isAsyncExport: function(func) {
isAsyncExport(func) {
return Asyncify.asyncExports && Asyncify.asyncExports.has(func);
},
handleSleep: function(startAsync) {
handleSleep(startAsync) {
{{{ runtimeKeepalivePush(); }}}
var promise = new Promise((resolve) => {
startAsync(resolve);
Expand All @@ -452,13 +452,13 @@ mergeInto(LibraryManager.library, {
});
return promise;
},
handleAsync: function(startAsync) {
handleAsync(startAsync) {
return Asyncify.handleSleep((wakeUp) => {
// TODO: add error handling as a second param when handleSleep implements it.
startAsync().then(wakeUp);
});
},
makeAsyncFunction: function(original) {
makeAsyncFunction(original) {
#if ASYNCIFY_DEBUG
dbg('asyncify: returnPromiseOnSuspend for', original);
#endif
Expand Down Expand Up @@ -553,7 +553,7 @@ mergeInto(LibraryManager.library, {
$Fibers: {
nextFiber: 0,
trampolineRunning: false,
trampoline: function() {
trampoline() {
if (!Fibers.trampolineRunning && Fibers.nextFiber) {
Fibers.trampolineRunning = true;
do {
Expand All @@ -570,7 +570,7 @@ mergeInto(LibraryManager.library, {
/*
* NOTE: This function is the asynchronous part of emscripten_fiber_swap.
*/
finishContextSwitch: function(newFiber) {
finishContextSwitch(newFiber) {
var stack_base = {{{ makeGetValue('newFiber', C_STRUCTS.emscripten_fiber_s.stack_base, '*') }}};
var stack_max = {{{ makeGetValue('newFiber', C_STRUCTS.emscripten_fiber_s.stack_limit, '*') }}};
_emscripten_stack_set_limits(stack_base, stack_max);
Expand Down
50 changes: 25 additions & 25 deletions src/library_browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ var LibraryBrowser = {
timingValue: 0,
currentFrameNumber: 0,
queue: [],
pause: function() {
pause() {
Browser.mainLoop.scheduler = null;
// Incrementing this signals the previous main loop that it's now become old, and it must return.
Browser.mainLoop.currentlyRunningMainloop++;
},
resume: function() {
resume() {
Browser.mainLoop.currentlyRunningMainloop++;
var timingMode = Browser.mainLoop.timingMode;
var timingValue = Browser.mainLoop.timingValue;
Expand All @@ -70,7 +70,7 @@ var LibraryBrowser = {
_emscripten_set_main_loop_timing(timingMode, timingValue);
Browser.mainLoop.scheduler();
},
updateStatus: function() {
updateStatus() {
if (Module['setStatus']) {
var message = Module['statusMessage'] || 'Please wait...';
var remaining = Browser.mainLoop.remainingBlockers;
Expand All @@ -86,7 +86,7 @@ var LibraryBrowser = {
}
}
},
runIter: function(func) {
runIter(func) {
if (ABORT) return;
if (Module['preMainLoop']) {
var preRet = Module['preMainLoop']();
Expand All @@ -103,7 +103,7 @@ var LibraryBrowser = {
moduleContextCreatedCallbacks: [],
workers: [],

init: function() {
init() {
if (Browser.initted) return;
Browser.initted = true;

Expand Down Expand Up @@ -255,7 +255,7 @@ var LibraryBrowser = {
}
},

createContext: function(/** @type {HTMLCanvasElement} */ canvas, useWebGL, setInModule, webGLContextAttributes) {
createContext(/** @type {HTMLCanvasElement} */ canvas, useWebGL, setInModule, webGLContextAttributes) {
if (useWebGL && Module.ctx && canvas == Module.canvas) return Module.ctx; // no need to recreate GL context if it's already been created for this canvas.

var ctx;
Expand Down Expand Up @@ -307,12 +307,12 @@ var LibraryBrowser = {
return ctx;
},

destroyContext: function(canvas, useWebGL, setInModule) {},
destroyContext(canvas, useWebGL, setInModule) {},

fullscreenHandlersInstalled: false,
lockPointer: undefined,
resizeCanvas: undefined,
requestFullscreen: function(lockPointer, resizeCanvas) {
requestFullscreen(lockPointer, resizeCanvas) {
Browser.lockPointer = lockPointer;
Browser.resizeCanvas = resizeCanvas;
if (typeof Browser.lockPointer == 'undefined') Browser.lockPointer = true;
Expand Down Expand Up @@ -372,12 +372,12 @@ var LibraryBrowser = {
},

#if ASSERTIONS
requestFullScreen: function() {
requestFullScreen() {
abort('Module.requestFullScreen has been replaced by Module.requestFullscreen (without a capital S)');
},
#endif

exitFullscreen: function() {
exitFullscreen() {
// This is workaround for chrome. Trying to exit from fullscreen
// not in fullscreen state will cause "TypeError: Document not active"
// in chrome. See https://github.com/emscripten-core/emscripten/pull/8236
Expand All @@ -397,7 +397,7 @@ var LibraryBrowser = {

nextRAF: 0,

fakeRequestAnimationFrame: function(func) {
fakeRequestAnimationFrame(func) {
// try to keep 60fps between calls to here
var now = Date.now();
if (Browser.nextRAF === 0) {
Expand All @@ -411,7 +411,7 @@ var LibraryBrowser = {
setTimeout(func, delay);
},

requestAnimationFrame: function(func) {
requestAnimationFrame(func) {
if (typeof requestAnimationFrame == 'function') {
requestAnimationFrame(func);
return;
Expand All @@ -432,21 +432,21 @@ var LibraryBrowser = {

// abort and pause-aware versions TODO: build main loop on top of this?

safeSetTimeout: function(func, timeout) {
safeSetTimeout(func, timeout) {
// Legacy function, this is used by the SDL2 port so we need to keep it
// around at least until that is updated.
// See https://github.com/libsdl-org/SDL/pull/6304
return safeSetTimeout(func, timeout);
},
safeRequestAnimationFrame: function(func) {
safeRequestAnimationFrame(func) {
{{{ runtimeKeepalivePush() }}}
return Browser.requestAnimationFrame(() => {
{{{ runtimeKeepalivePop() }}}
callUserCallback(func);
});
},

getMimetype: function(name) {
getMimetype(name) {
return {
'jpg': 'image/jpeg',
'jpeg': 'image/jpeg',
Expand All @@ -458,7 +458,7 @@ var LibraryBrowser = {
}[name.substr(name.lastIndexOf('.')+1)];
},

getUserMedia: function(func) {
getUserMedia(func) {
if (!window.getUserMedia) {
window.getUserMedia = navigator['getUserMedia'] ||
navigator['mozGetUserMedia'];
Expand All @@ -467,14 +467,14 @@ var LibraryBrowser = {
},


getMovementX: function(event) {
getMovementX(event) {
return event['movementX'] ||
event['mozMovementX'] ||
event['webkitMovementX'] ||
0;
},

getMovementY: function(event) {
getMovementY(event) {
return event['movementY'] ||
event['mozMovementY'] ||
event['webkitMovementY'] ||
Expand All @@ -490,7 +490,7 @@ var LibraryBrowser = {
// this as an integer, don't simply cast to int, or you may receive scroll events for wheel delta == 0.
// NOTE: We convert all units returned by events into steps, i.e. individual wheel notches.
// These conversions are only approximations. Changing browsers, operating systems, or even settings can change the values.
getMouseWheelDelta: function(event) {
getMouseWheelDelta(event) {
var delta = 0;
switch (event.type) {
case 'DOMMouseScroll':
Expand Down Expand Up @@ -533,7 +533,7 @@ var LibraryBrowser = {
touches: {},
lastTouches: {},

calculateMouseEvent: function(event) { // event should be mousemove, mousedown or mouseup
calculateMouseEvent(event) { // event should be mousemove, mousedown or mouseup
if (Browser.pointerLock) {
// When the pointer is locked, calculate the coordinates
// based on the movement of the mouse.
Expand Down Expand Up @@ -618,20 +618,20 @@ var LibraryBrowser = {

resizeListeners: [],

updateResizeListeners: function() {
updateResizeListeners() {
var canvas = Module['canvas'];
Browser.resizeListeners.forEach((listener) => listener(canvas.width, canvas.height));
},

setCanvasSize: function(width, height, noUpdates) {
setCanvasSize(width, height, noUpdates) {
var canvas = Module['canvas'];
Browser.updateCanvasDimensions(canvas, width, height);
if (!noUpdates) Browser.updateResizeListeners();
},

windowedWidth: 0,
windowedHeight: 0,
setFullscreenCanvasSize: function() {
setFullscreenCanvasSize() {
// check if SDL is available
if (typeof SDL != "undefined") {
var flags = {{{ makeGetValue('SDL.screen', '0', 'u32') }}};
Expand All @@ -642,7 +642,7 @@ var LibraryBrowser = {
Browser.updateResizeListeners();
},

setWindowedCanvasSize: function() {
setWindowedCanvasSize() {
// check if SDL is available
if (typeof SDL != "undefined") {
var flags = {{{ makeGetValue('SDL.screen', '0', 'u32') }}};
Expand All @@ -653,7 +653,7 @@ var LibraryBrowser = {
Browser.updateResizeListeners();
},

updateCanvasDimensions : function(canvas, wNative, hNative) {
updateCanvasDimensions(canvas, wNative, hNative) {
if (wNative && hNative) {
canvas.widthNative = wNative;
canvas.heightNative = hNative;
Expand Down
2 changes: 1 addition & 1 deletion src/library_dylink.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ var LibraryDylink = {
loadedLibsByName: {},
// handle -> dso; Used by dlsym
loadedLibsByHandle: {},
init: () => {
init() {
#if ASSERTIONS
// This function needs to run after the initial wasmImports object
// as been created.
Expand Down
Loading

0 comments on commit 0ac2d7d

Please sign in to comment.