Skip to content

Commit d6d34ea

Browse files
authored
Use more string templates in embind (#23984)
1 parent 7df1455 commit d6d34ea

File tree

4 files changed

+32
-31
lines changed

4 files changed

+32
-31
lines changed

src/lib/libembind.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -763,7 +763,7 @@ var LibraryEmbind = {
763763
// TODO: Remove this completely once all function invokers are being dynamically generated.
764764
var needsDestructorStack = usesDestructorStack(argTypes);
765765

766-
var returns = (argTypes[0].name !== "void");
766+
var returns = (argTypes[0].name !== 'void');
767767

768768
var expectedArgCount = argCount - 2;
769769
#if ASSERTIONS
@@ -842,7 +842,8 @@ var LibraryEmbind = {
842842
closureArgs.push(Asyncify);
843843
#endif
844844
if (!needsDestructorStack) {
845-
for (var i = isClassMethodFunc?1:2; i < argTypes.length; ++i) { // Skip return value at index 0 - it's not deleted here. Also skip class type if not a method.
845+
// Skip return value at index 0 - it's not deleted here. Also skip class type if not a method.
846+
for (var i = isClassMethodFunc?1:2; i < argTypes.length; ++i) {
846847
if (argTypes[i].destructorFunction !== null) {
847848
closureArgs.push(argTypes[i].destructorFunction);
848849
}
@@ -901,7 +902,7 @@ var LibraryEmbind = {
901902
}
902903

903904
var fp = makeDynCaller();
904-
if (typeof fp != "function") {
905+
if (typeof fp != 'function') {
905906
throwBindingError(`unknown function pointer with signature ${signature}: ${rawFunction}`);
906907
}
907908
return fp;
@@ -1632,7 +1633,7 @@ var LibraryEmbind = {
16321633
// Support `using ...` from https://github.com/tc39/proposal-explicit-resource-management.
16331634
const symbolDispose = Symbol.dispose;
16341635
if (symbolDispose) {
1635-
proto[symbolDispose] = proto["delete"];
1636+
proto[symbolDispose] = proto['delete'];
16361637
}
16371638
},
16381639

@@ -1753,10 +1754,10 @@ var LibraryEmbind = {
17531754

17541755
var constructor = createNamedFunction(name, function(...args) {
17551756
if (Object.getPrototypeOf(this) !== instancePrototype) {
1756-
throw new BindingError("Use 'new' to construct " + name);
1757+
throw new BindingError(`Use 'new' to construct ${name}`);
17571758
}
17581759
if (undefined === registeredClass.constructor_body) {
1759-
throw new BindingError(name + " has no accessible constructor");
1760+
throw new BindingError(`${name} has no accessible constructor`);
17601761
}
17611762
var body = registeredClass.constructor_body[args.length];
17621763
if (undefined === body) {
@@ -2069,7 +2070,7 @@ var LibraryEmbind = {
20692070
throwUnboundTypeError(`Cannot call ${humanName} due to unbound types`, rawArgTypes);
20702071
}
20712072

2072-
if (methodName.startsWith("@@")) {
2073+
if (methodName.startsWith('@@')) {
20732074
methodName = Symbol[methodName.substring(2)];
20742075
}
20752076

@@ -2202,20 +2203,20 @@ var LibraryEmbind = {
22022203
Object.defineProperty(this, '__parent', {
22032204
value: wrapperPrototype
22042205
});
2205-
this["__construct"](...args);
2206+
this['__construct'](...args);
22062207
});
22072208

22082209
// It's a little nasty that we're modifying the wrapper prototype here.
22092210

2210-
wrapperPrototype["__construct"] = function __construct(...args) {
2211+
wrapperPrototype['__construct'] = function __construct(...args) {
22112212
if (this === wrapperPrototype) {
22122213
throwBindingError("Pass correct 'this' to __construct");
22132214
}
22142215

2215-
var inner = baseConstructor["implement"](this, ...args);
2216+
var inner = baseConstructor['implement'](this, ...args);
22162217
detachFinalizer(inner);
22172218
var $$ = inner.$$;
2218-
inner["notifyOnDestruction"]();
2219+
inner['notifyOnDestruction']();
22192220
$$.preservePointerOnDelete = true;
22202221
Object.defineProperties(this, { $$: {
22212222
value: $$
@@ -2224,7 +2225,7 @@ var LibraryEmbind = {
22242225
registerInheritedInstance(registeredClass, $$.ptr, this);
22252226
};
22262227

2227-
wrapperPrototype["__destruct"] = function __destruct() {
2228+
wrapperPrototype['__destruct'] = function __destruct() {
22282229
if (this === wrapperPrototype) {
22292230
throwBindingError("Pass correct 'this' to __destruct");
22302231
}

src/lib/libemval.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ var LibraryEmVal = {
6868
$Emval: {
6969
toValue: (handle) => {
7070
if (!handle) {
71-
throwBindingError('Cannot use deleted val. handle = ' + handle);
71+
throwBindingError(`Cannot use deleted val. handle = ${handle}`);
7272
}
7373
#if ASSERTIONS
7474
// handle 2 is supposed to be `undefined`.
@@ -294,8 +294,8 @@ var LibraryEmVal = {
294294
$emval_lookupTypes: (argCount, argTypes) => {
295295
var a = new Array(argCount);
296296
for (var i = 0; i < argCount; ++i) {
297-
a[i] = requireRegisteredType({{{ makeGetValue('argTypes', 'i * ' + POINTER_SIZE, '*') }}},
298-
"parameter " + i);
297+
a[i] = requireRegisteredType({{{ makeGetValue('argTypes', `i*${POINTER_SIZE}`, '*') }}},
298+
`parameter ${i}`);
299299
}
300300
return a;
301301
},
@@ -357,26 +357,26 @@ var LibraryEmVal = {
357357
var offset = 0;
358358
var argsList = []; // 'obj?, arg0, arg1, arg2, ... , argN'
359359
if (kind === /* FUNCTION */ 0) {
360-
argsList.push("obj");
360+
argsList.push('obj');
361361
}
362-
var params = ["retType"];
362+
var params = ['retType'];
363363
var args = [retType];
364364
for (var i = 0; i < argCount; ++i) {
365-
argsList.push("arg" + i);
366-
params.push("argType" + i);
365+
argsList.push(`arg${i}`);
366+
params.push(`argType${i}`);
367367
args.push(types[i]);
368368
functionBody +=
369-
` var arg${i} = argType${i}.readValueFromPointer(args${offset ? "+" + offset : ""});\n`;
369+
` var arg${i} = argType${i}.readValueFromPointer(args${offset ? '+' + offset : ''});\n`;
370370
offset += types[i].argPackAdvance;
371371
}
372372
var invoker = kind === /* CONSTRUCTOR */ 1 ? 'new func' : 'func.call';
373373
functionBody +=
374-
` var rv = ${invoker}(${argsList.join(", ")});\n`;
374+
` var rv = ${invoker}(${argsList.join(', ')});\n`;
375375
if (!retType.isVoid) {
376-
params.push("emval_returnValue");
376+
params.push('emval_returnValue');
377377
args.push(emval_returnValue);
378378
functionBody +=
379-
" return emval_returnValue(retType, destructorsRef, rv);\n";
379+
' return emval_returnValue(retType, destructorsRef, rv);\n';
380380
}
381381
functionBody +=
382382
"};\n";

test/code_size/embind_hello_wasm.json

Lines changed: 4 additions & 4 deletions
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": 9473,
5-
"a.js.gz": 4157,
4+
"a.js": 9475,
5+
"a.js.gz": 4154,
66
"a.wasm": 7348,
77
"a.wasm.gz": 3378,
8-
"total": 17373,
9-
"total_gz": 7915
8+
"total": 17375,
9+
"total_gz": 7912
1010
}

test/code_size/embind_val_wasm.json

Lines changed: 4 additions & 4 deletions
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": 6938,
5-
"a.js.gz": 3005,
4+
"a.js": 6940,
5+
"a.js.gz": 3000,
66
"a.wasm": 9155,
77
"a.wasm.gz": 4722,
8-
"total": 16645,
9-
"total_gz": 8107
8+
"total": 16647,
9+
"total_gz": 8102
1010
}

0 commit comments

Comments
 (0)