Skip to content

Commit

Permalink
Remove deprecated Resource class from dart:core.
Browse files Browse the repository at this point in the history
BUG=
R=floitsch@google.com, mit@google.com

Review URL: https://codereview.chromium.org/2272373002 .

Committed: f611431
Committed: 35437dd
  • Loading branch information
lrhn committed Aug 26, 2016
1 parent 35437dd commit 99ec987
Show file tree
Hide file tree
Showing 14 changed files with 3 additions and 507 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## 1.20.0

### Core library changes
* `dart:core`: Remove deprecated `Resource` class.
Use the class in `package:resource` instead.
* `dart:async`
* `Future.wait` now catches synchronous errors and returns them in the
returned Future.
Expand Down
1 change: 0 additions & 1 deletion pkg/package_test_data/lib/resources/sample.txt

This file was deleted.

7 changes: 0 additions & 7 deletions pkg/package_test_data/pubspec.yaml

This file was deleted.

1 change: 0 additions & 1 deletion runtime/lib/core_sources.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
'object_patch.dart',
'regexp.cc',
'regexp_patch.dart',
'resource_patch.dart',
'stacktrace.cc',
'stacktrace.dart',
'stacktrace.h',
Expand Down
68 changes: 0 additions & 68 deletions runtime/lib/resource_patch.dart

This file was deleted.

93 changes: 0 additions & 93 deletions sdk/lib/_internal/js_runtime/lib/core_patch.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import 'dart:_js_helper' show checkInt,
patch_lazy,
patch_startup,
Primitives,
readHttp,
stringJoinUnchecked,
getTraceFromException;

Expand Down Expand Up @@ -640,12 +639,6 @@ class _Uri {
}
}

@patch
class Resource {
@patch
const factory Resource(String uri) = _Resource;
}

Uri _resolvePackageUri(Uri packageUri) {
assert(packageUri.scheme == "package");
if (packageUri.hasAuthority) {
Expand All @@ -655,92 +648,6 @@ Uri _resolvePackageUri(Uri packageUri) {
return resolved;
}

class _Resource implements Resource {
final String _location;

const _Resource(String uri) : _location = uri;

Uri get uri => Uri.base.resolve(_location);

Stream<List<int>> openRead() {
Uri uri = this.uri;
if (uri.scheme == "package") {
uri = _resolvePackageUri(uri);
}
if (uri.scheme == "http" || uri.scheme == "https") {
return _readAsStream(uri);
}
throw new StateError("Unable to find resource, unknown scheme: $_location");
}

Future<List<int>> readAsBytes() {
Uri uri = this.uri;
if (uri.scheme == "package") {
uri = _resolvePackageUri(uri);
}
if (uri.scheme == "http" || uri.scheme == "https") {
return _readAsBytes(uri);
}
throw new StateError("Unable to find resource, unknown scheme: $_location");
}

Future<String> readAsString({Encoding encoding: UTF8}) {
Uri uri = this.uri;
if (uri.scheme == "package") {
uri = _resolvePackageUri(uri);
}
if (uri.scheme == "http" || uri.scheme == "https") {
return _readAsString(uri, encoding);
}
throw new StateError("Unable to find resource, unknown scheme: $_location");
}

// TODO(het): Use a streaming XHR request instead of returning the entire
// payload in one event.
Stream<List<int>> _readAsStream(Uri uri) {
var controller = new StreamController.broadcast();
// We only need to implement the listener as there is no way to provide
// back pressure into the channel.
controller.onListen = () {
// Once there is a listener, we kick off the loading of the resource.
_readAsBytes(uri).then((value) {
// The resource loading implementation sends all of the data in a
// single message. So the stream will only get a single value posted.
controller.add(value);
controller.close();
},
onError: (e, s) {
// In case the future terminates with an error we propagate it to the
// stream.
controller.addError(e, s);
controller.close();
});
};

return controller.stream;
}

Future<List<int>> _readAsBytes(Uri uri) {
return readHttp('$uri').then((data) {
if (data is NativeUint8List) return data;
if (data is String) return data.codeUnits;
throw new StateError(
"Unable to read Resource, data could not be decoded");
});
}

Future<String> _readAsString(Uri uri, Encoding encoding) {
return readHttp('$uri').then((data) {
if (data is String) return data;
if (data is NativeUint8List) {
return encoding.decode(data);
};
throw new StateError(
"Unable to read Resource, data could not be decoded");
});
}
}

@patch
class StackTrace {
@patch
Expand Down
52 changes: 0 additions & 52 deletions sdk/lib/_internal/js_runtime/lib/js_helper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4024,58 +4024,6 @@ Future<Null> _loadHunk(String hunkName) {
return completer.future;
}

// Performs an HTTP GET of the given URI and returns the response. The response
// is either a String or a ByteBuffer.
Future<dynamic> readHttp(String uri) {
Completer completer = new Completer();

void failure([error, StackTrace stackTrace]) {
completer.completeError(
new Exception("Loading $uri failed: $error"),
stackTrace);
}

enterJsAsync();
completer.future.whenComplete(leaveJsAsync);

var xhr = JS('var', 'new XMLHttpRequest()');
JS('void', '#.open("GET", #)', xhr, uri);
JS('void', '#.addEventListener("load", #, false)',
xhr, convertDartClosureToJS((event) {
int status = JS('int', '#.status', xhr);
if (status != 200) {
failure("Status code: $status");
return;
}
String responseType = JS('String', '#.responseType', xhr);
var data;
if (responseType.isEmpty || responseType == 'text') {
data = JS('String', '#.response', xhr);
completer.complete(data);
} else if (responseType == 'document' || responseType == 'json') {
data = JS('String', '#.responseText', xhr);
completer.complete(data);
} else if (responseType == 'arraybuffer') {
data = JS('var', '#.response', xhr);
completer.complete(data);
} else if (responseType == 'blob') {
var reader = JS('var', 'new FileReader()');
JS('void', '#.addEventListener("loadend", #, false)',
reader, convertDartClosureToJS((event) {
data = JS('var', '#.result', reader);
completer.complete(data);
}, 1));
} else {
failure('Result had unexpected type: $responseType');
}
}, 1));

JS('void', '#.addEventListener("error", #, false)', xhr, failure);
JS('void', '#.addEventListener("abort", #, false)', xhr, failure);
JS('void', '#.send()', xhr);
return completer.future;
}

class MainError extends Error implements NoSuchMethodError {
final String _message;

Expand Down
4 changes: 1 addition & 3 deletions sdk/lib/core/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,9 +157,8 @@ import "dart:_internal" hide Symbol;
import "dart:_internal" as internal show Symbol;
import "dart:convert" show
Encoding, ASCII, LATIN1, UTF8,
BASE64, StringConversionSink, ChunkedConversionSink;
BASE64, StringConversionSink;
import "dart:math" show Random; // Used by List.shuffle.
import "dart:async" show Stream, Future; // Used by Resource.
import "dart:typed_data" show Uint8List;

part "annotations.dart";
Expand All @@ -185,7 +184,6 @@ part "object.dart";
part "pattern.dart";
part "print.dart";
part "regexp.dart";
part "resource.dart";
part "set.dart";
part "sink.dart";
part "stacktrace.dart";
Expand Down
1 change: 0 additions & 1 deletion sdk/lib/core/core_sources.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
'pattern.dart',
'print.dart',
'regexp.dart',
'resource.dart',
'set.dart',
'sink.dart',
'stacktrace.dart',
Expand Down
57 changes: 0 additions & 57 deletions sdk/lib/core/resource.dart

This file was deleted.

0 comments on commit 99ec987

Please sign in to comment.