Skip to content

Commit 4a76853

Browse files
authored
ifdef demangle JS support code, include it only when needed (#5857)
1 parent a243a94 commit 4a76853

File tree

1 file changed

+27
-23
lines changed

1 file changed

+27
-23
lines changed

src/preamble.js

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -791,36 +791,40 @@ function lengthBytesUTF32(str) {
791791
{{{ maybeExport('lengthBytesUTF32') }}}
792792

793793
function demangle(func) {
794+
#if DEMANGLE_SUPPORT
794795
var __cxa_demangle_func = Module['___cxa_demangle'] || Module['__cxa_demangle'];
795-
if (__cxa_demangle_func) {
796-
try {
797-
var s =
796+
assert(__cxa_demangle_func);
797+
try {
798+
var s =
798799
#if WASM_BACKEND
799-
func;
800+
func;
800801
#else
801-
func.substr(1);
802-
#endif
803-
var len = lengthBytesUTF8(s)+1;
804-
var buf = _malloc(len);
805-
stringToUTF8(s, buf, len);
806-
var status = _malloc(4);
807-
var ret = __cxa_demangle_func(buf, 0, 0, status);
808-
if (getValue(status, 'i32') === 0 && ret) {
809-
return Pointer_stringify(ret);
810-
}
811-
// otherwise, libcxxabi failed
812-
} catch(e) {
813-
// ignore problems here
814-
} finally {
815-
if (buf) _free(buf);
816-
if (status) _free(status);
817-
if (ret) _free(ret);
802+
func.substr(1);
803+
#endif
804+
var len = lengthBytesUTF8(s)+1;
805+
var buf = _malloc(len);
806+
stringToUTF8(s, buf, len);
807+
var status = _malloc(4);
808+
var ret = __cxa_demangle_func(buf, 0, 0, status);
809+
if (getValue(status, 'i32') === 0 && ret) {
810+
return Pointer_stringify(ret);
818811
}
819-
// failure when using libcxxabi, don't demangle
820-
return func;
812+
// otherwise, libcxxabi failed
813+
} catch(e) {
814+
// ignore problems here
815+
} finally {
816+
if (buf) _free(buf);
817+
if (status) _free(status);
818+
if (ret) _free(ret);
821819
}
820+
// failure when using libcxxabi, don't demangle
821+
return func;
822+
#else // DEMANGLE_SUPPORT
823+
#if ASSERTIONS
822824
Runtime.warnOnce('warning: build with -s DEMANGLE_SUPPORT=1 to link in libcxxabi demangling');
825+
#endif // ASSERTIONS
823826
return func;
827+
#endif // DEMANGLE_SUPPORT
824828
}
825829

826830
function demangleAll(text) {

0 commit comments

Comments
 (0)