Skip to content

Commit

Permalink
Added support for some debugging APIs with the DDC library bundle for…
Browse files Browse the repository at this point in the history
…mat - getRecordTypeFieldsJsExpression, callInstanceMethodJsExpression
  • Loading branch information
jyameo committed Dec 18, 2024
1 parent 067ab27 commit b9a8c2f
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 18 deletions.
2 changes: 1 addition & 1 deletion dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

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,
);
});
}

0 comments on commit b9a8c2f

Please sign in to comment.