Skip to content

Commit d00acae

Browse files
nshahanCommit Queue
authored andcommitted
[ddc] Remove old dwds versions fallback support
The dart:developer APIs `registerExtension()` and `postEvent()` no longer write directly to the console. Fixes: #48103 Change-Id: I41ee807eb376abbac87d0f353dde22bebd732faa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279233 Reviewed-by: Anna Gringauze <[email protected]> Commit-Queue: Nicholas Shahan <[email protected]>
1 parent 5aa5308 commit d00acae

File tree

3 files changed

+47
-131
lines changed

3 files changed

+47
-131
lines changed

sdk/lib/_internal/js_dev_runtime/patch/developer_patch.dart

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'dart:convert' show json;
1313
import 'dart:isolate';
1414

1515
var _issuedRegisterExtensionWarning = false;
16+
var _issuedPostEventWarning = false;
1617
final _developerSupportWarning = 'from dart:developer is only supported in '
1718
'build/run/test environments where the developer event method hooks have '
1819
'been set by package:dwds v11.1.0 or higher.';
@@ -86,10 +87,7 @@ _registerExtension(String method, ServiceExtensionHandler handler) {
8687
// See hooks assigned by package:dwds:
8788
// https://github.com/dart-lang/webdev/blob/de05cf9fbbfe088be74bb61df4a138289a94d902/dwds/web/client.dart#L223
8889
JS('', r'#.$emitRegisterEvent(#)', dart.global_, method);
89-
return;
9090
}
91-
// TODO(48103) Remove use of debug log in Dart 3.0.0.
92-
JS('', 'console.debug("dart.developer.registerExtension", #)', method);
9391
}
9492

9593
/// Returns a JS `Promise` that resolves with the result of invoking
@@ -124,16 +122,20 @@ bool get extensionStreamHasListener => _debuggerAttached;
124122

125123
@patch
126124
void _postEvent(String eventKind, String eventData) {
125+
if (!_debuggerAttached) {
126+
if (!_issuedPostEventWarning) {
127+
var message = 'postEvent() $_developerSupportWarning';
128+
JS('', 'console.warn(#)', message);
129+
_issuedPostEventWarning = true;
130+
}
131+
return;
132+
}
127133
// TODO(46377) Update this check when we have a documented API for DDC apps.
128134
if (JS<bool>('!', r'!!#.$emitDebugEvent', dart.global_)) {
129135
// See hooks assigned by package:dwds:
130136
// https://github.com/dart-lang/webdev/blob/de05cf9fbbfe088be74bb61df4a138289a94d902/dwds/web/client.dart#L220
131137
JS('', r'#.$emitDebugEvent(#, #)', dart.global_, eventKind, eventData);
132-
return;
133138
}
134-
// TODO(48103) Remove use of debug log in Dart 3.0.0.
135-
JS('', 'console.debug("dart.developer.postEvent", #, #)', eventKind,
136-
eventData);
137139
}
138140

139141
@patch

tests/dartdevc/developer_events_test.dart

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ library developer_events_test;
77

88
import 'dart:developer'
99
show postEvent, registerExtension, ServiceExtensionResponse;
10-
import 'dart:convert';
1110

1211
import 'package:js/js.dart';
1312
import 'package:expect/expect.dart';
@@ -50,69 +49,17 @@ class _TestDebugEvent {
5049
}
5150

5251
void main() {
53-
testBackwardsCompatibility();
54-
testWarningMessages();
52+
testRegisterExtensionWarningMessage();
5553
testPostEvent();
5654
testRegisterExtension();
5755
}
5856

