Skip to content

Commit 1ddaae4

Browse files
authored
Remove embind's extendError. NFC (#23987)
These days we can just write `extends Error`.
1 parent d6d34ea commit 1ddaae4

File tree

3 files changed

+7
-35
lines changed

3 files changed

+7
-35
lines changed

src/lib/libembind.js

Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@
2828
#include "libembind_shared.js"
2929

3030
var LibraryEmbind = {
31-
$UnboundTypeError__deps: ['$extendError'],
32-
$UnboundTypeError: "=Module['UnboundTypeError'] = extendError(Error, 'UnboundTypeError')",
33-
$PureVirtualError__deps: ['$extendError'],
34-
$PureVirtualError: "=Module['PureVirtualError'] = extendError(Error, 'PureVirtualError')",
31+
$UnboundTypeError: class extends Error {},
32+
$PureVirtualError: class extends Error {},
3533
$GenericWireTypeSize: {{{ 2 * POINTER_SIZE }}},
3634
#if EMBIND_AOT
3735
$InvokerFunctions: '<<< EMBIND_AOT_OUTPUT >>>',
@@ -148,32 +146,6 @@ var LibraryEmbind = {
148146
}
149147
},
150148

151-
// from https://github.com/imvu/imvujs/blob/master/src/error.js
152-
$extendError__deps: ['$createNamedFunction'],
153-
$extendError: (baseErrorType, errorName) => {
154-
var errorClass = createNamedFunction(errorName, function(message) {
155-
this.name = errorName;
156-
this.message = message;
157-
158-
var stack = (new Error(message)).stack;
159-
if (stack !== undefined) {
160-
this.stack = this.toString() + '\n' +
161-
stack.replace(/^Error(:[^\n]*)?\n/, '');
162-
}
163-
});
164-
errorClass.prototype = Object.create(baseErrorType.prototype);
165-
errorClass.prototype.constructor = errorClass;
166-
errorClass.prototype.toString = function() {
167-
if (this.message === undefined) {
168-
return this.name;
169-
} else {
170-
return `${this.name}: ${this.message}`;
171-
}
172-
};
173-
174-
return errorClass;
175-
},
176-
177149
$createNamedFunction: (name, func) => Object.defineProperty(func, 'name', { value: name }),
178150

179151
$embindRepr: (v) => {

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": 9475,
5-
"a.js.gz": 4154,
4+
"a.js": 9094,
5+
"a.js.gz": 3993,
66
"a.wasm": 7348,
77
"a.wasm.gz": 3378,
8-
"total": 17375,
9-
"total_gz": 7912
8+
"total": 16994,
9+
"total_gz": 7751
1010
}

test/test_other.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3363,7 +3363,7 @@ def test_embind(self, *extra_args):
33633363
'-Wno-deprecated-declarations',
33643364
'-lembind',
33653365
'-sRETAIN_COMPILER_SETTINGS',
3366-
'-sEXPORTED_RUNTIME_METHODS=getCompilerSetting,setDelayFunction,flushPendingDeletes',
3366+
'-sEXPORTED_RUNTIME_METHODS=getCompilerSetting,setDelayFunction,flushPendingDeletes,PureVirtualError',
33673367
'-sWASM_ASYNC_COMPILATION=0',
33683368
# This test uses a `CustomSmartPtr` class which has 1MB of data embedded in
33693369
# it which means we need more stack space than normal.

0 commit comments

Comments
 (0)