Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for some debugging APIs with the DDC library bundle format - part 5 #2549

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
## 24.3.0

- 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)
- 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)
- Fix issue where batched expression evals were failing if any subexpression failed. - [#2551](https://github.com/dart-lang/webdev/issues/2551)
- Expose a partial implementation of
`FrontendServerDdcLibraryBundleStrategyProvider`.
Expand Down
30 changes: 30 additions & 0 deletions dwds/lib/src/debugging/dart_runtime_debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
),
);
}
}
8 changes: 2 additions & 6 deletions dwds/lib/src/debugging/inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
11 changes: 2 additions & 9 deletions dwds/lib/src/debugging/instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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;
}
''';
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void runTests({
verboseCompiler: debug,
experiments: ['records', 'patterns'],
canaryFeatures: canaryFeatures,
moduleFormat: provider.ddcModuleFormat,
),
);
service = context.debugConnection.vmService;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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';

Expand All @@ -22,6 +23,7 @@ void main() {
final provider = TestSdkConfigurationProvider(
verbose: debug,
canaryFeatures: canaryFeatures,
ddcModuleFormat: ModuleFormat.amd,
);
tearDownAll(provider.dispose);

Expand Down
Original file line number Diff line number Diff line change
@@ -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.

Expand All @@ -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';

Expand All @@ -22,6 +23,7 @@ void main() {
final provider = TestSdkConfigurationProvider(
verbose: debug,
canaryFeatures: canaryFeatures,
ddcModuleFormat: ModuleFormat.amd,
);
tearDownAll(provider.dispose);

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
);
});
}
Loading