Keep only a single active stack trace, enables traces for thrown non-exceptions

BUG=
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/2545923002 .
This commit is contained in:
Alan Knight 2016-12-01 13:41:08 -08:00
parent 4d7c536c2f
commit 1ff09b431f
8 changed files with 24 additions and 40 deletions

View file

@ -1899,14 +1899,12 @@ define([], function() {
if (!condition) dart.throwAssertionError(); if (!condition) dart.throwAssertionError();
}; };
dart.throw = function(obj) { dart.throw = function(obj) {
if (obj != null && (typeof obj == 'object' || typeof obj == 'function')) { dart._stack = new Error();
dart._stack.set(obj, new Error());
}
throw obj; throw obj;
}; };
dart.getError = function(exception) { dart.getError = function(exception) {
var stack = dart._stack.get(exception); var stack = dart._stack;
return stack !== void 0 ? stack : exception; return stack !== null ? stack : exception;
}; };
dart.stackPrint = function(exception) { dart.stackPrint = function(exception) {
var error = dart.getError(exception); var error = dart.getError(exception);
@ -2664,7 +2662,7 @@ define([], function() {
return false; return false;
}); });
})(); })();
dart._stack = new WeakMap(); dart._stack = null;
dart._value = Symbol("_value"); dart._value = Symbol("_value");
dart.constants = new Map(); dart.constants = new Map();
dart.constantLists = new Map(); dart.constantLists = new Map();

View file

@ -1899,14 +1899,12 @@
if (!condition) dart.throwAssertionError(); if (!condition) dart.throwAssertionError();
}; };
dart.throw = function(obj) { dart.throw = function(obj) {
if (obj != null && (typeof obj == 'object' || typeof obj == 'function')) { dart._stack = new Error();
dart._stack.set(obj, new Error());
}
throw obj; throw obj;
}; };
dart.getError = function(exception) { dart.getError = function(exception) {
var stack = dart._stack.get(exception); var stack = dart._stack;
return stack !== void 0 ? stack : exception; return stack !== null ? stack : exception;
}; };
dart.stackPrint = function(exception) { dart.stackPrint = function(exception) {
var error = dart.getError(exception); var error = dart.getError(exception);
@ -2664,7 +2662,7 @@
return false; return false;
}); });
})(); })();
dart._stack = new WeakMap(); dart._stack = null;
dart._value = Symbol("_value"); dart._value = Symbol("_value");
dart.constants = new Map(); dart.constants = new Map();
dart.constantLists = new Map(); dart.constantLists = new Map();

View file

@ -1897,14 +1897,12 @@ dart.assert = function(condition) {
if (!condition) dart.throwAssertionError(); if (!condition) dart.throwAssertionError();
}; };
dart.throw = function(obj) { dart.throw = function(obj) {
if (obj != null && (typeof obj == 'object' || typeof obj == 'function')) { dart._stack = new Error();
dart._stack.set(obj, new Error());
}
throw obj; throw obj;
}; };
dart.getError = function(exception) { dart.getError = function(exception) {
var stack = dart._stack.get(exception); var stack = dart._stack;
return stack !== void 0 ? stack : exception; return stack !== null ? stack : exception;
}; };
dart.stackPrint = function(exception) { dart.stackPrint = function(exception) {
var error = dart.getError(exception); var error = dart.getError(exception);
@ -2662,7 +2660,7 @@ dart._ignoreTypeFailure = (() => {
return false; return false;
}); });
})(); })();
dart._stack = new WeakMap(); dart._stack = null;
dart._value = Symbol("_value"); dart._value = Symbol("_value");
dart.constants = new Map(); dart.constants = new Map();
dart.constantLists = new Map(); dart.constantLists = new Map();

View file

@ -1900,14 +1900,12 @@ dart_library.library('dart_sdk', null, /* Imports */[
if (!condition) dart.throwAssertionError(); if (!condition) dart.throwAssertionError();
}; };
dart.throw = function(obj) { dart.throw = function(obj) {
if (obj != null && (typeof obj == 'object' || typeof obj == 'function')) { dart._stack = new Error();
dart._stack.set(obj, new Error());
}
throw obj; throw obj;
}; };
dart.getError = function(exception) { dart.getError = function(exception) {
var stack = dart._stack.get(exception); var stack = dart._stack;
return stack !== void 0 ? stack : exception; return stack !== null ? stack : exception;
}; };
dart.stackPrint = function(exception) { dart.stackPrint = function(exception) {
var error = dart.getError(exception); var error = dart.getError(exception);
@ -2665,7 +2663,7 @@ dart_library.library('dart_sdk', null, /* Imports */[
return false; return false;
}); });
})(); })();
dart._stack = new WeakMap(); dart._stack = null;
dart._value = Symbol("_value"); dart._value = Symbol("_value");
dart.constants = new Map(); dart.constants = new Map();
dart.constantLists = new Map(); dart.constantLists = new Map();

