Skip to content
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
25 changes: 13 additions & 12 deletions src/lib/libembind.js
Original file line number Diff line number Diff line change
Expand Up @@ -763,7 +763,7 @@ var LibraryEmbind = {
// TODO: Remove this completely once all function invokers are being dynamically generated.
var needsDestructorStack = usesDestructorStack(argTypes);

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

var expectedArgCount = argCount - 2;
#if ASSERTIONS
Expand Down Expand Up @@ -842,7 +842,8 @@ var LibraryEmbind = {
closureArgs.push(Asyncify);
#endif
if (!needsDestructorStack) {
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.
// Skip return value at index 0 - it's not deleted here. Also skip class type if not a method.
for (var i = isClassMethodFunc?1:2; i < argTypes.length; ++i) {
if (argTypes[i].destructorFunction !== null) {
closureArgs.push(argTypes[i].destructorFunction);
}
Expand Down Expand Up @@ -901,7 +902,7 @@ var LibraryEmbind = {
}

var fp = makeDynCaller();
if (typeof fp != "function") {
if (typeof fp != 'function') {
throwBindingError(`unknown function pointer with signature ${signature}: ${rawFunction}`);
}
return fp;
Expand Down Expand Up @@ -1632,7 +1633,7 @@ var LibraryEmbind = {
// Support `using ...` from https://github.com/tc39/proposal-explicit-resource-management.
const symbolDispose = Symbol.dispose;
if (symbolDispose) {
proto[symbolDispose] = proto["delete"];
proto[symbolDispose] = proto['delete'];
}
},

Expand Down Expand Up @@ -1753,10 +1754,10 @@ var LibraryEmbind = {

var constructor = createNamedFunction(name, function(...args) {
if (Object.getPrototypeOf(this) !== instancePrototype) {
throw new BindingError("Use 'new' to construct " + name);
throw new BindingError(`Use 'new' to construct ${name}`);
}
if (undefined === registeredClass.constructor_body) {
throw new BindingError(name + " has no accessible constructor");
throw new BindingError(`${name} has no accessible constructor`);
}
var body = registeredClass.constructor_body[args.length];
if (undefined === body) {
Expand Down Expand Up @@ -2069,7 +2070,7 @@ var LibraryEmbind = {
throwUnboundTypeError(`Cannot call ${humanName} due to unbound types`, rawArgTypes);
}

if (methodName.startsWith("@@")) {
if (methodName.startsWith('@@')) {
methodName = Symbol[methodName.substring(2)];
}

Expand Down Expand Up @@ -2202,20 +2203,20 @@ var LibraryEmbind = {
Object.defineProperty(this, '__parent', {
value: wrapperPrototype
});
this["__construct"](...args);
this['__construct'](...args);
});

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

wrapperPrototype["__construct"] = function __construct(...args) {
wrapperPrototype['__construct'] = function __construct(...args) {
if (this === wrapperPrototype) {
throwBindingError("Pass correct 'this' to __construct");
}

var inner = baseConstructor["implement"](this, ...args);
var inner = baseConstructor['implement'](this, ...args);
detachFinalizer(inner);
var $$ = inner.$$;
inner["notifyOnDestruction"]();
inner['notifyOnDestruction']();
$$.preservePointerOnDelete = true;
Object.defineProperties(this, { $$: {
value: $$
Expand All @@ -2224,7 +2225,7 @@ var LibraryEmbind = {
registerInheritedInstance(registeredClass, $$.ptr, this);
};

wrapperPrototype["__destruct"] = function __destruct() {
wrapperPrototype['__destruct'] = function __destruct() {
if (this === wrapperPrototype) {
throwBindingError("Pass correct 'this' to __destruct");
}
Expand Down
22 changes: 11 additions & 11 deletions src/lib/libemval.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ var LibraryEmVal = {
$Emval: {
toValue: (handle) => {
if (!handle) {
throwBindingError('Cannot use deleted val. handle = ' + handle);
throwBindingError(`Cannot use deleted val. handle = ${handle}`);
}
#if ASSERTIONS
// handle 2 is supposed to be `undefined`.
Expand Down Expand Up @@ -294,8 +294,8 @@ var LibraryEmVal = {
$emval_lookupTypes: (argCount, argTypes) => {
var a = new Array(argCount);
for (var i = 0; i < argCount; ++i) {
a[i] = requireRegisteredType({{{ makeGetValue('argTypes', 'i * ' + POINTER_SIZE, '*') }}},
"parameter " + i);
a[i] = requireRegisteredType({{{ makeGetValue('argTypes', `i*${POINTER_SIZE}`, '*') }}},
`parameter ${i}`);
}
return a;
},
Expand Down Expand Up @@ -357,26 +357,26 @@ var LibraryEmVal = {
var offset = 0;
var argsList = []; // 'obj?, arg0, arg1, arg2, ... , argN'
if (kind === /* FUNCTION */ 0) {
argsList.push("obj");
argsList.push('obj');
}
var params = ["retType"];
var params = ['retType'];
var args = [retType];
for (var i = 0; i < argCount; ++i) {
argsList.push("arg" + i);
params.push("argType" + i);
argsList.push(`arg${i}`);
params.push(`argType${i}`);
args.push(types[i]);
functionBody +=
` var arg${i} = argType${i}.readValueFromPointer(args${offset ? "+" + offset : ""});\n`;
` var arg${i} = argType${i}.readValueFromPointer(args${offset ? '+' + offset : ''});\n`;
offset += types[i].argPackAdvance;
}
var invoker = kind === /* CONSTRUCTOR */ 1 ? 'new func' : 'func.call';
functionBody +=
` var rv = ${invoker}(${argsList.join(", ")});\n`;
` var rv = ${invoker}(${argsList.join(', ')});\n`;
if (!retType.isVoid) {
params.push("emval_returnValue");
params.push('emval_returnValue');
args.push(emval_returnValue);
functionBody +=
" return emval_returnValue(retType, destructorsRef, rv);\n";
' return emval_returnValue(retType, destructorsRef, rv);\n';
}
functionBody +=
"};\n";
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": 9473,
"a.js.gz": 4157,
"a.js": 9475,
"a.js.gz": 4154,
"a.wasm": 7348,
"a.wasm.gz": 3378,
"total": 17373,
"total_gz": 7915
"total": 17375,
"total_gz": 7912
}
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": 6938,
"a.js.gz": 3005,
"a.js": 6940,
"a.js.gz": 3000,
"a.wasm": 9155,
"a.wasm.gz": 4722,
"total": 16645,
"total_gz": 8107
"total": 16647,
"total_gz": 8102
}