mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 01:30:32 +00:00
[ddc] Remove old dwds versions fallback support
The dart:developer APIs `registerExtension()` and `postEvent()` no longer write directly to the console. Fixes: https://github.com/dart-lang/sdk/issues/48103 Change-Id: I41ee807eb376abbac87d0f353dde22bebd732faa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/279233 Reviewed-by: Anna Gringauze <annagrin@google.com> Commit-Queue: Nicholas Shahan <nshahan@google.com>
This commit is contained in:
parent
5aa53088e5
commit
d00acae4ae
|
@ -13,6 +13,7 @@ import 'dart:convert' show json;
|
|||
import 'dart:isolate';
|
||||
|
||||
var _issuedRegisterExtensionWarning = false;
|
||||
var _issuedPostEventWarning = false;
|
||||
final _developerSupportWarning = 'from dart:developer is only supported in '
|
||||
'build/run/test environments where the developer event method hooks have '
|
||||
'been set by package:dwds v11.1.0 or higher.';
|
||||
|
@ -86,10 +87,7 @@ _registerExtension(String method, ServiceExtensionHandler handler) {
|
|||
// See hooks assigned by package:dwds:
|
||||
// https://github.com/dart-lang/webdev/blob/de05cf9fbbfe088be74bb61df4a138289a94d902/dwds/web/client.dart#L223
|
||||
JS('', r'#.$emitRegisterEvent(#)', dart.global_, method);
|
||||
return;
|
||||
}
|
||||
// TODO(48103) Remove use of debug log in Dart 3.0.0.
|
||||
JS('', 'console.debug("dart.developer.registerExtension", #)', method);
|
||||
}
|
||||
|
||||
/// Returns a JS `Promise` that resolves with the result of invoking
|
||||
|
@ -124,16 +122,20 @@ bool get extensionStreamHasListener => _debuggerAttached;
|
|||
|
||||
@patch
|
||||
void _postEvent(String eventKind, String eventData) {
|
||||
if (!_debuggerAttached) {
|
||||
if (!_issuedPostEventWarning) {
|
||||
var message = 'postEvent() $_developerSupportWarning';
|
||||
JS('', 'console.warn(#)', message);
|
||||
_issuedPostEventWarning = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
// TODO(46377) Update this check when we have a documented API for DDC apps.
|
||||
if (JS<bool>('!', r'!!#.$emitDebugEvent', dart.global_)) {
|
||||
// See hooks assigned by package:dwds:
|
||||
// https://github.com/dart-lang/webdev/blob/de05cf9fbbfe088be74bb61df4a138289a94d902/dwds/web/client.dart#L220
|
||||
JS('', r'#.$emitDebugEvent(#, #)', dart.global_, eventKind, eventData);
|
||||
return;
|
||||
}
|
||||
// TODO(48103) Remove use of debug log in Dart 3.0.0.
|
||||
JS('', 'console.debug("dart.developer.postEvent", #, #)', eventKind,
|
||||
eventData);
|
||||
}
|
||||
|
||||
@patch
|
||||
|
|
|
@ -7,7 +7,6 @@ library developer_events_test;
|
|||
|
||||
import 'dart:developer'
|
||||
show postEvent, registerExtension, ServiceExtensionResponse;
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:js/js.dart';
|
||||
import 'package:expect/expect.dart';
|
||||
|
@ -50,69 +49,17 @@ class _TestDebugEvent {
|
|||
}
|
||||
|
||||
void main() {
|
||||
testBackwardsCompatibility();
|
||||
testWarningMessages();
|
||||
testRegisterExtensionWarningMessage();
|
||||
testPostEvent();
|
||||
testRegisterExtension();
|
||||
}
|
||||
|
||||
/// Verify backwards compatibility for sending messages on the console.debug log
|
||||
/// in the chrome browser when the hooks have not been set.
|
||||
// TODO(nshahan) Remove testing of debug log after package:dwds removes support.
|
||||
// https://github.com/dart-lang/webdev/issues/1342`
|
||||
void testBackwardsCompatibility() {
|
||||
var consoleDebugLog = <List>[];
|
||||
var savedConsoleDebug = consoleDebug;
|
||||
var savedDwdsVersion = dwdsVersion;
|
||||
|
||||
try {
|
||||
// Patch our own console.debug function for testing.
|
||||
consoleDebug = allowInterop((arg1, [arg2, arg3]) => consoleDebugLog.add([
|
||||
arg1,
|
||||
if (arg2 != null) arg2,
|
||||
if (arg3 != null) arg3,
|
||||
]));
|
||||
// Provide a version to signal there is an attached debugger.
|
||||
dwdsVersion = '1.0.0-for-test';
|
||||
|
||||
// All post and register events should go to the console debug log.
|
||||
var data0 = {'key0': 'value0'};
|
||||
postEvent('kind0', data0);
|
||||
|
||||
expect(consoleDebugLog.single[0], 'dart.developer.postEvent');
|
||||
expect(consoleDebugLog.single[1], 'kind0');
|
||||
Expect.contains('"key0":"value0"', consoleDebugLog.single[2]);
|
||||
|
||||
var testHandler = (String s, Map<String, String> m) async =>
|
||||
ServiceExtensionResponse.result('test result');
|
||||
|
||||
registerExtension('ext.method0', testHandler);
|
||||
expect(consoleDebugLog.length, 2);
|
||||
expect(consoleDebugLog[1].first, 'dart.developer.registerExtension');
|
||||
expect(consoleDebugLog[1].last, 'ext.method0');
|
||||
|
||||
var data1 = {'key1': 'value1'};
|
||||
postEvent('kind1', data1);
|
||||
|
||||
expect(consoleDebugLog.length, 3);
|
||||
expect(consoleDebugLog[2][0], 'dart.developer.postEvent');
|
||||
expect(consoleDebugLog[2][1], 'kind1');
|
||||
Expect.contains('"key1":"value1"', consoleDebugLog[2][2]);
|
||||
|
||||
registerExtension('ext.method1', testHandler);
|
||||
expect(consoleDebugLog.length, 4);
|
||||
expect(consoleDebugLog[3].first, 'dart.developer.registerExtension');
|
||||
expect(consoleDebugLog[3].last, 'ext.method1');
|
||||
} finally {
|
||||
// Restore actual console.debug function.
|
||||
consoleDebug = savedConsoleDebug;
|
||||
dwdsVersion = savedDwdsVersion;
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify that warning messages are printed on the first call of postEvent()
|
||||
/// and registerExtension() when the hooks are undefined.
|
||||
void testWarningMessages() {
|
||||
/// Verify that warning messages are printed on the first call of
|
||||
/// `registerExtension()` when the hooks are undefined.
|
||||
///
|
||||
/// Calls to `postEvent()` are always a no-op when no extension has been
|
||||
/// registered to listen which can never happen if the hook is undefined.
|
||||
void testRegisterExtensionWarningMessage() {
|
||||
final consoleWarnLog = <String>[];
|
||||
var savedConsoleWarn = consoleWarn;
|
||||
try {
|
||||
|
@ -130,8 +77,9 @@ void testWarningMessages() {
|
|||
var data1 = {'key1': 'value1'};
|
||||
postEvent('kind1', data1);
|
||||
|
||||
// No warnings should be issued because postEvent is a no-op.
|
||||
expect(consoleWarnLog.length, 0);
|
||||
// No warnings should be issued because postEvent is a no-op when no
|
||||
// extensions have been registered to listen.
|
||||
expect(consoleWarnLog.isEmpty, true);
|
||||
|
||||
consoleWarnLog.clear();
|
||||
|
||||
|
@ -154,6 +102,15 @@ void testWarningMessages() {
|
|||
|
||||
// A warning is only issued on the first call of `registerExtension()`.
|
||||
expect(consoleWarnLog.length, 1);
|
||||
|
||||
consoleWarnLog.clear();
|
||||
|
||||
// The earlier call to registerExtension() was a no-op and printed a warning
|
||||
// because no debugger hooks are defined. This means more calls to
|
||||
// `postEvent()` are still no ops.
|
||||
postEvent('kind0', data0);
|
||||
postEvent('kind1', data1);
|
||||
expect(consoleWarnLog.isEmpty, true);
|
||||
} finally {
|
||||
// Restore actual console.warn function.
|
||||
consoleWarn = savedConsoleWarn;
|
||||
|
|
|
@ -7,7 +7,6 @@ library developer_events_test;
|
|||
|
||||
import 'dart:developer'
|
||||
show postEvent, registerExtension, ServiceExtensionResponse;
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:js/js.dart';
|
||||
import 'package:expect/expect.dart';
|
||||
|
@ -50,69 +49,17 @@ class _TestDebugEvent {
|
|||
}
|
||||
|
||||
void main() {
|
||||
testBackwardsCompatibility();
|
||||
testWarningMessages();
|
||||
testRegisterExtensionWarningMessage();
|
||||
testPostEvent();
|
||||
testRegisterExtension();
|
||||
}
|
||||
|
||||
/// Verify backwards compatibility for sending messages on the console.debug log
|
||||
/// in the chrome browser when the hooks have not been set.
|
||||
// TODO(nshahan) Remove testing of debug log after package:dwds removes support.
|
||||
// https://github.com/dart-lang/webdev/issues/1342`
|
||||
void testBackwardsCompatibility() {
|
||||
var consoleDebugLog = <List>[];
|
||||
var savedConsoleDebug = consoleDebug;
|
||||
var savedDwdsVersion = dwdsVersion;
|
||||
|
||||
try {
|
||||
// Patch our own console.debug function for testing.
|
||||
consoleDebug = allowInterop((arg1, [arg2, arg3]) => consoleDebugLog.add([
|
||||
arg1,
|
||||
if (arg2 != null) arg2,
|
||||
if (arg3 != null) arg3,
|
||||
]));
|
||||
// Provide a version to signal there is an attached debugger.
|
||||
dwdsVersion = '1.0.0-for-test';
|
||||
|
||||
// All post and register events should go to the console debug log.
|
||||
var data0 = {'key0': 'value0'};
|
||||
postEvent('kind0', data0);
|
||||
|
||||
expect(consoleDebugLog.single[0], 'dart.developer.postEvent');
|
||||
expect(consoleDebugLog.single[1], 'kind0');
|
||||
Expect.contains('"key0":"value0"', consoleDebugLog.single[2]);
|
||||
|
||||
var testHandler = (String s, Map<String, String> m) async =>
|
||||
ServiceExtensionResponse.result('test result');
|
||||
|
||||
registerExtension('ext.method0', testHandler);
|
||||
expect(consoleDebugLog.length, 2);
|
||||
expect(consoleDebugLog[1].first, 'dart.developer.registerExtension');
|
||||
expect(consoleDebugLog[1].last, 'ext.method0');
|
||||
|
||||
var data1 = {'key1': 'value1'};
|
||||
postEvent('kind1', data1);
|
||||
|
||||
expect(consoleDebugLog.length, 3);
|
||||
expect(consoleDebugLog[2][0], 'dart.developer.postEvent');
|
||||
expect(consoleDebugLog[2][1], 'kind1');
|
||||
Expect.contains('"key1":"value1"', consoleDebugLog[2][2]);
|
||||
|
||||
registerExtension('ext.method1', testHandler);
|
||||
expect(consoleDebugLog.length, 4);
|
||||
expect(consoleDebugLog[3].first, 'dart.developer.registerExtension');
|
||||
expect(consoleDebugLog[3].last, 'ext.method1');
|
||||
} finally {
|
||||
// Restore actual console.debug function.
|
||||
consoleDebug = savedConsoleDebug;
|
||||
dwdsVersion = savedDwdsVersion;
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify that warning messages are printed on the first call of postEvent()
|
||||
/// and registerExtension() when the hooks are undefined.
|
||||
void testWarningMessages() {
|
||||
/// Verify that warning messages are printed on the first call of
|
||||
/// `registerExtension()` when the hooks are undefined.
|
||||
///
|
||||
/// Calls to `postEvent()` are always a no-op when no extension has been
|
||||
/// registered to listen which can never happen if the hook is undefined.
|
||||
void testRegisterExtensionWarningMessage() {
|
||||
final consoleWarnLog = <String>[];
|
||||
var savedConsoleWarn = consoleWarn;
|
||||
try {
|
||||
|
@ -130,8 +77,9 @@ void testWarningMessages() {
|
|||
var data1 = {'key1': 'value1'};
|
||||
postEvent('kind1', data1);
|
||||
|
||||
// No warnings should be issued because postEvent is a no-op.
|
||||
expect(consoleWarnLog.length, 0);
|
||||
// No warnings should be issued because postEvent is a no-op when no
|
||||
// extensions have been registered to listen.
|
||||
expect(consoleWarnLog.isEmpty, true);
|
||||
|
||||
consoleWarnLog.clear();
|
||||
|
||||
|
@ -154,6 +102,15 @@ void testWarningMessages() {
|
|||
|
||||
// A warning is only issued on the first call of `registerExtension()`.
|
||||
expect(consoleWarnLog.length, 1);
|
||||
|
||||
consoleWarnLog.clear();
|
||||
|
||||
// The earlier call to registerExtension() was a no-op and printed a warning
|
||||
// because no debugger hooks are defined. This means more calls to
|
||||
// `postEvent()` are still no ops.
|
||||
postEvent('kind0', data0);
|
||||
postEvent('kind1', data1);
|
||||
expect(consoleWarnLog.isEmpty, true);
|
||||
} finally {
|
||||
// Restore actual console.warn function.
|
||||
consoleWarn = savedConsoleWarn;
|
||||
|
|
Loading…
Reference in a new issue