Skip to content

Commit

Permalink
Revert "Support WASM for package:intl (#802)" (#822)
Browse files Browse the repository at this point in the history
This reverts commit aa45d57.
  • Loading branch information
mosuem authored Apr 4, 2024
1 parent 10e15f3 commit af15b06
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 63 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/intl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,3 @@ jobs:

- run: dart test
if: ${{matrix.run-tests}}

- name: Run Chrome tests - wasm
run: dart test --platform chrome --compiler dart2wasm
if: always() && matrix.sdk == 'dev'
3 changes: 0 additions & 3 deletions pkgs/intl/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
* Add example for pub.dev.
* Fix issues with AM/PM markers.
* Update to CLDR v44.1.
* Require Dart `^3.3`
* Require `package:web` `^0.5.0`.
* Support compiling to WASM

## 0.19.0
* Update to CLDR v44.
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl/lib/find_locale.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@

export 'src/intl_default.dart' // Stub implementation
// Browser implementation
if (dart.library.js_interop) 'intl_browser.dart'
if (dart.library.html) 'intl_browser.dart'
// Native implementation
if (dart.library.io) 'intl_standalone.dart';
2 changes: 1 addition & 1 deletion pkgs/intl/lib/intl_browser.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
library intl_browser;

import 'package:web/web.dart';
import 'dart:html';
import 'intl.dart';

// TODO(alanknight): The need to do this by forcing the user to specially
Expand Down
45 changes: 25 additions & 20 deletions pkgs/intl/lib/src/http_request_data_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,41 @@
library http_request_data_reader;

import 'dart:async';
import 'package:http/http.dart';
import 'dart:html';
import 'intl_helpers.dart';

class HttpRequestDataReader implements LocaleDataReader {
/// The base url from which we read the data.
String url;

HttpRequestDataReader(this.url);

@override
Future<String> read(String locale) {
final Client client = Client();
return _getString('$url$locale.json', client).timeout(
Duration(seconds: 5),
onTimeout: () {
client.close();
throw TimeoutException('Timeout while reading $locale');
},
);
var request = HttpRequest();
request.timeout = 5000;
return _getString('$url$locale.json', request).then((r) => r.responseText!);
}

Future<String> _getString(String url, Client client) async {
final response = await client.get(Uri.parse(url));

if ((response.statusCode >= 200 && response.statusCode < 300) ||
response.statusCode == 0 ||
response.statusCode == 304) {
return response.body;
} else {
throw Exception('Failed to load $url');
}
/// Read a string with the given request. This is a stripped down copy
/// of HttpRequest getString, but was the simplest way I could find to
/// issue a request with a timeout.
Future<HttpRequest> _getString(String url, HttpRequest xhr) {
var completer = Completer<HttpRequest>();
xhr.open('GET', url, async: true);
xhr.onLoad.listen((e) {
// Note: file:// URIs have status of 0.
if ((xhr.status! >= 200 && xhr.status! < 300) ||
xhr.status == 0 ||
xhr.status == 304) {
completer.complete(xhr);
} else {
completer.completeError(e);
}
});

xhr.onError.listen(completer.completeError);
xhr.send();

return completer.future;
}
}
2 changes: 1 addition & 1 deletion pkgs/intl/lib/src/locale/locale_extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class LocaleExtensions {
'RegExp/${_otherExtensionsValidValuesRE.pattern}. '
'Entries: ${otherExtensions.entries}.');
assert(
_xExtensions == null || _validXExtensionsRE.hasMatch(_xExtensions),
_xExtensions == null || _validXExtensionsRE.hasMatch(_xExtensions!),
'_xExtensions must match RegExp/${_validXExtensionsRE.pattern}/ '
'but is "$_xExtensions".');
}
Expand Down
2 changes: 1 addition & 1 deletion pkgs/intl/lib/src/locale/locale_implementation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class LocaleImplementation extends Locale {
if (scriptCode != null) out.add(scriptCode!);
if (countryCode != null) out.add(countryCode!);
out.addAll(variants);
if (_extensions != null) out.addAll(_extensions.subtags);
if (_extensions != null) out.addAll(_extensions!.subtags);
_languageTag = out.join('-');
}
return _languageTag!;
Expand Down
5 changes: 2 additions & 3 deletions pkgs/intl/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,17 @@ description: >-
repository: https://github.com/dart-lang/i18n/tree/main/pkgs/intl

environment:
sdk: ^3.3.0
sdk: ^3.0.0

dependencies:
clock: ^1.1.0
http: ^1.0.0
meta: ^1.0.2
path: ^1.8.0
web: ^0.5.0

dev_dependencies:
benchmark_harness: ^2.2.0
ffi: ^1.0.0
fixnum: ^1.0.0
js: ^0.6.3
lints: '>=1.0.0 <3.0.0'
test: ^1.16.0
52 changes: 23 additions & 29 deletions pkgs/intl/test/number_format_compact_web_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,13 @@
// consistency when the bug is fixed. Also fix documentation and perhaps
// merge tests: these tests currently also touch non-compact currency
// formatting.
import 'dart:js_interop';
import 'dart:js_interop_unsafe';
import 'package:intl/intl.dart' as intl;
import 'package:js/js_util.dart' as js;
import 'package:test/test.dart';

import 'compact_number_test_data.dart' as testdata;
import 'more_compact_number_test_data.dart' as more_testdata;

extension on JSNumber {
external String toLocaleString(String locale, [JSObject? options]);
}

void main() {
testdata.compactNumberTestData.forEach(_validate);
more_testdata.cldr35CompactNumTests.forEach(_validateMore);
Expand Down Expand Up @@ -70,20 +65,19 @@ String _ecmaFormatNumber(String locale, num number,
String? compactDisplay,
int? maximumSignificantDigits,
bool? useGrouping}) {
final options = JSObject();
if (notation != null) options['notation'] = notation.toJS;
var options = js.newObject();
if (notation != null) js.setProperty(options, 'notation', notation);
if (compactDisplay != null) {
options['compactDisplay'] = compactDisplay.toJS;
js.setProperty(options, 'compactDisplay', compactDisplay);
}
if (style != null) options['style'] = style.toJS;
if (currency != null) options['currency'] = currency.toJS;
if (style != null) js.setProperty(options, 'style', style);
if (currency != null) js.setProperty(options, 'currency', currency);
if (maximumSignificantDigits != null) {
options['maximumSignificantDigits'] = maximumSignificantDigits.toJS;
js.setProperty(
options, 'maximumSignificantDigits', maximumSignificantDigits);
}
if (useGrouping != null) {
options['useGrouping'] = useGrouping.toJS;
}
return number.toJS.toLocaleString(locale, options);
if (useGrouping != null) js.setProperty(options, 'useGrouping', useGrouping);
return js.callMethod(number, 'toLocaleString', [locale, options]);
}

var _unsupportedChromeLocales = [
Expand Down Expand Up @@ -158,40 +152,40 @@ void _validateLong(String locale, List<List<String>> expected) {
}

void _validateMore(more_testdata.CompactRoundingTestCase t) {
final options = JSObject();
options['notation'] = 'compact'.toJS;
var options = js.newObject();
js.setProperty(options, 'notation', 'compact');
if (t.maximumIntegerDigits != null) {
options['maximumIntegerDigits'] = t.maximumIntegerDigits!.toJS;
js.setProperty(options, 'maximumIntegerDigits', t.maximumIntegerDigits);
}

if (t.minimumIntegerDigits != null) {
options['minimumIntegerDigits'] = t.minimumIntegerDigits!.toJS;
js.setProperty(options, 'minimumIntegerDigits', t.minimumIntegerDigits);
}

if (t.maximumFractionDigits != null) {
options['maximumFractionDigits'] = t.maximumFractionDigits!.toJS;
js.setProperty(options, 'maximumFractionDigits', t.maximumFractionDigits);
}

if (t.minimumFractionDigits != null) {
options['minimumFractionDigits'] = t.minimumFractionDigits!.toJS;
js.setProperty(options, 'minimumFractionDigits', t.minimumFractionDigits);
}

if (t.minimumExponentDigits != null) {
options['minimumExponentDigits'] = t.minimumExponentDigits!.toJS;
js.setProperty(options, 'minimumExponentDigits', t.minimumExponentDigits);
}

if (t.maximumSignificantDigits != null) {
options['maximumSignificantDigits'] = t.maximumSignificantDigits!.toJS;
js.setProperty(
options, 'maximumSignificantDigits', t.maximumSignificantDigits);
}

if (t.minimumSignificantDigits != null) {
options['minimumSignificantDigits'] = t.minimumSignificantDigits!.toJS;
js.setProperty(
options, 'minimumSignificantDigits', t.minimumSignificantDigits);
}

test(t.toString(), () {
expect(
t.number.toJS.toLocaleString('en-US', options),
t.expected,
);
expect(js.callMethod(t.number, 'toLocaleString', ['en-US', options]),
t.expected);
});
}

0 comments on commit af15b06

Please sign in to comment.