Skip to content

Commit 81597c1

Browse files
committed
Reenabled tests in frontend_server_ddc_and_canary_evaluate_test.dart
1 parent 4fc9181 commit 81597c1

File tree

7 files changed

+105
-25
lines changed

7 files changed

+105
-25
lines changed

dwds/CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
- Added `useModuleName` option to `MetadataProvider` to determine whether or not
1111
to use the provided `name` in a `ModuleMetadata`. Metadata provided by DDC
1212
when using the library bundle format does not provide a useful bundle name.
13-
13+
- Refactored LoadStrategyHandler to streamline JS generation and added support for
14+
the dartDevEmbedder API for methods: getObjectMetadata, getObjectFieldNames, getSubRange, and getFunctionMetadata - [#2488](https://github.com/dart-lang/webdev/issues/2488)
15+
- Reenabled tests in frontend_server_ddc_and_canary_evaluate_test.dart. - [#2488](https://github.com/dart-lang/webdev/issues/2488)
1416
## 24.1.0
1517

1618
- Fix bug where debugging clients are not aware of service extensions when connecting to a new web app. - [#2388](https://github.com/dart-lang/webdev/pull/2388)

dwds/lib/src/debugging/inspector.dart

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:dwds/src/debugging/instance.dart';
1414
import 'package:dwds/src/debugging/libraries.dart';
1515
import 'package:dwds/src/debugging/location.dart';
1616
import 'package:dwds/src/debugging/remote_debugger.dart';
17+
import 'package:dwds/src/loaders/load_strategy_handler.dart';
1718
import 'package:dwds/src/readers/asset_reader.dart';
1819
import 'package:dwds/src/utilities/conversions.dart';
1920
import 'package:dwds/src/utilities/dart_uri.dart';
@@ -643,13 +644,8 @@ class AppInspector implements AppInspectorInterface {
643644
// If this is a List, just call sublist. If it's a Map, get the entries, but
644645
// avoid doing a toList on a large map using skip/take to get the section we
645646
// want. To make those alternatives easier in JS, pass both count and end.
646-
final expression = '''
647-
function (offset, count) {
648-
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}("dart_sdk");
649-
const dart = sdk.dart;
650-
return dart.getSubRange(this, offset, count);
651-
}
652-
''';
647+
final expression = LoadStrategyHandler(globalToolConfiguration.loadStrategy)
648+
.getSubRangeJsExpression();
653649

654650
return await jsCallFunctionOn(receiver, expression, args);
655651
}

dwds/lib/src/debugging/instance.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import 'package:dwds/src/config/tool_configuration.dart';
88
import 'package:dwds/src/debugging/inspector.dart';
99
import 'package:dwds/src/debugging/metadata/class.dart';
1010
import 'package:dwds/src/debugging/metadata/function.dart';
11+
import 'package:dwds/src/loaders/load_strategy_handler.dart';
1112
import 'package:dwds/src/utilities/conversions.dart';
1213
import 'package:dwds/src/utilities/domain.dart';
1314
import 'package:dwds/src/utilities/objects.dart';
@@ -773,8 +774,8 @@ class InstanceHelper extends Domain {
773774
// For maps and lists it's more complicated. Treat the actual SDK versions
774775
// of these as special.
775776
final fieldNameExpression =
776-
_jsRuntimeFunctionCall('getObjectFieldNames(this)');
777-
777+
LoadStrategyHandler(globalToolConfiguration.loadStrategy)
778+
.getObjectFieldNamesJsExpression();
778779
final result = await inspector.jsCallFunctionOn(
779780
remoteObject,
780781
fieldNameExpression,

dwds/lib/src/debugging/metadata/class.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:dwds/src/config/tool_configuration.dart';
6+
import 'package:dwds/src/loaders/load_strategy_handler.dart';
67
import 'package:dwds/src/services/chrome_debug_exception.dart';
78
import 'package:dwds/src/utilities/domain.dart';
89
import 'package:logging/logging.dart';
@@ -152,13 +153,9 @@ class ClassMetaDataHelper {
152153
/// Returns null if the [remoteObject] is not a Dart class.
153154
Future<ClassMetaData?> metaDataFor(RemoteObject remoteObject) async {
154155
try {
155-
final evalExpression = '''
156-
function(arg) {
157-
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk');
158-
const dart = sdk.dart;
159-
return dart.getObjectMetadata(arg);
160-
}
161-
''';
156+
final evalExpression =
157+
LoadStrategyHandler(globalToolConfiguration.loadStrategy)
158+
.getObjectMetadataJsExpression();
162159

163160
final result = await _inspector.jsCallFunctionOn(
164161
remoteObject,

dwds/lib/src/debugging/metadata/function.dart

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:dwds/src/config/tool_configuration.dart';
66
import 'package:dwds/src/debugging/remote_debugger.dart';
7+
import 'package:dwds/src/loaders/load_strategy_handler.dart';
78
import 'package:dwds/src/utilities/server.dart';
89
import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart';
910

@@ -17,13 +18,9 @@ class FunctionMetaData {
1718
RemoteDebugger remoteDebugger,
1819
RemoteObject remoteObject,
1920
) async {
20-
final evalExpression = '''
21-
function() {
22-
const sdk = ${globalToolConfiguration.loadStrategy.loadModuleSnippet}('dart_sdk');
23-
const dart = sdk.dart;
24-
return dart.getFunctionMetadata(this);
25-
}
26-
''';
21+
final evalExpression =
22+
LoadStrategyHandler(globalToolConfiguration.loadStrategy)
23+
.getFunctionMetadataJsExpression();
2724

2825
final response = await remoteDebugger.sendCommand(
2926
'Runtime.callFunctionOn',
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
// Copyright (c) 2024, the Dart project authors.
2+
// Please see the AUTHORS file for details.
3+
// All rights reserved. Use of this source code is governed by a
4+
// BSD-style license that can be found in the LICENSE file.
5+
6+
import 'package:dwds/src/loaders/strategy.dart';
7+
8+
class LoadStrategyHandler {
9+
final LoadStrategy _loadStrategy;
10+
11+
LoadStrategyHandler(this._loadStrategy);
12+
13+
String _generateJsExpression(
14+
String ddcExpression,
15+
String libraryBundleExpression,
16+
) {
17+
switch (_loadStrategy.id) {
18+
case 'ddc':
19+
case 'require-js':
20+
return ddcExpression;
21+
case 'ddc-library-bundle':
22+
return libraryBundleExpression;
23+
default:
24+
throw UnsupportedError('Unsupported load strategy: $_loadStrategy');
25+
}
26+
}
27+
28+
String _wrapWithSdkLoader(String args, String functionCall) {
29+
return '''
30+
function($args) {
31+
const sdk = ${_loadStrategy.loadModuleSnippet}("dart_sdk");
32+
const dart = sdk.dart;
33+
return dart.$functionCall;
34+
}
35+
''';
36+
}
37+
38+
String _wrapWithBundleLoader(String args, String functionCall) {
39+
return '''
40+
function($args) {
41+
return dartDevEmbedder.debugger.$functionCall;
42+
}
43+
''';
44+
}
45+
46+
String _buildExpression(
47+
String args,
48+
String ddcFunction,
49+
String libraryBundleFunction,
50+
) {
51+
return _generateJsExpression(
52+
_wrapWithSdkLoader(args, ddcFunction),
53+
_wrapWithBundleLoader(args, libraryBundleFunction),
54+
);
55+
}
56+
57+
String getObjectMetadataJsExpression() {
58+
return _buildExpression(
59+
'arg',
60+
'getObjectMetadata(arg)',
61+
'getObjectMetadata(arg)',
62+
);
63+
}
64+
65+
String getObjectFieldNamesJsExpression() {
66+
return _buildExpression(
67+
'',
68+
'getObjectFieldNames(this)',
69+
'getObjectFieldNames(this)',
70+
);
71+
}
72+
73+
String getFunctionMetadataJsExpression() {
74+
return _buildExpression(
75+
'',
76+
'getFunctionMetadata(this)',
77+
'getFunctionName(this)',
78+
);
79+
}
80+
81+
String getSubRangeJsExpression() {
82+
return _buildExpression(
83+
'offset, count',
84+
'getSubRange(this, offset, count)',
85+
'getSubRange(this, offset, count)',
86+
);
87+
}
88+
}

dwds/test/frontend_server_ddc_and_canary_evaluate_test.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ void main() async {
4545
// https://github.com/dart-lang/sdk/issues/49277, once
4646
// https://github.com/dart-lang/webdev/issues/2488 is resolved.
4747
// skip: indexBaseMode == IndexBaseMode.base && Platform.isWindows,
48-
skip: 'https://github.com/dart-lang/webdev/issues/2488',
4948
);
5049
}
5150
});

0 commit comments

Comments
 (0)