Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into dwds2421
Browse files Browse the repository at this point in the history
  • Loading branch information
srujzs committed Dec 17, 2024
2 parents 2985676 + 6465541 commit bc9df34
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 19 deletions.
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.

Expand Down
53 changes: 53 additions & 0 deletions dwds/lib/src/debugging/dart_runtime_debugger.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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)',
);
}
}
11 changes: 4 additions & 7 deletions dwds/lib/src/debugging/inspector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,8 @@ class AppInspector implements AppInspectorInterface {
/// Get the value of the field named [fieldName] from [receiver].
@override
Future<RemoteObject> 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, []);
}

Expand Down Expand Up @@ -748,8 +745,8 @@ class AppInspector implements AppInspectorInterface {

/// Runs an eval on the page to compute all existing registered extensions.
Future<List<String>> _getExtensionRpcs() async {
final expression =
"${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk').developer._extensions.keys.toList();";
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
.getDartDeveloperExtensionNamesJsExpression();
final extensionRpcs = <String>[];
final params = {
'expression': expression,
Expand Down
7 changes: 4 additions & 3 deletions dwds/lib/src/debugging/instance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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, []);
Expand Down
9 changes: 2 additions & 7 deletions dwds/lib/src/debugging/libraries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions dwds/test/instances/common/instance_inspection_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void runTests({
verboseCompiler: debug,
canaryFeatures: canaryFeatures,
experiments: ['records'],
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) 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.

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

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) 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.

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

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

0 comments on commit bc9df34

Please sign in to comment.