From a286ce72ef1a035b95e9921702ad4ab788ab3f88 Mon Sep 17 00:00:00 2001 From: Brian Quinlan Date: Thu, 26 Dec 2024 11:12:53 -0800 Subject: [PATCH 1/5] [io]: Fix a bug where HttpResponse.writeln did not honor the charset. Bug:https://github.com/dart-lang/sdk/issues/59719 Change-Id: Ie2606b557b1f9f50d52de23c56d36b45e52efda1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402281 Reviewed-by: Alexander Aprelev Commit-Queue: Brian Quinlan --- sdk/lib/_http/http.dart | 9 +- sdk/lib/_http/http_impl.dart | 2 +- .../io/http_server_encoding_test.dart | 229 ++++++++++++++++++ 3 files changed, 237 insertions(+), 3 deletions(-) create mode 100644 tests/standalone/io/http_server_encoding_test.dart diff --git a/sdk/lib/_http/http.dart b/sdk/lib/_http/http.dart index d8735245c8d7..e3adac0b9f9c 100644 --- a/sdk/lib/_http/http.dart +++ b/sdk/lib/_http/http.dart @@ -1040,6 +1040,10 @@ abstract interface class HttpRequest implements Stream { /// first time, the request header is sent. Calling any methods that /// change the header after it is sent throws an exception. /// +/// If no "Content-Type" header is set then a default of +/// "text/plain; charset=utf-8" is used and string data written to the IOSink +/// will be encoded using UTF-8. +/// /// ## Setting the headers /// /// The HttpResponse object has a number of properties for setting up @@ -1060,8 +1064,9 @@ abstract interface class HttpRequest implements Stream { /// response.headers.add(HttpHeaders.contentTypeHeader, "text/plain"); /// response.write(...); // Strings written will be ISO-8859-1 encoded. /// -/// An exception is thrown if you use the `write()` method -/// while an unsupported content-type is set. +/// If a charset is provided but it is not recognized, then the "Content-Type" +/// header will include that charset but string data will be encoded using +/// ISO-8859-1 (Latin 1). abstract interface class HttpResponse implements IOSink { // TODO(ajohnsen): Add documentation of how to pipe a file to the response. /// Gets and sets the content length of the response. If the size of diff --git a/sdk/lib/_http/http_impl.dart b/sdk/lib/_http/http_impl.dart index 258511064225..46cee6367a4a 100644 --- a/sdk/lib/_http/http_impl.dart +++ b/sdk/lib/_http/http_impl.dart @@ -1129,7 +1129,7 @@ class _IOSinkImpl extends _StreamSinkImpl> implements IOSink { } void writeln([Object? object = ""]) { - _writeString('$object\n'); + write('$object\n'); } void writeCharCode(int charCode) { diff --git a/tests/standalone/io/http_server_encoding_test.dart b/tests/standalone/io/http_server_encoding_test.dart new file mode 100644 index 000000000000..1df75de0ab8d --- /dev/null +++ b/tests/standalone/io/http_server_encoding_test.dart @@ -0,0 +1,229 @@ +// 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. + +// Tests that the server response body is returned according to defaults or the +// charset set in the "Content-Type" header. + +import 'dart:convert'; +import 'dart:io'; + +import "package:expect/expect.dart"; + +Future testWriteWithoutContentTypeJapanese() async { + final server = await HttpServer.bind(InternetAddress.anyIPv4, 0); + + server.first.then((request) { + request.response + ..write('日本語') + ..close(); + }); + final request = await HttpClient().get('localhost', server.port, '/'); + final response = await request.close(); + Expect.listEquals([ + 'text/plain; charset=utf-8', + ], response.headers[HttpHeaders.contentTypeHeader] ?? []); + final body = utf8.decode(await response.fold([], (o, n) => o + n)); + Expect.equals('日本語', body); +} + +Future testWritelnWithoutContentTypeJapanese() async { + final server = await HttpServer.bind(InternetAddress.anyIPv4, 0); + + server.first.then((request) { + request.response + ..writeln('日本語') + ..close(); + }); + final request = await HttpClient().get('localhost', server.port, '/'); + final response = await request.close(); + Expect.listEquals([ + 'text/plain; charset=utf-8', + ], response.headers[HttpHeaders.contentTypeHeader] ?? []); + final body = utf8.decode(await response.fold([], (o, n) => o + n)); + Expect.equals('日本語\n', body); +} + +Future testWriteAllWithoutContentTypeJapanese() async { + final server = await HttpServer.bind(InternetAddress.anyIPv4, 0); + + server.first.then((request) { + request.response + ..writeAll(['日', '本', '語']) + ..close(); + }); + final request = await HttpClient().get('localhost', server.port, '/'); + final response = await request.close(); + Expect.listEquals([ + 'text/plain; charset=utf-8', + ], response.headers[HttpHeaders.contentTypeHeader] ?? []); + final body = utf8.decode(await response.fold([], (o, n) => o + n)); + Expect.equals('日本語', body); +} + +Future testWriteCharCodeWithoutContentTypeJapanese() async { + final server = await HttpServer.bind(InternetAddress.anyIPv4, 0); + + server.first.then((request) { + request.response + ..writeCharCode(0x65E5) + ..close(); + }); + final request = await HttpClient().get('localhost', server.port, '/'); + final response = await request.close(); + Expect.listEquals([ + 'text/plain; charset=utf-8', + ], response.headers[HttpHeaders.contentTypeHeader] ?? []); + final body = utf8.decode(await response.fold([], (o, n) => o + n)); + Expect.equals('日', body); +} + +Future testWriteWithCharsetJapanese() async { + final server = await HttpServer.bind(InternetAddress.anyIPv4, 0); + + server.first.then((request) { + request.response + ..headers.contentType = ContentType('text', 'plain', charset: 'utf-8') + ..write('日本語') + ..close(); + }); + final request = await HttpClient().get('localhost', server.port, '/'); + final response = await request.close(); + Expect.listEquals([ + 'text/plain; charset=utf-8', + ], response.headers[HttpHeaders.contentTypeHeader] ?? []); + final body = utf8.decode(await response.fold([], (o, n) => o + n)); + Expect.equals('日本語', body); +} + +/// Tests for regression: https://github.com/dart-lang/sdk/issues/59719 +Future testWritelnWithCharsetJapanese() async { + final server = await HttpServer.bind(InternetAddress.anyIPv4, 0); + + server.first.then((request) { + request.response + ..headers.contentType = ContentType('text', 'plain', charset: 'utf-8') + ..writeln('日本語') + ..close(); + }); + final request = await HttpClient().get('localhost', server.port, '/'); + final response = await request.close(); + Expect.listEquals([ + 'text/plain; charset=utf-8', + ], response.headers[HttpHeaders.contentTypeHeader] ?? []); + final body = utf8.decode(await response.fold([], (o, n) => o + n)); + Expect.equals('日本語\n', body); +} + +Future testWriteAllWithCharsetJapanese() async { + final server = await HttpServer.bind(InternetAddress.anyIPv4, 0); + + server.first.then((request) { + request.response + ..headers.contentType = ContentType('text', 'plain', charset: 'utf-8') + ..writeAll(['日', '本', '語']) + ..close(); + }); + final request = await HttpClient().get('localhost', server.port, '/'); + final response = await request.close(); + Expect.listEquals([ + 'text/plain; charset=utf-8', + ], response.headers[HttpHeaders.contentTypeHeader] ?? []); + final body = utf8.decode(await response.fold([], (o, n) => o + n)); + Expect.equals('日本語', body); +} + +Future testWriteCharCodeWithCharsetJapanese() async { + final server = await HttpServer.bind(InternetAddress.anyIPv4, 0); + + server.first.then((request) { + request.response + ..headers.contentType = ContentType('text', 'plain', charset: 'utf-8') + ..writeCharCode(0x65E5) + ..close(); + }); + final request = await HttpClient().get('localhost', server.port, '/'); + final response = await request.close(); + Expect.listEquals([ + 'text/plain; charset=utf-8', + ], response.headers[HttpHeaders.contentTypeHeader] ?? []); + final body = utf8.decode(await response.fold([], (o, n) => o + n)); + Expect.equals('日', body); +} + +Future testWriteWithoutCharsetGerman() async { + final server = await HttpServer.bind(InternetAddress.anyIPv4, 0); + + server.first.then((request) { + request.response + ..headers.contentType = ContentType('text', 'plain') + ..write('Löscherstraße') + ..close(); + }); + final request = await HttpClient().get('localhost', server.port, '/'); + final response = await request.close(); + Expect.listEquals([ + 'text/plain', + ], response.headers[HttpHeaders.contentTypeHeader] ?? []); + final body = latin1.decode(await response.fold([], (o, n) => o + n)); + Expect.equals('Löscherstraße', body); +} + +/// If the charset is not recognized then the text is encoded using ISO-8859-1. +/// +/// NOTE: If you change this behavior, make sure that you change the +/// documentation for [HttpResponse]. +Future testWriteWithUnrecognizedCharsetGerman() async { + final server = await HttpServer.bind(InternetAddress.anyIPv4, 0); + + server.first.then((request) { + request.response + ..headers.contentType = ContentType('text', 'plain', charset: '123') + ..write('Löscherstraße') + ..close(); + }); + final request = await HttpClient().get('localhost', server.port, '/'); + final response = await request.close(); + Expect.listEquals([ + 'text/plain; charset=123', + ], response.headers[HttpHeaders.contentTypeHeader] ?? []); + final body = latin1.decode(await response.fold([], (o, n) => o + n)); + Expect.equals('Löscherstraße', body); +} + +Future testWriteWithoutContentTypeGerman() async { + final server = await HttpServer.bind(InternetAddress.anyIPv4, 0); + + server.first.then((request) { + request.response + ..write('Löscherstraße') + ..close(); + }); + final request = await HttpClient().get('localhost', server.port, '/'); + final response = await request.close(); + Expect.listEquals([ + 'text/plain; charset=utf-8', + ], response.headers[HttpHeaders.contentTypeHeader] ?? []); + final body = utf8.decode(await response.fold([], (o, n) => o + n)); + Expect.equals('Löscherstraße', body); +} + +main() async { + // Japanese, utf-8 (only built-in encoding that supports Japanese) + await testWriteWithoutContentTypeJapanese(); + await testWritelnWithoutContentTypeJapanese(); + await testWriteAllWithoutContentTypeJapanese(); + await testWriteCharCodeWithoutContentTypeJapanese(); + + await testWriteWithCharsetJapanese(); + await testWritelnWithCharsetJapanese(); + await testWriteAllWithCharsetJapanese(); + await testWriteCharCodeWithCharsetJapanese(); + + // Write using an invalid or non-utf-8 charset will fail for Japanese. + + // German + await testWriteWithoutCharsetGerman(); + await testWriteWithUnrecognizedCharsetGerman(); + await testWriteWithoutContentTypeGerman(); +} From b12fa8cfc224c1b4e666630b05545e19ff70e94f Mon Sep 17 00:00:00 2001 From: Kallen Tu Date: Thu, 26 Dec 2024 12:05:35 -0800 Subject: [PATCH 2/5] [tests] Enum shorthands - Collection literal tests for constructors and static methods. Tests for using static method and constructor shorthands in collection literals. Bug: https://github.com/dart-lang/sdk/issues/57038 Change-Id: I5151d53cc90966abb8d03dd453448987ccf8ce7a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401981 Reviewed-by: Erik Ernst Commit-Queue: Kallen Tu --- .../constructor_collection_literal_test.dart | 62 +++++++++++++++++++ ...static_method_collection_literal_test.dart | 38 ++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 tests/language/enum_shorthands/constructor/constructor_collection_literal_test.dart create mode 100644 tests/language/enum_shorthands/member/static_method_collection_literal_test.dart diff --git a/tests/language/enum_shorthands/constructor/constructor_collection_literal_test.dart b/tests/language/enum_shorthands/constructor/constructor_collection_literal_test.dart new file mode 100644 index 000000000000..4e6a1d1eeb3d --- /dev/null +++ b/tests/language/enum_shorthands/constructor/constructor_collection_literal_test.dart @@ -0,0 +1,62 @@ +// 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. + +// Context type is propagated down in collection literals. +// Testing with constructor shorthands. + +// SharedOptions=--enable-experiment=enum-shorthands + +import '../enum_shorthand_helper.dart'; + +void main() { + var ctorList = [ + .new(1), + .regular(1), + .named(x: 1), + .optional(1), + ]; + var ctorSet = { + .new(1), + .regular(1), + .named(x: 1), + .optional(1), + }; + var ctorMap = { + .new(1): .new(1), + .regular(1): .regular(1), + .named(x: 1): .named(x: 1), + .optional(1): .optional(1), + }; + var ctorMap2 = { + .new(1): (.new(1), .new(1)), + .regular(1): (.regular(1), .regular(1)), + .named(x: 1): (.named(x: 1), .named(x: 1)), + .optional(1): (.optional(1), .optional(1)), + }; + + var ctorExtList = [ + .new(1), + .regular(1), + .named(x: 1), + .optional(1), + ]; + var ctorExtSet = { + .new(1), + .regular(1), + .named(x: 1), + .optional(1), + }; + var ctorExtMap = { + .new(1): .new(1), + .regular(1): .regular(1), + .named(x: 1): .named(x: 1), + .optional(1): .optional(1), + }; + var ctorExtMap2 = { + .new(1): (.new(1), .new(1)), + .regular(1): (.regular(1), .regular(1)), + .named(x: 1): (.named(x: 1), .named(x: 1)), + .optional(1): (.optional(1), .optional(1)), + }; +} diff --git a/tests/language/enum_shorthands/member/static_method_collection_literal_test.dart b/tests/language/enum_shorthands/member/static_method_collection_literal_test.dart new file mode 100644 index 000000000000..a7bf76e3dbe6 --- /dev/null +++ b/tests/language/enum_shorthands/member/static_method_collection_literal_test.dart @@ -0,0 +1,38 @@ +// 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. + +// Context type is propagated down in collection literals. +// Testing with static method shorthands. + +// SharedOptions=--enable-experiment=enum-shorthands + +import '../enum_shorthand_helper.dart'; + +void main() { + var memberList = [.member(), .memberType('s'), .member()]; + var memberSet = {.member(), .memberType('s')}; + var memberMap = { + .member(): .memberType('s'), + .memberType('s'): .memberType('s'), + }; + var memberMap2 = { + .member(): (.member(), .memberType('s')), + .memberType('s'): (.memberType('s'), .memberType('s')), + }; + + var memberExtList = [ + .member(), + .memberType('s'), + .member(), + ]; + var memberExtSet = {.member(), .memberType('s')}; + var memberExtMap = { + .member(): .memberType('s'), + .memberType('s'): .memberType('s'), + }; + var memberExtMap2 = { + .member(): (.member(), .memberType('s')), + .memberType('s'): (.memberType('s'), .memberType('s')), + }; +} From a3ef4553a52a8e4653baecb8eb713f9fb9846826 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Thu, 26 Dec 2024 12:19:14 -0800 Subject: [PATCH 3/5] DAS: Small fixes for LegacyAnalysisServer docs and ctor * Fix two comment references * Mark AnalysisServer().enableBlazeWatcher as `@visibleForTesting`. * Use named super parameters where possible. Change-Id: Ic2561c7dd1a661857fbe2e7577fb29c55a5d57b4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402440 Commit-Queue: Konstantin Shcheglov Reviewed-by: Konstantin Shcheglov Auto-Submit: Samuel Rawlins Commit-Queue: Samuel Rawlins --- .../lib/src/analysis_server.dart | 3 +- .../lib/src/legacy_analysis_server.dart | 41 +++++++------------ .../lib/src/lsp/lsp_analysis_server.dart | 11 ++--- 3 files changed, 19 insertions(+), 36 deletions(-) diff --git a/pkg/analysis_server/lib/src/analysis_server.dart b/pkg/analysis_server/lib/src/analysis_server.dart index 88aa0ae64d91..8014e350434c 100644 --- a/pkg/analysis_server/lib/src/analysis_server.dart +++ b/pkg/analysis_server/lib/src/analysis_server.dart @@ -280,7 +280,8 @@ abstract class AnalysisServer { ProcessRunner? processRunner, this.notificationManager, { this.requestStatistics, - bool enableBlazeWatcher = false, + // Disable to avoid using this in unit tests. + @visibleForTesting bool enableBlazeWatcher = false, DartFixPromptManager? dartFixPromptManager, this.providedByteStore, PluginManager? pluginManager, diff --git a/pkg/analysis_server/lib/src/legacy_analysis_server.dart b/pkg/analysis_server/lib/src/legacy_analysis_server.dart index 66b44f10e4f0..51fcf2928e9f 100644 --- a/pkg/analysis_server/lib/src/legacy_analysis_server.dart +++ b/pkg/analysis_server/lib/src/legacy_analysis_server.dart @@ -93,9 +93,7 @@ import 'package:analysis_server/src/services/completion/completion_state.dart'; import 'package:analysis_server/src/services/execution/execution_context.dart'; import 'package:analysis_server/src/services/flutter/widget_descriptions.dart'; import 'package:analysis_server/src/services/refactoring/legacy/refactoring_manager.dart'; -import 'package:analysis_server/src/services/user_prompts/dart_fix_prompt_manager.dart'; import 'package:analysis_server/src/utilities/process.dart'; -import 'package:analysis_server/src/utilities/request_statistics.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/analysis/session.dart'; import 'package:analyzer/dart/ast/ast.dart'; @@ -167,8 +165,8 @@ class AnalysisServerOptions { } /// Instances of the class [LegacyAnalysisServer] implement a server that -/// listens on a [CommunicationChannel] for analysis requests and processes -/// them. +/// listens on a [ServerCommunicationChannel] for analysis requests and +/// processes them. class LegacyAnalysisServer extends AnalysisServer { /// A map from the name of a request to a function used to create a request /// handler. @@ -192,19 +190,19 @@ class LegacyAnalysisServer extends AnalysisServer { ANALYSIS_REQUEST_SET_SUBSCRIPTIONS: AnalysisSetSubscriptionsHandler.new, ANALYSIS_REQUEST_UPDATE_CONTENT: AnalysisUpdateContentHandler.new, ANALYSIS_REQUEST_UPDATE_OPTIONS: AnalysisUpdateOptionsHandler.new, - // + ANALYTICS_REQUEST_IS_ENABLED: AnalyticsIsEnabledHandler.new, ANALYTICS_REQUEST_ENABLE: AnalyticsEnableHandler.new, ANALYTICS_REQUEST_SEND_EVENT: AnalyticsSendEventHandler.new, ANALYTICS_REQUEST_SEND_TIMING: AnalyticsSendTimingHandler.new, - // + COMPLETION_REQUEST_GET_SUGGESTION_DETAILS2: CompletionGetSuggestionDetails2Handler.new, COMPLETION_REQUEST_GET_SUGGESTIONS2: CompletionGetSuggestions2Handler.new, - // + DIAGNOSTIC_REQUEST_GET_DIAGNOSTICS: DiagnosticGetDiagnosticsHandler.new, DIAGNOSTIC_REQUEST_GET_SERVER_PORT: DiagnosticGetServerPortHandler.new, - // + EDIT_REQUEST_FORMAT: EditFormatHandler.new, EDIT_REQUEST_FORMAT_IF_ENABLED: EditFormatIfEnabledHandler.new, EDIT_REQUEST_GET_ASSISTS: EditGetAssistsHandler.new, @@ -223,19 +221,19 @@ class LegacyAnalysisServer extends AnalysisServer { EDIT_REQUEST_GET_POSTFIX_COMPLETION: EditGetPostfixCompletionHandler.new, EDIT_REQUEST_LIST_POSTFIX_COMPLETION_TEMPLATES: EditListPostfixCompletionTemplatesHandler.new, - // + EXECUTION_REQUEST_CREATE_CONTEXT: ExecutionCreateContextHandler.new, EXECUTION_REQUEST_DELETE_CONTEXT: ExecutionDeleteContextHandler.new, EXECUTION_REQUEST_GET_SUGGESTIONS: ExecutionGetSuggestionsHandler.new, EXECUTION_REQUEST_MAP_URI: ExecutionMapUriHandler.new, EXECUTION_REQUEST_SET_SUBSCRIPTIONS: ExecutionSetSubscriptionsHandler.new, - // + FLUTTER_REQUEST_GET_WIDGET_DESCRIPTION: FlutterGetWidgetDescriptionHandler.new, FLUTTER_REQUEST_SET_WIDGET_PROPERTY_VALUE: FlutterSetWidgetPropertyValueHandler.new, FLUTTER_REQUEST_SET_SUBSCRIPTIONS: FlutterSetSubscriptionsHandler.new, - // + SEARCH_REQUEST_FIND_ELEMENT_REFERENCES: SearchFindElementReferencesHandler.new, SEARCH_REQUEST_FIND_MEMBER_DECLARATIONS: @@ -247,7 +245,7 @@ class LegacyAnalysisServer extends AnalysisServer { SEARCH_REQUEST_GET_ELEMENT_DECLARATIONS: SearchGetElementDeclarationsHandler.new, SEARCH_REQUEST_GET_TYPE_HIERARCHY: SearchGetTypeHierarchyHandler.new, - // + SERVER_REQUEST_CANCEL_REQUEST: ServerCancelRequestHandler.new, SERVER_REQUEST_GET_VERSION: ServerGetVersionHandler.new, SERVER_REQUEST_SET_CLIENT_CAPABILITIES: @@ -255,7 +253,6 @@ class LegacyAnalysisServer extends AnalysisServer { SERVER_REQUEST_SET_SUBSCRIPTIONS: ServerSetSubscriptionsHandler.new, SERVER_REQUEST_SHUTDOWN: ServerShutdownHandler.new, - // LSP_REQUEST_HANDLE: LspOverLegacyHandler.new, }; @@ -364,11 +361,6 @@ class LegacyAnalysisServer extends AnalysisServer { /// Initialize a newly created server to receive requests from and send /// responses to the given [channel]. - /// - /// If [rethrowExceptions] is true, then any exceptions thrown by analysis are - /// propagated up the call stack. The default is true to allow analysis - /// exceptions to show up in unit tests, but it should be set to false when - /// running a full analysis server. LegacyAnalysisServer( this.channel, ResourceProvider baseResourceProvider, @@ -379,15 +371,14 @@ class LegacyAnalysisServer extends AnalysisServer { InstrumentationService instrumentationService, { http.Client? httpClient, ProcessRunner? processRunner, - RequestStatisticsHelper? requestStatistics, + super.requestStatistics, DiagnosticServer? diagnosticServer, this.detachableFileSystemManager, - // Disable to avoid using this in unit tests. - bool enableBlazeWatcher = false, - DartFixPromptManager? dartFixPromptManager, + super.enableBlazeWatcher, + super.dartFixPromptManager, super.providedByteStore, super.pluginManager, - bool retainDataForTesting = false, + super.retainDataForTesting, }) : lspClientConfiguration = lsp.LspClientConfiguration( baseResourceProvider.pathContext, ), @@ -402,10 +393,6 @@ class LegacyAnalysisServer extends AnalysisServer { httpClient, processRunner, NotificationManager(channel, baseResourceProvider.pathContext), - requestStatistics: requestStatistics, - enableBlazeWatcher: enableBlazeWatcher, - dartFixPromptManager: dartFixPromptManager, - retainDataForTesting: retainDataForTesting, ) { var contextManagerCallbacks = ServerContextManagerCallbacks( this, diff --git a/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart b/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart index 5eec60be479f..57ce1642b744 100644 --- a/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart +++ b/pkg/analysis_server/lib/src/lsp/lsp_analysis_server.dart @@ -29,7 +29,6 @@ import 'package:analysis_server/src/server/diagnostic_server.dart'; import 'package:analysis_server/src/server/error_notifier.dart'; import 'package:analysis_server/src/server/message_scheduler.dart'; import 'package:analysis_server/src/server/performance.dart'; -import 'package:analysis_server/src/services/user_prompts/dart_fix_prompt_manager.dart'; import 'package:analysis_server/src/utilities/process.dart'; import 'package:analyzer/dart/analysis/results.dart'; import 'package:analyzer/dart/analysis/session.dart'; @@ -160,10 +159,9 @@ class LspAnalysisServer extends AnalysisServer { ProcessRunner? processRunner, DiagnosticServer? diagnosticServer, this.detachableFileSystemManager, - // Disable to avoid using this in unit tests. - bool enableBlazeWatcher = false, - DartFixPromptManager? dartFixPromptManager, - bool retainDataForTesting = false, + super.enableBlazeWatcher, + super.dartFixPromptManager, + super.retainDataForTesting, }) : lspClientConfiguration = LspClientConfiguration( baseResourceProvider.pathContext, ), @@ -178,9 +176,6 @@ class LspAnalysisServer extends AnalysisServer { httpClient, processRunner, LspNotificationManager(baseResourceProvider.pathContext), - enableBlazeWatcher: enableBlazeWatcher, - dartFixPromptManager: dartFixPromptManager, - retainDataForTesting: retainDataForTesting, ) { notificationManager.server = this; messageHandler = UninitializedStateMessageHandler(this); From 3b7716ab00c3514a446334cbb331707f2fc942c7 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Thu, 26 Dec 2024 12:28:38 -0800 Subject: [PATCH 4/5] [gardening] Fix embedder_samples_test leaks, uninitialized variables. Fixes https://github.com/dart-lang/sdk/issues/59810 TEST=ci Change-Id: I8dca122538195c8aad98e0d0fb64c7ea8e0d2e1a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402421 Reviewed-by: Brian Quinlan Commit-Queue: Alexander Aprelev --- samples/embedder/run_kernel.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/samples/embedder/run_kernel.cc b/samples/embedder/run_kernel.cc index 3b6927a0910f..a98d38e06300 100644 --- a/samples/embedder/run_kernel.cc +++ b/samples/embedder/run_kernel.cc @@ -73,7 +73,9 @@ std::string ReadSnapshot(std::string_view path) { char* bytes = static_cast(std::malloc(length)); source_file.read(bytes, length); - return std::string(bytes, length); + auto result = std::string(bytes, length); + std::free(bytes); + return result; } Dart_Handle ToDartStringList(const std::vector& values) { @@ -122,6 +124,7 @@ int main(int argc, char** argv) { // Start an isolate from a platform kernel. Dart_IsolateFlags isolate_flags; + Dart_IsolateFlagsInitialize(&isolate_flags); Dart_CreateIsolateGroupFromKernel( /*script_uri=*/snapshot_uri.c_str(), From ba9f3516fba5d75a39290f3a0a4a91d134bcf049 Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Thu, 26 Dec 2024 12:28:58 -0800 Subject: [PATCH 5/5] [gardening] Fix multi-line comment gcc warning. Fixes https://github.com/dart-lang/sdk/issues/59811 TEST=ci Change-Id: I12e8b97189b5d4621812030f6360cbb56b61f27f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402441 Commit-Queue: Alexander Aprelev Reviewed-by: Brian Quinlan --- runtime/bin/socket_base.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime/bin/socket_base.h b/runtime/bin/socket_base.h index a72a8b6dcd4d..af60b2416ad4 100644 --- a/runtime/bin/socket_base.h +++ b/runtime/bin/socket_base.h @@ -94,7 +94,7 @@ class SocketAddress { char as_string_[kMaxUnixPathLength]; #else char as_string_[INET6_ADDRSTRLEN]; -#endif // defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) || \ +#endif // defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) || // defined(DART_HOST_OS_ANDROID) RawAddr addr_;