Skip to content

Commit 75892b3

Browse files
authored
Use arrow function in library_webgl.js. NFC (#21186)
1 parent 4aefde3 commit 75892b3

File tree

5 files changed

+31
-34
lines changed

5 files changed

+31
-34
lines changed

src/library_webgl.js

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
136136
emscripten_webgl_enable_WEBGL_multi_draw: (ctx) => webgl_enable_WEBGL_multi_draw(GL.contexts[ctx].GLctx),
137137

138138
$getEmscriptenSupportedExtensions__internal: true,
139-
$getEmscriptenSupportedExtensions: function(ctx) {
139+
$getEmscriptenSupportedExtensions: (ctx) => {
140140
// Restrict the list of advertised extensions to those that we actually
141141
// support.
142142
var supportedExtensions = [
@@ -287,7 +287,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
287287
// glGetError() to fetch it. As per GLES2 spec, only the first error is
288288
// remembered, and subsequent errors are discarded until the user has
289289
// cleared the stored error by a call to glGetError().
290-
recordError: function recordError(errorCode) {
290+
recordError: (errorCode) => {
291291
#if GL_TRACK_ERRORS
292292
if (!GL.lastError) {
293293
GL.lastError = errorCode;
@@ -377,7 +377,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
377377
}
378378
},
379379

380-
getTempVertexBuffer: function getTempVertexBuffer(sizeBytes) {
380+
getTempVertexBuffer: (sizeBytes) => {
381381
var idx = GL.log2ceilLookup(sizeBytes);
382382
var ringbuffer = GL.currentContext.tempVertexBuffers1[idx];
383383
var nextFreeBufferIndex = GL.currentContext.tempVertexBufferCounters1[idx];
@@ -394,7 +394,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
394394
return ringbuffer[nextFreeBufferIndex];
395395
},
396396

397-
getTempIndexBuffer: function getTempIndexBuffer(sizeBytes) {
397+
getTempIndexBuffer: (sizeBytes) => {
398398
var idx = GL.log2ceilLookup(sizeBytes);
399399
var ibo = GL.currentContext.tempIndexBuffers[idx];
400400
if (ibo) {
@@ -412,7 +412,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
412412
// doublebuffered temp VB memory pointers, so that every second frame
413413
// utilizes different set of temp buffers. The aim is to keep the set of
414414
// buffers being rendered, and the set of buffers being updated disjoint.
415-
newRenderingFrameStarted: function newRenderingFrameStarted() {
415+
newRenderingFrameStarted: () => {
416416
if (!GL.currentContext) {
417417
return;
418418
}
@@ -457,13 +457,13 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
457457

458458
#if GL_FFP_ONLY
459459
enabledClientAttribIndices: [],
460-
enableVertexAttribArray: function enableVertexAttribArray(index) {
460+
enableVertexAttribArray: (index) => {
461461
if (!GL.enabledClientAttribIndices[index]) {
462462
GL.enabledClientAttribIndices[index] = true;
463463
GLctx.enableVertexAttribArray(index);
464464
}
465465
},
466-
disableVertexAttribArray: function disableVertexAttribArray(index) {
466+
disableVertexAttribArray: (index) => {
467467
if (GL.enabledClientAttribIndices[index]) {
468468
GL.enabledClientAttribIndices[index] = false;
469469
GLctx.disableVertexAttribArray(index);
@@ -472,7 +472,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
472472
#endif
473473

474474
#if FULL_ES2
475-
calcBufLength: function calcBufLength(size, type, stride, count) {
475+
calcBufLength: (size, type, stride, count) => {
476476
if (stride > 0) {
477477
return count * stride; // XXXvlad this is not exactly correct I don't think
478478
}
@@ -482,7 +482,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
482482

483483
usedTempBuffers: [],
484484

485-
preDrawHandleClientVertexAttribBindings: function preDrawHandleClientVertexAttribBindings(count) {
485+
preDrawHandleClientVertexAttribBindings: (count) => {
486486
GL.resetBufferBinding = false;
487487

488488
// TODO: initial pass to detect ranges we need to upload, might not need
@@ -506,7 +506,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
506506
}
507507
},
508508

509-
postDrawHandleClientVertexAttribBindings: function postDrawHandleClientVertexAttribBindings() {
509+
postDrawHandleClientVertexAttribBindings: () => {
510510
if (GL.resetBufferBinding) {
511511
GLctx.bindBuffer(0x8892 /*GL_ARRAY_BUFFER*/, GL.buffers[GLctx.currentArrayBufferBinding]);
512512
}
@@ -3680,7 +3680,7 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
36803680
, '$emulGlGenVertexArrays'
36813681
#endif
36823682
],
3683-
glGenVertexArrays: function (n, arrays) {
3683+
glGenVertexArrays: (n, arrays) => {
36843684
#if LEGACY_GL_EMULATION
36853685
emulGlGenVertexArrays(n, arrays);
36863686
#else
@@ -4211,13 +4211,13 @@ for (/**@suppress{duplicate}*/var i = 0; i < {{{ GL_POOL_TEMP_BUFFERS_SIZE }}};
42114211
'SDL_GL_GetProcAddress',
42124212
'eglGetProcAddress',
42134213
'glfwGetProcAddress'
4214-
].forEach(function(name) {
4215-
LibraryGL[name] = function(name) { abort(); return 0; };
4214+
].forEach((name) => {
4215+
LibraryGL[name] = (name) => { abort(); return 0; };
42164216
// Due to the two pass nature of compiling .js files,
42174217
// in INCLUDE_FULL_LIBRARY mode, we must include the above
42184218
// stub functions, but not their __deps message handlers.
42194219
#if !INCLUDE_FULL_LIBRARY
4220-
LibraryGL[name + '__deps'] = [function() {
4220+
LibraryGL[name + '__deps'] = [() => {
42214221
error(`linker: Undefined symbol: ${name}(). Please pass -sGL_ENABLE_GET_PROC_ADDRESS at link time to link in ${name}().`);
42224222
}];
42234223
#endif
@@ -4242,15 +4242,12 @@ function createGLPassthroughFunctions(lib, funcs) {
42424242
const num = data[0];
42434243
const names = data[1];
42444244
const args = range(num).map((i) => 'x' + i ).join(', ');
4245-
const plainStub = `(function(${args}) { GLctx.NAME(${args}) })`;
4246-
const returnStub = `(function(${args}) { return GLctx.NAME(${args}) })`;
4245+
const stub = `(${args}) => GLctx.NAME(${args})`;
42474246
const sigEnd = range(num).map(() => 'i').join('');
42484247
names.split(' ').forEach((name) => {
4249-
let stub = plainStub;
42504248
let sig;
42514249
if (name.endsWith('*')) {
42524250
name = name.slice(0, -1);
4253-
stub = returnStub;
42544251
sig = 'i' + sigEnd;
42554252
} else {
42564253
sig = 'v' + sigEnd;

test/code_size/hello_webgl2_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 569,
33
"a.html.gz": 379,
4-
"a.js": 4584,
5-
"a.js.gz": 2351,
4+
"a.js": 4540,
5+
"a.js.gz": 2345,
66
"a.wasm": 10451,
77
"a.wasm.gz": 6724,
8-
"total": 15604,
9-
"total_gz": 9454
8+
"total": 15560,
9+
"total_gz": 9448
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 17790,
5-
"a.js.gz": 7987,
4+
"a.js": 17746,
5+
"a.js.gz": 7982,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
8-
"total": 21480,
9-
"total_gz": 11059
8+
"total": 21436,
9+
"total_gz": 11054
1010
}

test/code_size/hello_webgl_wasm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 569,
33
"a.html.gz": 379,
4-
"a.js": 4071,
5-
"a.js.gz": 2179,
4+
"a.js": 4027,
5+
"a.js.gz": 2173,
66
"a.wasm": 10451,
77
"a.wasm.gz": 6724,
8-
"total": 15091,
9-
"total_gz": 9282
8+
"total": 15047,
9+
"total_gz": 9276
1010
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 567,
33
"a.html.gz": 379,
4-
"a.js": 17263,
5-
"a.js.gz": 7819,
4+
"a.js": 17219,
5+
"a.js.gz": 7814,
66
"a.mem": 3123,
77
"a.mem.gz": 2693,
8-
"total": 20953,
9-
"total_gz": 10891
8+
"total": 20909,
9+
"total_gz": 10886
1010
}

0 commit comments

Comments
 (0)