Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(172)

Unified Diff: sdk/lib/_internal/js_runtime/lib/core_patch.dart

Issue 1448003002: Add StackTrace.current getter. (Closed) Base URL: https://github.com/dart-lang/sdk.git@master
Patch Set: Created 5 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/js_runtime/lib/core_patch.dart
diff --git a/sdk/lib/_internal/js_runtime/lib/core_patch.dart b/sdk/lib/_internal/js_runtime/lib/core_patch.dart
index 301517ee669f5a532008375f12048c4f37bc0ba0..b448327caa13ab4f816e461a623b30eb75068822 100644
--- a/sdk/lib/_internal/js_runtime/lib/core_patch.dart
+++ b/sdk/lib/_internal/js_runtime/lib/core_patch.dart
@@ -671,3 +671,22 @@ class _Resource implements Resource {
});
}
}
+
+@patch
+class StackTrace {
+ @patch static StackTrace get current {
+ var error = JS("Object", "new Error()");
sra1 2015/11/17 19:11:37 Don't use "Object". That means any subclass of Obj
Lasse Reichstein Nielsen 2015/11/18 10:11:39 Done
+ var stack = JS("Object", "#.stack", error);
sra1 2015/11/17 19:11:37 The type here should be 'String|Null'. That will g
Lasse Reichstein Nielsen 2015/11/18 10:11:39 Done.
+ if (stack != null) return new StackTrace.fromString(stack);
sra1 2015/11/17 19:11:37 It would be a little safer for this test to be 'is
Lasse Reichstein Nielsen 2015/11/18 10:11:39 Done
+ if (JS("Object", "Error.captureStackTrace") != null) {
+ JS("void", "Error.captureStackTrace(#)", error);
+ var stack = JS("Object", "#.stack", error);
sra1 2015/11/17 19:11:37 'String|Null'
Lasse Reichstein Nielsen 2015/11/18 10:11:39 Done.
Lasse Reichstein Nielsen 2015/11/18 10:11:39 Done.
+ if (stack != null) return new StackTrace.fromString(stack);
+ }
+ try {
+ throw 0;
floitsch 2015/11/16 19:30:21 Which browsers still need this?
Lasse Reichstein Nielsen 2015/11/17 13:18:53 IE11 as far as I can see. Don't know about Safari
+ } catch (_, stackTrace) {
+ return stackTrace;
sra1 2015/11/17 19:11:37 This there a measurable performance benefit over s
Lasse Reichstein Nielsen 2015/11/18 10:11:39 It's not about performance, but about not interfer
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698