Skip to content

Commit 22833d5

Browse files
srujzsCommit Queue
authored andcommitted
[ddc, test_runner] Add stackTrace debugger helper to dartDevEmbedder and clean up test_runner
Adds a stackTrace helper that returns a stringified StackTrace for an arbitrary error. Removes importLibrary references in test_runner now that we have that and removes some calls that didn't do anything (addAsyncCallback, removeAsyncCallback, and startRootIsolate). addAsyncCallback and removeAsyncCallback are also removed from the runtime. Calling these were removed in 8bd3690 so this is just finishing up the clean-up. Change-Id: I9dacc2b3fd3e27468061d6e59a3207eecdb7cac8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393800 Reviewed-by: Nicholas Shahan <[email protected]> Commit-Queue: Srujan Gaddam <[email protected]> Reviewed-by: Bob Nystrom <[email protected]>
1 parent 680749e commit 22833d5

File tree

3 files changed

+24
-40
lines changed

3 files changed

+24
-40
lines changed

pkg/dev_compiler/lib/js/ddc/ddc_module_loader.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,6 +1909,18 @@ if (!self.deferred_loader) {
19091909
get extensionNames() {
19101910
return dartDeveloperLibrary()._extensions.keys().toList();
19111911
}
1912+
1913+
/**
1914+
* Returns a Dart stack trace string given an error caught in JS. If the
1915+
* error is a Dart error or JS `Error`, we use the built-in stack. If the
1916+
* error is neither, we try to construct a stack trace if possible.
1917+
*
1918+
* @param {any} error The error for which a stack trace will be produced.
1919+
* @returns {String} The stringified stack trace.
1920+
*/
1921+
stackTrace(error) {
1922+
return dartRuntimeLibrary().stackTrace(error).toString();
1923+
}
19121924
}
19131925

19141926
const debugger_ = new Debugger();

pkg/test_runner/lib/src/browser.dart

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,10 @@ String ddcHtml(
172172
var hotReloadFormat = ddcModuleFormat && canaryMode;
173173

174174
var sdkAndAsyncHelperSetup = """
175-
_isolate_helper.startRootIsolate(function() {}, []);
176175
_debugger.registerDevtoolsFormatter();
177176
178177
testErrorToStackTrace = function(error) {
179-
var stackTrace = runtime.stackTrace(error).toString();
178+
var stackTrace = getStackTraceString(error);
180179
181180
var lines = stackTrace.split("\\n");
182181
@@ -195,19 +194,6 @@ testErrorToStackTrace = function(error) {
195194
// lines too.
196195
return lines.join("\\n");
197196
};
198-
199-
runtime.addAsyncCallback = function() {
200-
expect.async_helper.asyncStart();
201-
};
202-
203-
runtime.removeAsyncCallback = function() {
204-
// removeAsyncCallback() is called *before* the async operation is
205-
// performed, but we don't want to report the test as being done until
206-
// after that operation completes, so wait for that callback to run.
207-
setTimeout(() => {
208-
expect.async_helper.asyncEnd();
209-
}, 0);
210-
};
211197
""";
212198

213199
var sdkFlagSetup = """
@@ -232,12 +218,11 @@ runtime.jsInteropNonNullAsserts($jsInteropNonNullAsserts);
232218
String libraryImports;
233219
String startCode;
234220
if (hotReloadFormat) {
235-
var import = 'dartDevEmbedder.importLibrary';
236221
libraryImports = """
237-
let runtime = $import("dart:_runtime");
238-
let expect = $import("package:expect/async_helper.dart");
239-
let _isolate_helper = $import("dart:_isolate_helper");
240-
let _debugger = $import("dart:_debugger");
222+
let _debugger = dartDevEmbedder.debugger;
223+
let getStackTraceString = function(error) {
224+
return _debugger.stackTrace(error);
225+
}
241226
""";
242227
sdkFlagSetup = """
243228
let sdkOptions = {
@@ -255,8 +240,9 @@ runtime.jsInteropNonNullAsserts($jsInteropNonNullAsserts);
255240
libraryImports = """
256241
let sdk = dart_library.import("dart_sdk", "$appName");
257242
let runtime = sdk.dart;
258-
let expect = dart_library.import("expect", "$appName");
259-
let _isolate_helper = sdk._isolate_helper;
243+
let getStackTraceString = function(error) {
244+
return runtime.stackTrace(error).toString();
245+
}
260246
let _debugger = sdk._debugger;
261247
""";
262248
startCode = """dart_library.start("$appName", "$uuid", "$testName",
@@ -305,10 +291,11 @@ $packagePaths
305291
<script type="text/javascript"
306292
src="/root_dart/third_party/requirejs/require.js"></script>
307293
<script type="text/javascript">
308-
requirejs(["$testName", "dart_sdk", "expect"],
309-
function($testId, sdk, expect) {
294+
requirejs(["$testName", "dart_sdk"], function($testId, sdk) {
310295
let runtime = sdk.dart;
311-
let _isolate_helper = sdk._isolate_helper;
296+
let getStackTraceString = function(error) {
297+
return runtime.stackTrace(error).toString();
298+
}
312299
let _debugger = sdk._debugger;
313300
314301
$sdkAndAsyncHelperSetup

sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/runtime.dart

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -275,18 +275,3 @@ void hotRestart() {
275275
JS('', '#.clear()', deferredImports);
276276
}
277277
}
278-
279-
/// Marks enqueuing an async operation.
280-
///
281-
/// This will be called by library code when enqueuing an async operation
282-
/// controlled by the JavaScript event handler.
283-
///
284-
/// It will also call [removeAsyncCallback] when Dart callback is about to be
285-
/// executed (note this is called *before* the callback executes, so more
286-
/// async operations could be added from that).
287-
void Function() addAsyncCallback = JS('', 'function() {}');
288-
289-
/// Marks leaving a javascript async operation.
290-
///
291-
/// See [addAsyncCallback].
292-
void Function() removeAsyncCallback = JS('', 'function() {}');

0 commit comments

Comments
 (0)