Skip to content

Commit 5da836c

Browse files
committed
Merge pull request #2544 from juj/stacktrace_js
IE stack trace fix.
2 parents 1937fe8 + ce462a2 commit 5da836c

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

src/library.js

+1-15
Original file line numberDiff line numberDiff line change
@@ -8521,21 +8521,7 @@ LibraryManager.library = {
85218521

85228522
emscripten_get_callstack_js__deps: ['_emscripten_traverse_stack'],
85238523
emscripten_get_callstack_js: function(flags) {
8524-
var err = new Error();
8525-
if (!err.stack) {
8526-
// IE10+ special cases: It does have callstack info, but it is only populated if an Error object is thrown,
8527-
// so try that as a special-case.
8528-
try {
8529-
throw new Error(0);
8530-
} catch(e) {
8531-
err = e;
8532-
}
8533-
if (!err.stack) {
8534-
Runtime.warnOnce('emscripten_get_callstack_js is not supported on this browser!');
8535-
return '';
8536-
}
8537-
}
8538-
var callstack = err.stack.toString();
8524+
var callstack = jsStackTrace();
85398525

85408526
// Find the symbols in the callstack that corresponds to the functions that report callstack information, and remove everyhing up to these from the output.
85418527
var iThisFunc = callstack.lastIndexOf('_emscripten_log');

src/preamble.js

+18-2
Original file line numberDiff line numberDiff line change
@@ -932,9 +932,25 @@ function demangleAll(text) {
932932
return text.replace(/__Z[\w\d_]+/g, function(x) { var y = demangle(x); return x === y ? x : (x + ' [' + y + ']') });
933933
}
934934

935+
function jsStackTrace() {
936+
var err = new Error();
937+
if (!err.stack) {
938+
// IE10+ special cases: It does have callstack info, but it is only populated if an Error object is thrown,
939+
// so try that as a special-case.
940+
try {
941+
throw new Error(0);
942+
} catch(e) {
943+
err = e;
944+
}
945+
if (!err.stack) {
946+
return '(no stack trace available)';
947+
}
948+
}
949+
return err.stack.toString();
950+
}
951+
935952
function stackTrace() {
936-
var stack = new Error().stack;
937-
return stack ? demangleAll(stack) : '(no stack trace available)'; // Stack trace is not available at least on IE10 and Safari 6.
953+
return demangleAll(jsStackTrace());
938954
}
939955
Module['stackTrace'] = stackTrace;
940956

0 commit comments

Comments
 (0)