diff --git a/dwds/CHANGELOG.md b/dwds/CHANGELOG.md index 55eb577d2..3aa5919d9 100644 --- a/dwds/CHANGELOG.md +++ b/dwds/CHANGELOG.md @@ -1,7 +1,7 @@ ## 24.2.1-wip - 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),[#2544](https://github.com/dart-lang/webdev/issues/2544) +- Added support for some debugging APIs with the DDC library bundle format. - [#2537](https://github.com/dart-lang/webdev/issues/2537),[#2544](https://github.com/dart-lang/webdev/issues/2544),[#2548](https://github.com/dart-lang/webdev/issues/2548) ## 24.2.0 diff --git a/dwds/lib/src/debugging/dart_runtime_debugger.dart b/dwds/lib/src/debugging/dart_runtime_debugger.dart index 90b47d581..e09c86e5d 100644 --- a/dwds/lib/src/debugging/dart_runtime_debugger.dart +++ b/dwds/lib/src/debugging/dart_runtime_debugger.dart @@ -169,4 +169,34 @@ class DartRuntimeDebugger { 'getRecordFields(this)', ); } + + /// Generates a JS expression for retrieving the fields of a record type. + String getRecordTypeFieldsJsExpression() { + return _buildExpression( + '', + 'getRecordTypeFields(this)', + 'getRecordTypeFields(this)', + ); + } + + /// Generates a JS expression for calling an instance method on an object. + String callInstanceMethodJsExpression(String methodName) { + String generateInstanceMethodJsExpression(String functionCall) { + return ''' + function () { + if (!Object.getPrototypeOf(this)) { return 'Instance of PlainJavaScriptObject'; } + return $functionCall; + } + '''; + } + + return _generateJsExpression( + generateInstanceMethodJsExpression( + '${_loadStrategy.loadModuleSnippet}("dart_sdk").dart.dsendRepl(this, "$methodName", arguments)', + ), + generateInstanceMethodJsExpression( + 'dartDevEmbedder.debugger.callInstanceMethod(this, "$methodName", arguments)', + ), + ); + } } diff --git a/dwds/lib/src/debugging/inspector.dart b/dwds/lib/src/debugging/inspector.dart index 23f47504d..4ce408b3d 100644 --- a/dwds/lib/src/debugging/inspector.dart +++ b/dwds/lib/src/debugging/inspector.dart @@ -210,12 +210,8 @@ class AppInspector implements AppInspectorInterface { throw UnsupportedError('Named arguments are not yet supported'); } // We use the JS pseudo-variable 'arguments' to get the list of all arguments. - final send = ''' - function () { - if (!Object.getPrototypeOf(this)) { return 'Instance of PlainJavaScriptObject';} - return ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk").dart.dsendRepl(this, "$methodName", arguments); - } - '''; + final send = globalToolConfiguration.loadStrategy.dartRuntimeDebugger + .callInstanceMethodJsExpression(methodName); final remote = await jsCallFunctionOn(receiver, send, positionalArgs); return remote; } diff --git a/dwds/lib/src/debugging/instance.dart b/dwds/lib/src/debugging/instance.dart index 2815b255a..0db74d5ae 100644 --- a/dwds/lib/src/debugging/instance.dart +++ b/dwds/lib/src/debugging/instance.dart @@ -653,7 +653,8 @@ class InstanceHelper extends Domain { // We do this in in awkward way because we want the names and types, 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('getRecordTypeFields(this)'); + final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger + .getRecordTypeFieldsJsExpression(); final result = await inspector.jsCallFunctionOn(record, expression, []); final fieldNameElements = @@ -887,11 +888,3 @@ class InstanceHelper extends Domain { } } } - -String _jsRuntimeFunctionCall(String expression) => ''' - function() { - const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk'); - const dart = sdk.dart; - return dart.$expression; - } -'''; diff --git a/dwds/test/instances/common/record_type_inspection_common.dart b/dwds/test/instances/common/record_type_inspection_common.dart index 2d51bee26..241195da5 100644 --- a/dwds/test/instances/common/record_type_inspection_common.dart +++ b/dwds/test/instances/common/record_type_inspection_common.dart @@ -64,6 +64,7 @@ void runTests({ verboseCompiler: debug, experiments: ['records', 'patterns'], canaryFeatures: canaryFeatures, + moduleFormat: provider.ddcModuleFormat, ), ); service = context.debugConnection.vmService; diff --git a/dwds/test/instances/record_type_inspection_canary_test.dart b/dwds/test/instances/record_type_inspection_amd_canary_test.dart similarity index 86% rename from dwds/test/instances/record_type_inspection_canary_test.dart rename to dwds/test/instances/record_type_inspection_amd_canary_test.dart index 2bc861f58..02d5f826b 100644 --- a/dwds/test/instances/record_type_inspection_canary_test.dart +++ b/dwds/test/instances/record_type_inspection_amd_canary_test.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, 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/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/record_type_inspection_test.dart b/dwds/test/instances/record_type_inspection_amd_test.dart similarity index 86% rename from dwds/test/instances/record_type_inspection_test.dart rename to dwds/test/instances/record_type_inspection_amd_test.dart index 342d75b4e..d471b0769 100644 --- a/dwds/test/instances/record_type_inspection_test.dart +++ b/dwds/test/instances/record_type_inspection_amd_test.dart @@ -1,4 +1,4 @@ -// Copyright (c) 2023, 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/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/record_type_inspection_ddc_library_bundle_test.dart b/dwds/test/instances/record_type_inspection_ddc_library_bundle_test.dart new file mode 100644 index 000000000..9e5cb3c11 --- /dev/null +++ b/dwds/test/instances/record_type_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/record_type_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, + ); + }); +}