Skip to content

ifdef demangle JS support code, include it only when needed #5857

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 28, 2017
Merged
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
50 changes: 27 additions & 23 deletions src/preamble.js
Original file line number Diff line number Diff line change
Expand Up @@ -791,36 +791,40 @@ function lengthBytesUTF32(str) {
{{{ maybeExport('lengthBytesUTF32') }}}

function demangle(func) {
#if DEMANGLE_SUPPORT
var __cxa_demangle_func = Module['___cxa_demangle'] || Module['__cxa_demangle'];
if (__cxa_demangle_func) {
try {
var s =
assert(__cxa_demangle_func);
try {
var s =
#if WASM_BACKEND
func;
func;
#else
func.substr(1);
#endif
var len = lengthBytesUTF8(s)+1;
var buf = _malloc(len);
stringToUTF8(s, buf, len);
var status = _malloc(4);
var ret = __cxa_demangle_func(buf, 0, 0, status);
if (getValue(status, 'i32') === 0 && ret) {
return Pointer_stringify(ret);
}
// otherwise, libcxxabi failed
} catch(e) {
// ignore problems here
} finally {
if (buf) _free(buf);
if (status) _free(status);
if (ret) _free(ret);
func.substr(1);
#endif
var len = lengthBytesUTF8(s)+1;
var buf = _malloc(len);
stringToUTF8(s, buf, len);
var status = _malloc(4);
var ret = __cxa_demangle_func(buf, 0, 0, status);
if (getValue(status, 'i32') === 0 && ret) {
return Pointer_stringify(ret);
}
// failure when using libcxxabi, don't demangle
return func;
// otherwise, libcxxabi failed
} catch(e) {
// ignore problems here
} finally {
if (buf) _free(buf);
if (status) _free(status);
if (ret) _free(ret);
}
// failure when using libcxxabi, don't demangle
return func;
#else // DEMANGLE_SUPPORT
#if ASSERTIONS
Runtime.warnOnce('warning: build with -s DEMANGLE_SUPPORT=1 to link in libcxxabi demangling');
#endif // ASSERTIONS
return func;
#endif // DEMANGLE_SUPPORT
}

function demangleAll(text) {
Expand Down