Skip to content

Commit c09f5a0

Browse files
authored
Simplify use of new Function in embind. NFC (emscripten-core#23954)
Passing the function body explicitly seems less magical, and also saves a little on code size.
1 parent a37420b commit c09f5a0

File tree

3 files changed

+6
-9
lines changed

3 files changed

+6
-9
lines changed

src/lib/libembind.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -858,9 +858,7 @@ var LibraryEmbind = {
858858
#else
859859

860860
let [args, invokerFnBody] = createJsInvoker(argTypes, isClassMethodFunc, returns, isAsync);
861-
args.push(invokerFnBody);
862-
var invokerFn = new Function(...args)(...closureArgs);
863-
861+
var invokerFn = new Function(...args, invokerFnBody)(...closureArgs);
864862
#endif
865863
#endif
866864
return createNamedFunction(humanName, invokerFn);

src/lib/libemval.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -381,8 +381,7 @@ var LibraryEmVal = {
381381
functionBody +=
382382
"};\n";
383383

384-
params.push(functionBody);
385-
var invokerFunction = new Function(...params)(...args);
384+
var invokerFunction = new Function(...params, functionBody)(...args);
386385
#endif
387386
var functionName = `methodCaller<(${types.map(t => t.name).join(', ')}) => ${retType.name}>`;
388387
return emval_addMethodCaller(createNamedFunction(functionName, invokerFunction));

test/code_size/embind_hello_wasm.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
{
22
"a.html": 552,
33
"a.html.gz": 380,
4-
"a.js": 9482,
5-
"a.js.gz": 4164,
4+
"a.js": 9473,
5+
"a.js.gz": 4157,
66
"a.wasm": 7348,
77
"a.wasm.gz": 3378,
8-
"total": 17382,
9-
"total_gz": 7922
8+
"total": 17373,
9+
"total_gz": 7915
1010
}

0 commit comments

Comments
 (0)