Binary file not shown.

View file

@ -1315,7 +1315,7 @@ class CodeGenerator extends GeneralizingAstVisitor
jsMethods.add(new JS.Method( jsMethods.add(new JS.Method(
_propertyName('constructor'), _propertyName('constructor'),
js.call('function(...args) { return this.new.apply(this, args); }') js.call('function(...args) { return this.new.apply(this, args); }')
as JS.Fun)); as JS.Fun));
} else if (ctors.isEmpty) { } else if (ctors.isEmpty) {
jsMethods.add(_emitImplicitConstructor(node, fields, virtualFields)); jsMethods.add(_emitImplicitConstructor(node, fields, virtualFields));
} }
@ -3968,7 +3968,7 @@ class CodeGenerator extends GeneralizingAstVisitor
new JS.Method( new JS.Method(
access, access,
js.call('function() { return #; }', _visitInitializer(node)) js.call('function() { return #; }', _visitInitializer(node))
as JS.Fun, as JS.Fun,
isGetter: true), isGetter: true),
node, node,
_findAccessor(element, getter: true))); _findAccessor(element, getter: true)));
@ -4528,7 +4528,7 @@ class CodeGenerator extends GeneralizingAstVisitor
} }
result = astFactory.prefixedIdentifier( result = astFactory.prefixedIdentifier(
_bindValue(scope, 'o', ident.prefix, context: context) _bindValue(scope, 'o', ident.prefix, context: context)
as SimpleIdentifier, as SimpleIdentifier,
ident.period, ident.period,
ident.identifier); ident.identifier);
} else { } else {

View file

@ -275,8 +275,6 @@ define(['dart_sdk', 'async_helper', 'expect', 'unittest', 'is', 'require'],
'setter_no_getter_test_01_multi': skip_fail, 'setter_no_getter_test_01_multi': skip_fail,
'stack_overflow_stacktrace_test': skip_fail, 'stack_overflow_stacktrace_test': skip_fail,
'stack_overflow_test': skip_fail, 'stack_overflow_test': skip_fail,
'stack_trace_test': skip_fail,
'stacktrace_rethrow_nonerror_test': skip_fail, // mismatch from Karma's file hash
'stacktrace_rethrow_error_test_none_multi': skip_fail, 'stacktrace_rethrow_error_test_none_multi': skip_fail,
'stacktrace_rethrow_error_test_withtraceparameter_multi': skip_fail, 'stacktrace_rethrow_error_test_withtraceparameter_multi': skip_fail,
'stacktrace_test': skip_fail, 'stacktrace_test': skip_fail,
@ -377,7 +375,6 @@ define(['dart_sdk', 'async_helper', 'expect', 'unittest', 'is', 'require'],
'regress_r21715_test': fail, 'regress_r21715_test': fail,
'throw_half_surrogate_pair_test_02_multi': fail, 'throw_half_surrogate_pair_test_02_multi': fail,
'splay_tree_from_iterable_test': firefox_fail, 'splay_tree_from_iterable_test': firefox_fail,
'stacktrace_current_test': chrome_fail,
'string_case_test_01_multi': firefox_fail, 'string_case_test_01_multi': firefox_fail,
'string_fromcharcodes_test': skip_timeout, 'string_fromcharcodes_test': skip_timeout,
'string_operations_with_null_test': fail, 'string_operations_with_null_test': fail,

View file

@ -552,25 +552,20 @@ assert_(condition) => JS(
if (!$condition) $throwAssertionError(); if (!$condition) $throwAssertionError();
})()'''); })()''');
final _stack = JS('', 'new WeakMap()'); var _stack = null;
@JSExportName('throw') @JSExportName('throw')
throw_(obj) => JS( throw_(obj) => JS(
'', '',
'''(() => { '''(() => {
if ($obj != null && (typeof $obj == 'object' || typeof $obj == 'function')) { $_stack = new Error();
// TODO(jmesserly): couldn't we store the most recent stack in a single throw $obj;
// variable? There should only be one active stack trace. That would
// allow it to work for things like strings and numbers.
$_stack.set($obj, new Error());
}
throw $obj;
})()'''); })()''');
getError(exception) => JS( getError(exception) => JS(
'', '',
'''(() => { '''(() => {
var stack = $_stack.get($exception); var stack = $_stack;
return stack !== void 0 ? stack : $exception; return stack !== null ? stack : $exception;
})()'''); })()''');
// This is a utility function: it is only intended to be called from dev // This is a utility function: it is only intended to be called from dev