Skip to content

[embind] Remove argPackAdvance. NFC #24519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
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
24 changes: 2 additions & 22 deletions src/lib/libembind.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,13 @@
var LibraryEmbind = {
$UnboundTypeError: class extends Error {},
$PureVirtualError: class extends Error {},
$GenericWireTypeSize: {{{ 2 * POINTER_SIZE }}},
#if EMBIND_AOT
$InvokerFunctions: '<<< EMBIND_AOT_INVOKERS >>>',
#endif
// If register_type is used, emval will be registered multiple times for
// different type id's, but only a single type object is needed on the JS side
// for all of them. Store the type for reuse.
$EmValType__deps: ['_emval_decref', '$Emval', '$readPointer', '$GenericWireTypeSize'],
$EmValType__deps: ['_emval_decref', '$Emval', '$readPointer'],
$EmValType: `{
name: 'emscripten::val',
'fromWireType': (handle) => {
Expand All @@ -46,7 +45,6 @@ var LibraryEmbind = {
return rv;
},
'toWireType': (destructors, value) => Emval.toHandle(value),
argPackAdvance: GenericWireTypeSize,
'readValueFromPointer': readPointer,
destructorFunction: null, // This type does not need a destructor

Expand Down Expand Up @@ -221,11 +219,6 @@ var LibraryEmbind = {
$registerType__deps: ['$sharedRegisterType'],
$registerType__docs: '/** @param {Object=} options */',
$registerType: function(rawType, registeredInstance, options = {}) {
#if ASSERTIONS
if (registeredInstance.argPackAdvance === undefined) {
throw new TypeError('registerType registeredInstance requires argPackAdvance');
}
#endif
return sharedRegisterType(rawType, registeredInstance, options);
},

Expand All @@ -235,15 +228,14 @@ var LibraryEmbind = {
registerType(rawType, {
isVoid: true, // void return values can be optimized out sometimes
name,
argPackAdvance: 0,
'fromWireType': () => undefined,
// TODO: assert if anything else is given?
'toWireType': (destructors, o) => undefined,
});
},

_embind_register_bool__docs: '/** @suppress {globalThis} */',
_embind_register_bool__deps: ['$AsciiToString', '$registerType', '$GenericWireTypeSize'],
_embind_register_bool__deps: ['$AsciiToString', '$registerType'],
_embind_register_bool: (rawType, name, trueValue, falseValue) => {
name = AsciiToString(name);
registerType(rawType, {
Expand All @@ -256,7 +248,6 @@ var LibraryEmbind = {
'toWireType': function(destructors, o) {
return o ? trueValue : falseValue;
},
argPackAdvance: GenericWireTypeSize,
'readValueFromPointer': function(pointer) {
return this['fromWireType'](HEAPU8[pointer]);
},
Expand Down Expand Up @@ -363,7 +354,6 @@ var LibraryEmbind = {
// https://www.w3.org/TR/wasm-js-api-1/#towebassemblyvalue
return value;
},
argPackAdvance: GenericWireTypeSize,
'readValueFromPointer': integerReadValueFromPointer(name, size, minRange !== 0),
destructorFunction: null, // This type does not need a destructor
});
Expand Down Expand Up @@ -415,7 +405,6 @@ var LibraryEmbind = {
#endif
return value;
},
argPackAdvance: GenericWireTypeSize,
'readValueFromPointer': integerReadValueFromPointer(name, size, !isUnsignedType),
destructorFunction: null, // This type does not need a destructor
});
Expand Down Expand Up @@ -446,7 +435,6 @@ var LibraryEmbind = {
// https://www.w3.org/TR/wasm-js-api-1/#towebassemblyvalue
return value;
},
argPackAdvance: GenericWireTypeSize,
'readValueFromPointer': floatReadValueFromPointer(name, size),
destructorFunction: null, // This type does not need a destructor
});
Expand Down Expand Up @@ -536,7 +524,6 @@ var LibraryEmbind = {
}
return base;
},
argPackAdvance: GenericWireTypeSize,
'readValueFromPointer': readPointer,
destructorFunction(ptr) {
_free(ptr);
Expand Down Expand Up @@ -592,7 +579,6 @@ var LibraryEmbind = {
}
return ptr;
},
argPackAdvance: GenericWireTypeSize,
'readValueFromPointer': readPointer,
destructorFunction(ptr) {
_free(ptr);
Expand Down Expand Up @@ -643,7 +629,6 @@ var LibraryEmbind = {
registerType(rawType, {
name,
'fromWireType': decodeMemoryView,
argPackAdvance: GenericWireTypeSize,
'readValueFromPointer': decodeMemoryView,
}, {
ignoreDuplicateRegistrations: true,
Expand Down Expand Up @@ -971,7 +956,6 @@ var LibraryEmbind = {
}
return ptr;
},
argPackAdvance: GenericWireTypeSize,
'readValueFromPointer': readPointer,
destructorFunction: rawDestructor,
}];
Expand Down Expand Up @@ -1082,7 +1066,6 @@ var LibraryEmbind = {
}
return ptr;
},
argPackAdvance: GenericWireTypeSize,
'readValueFromPointer': readPointer,
destructorFunction: rawDestructor,
}];
Expand Down Expand Up @@ -1218,7 +1201,6 @@ var LibraryEmbind = {
'$RegisteredPointer',
'$readPointer',
'$RegisteredPointer_fromWireType',
'$GenericWireTypeSize',
],
$init_RegisteredPointer: () => {
Object.assign(RegisteredPointer.prototype, {
Expand All @@ -1231,7 +1213,6 @@ var LibraryEmbind = {
destructor(ptr) {
this.rawDestructor?.(ptr);
},
argPackAdvance: GenericWireTypeSize,
'readValueFromPointer': readPointer,
'fromWireType': RegisteredPointer_fromWireType,
});
Expand Down Expand Up @@ -2255,7 +2236,6 @@ var LibraryEmbind = {
return this.constructor.values[c];
},
'toWireType': (destructors, c) => c.value,
argPackAdvance: GenericWireTypeSize,
'readValueFromPointer': enumReadValueFromPointer(name, size, isSigned),
destructorFunction: null,
});
Expand Down
6 changes: 4 additions & 2 deletions src/lib/libemval.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,8 @@ var LibraryEmVal = {
'$createNamedFunction', '$emval_returnValue',
],
_emval_get_method_caller: (argCount, argTypes, kind) => {
var GenericWireTypeSize = {{{ 2 * POINTER_SIZE }}};

var types = emval_lookupTypes(argCount, argTypes);
var retType = types.shift();
argCount--; // remove the shifted off return type
Expand All @@ -320,7 +322,7 @@ var LibraryEmVal = {
var offset = 0;
for (var i = 0; i < argCount; ++i) {
argN[i] = types[i]['readValueFromPointer'](args + offset);
offset += types[i].argPackAdvance;
offset += GenericWireTypeSize;
}
var rv = kind === /* CONSTRUCTOR */ 1 ? Reflect.construct(func, argN) : func.apply(obj, argN);
return emval_returnValue(retType, destructorsRef, rv);
Expand All @@ -342,7 +344,7 @@ var LibraryEmVal = {
args.push(types[i]);
functionBody +=
` var arg${i} = argType${i}.readValueFromPointer(args${offset ? '+' + offset : ''});\n`;
offset += types[i].argPackAdvance;
offset += GenericWireTypeSize;
}
var invoker = kind === /* CONSTRUCTOR */ 1 ? 'new func' : 'func.call';
functionBody +=
Expand Down
8 changes: 4 additions & 4 deletions test/code_size/embind_hello_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 552,
"a.html.gz": 380,
"a.js": 7716,
"a.js.gz": 3372,
"a.js": 7680,
"a.js.gz": 3363,
"a.wasm": 7290,
"a.wasm.gz": 3343,
"total": 15558,
"total_gz": 7095
"total": 15522,
"total_gz": 7086
}
8 changes: 4 additions & 4 deletions test/code_size/embind_val_wasm.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"a.html": 552,
"a.html.gz": 380,
"a.js": 5726,
"a.js.gz": 2548,
"a.js": 5685,
"a.js.gz": 2538,
"a.wasm": 9083,
"a.wasm.gz": 4682,
"total": 15361,
"total_gz": 7610
"total": 15320,
"total_gz": 7600
}