[dart2js] Add `--utf8` canary option
Change-Id: I98078be0fe07b1037d0bb70986be8769e170708a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/225520
Reviewed-by: Joshua Litt <joshualitt@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
diff --git a/pkg/compiler/lib/src/js/js.dart b/pkg/compiler/lib/src/js/js.dart
index 6a8fecd..ac9131a 100644
--- a/pkg/compiler/lib/src/js/js.dart
+++ b/pkg/compiler/lib/src/js/js.dart
@@ -37,6 +37,7 @@
bool allowVariableMinification = true,
List<CodeOutputListener> listeners = const []}) {
JavaScriptPrintingOptions options = JavaScriptPrintingOptions(
+ utf8: compilerOptions.features.writeUtf8.isEnabled,
shouldCompressOutput: compilerOptions.enableMinification,
minifyLocalVariables: allowVariableMinification);
CodeBuffer outBuffer = CodeBuffer(listeners);
diff --git a/pkg/compiler/lib/src/options.dart b/pkg/compiler/lib/src/options.dart
index b0be710..c2efa63 100644
--- a/pkg/compiler/lib/src/options.dart
+++ b/pkg/compiler/lib/src/options.dart
@@ -76,6 +76,9 @@
/// Whether to generate code compliant with Content Security Policy.
FeatureOption useContentSecurityPolicy = FeatureOption('csp');
+ /// Whether to emit JavaScript encoded as UTF-8.
+ FeatureOption writeUtf8 = FeatureOption('utf8');
+
/// [FeatureOption]s which are shipped and cannot be toggled.
late final List<FeatureOption> shipped = [
newHolders,
@@ -84,11 +87,13 @@
/// [FeatureOption]s which default to enabled.
late final List<FeatureOption> shipping = [
legacyJavaScript,
- useContentSecurityPolicy
+ useContentSecurityPolicy,
];
/// [FeatureOption]s which default to disabled.
- late final List<FeatureOption> canary = [];
+ late final List<FeatureOption> canary = [
+ writeUtf8,
+ ];
/// Forces canary feature on. This must run after [Option].parse.
void forceCanary() {
diff --git a/pkg/test_runner/lib/src/browser.dart b/pkg/test_runner/lib/src/browser.dart
index 6625a5a..f7174a2 100644
--- a/pkg/test_runner/lib/src/browser.dart
+++ b/pkg/test_runner/lib/src/browser.dart
@@ -14,6 +14,7 @@
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta charset="utf-8">
<meta name="dart.unittest" content="full-stack-traces">
<title> Test $title </title>
<style>
@@ -172,6 +173,7 @@
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
+ <meta charset="utf-8">
<meta name="dart.unittest" content="full-stack-traces">
<title>Test $testName</title>
<style>
diff --git a/pkg/test_runner/lib/src/browser_controller.dart b/pkg/test_runner/lib/src/browser_controller.dart
index 2920dc1..607c5f1 100644
--- a/pkg/test_runner/lib/src/browser_controller.dart
+++ b/pkg/test_runner/lib/src/browser_controller.dart
@@ -1342,6 +1342,7 @@
<!DOCTYPE html><html>
<head>
<title>Driving page</title>
+ <meta charset="utf-8">
<style>
.big-notice {
background-color: red;
diff --git a/pkg/test_runner/lib/src/testing_servers.dart b/pkg/test_runner/lib/src/testing_servers.dart
index ca69031..ac04529 100644
--- a/pkg/test_runner/lib/src/testing_servers.dart
+++ b/pkg/test_runner/lib/src/testing_servers.dart
@@ -301,6 +301,7 @@
<html>
<head>
<title>${request.uri.path}</title>
+ <meta charset="utf-8">
</head>
<body>
<code>