From b7bafd2acfdc88db303326868cd73eb1b1f709a0 Mon Sep 17 00:00:00 2001 From: Anna Gringauze Date: Mon, 6 Sep 2021 14:24:28 -0700 Subject: [PATCH] Optimize url encoding, use default port for debugger service --- dwds/CHANGELOG.md | 4 + dwds/lib/dwds.dart | 8 +- dwds/lib/src/handlers/injector.dart | 6 +- dwds/lib/src/injected/client.js | 231 +++++++++++------------ dwds/lib/src/services/debug_service.dart | 2 +- dwds/lib/src/utilities/shared.dart | 6 +- dwds/test/handlers/injector_test.dart | 3 +- 7 files changed, 126 insertions(+), 134 deletions(-) diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index b0e2046f2..af69b0016 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,5 +1,9 @@ ## 11.3.1-dev +- Encode extension url asynchronously. +- Use default constant port for debug service. + - If we fail binding to the port, fall back to previous strategy + of finding unbound ports. - Add metrics measuring DevTools Initial Page Load time. - Add `ext.dwds.sendEvent` service extension to dwds so other tools can send events to the debugger. diff --git a/dwds/lib/dwds.dart b/dwds/lib/dwds.dart index 5c385aae0..0a0c3fd9a 100644 --- a/dwds/lib/dwds.dart +++ b/dwds/lib/dwds.dart @@ -121,7 +121,7 @@ class Dwds { globalLoadStrategy = loadStrategy; DevTools devTools; - String extensionUri; + Future extensionUri; ExtensionBackend extensionBackend; if (enableDebugExtension) { final handler = useSseForDebugBackend @@ -134,13 +134,13 @@ class Dwds { : WebSocketSocketHandler(); extensionBackend = await ExtensionBackend.start(handler, hostname); - extensionUri = Uri( + extensionUri = Future.value(Uri( scheme: useSseForDebugBackend ? 'http' : 'ws', host: extensionBackend.hostname, port: extensionBackend.port, path: r'$debug') - .toString(); - if (urlEncoder != null) extensionUri = await urlEncoder(extensionUri); + .toString()); + if (urlEncoder != null) extensionUri = urlEncoder(await extensionUri); } var serveDevTools = devtoolsLauncher != null; diff --git a/dwds/lib/src/handlers/injector.dart b/dwds/lib/src/handlers/injector.dart index fa139dc03..a57ee5cb8 100644 --- a/dwds/lib/src/handlers/injector.dart +++ b/dwds/lib/src/handlers/injector.dart @@ -33,7 +33,7 @@ const _clientScript = 'dwds/src/injected/client'; /// information. class DwdsInjector { final LoadStrategy _loadStrategy; - final String _extensionUri; + final Future _extensionUri; final _devHandlerPaths = StreamController(); final _logger = Logger('DwdsInjector'); final bool _enableDevtoolsLaunch; @@ -41,7 +41,7 @@ class DwdsInjector { DwdsInjector( this._loadStrategy, { - String extensionUri, + Future extensionUri, bool enableDevtoolsLaunch, bool useSseForInjectedClient, }) : _extensionUri = extensionUri, @@ -104,7 +104,7 @@ class DwdsInjector { appId, devHandlerPath, entrypoint, - _extensionUri, + await _extensionUri, _loadStrategy, _enableDevtoolsLaunch, ); diff --git a/dwds/lib/src/injected/client.js b/dwds/lib/src/injected/client.js index bfdf32add..6afc3e8ab 100644 --- a/dwds/lib/src/injected/client.js +++ b/dwds/lib/src/injected/client.js @@ -1,4 +1,4 @@ -// Generated by dart2js (NullSafetyMode.unsound, no-legacy-javascript), the Dart to JavaScript compiler version: 2.15.0-82.0.dev. +// Generated by dart2js (NullSafetyMode.unsound, no-legacy-javascript), the Dart to JavaScript compiler version: 2.15.0-101.0.dev. // The code supports the following hooks: // dartPrint(message): // if this function is defined it is called instead of the Dart [print] @@ -7576,10 +7576,6 @@ Duration: function Duration(t0) { this._duration = t0; }, - Duration_toString_sixDigits: function Duration_toString_sixDigits() { - }, - Duration_toString_twoDigits: function Duration_toString_twoDigits() { - }, Error: function Error() { }, AssertionError: function AssertionError(t0) { @@ -10030,7 +10026,7 @@ call$0() { return P.Future_Future$value(null, type$.Null); }, - $signature: 25 + $signature: 24 }; H.NotNullableError.prototype = { toString$0(_) { @@ -10997,7 +10993,7 @@ call$1(tag) { return this.prototypeForTag(H._asStringS(tag)); }, - $signature: 80 + $signature: 96 }; H.JSSyntaxRegExp.prototype = { toString$0(_) { @@ -11505,7 +11501,7 @@ call$2(error, stackTrace) { this.bodyFunction.call$2(1, new H.ExceptionAndStackTrace(error, type$.StackTrace._as(stackTrace))); }, - $signature: 37 + $signature: 50 }; P._wrapJsFunctionForAsync_closure.prototype = { call$2(errorCode, result) { @@ -11914,7 +11910,7 @@ call$1(_) { return this.originalSource; }, - $signature: 98 + $signature: 97 }; P._Future__propagateToListeners_handleValueCallback.prototype = { call$0() { @@ -13246,7 +13242,7 @@ t3._processUncaughtError$3(zone, e, t1._as(s)); } }, - $signature: 60 + $signature: 79 }; P._HashMap.prototype = { get$length(_) { @@ -15755,42 +15751,31 @@ return C.JSInt_methods.compareTo$1(this._duration, type$.Duration._as(other)._duration); }, toString$0(_) { - var twoDigitMinutes, twoDigitSeconds, sixDigitUs, - t1 = new P.Duration_toString_twoDigits(), - t2 = this._duration; - if (t2 < 0) - return "-" + new P.Duration(0 - t2).toString$0(0); - twoDigitMinutes = t1.call$1(C.JSInt_methods._tdivFast$1(t2, 60000000) % 60); - twoDigitSeconds = t1.call$1(C.JSInt_methods._tdivFast$1(t2, 1000000) % 60); - sixDigitUs = new P.Duration_toString_sixDigits().call$1(t2 % 1000000); - return "" + C.JSInt_methods._tdivFast$1(t2, 3600000000) + ":" + H.S(twoDigitMinutes) + ":" + H.S(twoDigitSeconds) + "." + H.S(sixDigitUs); + var minutes, seconds, + buffer = P.List_List$filled(9, "", false, type$.String), + microseconds = this._duration, + hours = C.JSInt_methods._tdivFast$1(microseconds, 3600000000); + microseconds %= 3600000000; + if (microseconds < 0) + microseconds = -microseconds; + C.JSArray_methods.$indexSet(buffer, 0, C.JSInt_methods.toString$0(hours)); + C.JSArray_methods.$indexSet(buffer, 1, ":"); + minutes = C.JSInt_methods._tdivFast$1(microseconds, 60000000); + microseconds %= 60000000; + if (minutes < 10) + C.JSArray_methods.$indexSet(buffer, 2, "0"); + C.JSArray_methods.$indexSet(buffer, 3, C.JSInt_methods.toString$0(minutes)); + C.JSArray_methods.$indexSet(buffer, 4, ":"); + seconds = C.JSInt_methods._tdivFast$1(microseconds, 1000000); + if (seconds < 10) + C.JSArray_methods.$indexSet(buffer, 5, "0"); + C.JSArray_methods.$indexSet(buffer, 6, C.JSInt_methods.toString$0(seconds)); + C.JSArray_methods.$indexSet(buffer, 7, "."); + C.JSArray_methods.$indexSet(buffer, 8, C.JSString_methods.padLeft$2(C.JSInt_methods.toString$0(microseconds % 1000000), 6, "0")); + return C.JSArray_methods.join$1(buffer, ""); }, $isComparable: 1 }; - P.Duration_toString_sixDigits.prototype = { - call$1(n) { - if (n >= 100000) - return "" + n; - if (n >= 10000) - return "0" + n; - if (n >= 1000) - return "00" + n; - if (n >= 100) - return "000" + n; - if (n >= 10) - return "0000" + n; - return "00000" + n; - }, - $signature: 22 - }; - P.Duration_toString_twoDigits.prototype = { - call$1(n) { - if (n >= 10) - return "" + n; - return "0" + n; - }, - $signature: 22 - }; P.Error.prototype = { get$stackTrace() { return H.getTraceFromException(this.$thrownJsError); @@ -16163,7 +16148,7 @@ call$2(msg, position) { throw H.wrapException(P.FormatException$("Illegal IPv4 address, " + msg, this.host, position)); }, - $signature: 53 + $signature: 52 }; P.Uri_parseIPv6Address_error.prototype = { call$2(msg, position) { @@ -16172,7 +16157,7 @@ call$1(msg) { return this.call$2(msg, null); }, - $signature: 54 + $signature: 53 }; P.Uri_parseIPv6Address_parseHex.prototype = { call$2(start, end) { @@ -16355,7 +16340,7 @@ call$1(s) { return P._Uri__uriEncode(C.List_qg40, H._asStringS(s), C.C_Utf8Codec, false); }, - $signature: 23 + $signature: 22 }; P.UriData.prototype = { get$uri() { @@ -16396,7 +16381,7 @@ C.NativeUint8List_methods.fillRange$3(t1, 0, 96, defaultTransition); return t1; }, - $signature: 61 + $signature: 60 }; P._createTables_setChars.prototype = { call$3(target, chars, transition) { @@ -16408,7 +16393,7 @@ target[t2] = transition; } }, - $signature: 24 + $signature: 23 }; P._createTables_setRange.prototype = { call$3(target, range, transition) { @@ -16420,7 +16405,7 @@ target[t1] = transition; } }, - $signature: 24 + $signature: 23 }; P._SimpleUri.prototype = { get$hasAuthority() { @@ -16869,7 +16854,7 @@ call$1(e) { return type$.Element._is(type$.Node._as(e)); }, - $signature: 81 + $signature: 80 }; W.Event.prototype = {$isEvent: 1}; W.EventSource.prototype = {$isEventSource: 1}; @@ -17002,7 +16987,7 @@ else t3.completeError$1(e); }, - $signature: 33 + $signature: 32 }; W.HttpRequestEventTarget.prototype = {}; W.ImageData.prototype = {$isImageData: 1}; @@ -17462,7 +17447,7 @@ call$2(k, v) { return C.JSArray_methods.add$1(this.keys, k); }, - $signature: 34 + $signature: 33 }; W.StyleSheet.prototype = {$isStyleSheet: 1}; W.TableElement.prototype = { @@ -18099,13 +18084,13 @@ call$1(v) { return type$.NodeValidator._as(v).allowsElement$1(this.element); }, - $signature: 26 + $signature: 25 }; W.NodeValidatorBuilder_allowsAttribute_closure.prototype = { call$1(v) { return type$.NodeValidator._as(v).allowsAttribute$3(this.element, this.attributeName, this.value); }, - $signature: 26 + $signature: 25 }; W._SimpleNodeValidator.prototype = { _SimpleNodeValidator$4$allowedAttributes$allowedElements$allowedUriAttributes(uriPolicy, allowedAttributes, allowedElements, allowedUriAttributes) { @@ -18148,13 +18133,13 @@ call$1(x) { return !C.JSArray_methods.contains$1(C.List_yrN, H._asStringS(x)); }, - $signature: 27 + $signature: 26 }; W._SimpleNodeValidator_closure0.prototype = { call$1(x) { return C.JSArray_methods.contains$1(C.List_yrN, H._asStringS(x)); }, - $signature: 27 + $signature: 26 }; W._TemplatingNodeValidator.prototype = { allowsAttribute$3(element, attributeName, value) { @@ -18171,7 +18156,7 @@ call$1(attr) { return "TEMPLATE::" + H.S(H._asStringS(attr)); }, - $signature: 23 + $signature: 22 }; W._SvgNodeValidator.prototype = { allowsElement$1(element) { @@ -18390,7 +18375,7 @@ child = nextChild; } }, - $signature: 38 + $signature: 37 }; W._CssStyleDeclaration_Interceptor_CssStyleDeclarationBase.prototype = {}; W._DomRectList_Interceptor_ListMixin.prototype = {}; @@ -18528,7 +18513,7 @@ call$2(key, value) { this._box_0.copy[key] = this.$this.walk$1(value); }, - $signature: 39 + $signature: 38 }; P._AcceptStructuredClone.prototype = { findSlot$1(value) { @@ -18604,7 +18589,7 @@ J.$indexSet$ax(t1, key, t2); return t2; }, - $signature: 40 + $signature: 39 }; P._convertDartToNative_Value_closure.prototype = { call$1(element) { @@ -18663,19 +18648,19 @@ call$1(o) { return new P.JsFunction(o); }, - $signature: 41 + $signature: 40 }; P._wrapToDart_closure0.prototype = { call$1(o) { return new P.JsArray(o, type$.JsArray_dynamic); }, - $signature: 42 + $signature: 41 }; P._wrapToDart_closure1.prototype = { call$1(o) { return new P.JsObject(o); }, - $signature: 43 + $signature: 42 }; P.JsObject.prototype = { $index(_, property) { @@ -19226,7 +19211,7 @@ call$2(h, i) { return A._combine(H._asIntS(h), J.get$hashCode$(i)); }, - $signature: 44 + $signature: 43 }; D.BuiltList.prototype = { toBuilder$0() { @@ -20164,7 +20149,7 @@ $._indentingBuiltValueToStringHelperIndent = $._indentingBuiltValueToStringHelperIndent + 2; return new Y.IndentingBuiltValueToStringHelper(t1); }, - $signature: 45 + $signature: 44 }; Y.IndentingBuiltValueToStringHelper.prototype = { add$2(_, field, value) { @@ -20298,34 +20283,34 @@ call$0() { return D.ListBuilder_ListBuilder(C.List_empty0, type$.Object); }, - $signature: 46 + $signature: 45 }; U.Serializers_Serializers_closure0.prototype = { call$0() { var t1 = type$.Object; return R.ListMultimapBuilder_ListMultimapBuilder(t1, t1); }, - $signature: 47 + $signature: 46 }; U.Serializers_Serializers_closure1.prototype = { call$0() { var t1 = type$.Object; return A.MapBuilder_MapBuilder(t1, t1); }, - $signature: 48 + $signature: 47 }; U.Serializers_Serializers_closure2.prototype = { call$0() { return X.SetBuilder_SetBuilder(type$.Object); }, - $signature: 49 + $signature: 48 }; U.Serializers_Serializers_closure3.prototype = { call$0() { var t1 = type$.Object; return M.SetMultimapBuilder_SetMultimapBuilder(t1, t1); }, - $signature: 50 + $signature: 49 }; U.FullType.prototype = { $eq(_, other) { @@ -20746,7 +20731,7 @@ call$1(value) { return this.serializers.deserialize$2$specifiedType(value, this.valueType); }, - $signature: 28 + $signature: 27 }; K.BuiltListSerializer.prototype = { serialize$3$specifiedType(serializers, builtList, specifiedType) { @@ -22882,7 +22867,7 @@ call$0() { return D.ListBuilder_ListBuilder(C.List_empty0, type$.legacy_ExtensionEvent); }, - $signature: 56 + $signature: 55 }; R.SocketClient.prototype = {}; R.SseSocketClient.prototype = { @@ -22911,7 +22896,7 @@ call$1(o) { return o == null ? null : J.toString$0$(o); }, - $signature: 57 + $signature: 56 }; V.Int64.prototype = { $add(_, other) { @@ -23155,7 +23140,7 @@ $parent._children.$indexSet(0, thisName, t1); return t1; }, - $signature: 58 + $signature: 57 }; O.Pool.prototype = { request$0(_) { @@ -23482,7 +23467,7 @@ }); return P._asyncStartSync($async$call$0, $async$completer); }, - $signature: 25 + $signature: 24 }; T.generateUuidV4__generateBits.prototype = { call$1(bitCount) { @@ -23494,13 +23479,13 @@ call$2(value, count) { return C.JSString_methods.padLeft$2(C.JSInt_methods.toRadixString$1(value, 16), count, "0"); }, - $signature: 29 + $signature: 28 }; T.generateUuidV4__bitsDigits.prototype = { call$2(bitCount, digitCount) { return this._printDigits.call$2(this._generateBits.call$1(bitCount), digitCount); }, - $signature: 29 + $signature: 28 }; K.GuaranteeChannel.prototype = { get$stream(_) { @@ -23855,7 +23840,7 @@ type$.Event._as(_); this.$this._listen$0(); }, - $signature: 30 + $signature: 29 }; A.HtmlWebSocketChannel_closure0.prototype = { call$1(_) { @@ -23865,7 +23850,7 @@ t1.get$_local().get$sink().addError$1(new E.WebSocketChannelException("WebSocket connection failed.")); t1.get$_local().get$sink().close$0(0); }, - $signature: 30 + $signature: 29 }; A.HtmlWebSocketChannel_closure1.prototype = { call$1($event) { @@ -23874,7 +23859,7 @@ data = H.NativeUint8List_NativeUint8List$view(data, 0, null); this.$this._html$_controller.get$_local().get$sink().add$1(0, data); }, - $signature: 62 + $signature: 61 }; A.HtmlWebSocketChannel_closure2.prototype = { call$1($event) { @@ -23883,7 +23868,7 @@ $event.reason; this.$this._html$_controller.get$_local().get$sink().close$0(0); }, - $signature: 63 + $signature: 62 }; A.HtmlWebSocketChannel__listen_closure.prototype = { call$0() { @@ -23988,13 +23973,13 @@ }); return P._asyncStartSync($async$call$0, $async$completer); }, - $signature: 64 + $signature: 63 }; D.main__closure.prototype = { call$0() { return S.toPromise(this.manager.hotRestart$0(), type$.legacy_bool); }, - $signature: 82 + $signature: 81 }; D.main__closure0.prototype = { call$2(kind, eventData) { @@ -24007,7 +23992,7 @@ type$.legacy_void_Function_legacy_DebugEventBuilder._as(new D.main___closure1(kind, eventData)).call$1(t3); t1.add$1(0, C.C_JsonCodec.encode$2$toEncodable(t2.serialize$1(t3.build$0()), null)); }, - $signature: 66 + $signature: 65 }; D.main___closure1.prototype = { call$1(b) { @@ -24017,7 +24002,7 @@ b.get$_debug_event$_$this()._eventData = this.eventData; return b; }, - $signature: 67 + $signature: 66 }; D.main__closure1.prototype = { call$1(eventData) { @@ -24029,7 +24014,7 @@ type$.legacy_void_Function_legacy_RegisterEventBuilder._as(new D.main___closure0(eventData)).call$1(t3); t1.add$1(0, C.C_JsonCodec.encode$2$toEncodable(t2.serialize$1(t3.build$0()), null)); }, - $signature: 68 + $signature: 67 }; D.main___closure0.prototype = { call$1(b) { @@ -24038,7 +24023,7 @@ b.get$_register_event$_$this()._register_event$_eventData = this.eventData; return b; }, - $signature: 69 + $signature: 68 }; D.main__closure2.prototype = { call$0() { @@ -24063,7 +24048,7 @@ b.get$_devtools_request$_$this()._devtools_request$_instanceId = t1; return b; }, - $signature: 70 + $signature: 69 }; D.main__closure3.prototype = { call$1(serialized) { @@ -24142,7 +24127,7 @@ }); return P._asyncStartSync($async$call$1, $async$completer); }, - $signature: 71 + $signature: 70 }; D.main__closure4.prototype = { call$1(error) { @@ -24156,7 +24141,7 @@ self.$launchDevTools.call$0(); } }, - $signature: 72 + $signature: 71 }; D.main__closure6.prototype = { call$1(b) { @@ -24168,14 +24153,14 @@ b.get$_$this()._entrypointPath = t1; return b; }, - $signature: 73 + $signature: 72 }; D.main_closure0.prototype = { call$2(error, stackTrace) { type$.legacy_StackTrace._as(stackTrace); P.print("Unhandled error detected in the injected client.js script.\n\nYou can disable this script in webdev by passing --no-injected-client if it\nis preventing your app from loading, but note that this will also prevent\nall debugging and hot reload/restart functionality from working.\n\nThe original error is below, please file an issue at\nhttps://github.com/dart-lang/webdev/issues/new and attach this output:\n\n" + H.S(error) + "\n" + H.S(stackTrace) + "\n"); }, - $signature: 74 + $signature: 73 }; Z.LegacyRestarter.prototype = { restart$0() { @@ -24227,7 +24212,7 @@ this._box_0.sub.cancel$0(0); } }, - $signature: 75 + $signature: 74 }; Q.ReloadingManager.prototype = { hotRestart$0() { @@ -24614,7 +24599,7 @@ call$1(e) { return this.completer.completeError$2(new X.HotReloadFailedException(J.get$message$x(type$.legacy_JsError._as(e))), this.stackTrace); }, - $signature: 78 + $signature: 77 }; V._createScript_closure.prototype = { call$0() { @@ -24623,13 +24608,13 @@ return new V._createScript__closure(); return new V._createScript__closure0(nonce); }, - $signature: 79 + $signature: 78 }; V._createScript__closure.prototype = { call$0() { return document.createElement("script"); }, - $signature: 31 + $signature: 30 }; V._createScript__closure0.prototype = { call$0() { @@ -24637,7 +24622,7 @@ t1.setAttribute("nonce", this.nonce); return t1; }, - $signature: 31 + $signature: 30 }; (function aliases() { var _ = J.Interceptor.prototype; @@ -24685,7 +24670,7 @@ _instance_0_u = hunkHelpers._instance_0u, _instance_1_u = hunkHelpers._instance_1u, _instance_0_i = hunkHelpers._instance_0i; - _static_2(J, "_interceptors_JSArray__compareAny$closure", "JSArray__compareAny", 32); + _static_2(J, "_interceptors_JSArray__compareAny$closure", "JSArray__compareAny", 31); _static_1(P, "async__AsyncRun__scheduleImmediateJsOverride$closure", "_AsyncRun__scheduleImmediateJsOverride", 10); _static_1(P, "async__AsyncRun__scheduleImmediateWithSetImmediate$closure", "_AsyncRun__scheduleImmediateWithSetImmediate", 10); _static_1(P, "async__AsyncRun__scheduleImmediateWithTimer$closure", "_AsyncRun__scheduleImmediateWithTimer", 10); @@ -24693,38 +24678,38 @@ _static_1(P, "async___nullDataHandler$closure", "_nullDataHandler", 4); _static_2(P, "async___nullErrorHandler$closure", "_nullErrorHandler", 16); _static_0(P, "async___nullDoneHandler$closure", "_nullDoneHandler", 0); - _static(P, "async___rootHandleUncaughtError$closure", 5, null, ["call$5"], ["_rootHandleUncaughtError"], 83, 0); + _static(P, "async___rootHandleUncaughtError$closure", 5, null, ["call$5"], ["_rootHandleUncaughtError"], 82, 0); _static(P, "async___rootRun$closure", 4, null, ["call$1$4", "call$4"], ["_rootRun", function($self, $parent, zone, f) { return P._rootRun($self, $parent, zone, f, type$.dynamic); - }], 84, 1); + }], 83, 1); _static(P, "async___rootRunUnary$closure", 5, null, ["call$2$5", "call$5"], ["_rootRunUnary", function($self, $parent, zone, f, arg) { return P._rootRunUnary($self, $parent, zone, f, arg, type$.dynamic, type$.dynamic); - }], 85, 1); + }], 84, 1); _static(P, "async___rootRunBinary$closure", 6, null, ["call$3$6", "call$6"], ["_rootRunBinary", function($self, $parent, zone, f, arg1, arg2) { return P._rootRunBinary($self, $parent, zone, f, arg1, arg2, type$.dynamic, type$.dynamic, type$.dynamic); - }], 86, 1); + }], 85, 1); _static(P, "async___rootRegisterCallback$closure", 4, null, ["call$1$4", "call$4"], ["_rootRegisterCallback", function($self, $parent, zone, f) { return P._rootRegisterCallback($self, $parent, zone, f, type$.dynamic); - }], 87, 0); + }], 86, 0); _static(P, "async___rootRegisterUnaryCallback$closure", 4, null, ["call$2$4", "call$4"], ["_rootRegisterUnaryCallback", function($self, $parent, zone, f) { return P._rootRegisterUnaryCallback($self, $parent, zone, f, type$.dynamic, type$.dynamic); - }], 88, 0); + }], 87, 0); _static(P, "async___rootRegisterBinaryCallback$closure", 4, null, ["call$3$4", "call$4"], ["_rootRegisterBinaryCallback", function($self, $parent, zone, f) { return P._rootRegisterBinaryCallback($self, $parent, zone, f, type$.dynamic, type$.dynamic, type$.dynamic); - }], 89, 0); - _static(P, "async___rootErrorCallback$closure", 5, null, ["call$5"], ["_rootErrorCallback"], 90, 0); - _static(P, "async___rootScheduleMicrotask$closure", 4, null, ["call$4"], ["_rootScheduleMicrotask"], 91, 0); - _static(P, "async___rootCreateTimer$closure", 5, null, ["call$5"], ["_rootCreateTimer"], 92, 0); - _static(P, "async___rootCreatePeriodicTimer$closure", 5, null, ["call$5"], ["_rootCreatePeriodicTimer"], 93, 0); - _static(P, "async___rootPrint$closure", 4, null, ["call$4"], ["_rootPrint"], 94, 0); - _static_1(P, "async___printToZone$closure", "_printToZone", 95); - _static(P, "async___rootFork$closure", 5, null, ["call$5"], ["_rootFork"], 96, 0); + }], 88, 0); + _static(P, "async___rootErrorCallback$closure", 5, null, ["call$5"], ["_rootErrorCallback"], 89, 0); + _static(P, "async___rootScheduleMicrotask$closure", 4, null, ["call$4"], ["_rootScheduleMicrotask"], 90, 0); + _static(P, "async___rootCreateTimer$closure", 5, null, ["call$5"], ["_rootCreateTimer"], 91, 0); + _static(P, "async___rootCreatePeriodicTimer$closure", 5, null, ["call$5"], ["_rootCreatePeriodicTimer"], 92, 0); + _static(P, "async___rootPrint$closure", 4, null, ["call$4"], ["_rootPrint"], 93, 0); + _static_1(P, "async___printToZone$closure", "_printToZone", 94); + _static(P, "async___rootFork$closure", 5, null, ["call$5"], ["_rootFork"], 95, 0); _instance(P._Completer.prototype, "get$completeError", 0, 1, function() { return [null]; }, ["call$2", "call$1"], ["completeError$2", "completeError$1"], 15, 0, 0); _instance(P._AsyncCompleter.prototype, "get$complete", 1, 0, function() { return [null]; - }, ["call$1", "call$0"], ["complete$1", "complete$0"], 97, 0, 0); + }, ["call$1", "call$0"], ["complete$1", "complete$0"], 34, 0, 0); _instance_2_u(P._Future.prototype, "get$_completeError", "_completeError$2", 16); var _; _instance_1_i(_ = P._StreamController.prototype, "get$add", "add$1", 17); @@ -24738,11 +24723,11 @@ _instance_0_u(_ = P._ForwardingStreamSubscription.prototype, "get$_onPause", "_onPause$0", 0); _instance_0_u(_, "get$_onResume", "_onResume$0", 0); _instance_1_u(_, "get$_handleData", "_handleData$1", 17); - _instance_2_u(_, "get$_handleError", "_handleError$2", 52); + _instance_2_u(_, "get$_handleError", "_handleError$2", 59); _instance_0_u(_, "get$_handleDone", "_handleDone$0", 0); _static_2(P, "collection___defaultEquals$closure", "_defaultEquals", 12); _static_1(P, "collection___defaultHashCode$closure", "_defaultHashCode", 13); - _static_2(P, "collection_ListMixin__compareAny$closure", "ListMixin__compareAny", 32); + _static_2(P, "collection_ListMixin__compareAny$closure", "ListMixin__compareAny", 31); _static_1(P, "convert___defaultToEncodable$closure", "_defaultToEncodable", 1); _static_1(P, "core__identityHashCode$closure", "identityHashCode", 13); _static_2(P, "core__identical$closure", "identical", 12); @@ -24750,18 +24735,18 @@ _static(W, "html0__Html5NodeValidator__uriAttributeValidator$closure", 4, null, ["call$4"], ["_Html5NodeValidator__uriAttributeValidator"], 14, 0); _instance_0_i(W.Node.prototype, "get$remove", "remove$0", 0); _instance_1_i(W.WebSocket.prototype, "get$send", "send$1", 4); - _static_1(P, "js___convertToJS$closure", "_convertToJS", 28); + _static_1(P, "js___convertToJS$closure", "_convertToJS", 27); _static_1(P, "js___convertToDart$closure", "_convertToDart", 3); _instance_2_u(_ = U.DeepCollectionEquality.prototype, "get$equals", "equals$2", 12); _instance_1_i(_, "get$hash", "hash$1", 13); - _instance_1_u(_, "get$isValidKey", "isValidKey$1", 55); - _static_2(L, "strongly_connected_components___defaultEquals$closure", "_defaultEquals0", 65); + _instance_1_u(_, "get$isValidKey", "isValidKey$1", 54); + _static_2(L, "strongly_connected_components___defaultEquals$closure", "_defaultEquals0", 64); _instance_1_u(_ = M.SseClient.prototype, "get$_onIncomingControlMessage", "_onIncomingControlMessage$1", 5); _instance_1_u(_, "get$_onIncomingMessage", "_onIncomingMessage$1", 5); _instance_0_u(_, "get$_onOutgoingDone", "_onOutgoingDone$0", 0); - _instance_1_u(_, "get$_onOutgoingMessage", "_onOutgoingMessage$1", 59); - _instance_1_u(_ = X.RequireRestarter.prototype, "get$_moduleParents", "_moduleParents$1", 76); - _instance_2_u(_, "get$_moduleTopologicalCompare", "_moduleTopologicalCompare$2", 77); + _instance_1_u(_, "get$_onOutgoingMessage", "_onOutgoingMessage$1", 58); + _instance_1_u(_ = X.RequireRestarter.prototype, "get$_moduleParents", "_moduleParents$1", 75); + _instance_2_u(_, "get$_moduleTopologicalCompare", "_moduleTopologicalCompare$2", 76); })(); (function inheritance() { var _mixin = hunkHelpers.mixin, @@ -24777,7 +24762,7 @@ _inheritMany(H._CastIterableBase, [H.CastIterable, H.__CastListBase__CastIterableBase_ListMixin]); _inherit(H._EfficientLengthCastIterable, H.CastIterable); _inherit(H._CastListBase, H.__CastListBase__CastIterableBase_ListMixin); - _inheritMany(H.Closure, [H.Closure2Args, H.Closure0Args, H.TearOffClosure, H.initHooks_closure, H.initHooks_closure1, P._AsyncRun__initializeScheduleImmediate_internalCallback, P._AsyncRun__initializeScheduleImmediate_closure, P._awaitOnObject_closure, P._Future__chainForeignFuture_closure, P._Future__propagateToListeners_handleWhenCompleteCallback_closure, P.Stream_length_closure, P.Stream_first_closure0, P._CustomZone_bindUnaryCallback_closure, P._CustomZone_bindUnaryCallbackGuarded_closure, P._RootZone_bindUnaryCallback_closure, P._RootZone_bindUnaryCallbackGuarded_closure, P.runZonedGuarded_closure, P._CustomHashMap_closure, P._LinkedCustomHashMap_closure, P.SplayTreeSet_closure, P._BigIntImpl_hashCode_finish, P.Duration_toString_sixDigits, P.Duration_toString_twoDigits, P.Uri_parseIPv6Address_error, P._Uri__makePath_closure, P._createTables_setChars, P._createTables_setRange, W.Element_Element$html_closure, W.HttpRequest_request_closure, W._EventStreamSubscription_closure, W._EventStreamSubscription_onData_closure, W.NodeValidatorBuilder_allowsElement_closure, W.NodeValidatorBuilder_allowsAttribute_closure, W._SimpleNodeValidator_closure, W._SimpleNodeValidator_closure0, W._TemplatingNodeValidator_closure, P._convertDartToNative_Value_closure, P._convertToJS_closure, P._convertToJS_closure0, P._wrapToDart_closure, P._wrapToDart_closure0, P._wrapToDart_closure1, P.promiseToFuture_closure, P.promiseToFuture_closure0, R.BuiltListMultimap_BuiltListMultimap_closure, R.BuiltListMultimap_hashCode_closure, R.ListMultimapBuilder_replace_closure, A.BuiltMap_BuiltMap_closure, A.BuiltMap_hashCode_closure, X.BuiltSet_hashCode_closure, M.BuiltSetMultimap_hashCode_closure, M.SetMultimapBuilder_replace_closure, Y.newBuiltValueToStringHelper_closure, R.BuiltListMultimapSerializer_serialize_closure, R.BuiltListMultimapSerializer_deserialize_closure, K.BuiltListSerializer_serialize_closure, K.BuiltListSerializer_deserialize_closure, R.BuiltSetMultimapSerializer_serialize_closure, R.BuiltSetMultimapSerializer_deserialize_closure, O.BuiltSetSerializer_serialize_closure, O.BuiltSetSerializer_deserialize_closure, R.WebSocketClient_stream_closure, L.stronglyConnectedComponents_strongConnect, O.Pool__runOnRelease_closure, M.SseClient_closure0, M.SseClient_closure1, T.generateUuidV4__generateBits, K._GuaranteeSink__addError_closure, A.HtmlWebSocketChannel_closure, A.HtmlWebSocketChannel_closure0, A.HtmlWebSocketChannel_closure1, A.HtmlWebSocketChannel_closure2, D.main___closure1, D.main__closure1, D.main___closure0, D.main___closure, D.main__closure3, D.main__closure4, D.main__closure5, D.main__closure6, Z.LegacyRestarter_restart_closure, X.RequireRestarter__reloadModule_closure0]); + _inheritMany(H.Closure, [H.Closure2Args, H.Closure0Args, H.TearOffClosure, H.initHooks_closure, H.initHooks_closure1, P._AsyncRun__initializeScheduleImmediate_internalCallback, P._AsyncRun__initializeScheduleImmediate_closure, P._awaitOnObject_closure, P._Future__chainForeignFuture_closure, P._Future__propagateToListeners_handleWhenCompleteCallback_closure, P.Stream_length_closure, P.Stream_first_closure0, P._CustomZone_bindUnaryCallback_closure, P._CustomZone_bindUnaryCallbackGuarded_closure, P._RootZone_bindUnaryCallback_closure, P._RootZone_bindUnaryCallbackGuarded_closure, P.runZonedGuarded_closure, P._CustomHashMap_closure, P._LinkedCustomHashMap_closure, P.SplayTreeSet_closure, P._BigIntImpl_hashCode_finish, P.Uri_parseIPv6Address_error, P._Uri__makePath_closure, P._createTables_setChars, P._createTables_setRange, W.Element_Element$html_closure, W.HttpRequest_request_closure, W._EventStreamSubscription_closure, W._EventStreamSubscription_onData_closure, W.NodeValidatorBuilder_allowsElement_closure, W.NodeValidatorBuilder_allowsAttribute_closure, W._SimpleNodeValidator_closure, W._SimpleNodeValidator_closure0, W._TemplatingNodeValidator_closure, P._convertDartToNative_Value_closure, P._convertToJS_closure, P._convertToJS_closure0, P._wrapToDart_closure, P._wrapToDart_closure0, P._wrapToDart_closure1, P.promiseToFuture_closure, P.promiseToFuture_closure0, R.BuiltListMultimap_BuiltListMultimap_closure, R.BuiltListMultimap_hashCode_closure, R.ListMultimapBuilder_replace_closure, A.BuiltMap_BuiltMap_closure, A.BuiltMap_hashCode_closure, X.BuiltSet_hashCode_closure, M.BuiltSetMultimap_hashCode_closure, M.SetMultimapBuilder_replace_closure, Y.newBuiltValueToStringHelper_closure, R.BuiltListMultimapSerializer_serialize_closure, R.BuiltListMultimapSerializer_deserialize_closure, K.BuiltListSerializer_serialize_closure, K.BuiltListSerializer_deserialize_closure, R.BuiltSetMultimapSerializer_serialize_closure, R.BuiltSetMultimapSerializer_deserialize_closure, O.BuiltSetSerializer_serialize_closure, O.BuiltSetSerializer_deserialize_closure, R.WebSocketClient_stream_closure, L.stronglyConnectedComponents_strongConnect, O.Pool__runOnRelease_closure, M.SseClient_closure0, M.SseClient_closure1, T.generateUuidV4__generateBits, K._GuaranteeSink__addError_closure, A.HtmlWebSocketChannel_closure, A.HtmlWebSocketChannel_closure0, A.HtmlWebSocketChannel_closure1, A.HtmlWebSocketChannel_closure2, D.main___closure1, D.main__closure1, D.main___closure0, D.main___closure, D.main__closure3, D.main__closure4, D.main__closure5, D.main__closure6, Z.LegacyRestarter_restart_closure, X.RequireRestarter__reloadModule_closure0]); _inheritMany(H.Closure2Args, [H._CastListBase_sort_closure, H.CastMap_forEach_closure, H.ConstantMap_map_closure, H.Primitives_functionNoSuchMethod_closure, H.JsLinkedHashMap_addAll_closure, H.initHooks_closure0, P._awaitOnObject_closure0, P._wrapJsFunctionForAsync_closure, P._Future__chainForeignFuture_closure0, P._BufferingStreamSubscription_asFuture_closure0, P.LinkedHashMap_LinkedHashMap$from_closure, P.MapBase_mapToString_closure, P._JsonStringifier_writeMap_closure, P._symbolMapToStringMap_closure, P.NoSuchMethodError_toString_closure, P._BigIntImpl_hashCode_combine, P.Uri__parseIPv4Address_error, P.Uri_parseIPv6Address_parseHex, P._createTables_build, W.MidiInputMap_keys_closure, W.MidiOutputMap_keys_closure, W.RtcStatsReport_keys_closure, W.Storage_keys_closure, W._ValidatingTreeSanitizer_sanitizeTree_walk, P._StructuredClone_walk_closure, P._StructuredClone_walk_closure0, P._AcceptStructuredClone_walk_closure, P.convertDartToNative_Dictionary_closure, P.AudioParamMap_keys_closure, A.hashObjects_closure, A.MapBuilder_replace_closure, O.Pool__runOnRelease_closure0, T.generateUuidV4__printDigits, T.generateUuidV4__bitsDigits, D.main__closure0, D.main_closure0, S.toPromise_closure]); _inherit(H.CastList, H._CastListBase); _inherit(P.MapBase, P.MapMixin); @@ -25000,7 +24985,7 @@ typeUniverse: {eC: new Map(), tR: {}, eT: {}, tPV: {}, sEA: []}, mangledGlobalNames: {int: "int", double: "double", num: "num", String: "String", bool: "bool", Null: "Null", List: "List"}, mangledNames: {}, - types: ["~()", "@(@)", "Null()", "Object?(@)", "~(@)", "~(Event)", "~(String,@)", "Null(@)", "~(@,@)", "Null(Object,StackTrace)", "~(~())", "bool(@)", "bool(Object?,Object?)", "int(Object?)", "bool(Element,String,String,_Html5NodeValidator)", "~(Object[StackTrace?])", "~(Object,StackTrace)", "~(Object?)", "~(Object?,Object?)", "~(Symbol0,@)", "int(int,int)", "int(int)", "String(int)", "String(String)", "~(Uint8List,String,int)", "Future()", "bool(NodeValidator)", "bool(String)", "Object?(Object?)", "String(int,int)", "Null(Event)", "ScriptElement*()", "int(@,@)", "~(ProgressEvent)", "~(String,String)", "@(@,String)", "Null(~())", "Null(@,StackTrace)", "~(Node,Node?)", "Null(@,@)", "@(@,@)", "JsFunction(@)", "JsArray<@>(@)", "JsObject(@)", "int(int,@)", "IndentingBuiltValueToStringHelper(String)", "ListBuilder()", "ListMultimapBuilder()", "MapBuilder()", "SetBuilder()", "SetMultimapBuilder()", "~(int,@)", "~(@,StackTrace)", "~(String,int)", "~(String[@])", "bool(Object?)", "ListBuilder*()", "String*(@)", "Logger()", "~(String?)", "~(Zone,ZoneDelegate,Zone,Object,StackTrace)", "Uint8List(@,@)", "~(MessageEvent)", "Null(CloseEvent)", "Future*()", "bool(Object,Object)", "Null(String*,String*)", "DebugEventBuilder*(DebugEventBuilder*)", "Null(String*)", "RegisterEventBuilder*(RegisterEventBuilder*)", "DevToolsRequestBuilder*(DevToolsRequestBuilder*)", "Future*(String*)", "Null(Event*)", "ConnectRequestBuilder*(ConnectRequestBuilder*)", "Null(Object*,StackTrace*)", "Null(MessageEvent*)", "List*(String*)", "int*(String*,String*)", "~(JsError*)", "ScriptElement*()*()", "@(String)", "bool(Node)", "Promise<1&>*()", "~(Zone?,ZoneDelegate?,Zone,Object,StackTrace)", "0^(Zone?,ZoneDelegate?,Zone,0^())", "0^(Zone?,ZoneDelegate?,Zone,0^(1^),1^)", "0^(Zone?,ZoneDelegate?,Zone,0^(1^,2^),1^,2^)", "0^()(Zone,ZoneDelegate,Zone,0^())", "0^(1^)(Zone,ZoneDelegate,Zone,0^(1^))", "0^(1^,2^)(Zone,ZoneDelegate,Zone,0^(1^,2^))", "AsyncError?(Zone,ZoneDelegate,Zone,Object,StackTrace?)", "~(Zone?,ZoneDelegate?,Zone,~())", "Timer(Zone,ZoneDelegate,Zone,Duration,~())", "Timer(Zone,ZoneDelegate,Zone,Duration,~(Timer))", "~(Zone,ZoneDelegate,Zone,String)", "~(String)", "Zone(Zone?,ZoneDelegate?,Zone,ZoneSpecification?,Map?)", "~([Object?])", "_Future<@>(@)"], + types: ["~()", "@(@)", "Null()", "Object?(@)", "~(@)", "~(Event)", "~(String,@)", "Null(@)", "~(@,@)", "Null(Object,StackTrace)", "~(~())", "bool(@)", "bool(Object?,Object?)", "int(Object?)", "bool(Element,String,String,_Html5NodeValidator)", "~(Object[StackTrace?])", "~(Object,StackTrace)", "~(Object?)", "~(Object?,Object?)", "~(Symbol0,@)", "int(int,int)", "int(int)", "String(String)", "~(Uint8List,String,int)", "Future()", "bool(NodeValidator)", "bool(String)", "Object?(Object?)", "String(int,int)", "Null(Event)", "ScriptElement*()", "int(@,@)", "~(ProgressEvent)", "~(String,String)", "~([Object?])", "@(@,String)", "Null(~())", "~(Node,Node?)", "Null(@,@)", "@(@,@)", "JsFunction(@)", "JsArray<@>(@)", "JsObject(@)", "int(int,@)", "IndentingBuiltValueToStringHelper(String)", "ListBuilder()", "ListMultimapBuilder()", "MapBuilder()", "SetBuilder()", "SetMultimapBuilder()", "Null(@,StackTrace)", "~(int,@)", "~(String,int)", "~(String[@])", "bool(Object?)", "ListBuilder*()", "String*(@)", "Logger()", "~(String?)", "~(@,StackTrace)", "Uint8List(@,@)", "~(MessageEvent)", "Null(CloseEvent)", "Future*()", "bool(Object,Object)", "Null(String*,String*)", "DebugEventBuilder*(DebugEventBuilder*)", "Null(String*)", "RegisterEventBuilder*(RegisterEventBuilder*)", "DevToolsRequestBuilder*(DevToolsRequestBuilder*)", "Future*(String*)", "Null(Event*)", "ConnectRequestBuilder*(ConnectRequestBuilder*)", "Null(Object*,StackTrace*)", "Null(MessageEvent*)", "List*(String*)", "int*(String*,String*)", "~(JsError*)", "ScriptElement*()*()", "~(Zone,ZoneDelegate,Zone,Object,StackTrace)", "bool(Node)", "Promise<1&>*()", "~(Zone?,ZoneDelegate?,Zone,Object,StackTrace)", "0^(Zone?,ZoneDelegate?,Zone,0^())", "0^(Zone?,ZoneDelegate?,Zone,0^(1^),1^)", "0^(Zone?,ZoneDelegate?,Zone,0^(1^,2^),1^,2^)", "0^()(Zone,ZoneDelegate,Zone,0^())", "0^(1^)(Zone,ZoneDelegate,Zone,0^(1^))", "0^(1^,2^)(Zone,ZoneDelegate,Zone,0^(1^,2^))", "AsyncError?(Zone,ZoneDelegate,Zone,Object,StackTrace?)", "~(Zone?,ZoneDelegate?,Zone,~())", "Timer(Zone,ZoneDelegate,Zone,Duration,~())", "Timer(Zone,ZoneDelegate,Zone,Duration,~(Timer))", "~(Zone,ZoneDelegate,Zone,String)", "~(String)", "Zone(Zone?,ZoneDelegate?,Zone,ZoneSpecification?,Map?)", "@(String)", "_Future<@>(@)"], interceptorsByTag: null, leafTags: null, arrayRti: Symbol("$ti") diff --git a/dwds/lib/src/services/debug_service.dart b/dwds/lib/src/services/debug_service.dart index f9c4819fe..b15c7b0f1 100644 --- a/dwds/lib/src/services/debug_service.dart +++ b/dwds/lib/src/services/debug_service.dart @@ -252,7 +252,7 @@ class DebugService { return innerHandler(request); }; } - var server = await startHttpServer(hostname); + var server = await startHttpServer(hostname, port: 44456); serveRequests(server, handler); return DebugService._( chromeProxyService, diff --git a/dwds/lib/src/utilities/shared.dart b/dwds/lib/src/utilities/shared.dart index a485f70d2..a5e281371 100644 --- a/dwds/lib/src/utilities/shared.dart +++ b/dwds/lib/src/utilities/shared.dart @@ -52,19 +52,21 @@ Future findUnusedPort() async { /// /// Retries a few times to recover from errors due to /// another thread or process opening the same port. +/// Starts by trying to bind to [port] if specified. Future startHttpServer(String hostname, {int port}) async { HttpServer httpServer; var retries = 5; var i = 0; + port = port ?? await findUnusedPort(); while (i < retries) { i++; try { - httpServer = - await HttpMultiServer.bind(hostname, port ?? await findUnusedPort()); + httpServer = await HttpMultiServer.bind(hostname, port); } on SocketException { if (i == retries) rethrow; } if (httpServer != null || i == retries) return httpServer; + port = await findUnusedPort(); await Future.delayed(const Duration(milliseconds: 100)); } return httpServer; diff --git a/dwds/test/handlers/injector_test.dart b/dwds/test/handlers/injector_test.dart index 7b9f49fa1..7ece9da12 100644 --- a/dwds/test/handlers/injector_test.dart +++ b/dwds/test/handlers/injector_test.dart @@ -252,7 +252,8 @@ void main() { setUp(() async { var extensionUri = 'http://localhost:4000'; var pipeline = const Pipeline().addMiddleware( - DwdsInjector(loadStrategy, extensionUri: extensionUri).middleware); + DwdsInjector(loadStrategy, extensionUri: Future.value(extensionUri)) + .middleware); server = await shelf_io.serve(pipeline.addHandler((request) { return Response.ok( '$entrypointExtensionMarker\n'