Skip to content

Commit

Permalink
Style fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
natebiggs committed Jan 24, 2025
1 parent e027e8e commit 79aa3b1
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 31 deletions.
16 changes: 7 additions & 9 deletions pkgs/dart_services/lib/src/compiling.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand Down
4 changes: 2 additions & 2 deletions pkgs/dart_services/tool/grind.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -123,7 +123,7 @@ const _flutterPackages = [
'shared_preferences_platform_interface',
'video_player_platform_interface',
'web',
];
};

Future<String> _buildStorageArtifacts(
Directory dir,
Expand Down
77 changes: 57 additions & 20 deletions pkgs/dartpad_ui/lib/execution/frame.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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({
Expand All @@ -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}');
Expand All @@ -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('''
Expand Down

0 comments on commit 79aa3b1

Please sign in to comment.