Skip to content

Commit 3e8be5e

Browse files
derekxu16Commit Queue
authored andcommitted
[VM/Service] Introduce some string constants in running_isolates.dart
CoreLibraryReviewExempt: This CL does not include any core library API changes, only VM Service implementation changes within sdk/lib/vmservice/running_isolates.dart. Change-Id: I0f54d37ecba5a6d38c5d0e0865a717e89af0b880 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401645 Reviewed-by: Ben Konyi <[email protected]> Commit-Queue: Derek Xu <[email protected]>
1 parent 0931a60 commit 3e8be5e

File tree

1 file changed

+49
-32
lines changed

1 file changed

+49
-32
lines changed

sdk/lib/vmservice/running_isolates.dart

Lines changed: 49 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,22 @@ final class _ResidentCompilerInfo {
130130

131131
/// Class that knows how to orchestrate expression evaluation in dart2 world.
132132
class _Evaluator {
133+
static const _successString = 'success';
134+
static const _compileExpressionString = 'compileExpression';
135+
static const _isolateIdString = 'isolateId';
136+
static const _expressionString = 'expression';
137+
static const _definitionsString = 'definitions';
138+
static const _definitionTypesString = 'definitionTypes';
139+
static const _typeDefinitionsString = 'typeDefinitions';
140+
static const _typeBoundsString = 'typeBounds';
141+
static const _typeDefaultsString = 'typeDefaults';
142+
static const _libraryUriString = 'libraryUri';
143+
static const _tokenPosString = 'tokenPos';
144+
static const _isStaticString = 'isStatic';
145+
static const _scriptUriString = 'scriptUri';
146+
static const _methodString = 'method';
147+
static const _rootLibraryUriString = 'rootLibraryUri';
148+
133149
_Evaluator(this._message, this._isolate, this._service);
134150

135151
Future<Response> run() async {
@@ -232,7 +248,7 @@ class _Evaluator {
232248
jsonResponse = jsonDecode(data);
233249
} catch (e) {
234250
jsonResponse = <String, dynamic>{
235-
'success': false,
251+
_successString: false,
236252
'errorMessage': e.toString(),
237253
};
238254
}
@@ -248,36 +264,36 @@ class _Evaluator {
248264
Map<String, dynamic> buildScopeResponseResult,
249265
) async {
250266
Client? externalClient = _service._findFirstClientThatHandlesService(
251-
'compileExpression',
267+
_compileExpressionString,
252268
);
253269

254270
final compileParams = <String, dynamic>{
255-
'isolateId': _message.params['isolateId']!,
256-
'expression': _message.params['expression']!,
257-
'definitions': buildScopeResponseResult['param_names']!,
258-
'definitionTypes': buildScopeResponseResult['param_types']!,
259-
'typeDefinitions': buildScopeResponseResult['type_params_names']!,
260-
'typeBounds': buildScopeResponseResult['type_params_bounds']!,
261-
'typeDefaults': buildScopeResponseResult['type_params_defaults']!,
262-
'libraryUri': buildScopeResponseResult['libraryUri']!,
263-
'tokenPos': buildScopeResponseResult['tokenPos']!,
264-
'isStatic': buildScopeResponseResult['isStatic']!,
271+
_isolateIdString: _message.params[_isolateIdString]!,
272+
_expressionString: _message.params[_expressionString]!,
273+
_definitionsString: buildScopeResponseResult['param_names']!,
274+
_definitionTypesString: buildScopeResponseResult['param_types']!,
275+
_typeDefinitionsString: buildScopeResponseResult['type_params_names']!,
276+
_typeBoundsString: buildScopeResponseResult['type_params_bounds']!,
277+
_typeDefaultsString: buildScopeResponseResult['type_params_defaults']!,
278+
_libraryUriString: buildScopeResponseResult[_libraryUriString]!,
279+
_tokenPosString: buildScopeResponseResult[_tokenPosString]!,
280+
_isStaticString: buildScopeResponseResult[_isStaticString]!,
265281
};
266282
final klass = buildScopeResponseResult['klass'];
267283
if (klass != null) {
268284
compileParams['klass'] = klass;
269285
}
270-
final scriptUri = buildScopeResponseResult['scriptUri'];
286+
final scriptUri = buildScopeResponseResult[_scriptUriString];
271287
if (scriptUri != null) {
272-
compileParams['scriptUri'] = scriptUri;
288+
compileParams[_scriptUriString] = scriptUri;
273289
}
274-
final method = buildScopeResponseResult['method'];
290+
final method = buildScopeResponseResult[_methodString];
275291
if (method != null) {
276-
compileParams['method'] = method;
292+
compileParams[_methodString] = method;
277293
}
278294
if (externalClient != null) {
279295
// Let the external client handle expression compilation.
280-
final compileExpression = Message.forMethod('compileExpression');
296+
final compileExpression = Message.forMethod(_compileExpressionString);
281297
compileExpression.client = externalClient;
282298
compileExpression.params.addAll(compileParams);
283299

@@ -295,7 +311,7 @@ class _Evaluator {
295311
Response.json(
296312
compileExpression.forwardToJson({
297313
'id': id,
298-
'method': 'compileExpression',
314+
_methodString: _compileExpressionString,
299315
}),
300316
),
301317
);
@@ -311,25 +327,26 @@ class _Evaluator {
311327
final response =
312328
await _sendRequestToResidentFrontendCompilerAndRecieveResponse(
313329
jsonEncode({
314-
'command': 'compileExpression',
315-
'expression': compileParams['expression'],
316-
'definitions': compileParams['definitions'],
317-
'definitionTypes': compileParams['definitionTypes'],
318-
'typeDefinitions': compileParams['typeDefinitions'],
319-
'typeBounds': compileParams['typeBounds'],
320-
'typeDefaults': compileParams['typeDefaults'],
321-
'libraryUri': compileParams['libraryUri'],
322-
'offset': compileParams['tokenPos'],
323-
'isStatic': compileParams['isStatic'],
330+
'command': _compileExpressionString,
331+
_expressionString: compileParams[_expressionString],
332+
_definitionsString: compileParams[_definitionsString],
333+
_definitionTypesString: compileParams[_definitionTypesString],
334+
_typeDefinitionsString: compileParams[_typeDefinitionsString],
335+
_typeBoundsString: compileParams[_typeBoundsString],
336+
_typeDefaultsString: compileParams[_typeDefaultsString],
337+
_libraryUriString: compileParams[_libraryUriString],
338+
'offset': compileParams[_tokenPosString],
339+
_isStaticString: compileParams[_isStaticString],
324340
'class': compileParams['klass'],
325-
'scriptUri': compileParams['scriptUri'],
326-
'method': compileParams['method'],
327-
'rootLibraryUri': buildScopeResponseResult['rootLibraryUri'],
341+
_scriptUriString: compileParams[_scriptUriString],
342+
_methodString: compileParams[_methodString],
343+
_rootLibraryUriString:
344+
buildScopeResponseResult[_rootLibraryUriString],
328345
}),
329346
VMServiceEmbedderHooks.getResidentCompilerInfoFile!()!,
330347
);
331348

332-
if (response['success'] == true) {
349+
if (response[_successString] == true) {
333350
return response['kernelBytes'];
334351
} else if (response['errorMessage'] != null) {
335352
throw _CompileExpressionErrorDetails(response['errorMessage']);

0 commit comments

Comments
 (0)