Skip to content

Commit

Permalink
Merge branch 'main' of github.com:dart-lang/webdev into dds_port
Browse files Browse the repository at this point in the history
  • Loading branch information
bkonyi committed Dec 19, 2024
2 parents dd229b4 + edcfbf1 commit 1337a21
Show file tree
Hide file tree
Showing 17 changed files with 186 additions and 29 deletions.
1 change: 1 addition & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Update to be forward compatible with changes to `package:shelf_web_socket`.
- Add support for binding DDS to a custom port.
- 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)

## 24.2.0

Expand Down
62 changes: 62 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,66 @@ 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)',
);
}

/// Generates a JS expression for retrieving the fields of a record.
String getRecordFieldsJsExpression() {
return _buildExpression(
'',
'getRecordFields(this)',
'getRecordFields(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
10 changes: 6 additions & 4 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 @@ -523,7 +524,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('getRecordFields(this)');
final expression = globalToolConfiguration.loadStrategy.dartRuntimeDebugger
.getRecordFieldsJsExpression();

final result = await inspector.jsCallFunctionOn(record, expression, []);
final fieldNameElements =
Expand Down Expand Up @@ -674,8 +676,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
24 changes: 19 additions & 5 deletions dwds/test/instances/common/patterns_inspection_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import 'package:test/test.dart';
import 'package:test_common/logging.dart';
import 'package:test_common/test_sdk_configuration.dart';
import 'package:test_common/utilities.dart';
import 'package:vm_service/vm_service.dart';

import '../../fixtures/context.dart';
Expand Down Expand Up @@ -96,11 +97,24 @@ void runTests({
await onBreakPoint('testPatternCase2', (event) async {
final frame = event.topFrame!;

expect(await getFrameVariables(frame), {
'obj': matchListInstance(type: 'Object'),
'a': matchPrimitiveInstance(kind: InstanceKind.kString, value: 'b'),
'n': matchPrimitiveInstance(kind: InstanceKind.kDouble, value: 3.14),
});
if (dartSdkIsAtLeast('3.7.0-246.0.dev')) {
expect(await getFrameVariables(frame), {
'obj': matchListInstance(type: 'Object'),
// Renamed to avoid shadowing variables from previous case.
'a\$':
matchPrimitiveInstance(kind: InstanceKind.kString, value: 'b'),
'n\$':
matchPrimitiveInstance(kind: InstanceKind.kDouble, value: 3.14),
});
} else {
expect(await getFrameVariables(frame), {
'obj': matchListInstance(type: 'Object'),
// Renamed to avoid shadowing variables from previous case.
'a': matchPrimitiveInstance(kind: InstanceKind.kString, value: 'b'),
'n':
matchPrimitiveInstance(kind: InstanceKind.kDouble, value: 3.14),
});
}
});
});

Expand Down
1 change: 1 addition & 0 deletions dwds/test/instances/common/record_inspection_common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,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) 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,
);
});
}
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/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) 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/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
37 changes: 37 additions & 0 deletions dwds/test/instances/record_inspection_ddc_library_bundle_test.dart
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/src/services/expression_compiler.dart';
import 'package:test/test.dart';
import 'package:test_common/test_sdk_configuration.dart';

import '../fixtures/context.dart';
import 'common/record_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,
);
});
}
2 changes: 2 additions & 0 deletions webdev/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
## 3.7.1-wip

## 3.7.0

- Update `dwds` constraint to `24.2.0`.
Expand Down
2 changes: 1 addition & 1 deletion webdev/lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion webdev/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: webdev
# Every time this changes you need to run `dart run build_runner build`.
version: 3.7.0
version: 3.7.1-wip
# We should not depend on a dev SDK before publishing.
# publish_to: none
description: >-
Expand Down

0 comments on commit 1337a21

Please sign in to comment.