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
92 changes: 45 additions & 47 deletions src/embind/embind.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ var LibraryEmbind = {
proto[methodName] = function() {
// TODO This check can be removed in -O3 level "unsafe" optimizations.
if (!proto[methodName].overloadTable.hasOwnProperty(arguments.length)) {
throwBindingError("Function '" + humanName + "' called with an invalid number of arguments (" + arguments.length + ") - expects one of (" + proto[methodName].overloadTable + ")!");
throwBindingError(`Function '${humanName}' called with an invalid number of arguments (${arguments.length}) - expects one of (${proto[methodName].overloadTable})!`);
}
return proto[methodName].overloadTable[arguments.length].apply(this, arguments);
};
Expand All @@ -118,14 +118,14 @@ var LibraryEmbind = {
$exposePublicSymbol: function(name, value, numArguments) {
if (Module.hasOwnProperty(name)) {
if (undefined === numArguments || (undefined !== Module[name].overloadTable && undefined !== Module[name].overloadTable[numArguments])) {
throwBindingError("Cannot register public name '" + name + "' twice");
throwBindingError(`Cannot register public name '${name}' twice`);
}

// We are exposing a function with the same name as an existing function. Create an overload table and a function selector
// that routes between the two.
ensureOverloadTable(Module, name, name);
if (Module.hasOwnProperty(numArguments)) {
throwBindingError("Cannot register multiple overloads of a function with the same number of arguments (" + numArguments + ")!");
throwBindingError(`Cannot register multiple overloads of a function with the same number of arguments (${numArguments})!`);
}
// Add the new function into the overload table.
Module[name].overloadTable[numArguments] = value;
Expand Down Expand Up @@ -282,19 +282,19 @@ var LibraryEmbind = {
$registerType__docs: '/** @param {Object=} options */',
$registerType: function(rawType, registeredInstance, options = {}) {
if (!('argPackAdvance' in registeredInstance)) {
throw new TypeError('registerType registeredInstance requires argPackAdvance');
throw new TypeError('registerType registeredInstance requires argPackAdvance');
}

var name = registeredInstance.name;
if (!rawType) {
throwBindingError('type "' + name + '" must have a positive integer typeid pointer');
throwBindingError(`type "${name}" must have a positive integer typeid pointer`);
}
if (registeredTypes.hasOwnProperty(rawType)) {
if (options.ignoreDuplicateRegistrations) {
return;
} else {
throwBindingError("Cannot register type '" + name + "' twice");
}
if (options.ignoreDuplicateRegistrations) {
return;
} else {
throwBindingError(`Cannot register type '${name}' twice`);
}
}

registeredTypes[rawType] = registeredInstance;
Expand Down Expand Up @@ -546,10 +546,10 @@ var LibraryEmbind = {
var checkAssertions = (value, toTypeName) => {
#if ASSERTIONS
if (typeof value != "number" && typeof value != "boolean") {
throw new TypeError('Cannot convert "' + embindRepr(value) + '" to ' + toTypeName);
throw new TypeError(`Cannot convert "${embindRepr(value)}" to ${toTypeName}`);
}
if (value < minRange || value > maxRange) {
throw new TypeError('Passing a number "' + embindRepr(value) + '" from JS side to C/C++ side to an argument of type "' + name + '", which is outside the valid range [' + minRange + ', ' + maxRange + ']!');
throw new TypeError(`Passing a number "${embindRepr(value)}" from JS side to C/C++ side to an argument of type "${name}", which is outside the valid range [${minRange}, ${maxRange}]!`);
}
#endif
}
Expand Down Expand Up @@ -599,10 +599,10 @@ var LibraryEmbind = {
},
'toWireType': function (destructors, value) {
if (typeof value != "bigint" && typeof value != "number") {
throw new TypeError('Cannot convert "' + embindRepr(value) + '" to ' + this.name);
throw new TypeError(`Cannot convert "${embindRepr(value)}" to ${this.name}`);
}
if (value < minRange || value > maxRange) {
throw new TypeError('Passing a number "' + embindRepr(value) + '" from JS side to C/C++ side to an argument of type "' + name + '", which is outside the valid range [' + minRange + ', ' + maxRange + ']!');
throw new TypeError(`Passing a number "${embindRepr(value)}" from JS side to C/C++ side to an argument of type "${name}", which is outside the valid range [${minRange}, ${maxRange}]!`);
}
return value;
},
Expand Down Expand Up @@ -630,7 +630,7 @@ var LibraryEmbind = {
'toWireType': function(destructors, value) {
#if ASSERTIONS
if (typeof value != "number" && typeof value != "boolean") {
throw new TypeError('Cannot convert "' + embindRepr(value) + '" to ' + this.name);
throw new TypeError(`Cannot convert ${embindRepr(value)} to ${this.name}`);
}
#endif
// The VM will perform JS to Wasm value conversion, according to the spec:
Expand Down Expand Up @@ -902,7 +902,7 @@ var LibraryEmbind = {
$newFunc__deps: ['$createNamedFunction'],
$newFunc: function(constructor, argumentList) {
if (!(constructor instanceof Function)) {
throw new TypeError('new_ called with constructor type ' + typeof(constructor) + " which is not a function");
throw new TypeError(`new_ called with constructor type ${typeof(constructor)} which is not a function`);
}
/*
* Previously, the following line was just:
Expand Down Expand Up @@ -990,9 +990,7 @@ var LibraryEmbind = {
var destructors = [];
return function() {
if (arguments.length !== expectedArgCount) {
throwBindingError('function ' + humanName + ' called with ' +
arguments.length + ' arguments, expected ' + expectedArgCount +
' args!');
throwBindingError(`function ${humanName} called with ${arguments.length} arguments, expected ${expectedArgCount} args!`);
}
#if EMSCRIPTEN_TRACING
Module.emscripten_trace_enter_context('embind::' + humanName);
Expand Down Expand Up @@ -1060,7 +1058,7 @@ var LibraryEmbind = {
"}\n";

#if EMSCRIPTEN_TRACING
invokerFnBody += "Module.emscripten_trace_enter_context('embind::" + humanName + "');\n";
invokerFnBody += `Module.emscripten_trace_enter_context('embind::${humanName}');\n`;
#endif

if (needsDestructorStack) {
Expand Down Expand Up @@ -1169,7 +1167,7 @@ var LibraryEmbind = {

var fp = makeDynCaller();
if (typeof fp != "function") {
throwBindingError("unknown function pointer with signature " + signature + ": " + rawFunction);
throwBindingError(`unknown function pointer with signature ${signature}: ${rawFunction}`);
}
return fp;
},
Expand All @@ -1185,7 +1183,7 @@ var LibraryEmbind = {
rawInvoker = embind__requireFunction(signature, rawInvoker);

exposePublicSymbol(name, function() {
throwUnboundTypeError('Cannot call ' + name + ' due to unbound types', argTypes);
throwUnboundTypeError(`Cannot call ${name} due to unbound types`, argTypes);
}, argCount - 1);

whenDependentTypesAreResolved([], argTypes, function(argTypes) {
Expand Down Expand Up @@ -1282,7 +1280,7 @@ var LibraryEmbind = {
},
'toWireType': function(destructors, o) {
if (elementsLength !== o.length) {
throw new TypeError("Incorrect number of tuple elements for " + reg.name + ": expected=" + elementsLength + ", actual=" + o.length);
throw new TypeError(`Incorrect number of tuple elements for ${reg.name}: expected=${elementsLength}, actual=${o.length}`);
}
var ptr = rawConstructor();
for (var i = 0; i < elementsLength; ++i) {
Expand Down Expand Up @@ -1395,7 +1393,7 @@ var LibraryEmbind = {
// assume all fields are present without checking.
for (var fieldName in fields) {
if (!(fieldName in o)) {
throw new TypeError('Missing field: "' + fieldName + '"');
throw new TypeError(`Missing field: "${fieldName}"`);
}
}
var ptr = rawConstructor();
Expand Down Expand Up @@ -1434,13 +1432,13 @@ var LibraryEmbind = {
}

if (!handle.$$) {
throwBindingError('Cannot pass "' + embindRepr(handle) + '" as a ' + this.name);
throwBindingError(`Cannot pass "${embindRepr(handle)}" as a ${this.name}`);
}
if (!handle.$$.ptr) {
throwBindingError('Cannot pass deleted object as a pointer of type ' + this.name);
throwBindingError(`Cannot pass deleted object as a pointer of type ${this.name}`);
}
if (!this.isConst && handle.$$.ptrType.isConst) {
throwBindingError('Cannot convert argument of type ' + (handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name) + ' to parameter type ' + this.name);
throwBindingError(`Cannot convert argument of type ${(handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name)} to parameter type ${this.name}`);
}
var handleClass = handle.$$.ptrType.registeredClass;
ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
Expand All @@ -1459,7 +1457,7 @@ var LibraryEmbind = {
if (handle.$$.smartPtrType === this) {
ptr = handle.$$.smartPtr;
} else {
throwBindingError('Cannot convert argument of type ' + (handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name) + ' to parameter type ' + this.name);
throwBindingError(`Cannot convert argument of type ${(handle.$$.smartPtrType ? handle.$$.smartPtrType.name : handle.$$.ptrType.name)} to parameter type ${this.name}`);
}
break;

Expand Down Expand Up @@ -1503,7 +1501,7 @@ var LibraryEmbind = {
}

if (!handle.$$) {
throwBindingError('Cannot pass "' + embindRepr(handle) + '" as a ' + this.name);
throwBindingError(`Cannot pass "${embindRepr(handle)}" as a ${this.name}`);
}
if (!handle.$$.ptr) {
throwBindingError('Cannot pass deleted object as a pointer of type ' + this.name);
Expand All @@ -1525,13 +1523,13 @@ var LibraryEmbind = {
}

if (!handle.$$) {
throwBindingError('Cannot pass "' + embindRepr(handle) + '" as a ' + this.name);
throwBindingError(`Cannot pass "${embindRepr(handle)}" as a ${this.name}`);
}
if (!handle.$$.ptr) {
throwBindingError('Cannot pass deleted object as a pointer of type ' + this.name);
throwBindingError(`Cannot pass deleted object as a pointer of type ${this.name}`);
}
if (handle.$$.ptrType.isConst) {
throwBindingError('Cannot convert argument of type ' + handle.$$.ptrType.name + ' to parameter type ' + this.name);
throwBindingError(`Cannot convert argument of type ${handle.$$.ptrType.name} to parameter type ${this.name}`);
}
var handleClass = handle.$$.ptrType.registeredClass;
var ptr = upcastPointer(handle.$$.ptr, handleClass, this.registeredClass);
Expand Down Expand Up @@ -1768,7 +1766,7 @@ var LibraryEmbind = {
// This is more useful than the empty stacktrace of `FinalizationRegistry`
// callback.
var cls = $$.ptrType.registeredClass;
info.leakWarning = new Error("Embind found a leaked C++ instance " + cls.name + " <" + ptrToString($$.ptr) + ">.\n" +
info.leakWarning = new Error(`Embind found a leaked C++ instance ${cls.name} <${ptrToString($$.ptr)}>.\n` +
"We'll free it automatically in this case, but this functionality is not reliable across various environments.\n" +
"Make sure to invoke .delete() manually once you're done with the instance instead.\n" +
"Originally allocated"); // `.stack` will add "at ..." after this sentence
Expand Down Expand Up @@ -2002,7 +2000,7 @@ var LibraryEmbind = {

exposePublicSymbol(legalFunctionName, function() {
// this code cannot run if baseClassRawType is zero
throwUnboundTypeError('Cannot construct ' + name + ' due to unbound types', [baseClassRawType]);
throwUnboundTypeError(`Cannot construct ${name} due to unbound types`, [baseClassRawType]);
});

whenDependentTypesAreResolved(
Expand All @@ -2029,7 +2027,7 @@ var LibraryEmbind = {
}
var body = registeredClass.constructor_body[arguments.length];
if (undefined === body) {
throw new BindingError("Tried to invoke ctor of " + name + " with invalid number of parameters (" + arguments.length + ") - expected (" + Object.keys(registeredClass.constructor_body).toString() + ") parameters instead!");
throw new BindingError(`Tried to invoke ctor of ${name} with invalid number of parameters (${arguments.length}) - expected (${Object.keys(registeredClass.constructor_body).toString()}) parameters instead!`);
}
return body.apply(this, arguments);
});
Expand Down Expand Up @@ -2105,10 +2103,10 @@ var LibraryEmbind = {
classType.registeredClass.constructor_body = [];
}
if (undefined !== classType.registeredClass.constructor_body[argCount - 1]) {
throw new BindingError("Cannot register multiple constructors with identical number of parameters (" + (argCount-1) + ") for class '" + classType.name + "'! Overload resolution is currently only performed using the parameter count, not actual type info!");
throw new BindingError(`Cannot register multiple constructors with identical number of parameters (${argCount-1}) for class '${classType.name}'! Overload resolution is currently only performed using the parameter count, not actual type info!`);
}
classType.registeredClass.constructor_body[argCount - 1] = () => {
throwUnboundTypeError('Cannot construct ' + classType.name + ' due to unbound types', rawArgTypes);
throwUnboundTypeError(`Cannot construct ${classType.name} due to unbound types`, rawArgTypes);
};

whenDependentTypesAreResolved([], rawArgTypes, function(argTypes) {
Expand Down Expand Up @@ -2140,7 +2138,7 @@ var LibraryEmbind = {
$upcastPointer: function(ptr, ptrClass, desiredClass) {
while (ptrClass !== desiredClass) {
if (!ptrClass.upcast) {
throwBindingError("Expected null or instance of " + desiredClass.name + ", got an instance of " + ptrClass.name);
throwBindingError(`Expected null or instance of ${desiredClass.name}, got an instance of ${ptrClass.name}`);
}
ptr = ptrClass.upcast(ptr);
ptrClass = ptrClass.baseClass;
Expand All @@ -2157,7 +2155,7 @@ var LibraryEmbind = {
throwBindingError(humanName + ' incompatible with "this" of type ' + this_.constructor.name);
}
if (!this_.$$.ptr) {
throwBindingError('cannot call emscripten binding method ' + humanName + ' on deleted object');
throwBindingError(`cannot call emscripten binding method ${humanName} on deleted object`);
}

// todo: kill this
Expand Down Expand Up @@ -2196,7 +2194,7 @@ var LibraryEmbind = {
}

function unboundTypesHandler() {
throwUnboundTypeError('Cannot call ' + humanName + ' due to unbound types', rawArgTypes);
throwUnboundTypeError(`Cannot call ${humanName} due to unbound types`, rawArgTypes);
}

var proto = classType.registeredClass.instancePrototype;
Expand Down Expand Up @@ -2255,14 +2253,14 @@ var LibraryEmbind = {
var humanName = classType.name + '.' + fieldName;
var desc = {
get: function() {
throwUnboundTypeError('Cannot access ' + humanName + ' due to unbound types', [getterReturnType, setterArgumentType]);
throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`, [getterReturnType, setterArgumentType]);
},
enumerable: true,
configurable: true
};
if (setter) {
desc.set = () => {
throwUnboundTypeError('Cannot access ' + humanName + ' due to unbound types', [getterReturnType, setterArgumentType]);
throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`, [getterReturnType, setterArgumentType]);
};
} else {
desc.set = (v) => {
Expand Down Expand Up @@ -2324,7 +2322,7 @@ var LibraryEmbind = {
var humanName = classType.name + '.' + methodName;

function unboundTypesHandler() {
throwUnboundTypeError('Cannot call ' + humanName + ' due to unbound types', rawArgTypes);
throwUnboundTypeError(`Cannot call ${humanName} due to unbound types`, rawArgTypes);
}

if (methodName.startsWith("@@")) {
Expand Down Expand Up @@ -2381,18 +2379,18 @@ var LibraryEmbind = {
var humanName = classType.name + '.' + fieldName;
var desc = {
get: function() {
throwUnboundTypeError('Cannot access ' + humanName + ' due to unbound types', [rawFieldType]);
throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`, [rawFieldType]);
},
enumerable: true,
configurable: true
};
if (setter) {
desc.set = () => {
throwUnboundTypeError('Cannot access ' + humanName + ' due to unbound types', [rawFieldType]);
throwUnboundTypeError(`Cannot access ${humanName} due to unbound types`, [rawFieldType]);
};
} else {
desc.set = (v) => {
throwBindingError(humanName + ' is a read-only property');
throwBindingError(`${humanName} is a read-only property`);
};
}

Expand Down Expand Up @@ -2445,7 +2443,7 @@ var LibraryEmbind = {
var ctor = createNamedFunction(constructorName, function() {
registeredClass.baseClass.pureVirtualFunctions.forEach(function(name) {
if (this[name] === baseClassPrototype[name]) {
throw new PureVirtualError('Pure virtual function ' + name + ' must be implemented in JavaScript');
throw new PureVirtualError(`Pure virtual function ${name} must be implemented in JavaScript`);
}
}.bind(this));

Expand Down
Loading