diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index e6bbfb991..01a70eb33 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,6 +1,7 @@ ## 24.2.1 - Update to be forward compatible with changes to `package:shelf_web_socket`. +- Added support for some debugging APIs with the DDC library bundle format. - [#2537](https://github.com/dart-lang/webdev/issues/2537) - Expose a partial implementation of `FrontendServerDdcLibraryBundleStrategyProvider`. diff --git a/dwds/lib/src/debugging/dart_runtime_debugger.dart b/dwds/lib/src/debugging/dart_runtime_debugger.dart index beb2f6520..0a8cd4d2f 100644 --- a/dwds/lib/src/debugging/dart_runtime_debugger.dart +++ b/dwds/lib/src/debugging/dart_runtime_debugger.dart @@ -107,4 +107,57 @@ class DartRuntimeDebugger { // Use the helper method to wrap this in an IIFE return _wrapInIIFE(expression); } + + /// Generates a JS expression for retrieving Dart Developer Extension Names. + String getDartDeveloperExtensionNamesJsExpression() { + return _generateJsExpression( + "${_loadStrategy.loadModuleSnippet}('dart_sdk').developer._extensions.keys.toList();", + 'dartDevEmbedder.debugger.extensionNames', + ); + } + + /// Generates a JS expression for retrieving metadata of classes in a library. + String getClassesInLibraryJsExpression(String libraryUri) { + final expression = _buildExpression( + '', + "getLibraryMetadata('$libraryUri')", + "getClassesInLibrary('$libraryUri')", + ); + // Use the helper method to wrap this in an IIFE + return _wrapInIIFE(expression); + } + + /// Generates a JS expression for retrieving map elements. + String getMapElementsJsExpression() { + return _buildExpression( + '', + 'getMapElements(this)', + 'getMapElements(this)', + ); + } + + /// Generates a JS expression for getting a property from a JS object. + String getPropertyJsExpression(String fieldName) { + return _generateJsExpression( + ''' + function() { + return this["$fieldName"]; + } + ''', + ''' + function() { + return this["$fieldName"]; + } + ''', + ); + } + + /// Generates a JS expression for retrieving set elements. + String getSetElementsJsExpression() { + return _buildExpression( + '', + 'getSetElements(this)', + 'getSetElements(this)', + ); + } } diff --git a/dwds/lib/src/debugging/inspector.dart b/dwds/lib/src/debugging/inspector.dart index 49a3b443a..23f47504d 100644 --- a/dwds/lib/src/debugging/inspector.dart +++ b/dwds/lib/src/debugging/inspector.dart @@ -192,11 +192,8 @@ class AppInspector implements AppInspectorInterface { /// Get the value of the field named [fieldName] from [receiver]. @override Future loadField(RemoteObject receiver, String fieldName) { - final load = ''' - function() { - return ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").dart.dloadRepl(this, "$fieldName"); - } - '''; + final load = globalToolConfiguration.loadStrategy.dartRuntimeDebugger + .getPropertyJsExpression(fieldName); return jsCallFunctionOn(receiver, load, []); } @@ -748,8 +745,8 @@ class AppInspector implements AppInspectorInterface { /// Runs an eval on the page to compute all existing registered extensions. Future> _getExtensionRpcs() async { - final expression = - "${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk').developer._extensions.keys.toList();"; + final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger + .getDartDeveloperExtensionNamesJsExpression(); final extensionRpcs = []; final params = { 'expression': expression, diff --git a/dwds/lib/src/debugging/instance.dart b/dwds/lib/src/debugging/instance.dart index e11e9dda5..35c8698f9 100644 --- a/dwds/lib/src/debugging/instance.dart +++ b/dwds/lib/src/debugging/instance.dart @@ -306,7 +306,8 @@ class InstanceHelper extends Domain { // We do this in in awkward way because we want the keys and values, but we // can't return things by value or some Dart objects will come back as // values that we need to be RemoteObject, e.g. a List of int. - final expression = _jsRuntimeFunctionCall('getMapElements(this)'); + final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger + .getMapElementsJsExpression(); final keysAndValues = await inspector.jsCallFunctionOn(map, expression, []); final keys = await inspector.loadField(keysAndValues, 'keys'); @@ -674,8 +675,8 @@ class InstanceHelper extends Domain { final length = metaData.length; final objectId = remoteObject.objectId; if (objectId == null) return null; - - final expression = _jsRuntimeFunctionCall('getSetElements(this)'); + final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger + .getSetElementsJsExpression(); final result = await inspector.jsCallFunctionOn(remoteObject, expression, []); diff --git a/dwds/lib/src/debugging/libraries.dart b/dwds/lib/src/debugging/libraries.dart index f36e11e6a..0b50f6518 100644 --- a/dwds/lib/src/debugging/libraries.dart +++ b/dwds/lib/src/debugging/libraries.dart @@ -82,13 +82,8 @@ class LibraryHelper extends Domain { final libraryUri = libraryRef.uri; if (libraryId == null || libraryUri == null) return null; // Fetch information about all the classes in this library. - final expression = ''' - (function() { - const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk'); - const dart = sdk.dart; - return dart.getLibraryMetadata('$libraryUri'); - })() - '''; + final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger + .getClassesInLibraryJsExpression(libraryUri); RemoteObject? result; try { diff --git a/dwds/test/instances/common/instance_inspection_common.dart b/dwds/test/instances/common/instance_inspection_common.dart index 099d326cf..c0d57ed76 100644 --- a/dwds/test/instances/common/instance_inspection_common.dart +++ b/dwds/test/instances/common/instance_inspection_common.dart @@ -62,6 +62,7 @@ void runTests({ verboseCompiler: debug, canaryFeatures: canaryFeatures, experiments: ['records'], + moduleFormat: provider.ddcModuleFormat, ), ); service = context.debugConnection.vmService; diff --git a/dwds/test/instances/instance_inspection_canary_test.dart b/dwds/test/instances/instance_inspection_amd_canary_test.dart similarity index 85% rename from dwds/test/instances/instance_inspection_canary_test.dart rename to dwds/test/instances/instance_inspection_amd_canary_test.dart index 68e36b829..c9dbaf5cf 100644 --- a/dwds/test/instances/instance_inspection_canary_test.dart +++ b/dwds/test/instances/instance_inspection_amd_canary_test.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -7,6 +7,7 @@ @Timeout(Duration(minutes: 2)) library; +import 'package:dwds/src/services/expression_compiler.dart'; import 'package:test/test.dart'; import 'package:test_common/test_sdk_configuration.dart'; @@ -22,6 +23,7 @@ void main() { final provider = TestSdkConfigurationProvider( verbose: debug, canaryFeatures: canaryFeatures, + ddcModuleFormat: ModuleFormat.amd, ); tearDownAll(provider.dispose); diff --git a/dwds/test/instances/instance_inspection_test.dart b/dwds/test/instances/instance_inspection_amd_test.dart similarity index 85% rename from dwds/test/instances/instance_inspection_test.dart rename to dwds/test/instances/instance_inspection_amd_test.dart index 8765583e8..a8f7df0d7 100644 --- a/dwds/test/instances/instance_inspection_test.dart +++ b/dwds/test/instances/instance_inspection_amd_test.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. @@ -7,6 +7,7 @@ @Timeout(Duration(minutes: 2)) library; +import 'package:dwds/src/services/expression_compiler.dart'; import 'package:test/test.dart'; import 'package:test_common/test_sdk_configuration.dart'; @@ -22,6 +23,7 @@ void main() { final provider = TestSdkConfigurationProvider( verbose: debug, canaryFeatures: canaryFeatures, + ddcModuleFormat: ModuleFormat.amd, ); tearDownAll(provider.dispose); diff --git a/dwds/test/instances/instance_inspection_ddc_library_bundle_test.dart b/dwds/test/instances/instance_inspection_ddc_library_bundle_test.dart new file mode 100644 index 000000000..bfca2b3c7 --- /dev/null +++ b/dwds/test/instances/instance_inspection_ddc_library_bundle_test.dart @@ -0,0 +1,37 @@ +// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file +// for details. All rights reserved. Use of this source code is governed by a +// BSD-style license that can be found in the LICENSE file. + +@Tags(['daily']) +@TestOn('vm') +@Timeout(Duration(minutes: 2)) +library; + +import 'package:dwds/expression_compiler.dart'; +import 'package:test/test.dart'; +import 'package:test_common/test_sdk_configuration.dart'; + +import '../fixtures/context.dart'; +import 'common/instance_inspection_common.dart'; + +void main() { + // Enable verbose logging for debugging. + final debug = false; + final canaryFeatures = true; + final compilationMode = CompilationMode.frontendServer; + + group('canary: $canaryFeatures |', () { + final provider = TestSdkConfigurationProvider( + verbose: debug, + canaryFeatures: canaryFeatures, + ddcModuleFormat: ModuleFormat.ddc, + ); + tearDownAll(provider.dispose); + runTests( + provider: provider, + compilationMode: compilationMode, + canaryFeatures: canaryFeatures, + debug: debug, + ); + }); +}