59-
/// Verify backwards compatibility for sending messages on the console.debug log
60-
/// in the chrome browser when the hooks have not been set.
61-
// TODO(nshahan) Remove testing of debug log after package:dwds removes support.
62-
// https://github.com/dart-lang/webdev/issues/1342`
63-
void testBackwardsCompatibility() {
64-
var consoleDebugLog = <List>[];
65-
var savedConsoleDebug = consoleDebug;
66-
var savedDwdsVersion = dwdsVersion;
67-
68-
try {
69-
// Patch our own console.debug function for testing.
70-
consoleDebug = allowInterop((arg1, [arg2, arg3]) => consoleDebugLog.add([
71-
arg1,
72-
if (arg2 != null) arg2,
73-
if (arg3 != null) arg3,
74-
]));
75-
// Provide a version to signal there is an attached debugger.
76-
dwdsVersion = '1.0.0-for-test';
77-
78-
// All post and register events should go to the console debug log.
79-
var data0 = {'key0': 'value0'};
80-
postEvent('kind0', data0);
81-
82-
expect(consoleDebugLog.single[0], 'dart.developer.postEvent');
83-
expect(consoleDebugLog.single[1], 'kind0');
84-
Expect.contains('"key0":"value0"', consoleDebugLog.single[2]);
85-
86-
var testHandler = (String s, Map<String, String> m) async =>
87-
ServiceExtensionResponse.result('test result');
88-
89-
registerExtension('ext.method0', testHandler);
90-
expect(consoleDebugLog.length, 2);
91-
expect(consoleDebugLog[1].first, 'dart.developer.registerExtension');
92-
expect(consoleDebugLog[1].last, 'ext.method0');
93-
94-
var data1 = {'key1': 'value1'};
95-
postEvent('kind1', data1);
96-
97-
expect(consoleDebugLog.length, 3);
98-
expect(consoleDebugLog[2][0], 'dart.developer.postEvent');
99-
expect(consoleDebugLog[2][1], 'kind1');
100-
Expect.contains('"key1":"value1"', consoleDebugLog[2][2]);
101-
102-
registerExtension('ext.method1', testHandler);
103-
expect(consoleDebugLog.length, 4);
104-
expect(consoleDebugLog[3].first, 'dart.developer.registerExtension');
105-
expect(consoleDebugLog[3].last, 'ext.method1');
106-
} finally {
107-
// Restore actual console.debug function.
108-
consoleDebug = savedConsoleDebug;
109-
dwdsVersion = savedDwdsVersion;
110-
}
111-
}
112-
113-
/// Verify that warning messages are printed on the first call of postEvent()
114-
/// and registerExtension() when the hooks are undefined.
115-
void testWarningMessages() {
57+
/// Verify that warning messages are printed on the first call of
58+
/// `registerExtension()` when the hooks are undefined.
59+
///
60+
/// Calls to `postEvent()` are always a no-op when no extension has been
61+
/// registered to listen which can never happen if the hook is undefined.
62+
void testRegisterExtensionWarningMessage() {
11663
final consoleWarnLog = <String>[];
11764
var savedConsoleWarn = consoleWarn;
11865
try {
@@ -130,8 +77,9 @@ void testWarningMessages() {
13077
var data1 = {'key1': 'value1'};
13178
postEvent('kind1', data1);
13279

133-
// No warnings should be issued because postEvent is a no-op.
134-
expect(consoleWarnLog.length, 0);
80+
// No warnings should be issued because postEvent is a no-op when no
81+
// extensions have been registered to listen.
82+
expect(consoleWarnLog.isEmpty, true);
13583

13684
consoleWarnLog.clear();
13785

@@ -154,6 +102,15 @@ void testWarningMessages() {
154102

155103
// A warning is only issued on the first call of `registerExtension()`.
156104
expect(consoleWarnLog.length, 1);
105+
106+
consoleWarnLog.clear();
107+
108+
// The earlier call to registerExtension() was a no-op and printed a warning
109+
// because no debugger hooks are defined. This means more calls to
110+
// `postEvent()` are still no ops.
111+
postEvent('kind0', data0);
112+
postEvent('kind1', data1);
113+
expect(consoleWarnLog.isEmpty, true);
157114
} finally {
158115
// Restore actual console.warn function.
159116
consoleWarn = savedConsoleWarn;

tests/dartdevc_2/developer_events_test.dart

Lines changed: 19 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ library developer_events_test;
77

88
import 'dart:developer'
99
show postEvent, registerExtension, ServiceExtensionResponse;
10-
import 'dart:convert';
1110

1211
import 'package:js/js.dart';
1312
import 'package:expect/expect.dart';
@@ -50,69 +49,17 @@ class _TestDebugEvent {
5049
}
5150

5251
void main() {
53-
testBackwardsCompatibility();
54-
testWarningMessages();
52+
testRegisterExtensionWarningMessage();
5553
testPostEvent();
5654
testRegisterExtension();
5755
}
5856

59-
/// Verify backwards compatibility for sending messages on the console.debug log
60-
/// in the chrome browser when the hooks have not been set.
61-
// TODO(nshahan) Remove testing of debug log after package:dwds removes support.
62-
// https://github.com/dart-lang/webdev/issues/1342`
63-
void testBackwardsCompatibility() {
64-
var consoleDebugLog = <List>[];
65-
var savedConsoleDebug = consoleDebug;
66-
var savedDwdsVersion = dwdsVersion;
67-
68-
try {
69-
// Patch our own console.debug function for testing.
70-
consoleDebug = allowInterop((arg1, [arg2, arg3]) => consoleDebugLog.add([
71-
arg1,
72-
if (arg2 != null) arg2,
73-
if (arg3 != null) arg3,
74-
]));
75-
// Provide a version to signal there is an attached debugger.
76-
dwdsVersion = '1.0.0-for-test';
77-
78-
// All post and register events should go to the console debug log.
79-
var data0 = {'key0': 'value0'};
80-
postEvent('kind0', data0);
81-
82-
expect(consoleDebugLog.single[0], 'dart.developer.postEvent');
83-
expect(consoleDebugLog.single[1], 'kind0');
84-
Expect.contains('"key0":"value0"', consoleDebugLog.single[2]);
85-
86-
var testHandler = (String s, Map<String, String> m) async =>
87-
ServiceExtensionResponse.result('test result');
88-
89-
registerExtension('ext.method0', testHandler);
90-
expect(consoleDebugLog.length, 2);
91-
expect(consoleDebugLog[1].first, 'dart.developer.registerExtension');
92-
expect(consoleDebugLog[1].last, 'ext.method0');
93-
94-
var data1 = {'key1': 'value1'};
95-
postEvent('kind1', data1);
96-
97-
expect(consoleDebugLog.length, 3);
98-
expect(consoleDebugLog[2][0], 'dart.developer.postEvent');
99-
expect(consoleDebugLog[2][1], 'kind1');
100-
Expect.contains('"key1":"value1"', consoleDebugLog[2][2]);
101-
102-
registerExtension('ext.method1', testHandler);
103-
expect(consoleDebugLog.length, 4);
104-
expect(consoleDebugLog[3].first, 'dart.developer.registerExtension');
105-
expect(consoleDebugLog[3].last, 'ext.method1');
106-
} finally {
107-
// Restore actual console.debug function.
108-
consoleDebug = savedConsoleDebug;
109-
dwdsVersion = savedDwdsVersion;
110-
}
111-
}
112-
113-
/// Verify that warning messages are printed on the first call of postEvent()
114-
/// and registerExtension() when the hooks are undefined.
115-
void testWarningMessages() {
57+
/// Verify that warning messages are printed on the first call of
58+
/// `registerExtension()` when the hooks are undefined.
59+
///
60+
/// Calls to `postEvent()` are always a no-op when no extension has been
61+
/// registered to listen which can never happen if the hook is undefined.
62+
void testRegisterExtensionWarningMessage() {
11663
final consoleWarnLog = <String>[];
11764
var savedConsoleWarn = consoleWarn;
11865
try {
@@ -130,8 +77,9 @@ void testWarningMessages() {
13077
var data1 = {'key1': 'value1'};
13178
postEvent('kind1', data1);
13279

133-
// No warnings should be issued because postEvent is a no-op.
134-
expect(consoleWarnLog.length, 0);
80+
// No warnings should be issued because postEvent is a no-op when no
81+
// extensions have been registered to listen.
82+
expect(consoleWarnLog.isEmpty, true);
13583

13684
consoleWarnLog.clear();
13785

@@ -154,6 +102,15 @@ void testWarningMessages() {
154102

155103
// A warning is only issued on the first call of `registerExtension()`.
156104
expect(consoleWarnLog.length, 1);
105+
106+
consoleWarnLog.clear();
107+
108+
// The earlier call to registerExtension() was a no-op and printed a warning
109+
// because no debugger hooks are defined. This means more calls to
110+
// `postEvent()` are still no ops.
111+
postEvent('kind0', data0);
112+
postEvent('kind1', data1);
113+
expect(consoleWarnLog.isEmpty, true);
157114
} finally {
158115
// Restore actual console.warn function.
159116
consoleWarn = savedConsoleWarn;

0 commit comments

Comments
 (0)