From 79aa3b10d73f4dcecc0d1c1cfd49348f0d585d45 Mon Sep 17 00:00:00 2001 From: Nate Biggs Date: Fri, 24 Jan 2025 03:04:42 -0500 Subject: [PATCH] Style fixes. --- pkgs/dart_services/lib/src/compiling.dart | 16 +++-- pkgs/dart_services/tool/grind.dart | 4 +- pkgs/dartpad_ui/lib/execution/frame.dart | 77 +++++++++++++++++------ 3 files changed, 66 insertions(+), 31 deletions(-) diff --git a/pkgs/dart_services/lib/src/compiling.dart b/pkgs/dart_services/lib/src/compiling.dart index a57717d01..e6ef38c36 100644 --- a/pkgs/dart_services/lib/src/compiling.dart +++ b/pkgs/dart_services/lib/src/compiling.dart @@ -33,15 +33,13 @@ class Compiler { }) : this._(sdk, path.join(sdk.dartSdkPath, 'bin', 'dart'), storageBucket); Compiler._(this._sdk, this._dartPath, this._storageBucket) - : _ddcDriver = BazelWorkerDriver(() async { - final p = await Process.start(_dartPath, [ - path.join( - _sdk.dartSdkPath, 'bin', 'snapshots', 'dartdevc.dart.snapshot'), - '--persistent_worker' - ]); - p.stderr.listen((e) => print(utf8.decode(e))); - return p; - }, maxWorkers: 1), + : _ddcDriver = BazelWorkerDriver( + () => Process.start(_dartPath, [ + path.join(_sdk.dartSdkPath, 'bin', 'snapshots', + 'dartdevc.dart.snapshot'), + '--persistent_worker' + ]), + maxWorkers: 1), _projectTemplates = ProjectTemplates.projectTemplates; /// Compile the given string and return the resulting [CompilationResults]. diff --git a/pkgs/dart_services/tool/grind.dart b/pkgs/dart_services/tool/grind.dart index 5074de469..bf24dc9c5 100644 --- a/pkgs/dart_services/tool/grind.dart +++ b/pkgs/dart_services/tool/grind.dart @@ -114,7 +114,7 @@ void buildStorageArtifacts() async { // Packages to include in flutter_web.js. These are implicitly imported by all // flutter apps. Since DDC doesn't do tree-shaking these would be included in // every compilation. -const _flutterPackages = [ +const _flutterPackages = { 'flutter', 'flutter_test', 'url_launcher_web', @@ -123,7 +123,7 @@ const _flutterPackages = [ 'shared_preferences_platform_interface', 'video_player_platform_interface', 'web', -]; +}; Future _buildStorageArtifacts( Directory dir, diff --git a/pkgs/dartpad_ui/lib/execution/frame.dart b/pkgs/dartpad_ui/lib/execution/frame.dart index f06806743..2e8dd2b0a 100644 --- a/pkgs/dartpad_ui/lib/execution/frame.dart +++ b/pkgs/dartpad_ui/lib/execution/frame.dart @@ -70,8 +70,9 @@ class ExecutionServiceImpl implements ExecutionService { final script = StringBuffer(); - // Redirect print messages to the host. - script.writeln(''' + if (isNewDDC) { + // Redirect print messages to the host. + script.writeln(''' function dartPrint(message) { parent.postMessage({ 'sender': 'frame', @@ -81,19 +82,12 @@ function dartPrint(message) { } '''); - if (!isNewDDC) { + // The JavaScript exception handling for DartPad catches both errors + // directly raised by `main()` (in which case we might have useful Dart + // exception information we don't want to discard), as well as errors + // generated by other means, like assertion errors when starting up + // asynchronous functions. script.writeln(''' -// Unload any previous version. -require.undef('dartpad_main'); -'''); - } - - // The JavaScript exception handling for DartPad catches both errors - // directly raised by `main()` (in which case we might have useful Dart - // exception information we don't want to discard), as well as errors - // generated by other means, like assertion errors when starting up - // asynchronous functions. - script.writeln(''' window.onerror = function(message, url, line, column, error) { var errorMessage = error == null ? '' : ', error: ' + error; parent.postMessage({ @@ -104,19 +98,18 @@ window.onerror = function(message, url, line, column, error) { }; '''); - // Set the crossorigin: anonymous attribute on require.js scripts. - // For example, dart_sdk.js or flutter_web.js. - if (modulesBaseUrl != null) { - script.writeln(''' + // Set the crossorigin: anonymous attribute on require.js scripts. + // For example, dart_sdk.js or flutter_web.js. + if (modulesBaseUrl != null) { + script.writeln(''' require.config({ "baseUrl": "$modulesBaseUrl", "waitSeconds": 60, "onNodeCreated": function(node, config, id, url) { node.setAttribute('crossorigin', 'anonymous'); } }); '''); - } + } - if (isNewDDC) { // The code depends on ddc_module_loader already being loaded in the page. // Wrap in a function that we'll call after the module loader is loaded. script.writeln('let __ddcInitCode = function() {$javaScript}'); @@ -134,6 +127,50 @@ function contextLoaded() { 'require(["dart_sdk_new", "ddc_module_loader"], contextLoaded);'); } } else { + // Redirect print messages to the host. + script.writeln(''' +function dartPrint(message) { + parent.postMessage({ + 'sender': 'frame', + 'type': 'stdout', + 'message': message.toString() + }, '*'); +} +'''); + + script.writeln(''' +// Unload any previous version. +require.undef('dartpad_main'); +'''); + + // The JavaScript exception handling for DartPad catches both errors + // directly raised by `main()` (in which case we might have useful Dart + // exception information we don't want to discard), as well as errors + // generated by other means, like assertion errors when starting up + // asynchronous functions. + script.writeln(''' +window.onerror = function(message, url, line, column, error) { + var errorMessage = error == null ? '' : ', error: ' + error; + parent.postMessage({ + 'sender': 'frame', + 'type': 'stderr', + 'message': message + errorMessage + }, '*'); +}; +'''); + + // Set the crossorigin: anonymous attribute on require.js scripts. + // For example, dart_sdk.js or flutter_web.js. + if (modulesBaseUrl != null) { + script.writeln(''' +require.config({ + "baseUrl": "$modulesBaseUrl", + "waitSeconds": 60, + "onNodeCreated": function(node, config, id, url) { node.setAttribute('crossorigin', 'anonymous'); } +}); +'''); + } + script.writeln(javaScript); script.writeln('''