Consider the following code:
import 'dart:html';
void main() {
var xhr = new HttpRequest();
xhr.responseType = 'arraybuffer';
xhr.open('GET', '/');
xhr.onLoad.first.then((_) => print(xhr.response.length));
xhr.send();
}
I'd expect this to return the length of the response body. It does so on Dartium. Under dart2js, though, it throws "TypeError: undefined is not a function". Further inspection indicates that the XHR response isn't being correctly interpreted/wrapped as Dart typed data.
_Removed Priority-Unassigned label._
_Added Priority-Medium label._
Please re-open if this is still the case with the latest 2.0.0-dev SDK.
Was this verified fixed before closing? I just took a few seconds to copy and past the code above and I'm still getting an error, both with DDC and dart2js, sdk 2.7.0-dev.0.0.
dart2js unminified error:
Uncaught TypeError: J.getInterceptor$asx(...).get$length is not a function
at Object.get$length$asx (main.dart.js:1751)
at load_closure.call$1 (main.dart:31)
at _RootZone.runUnary$2$2 (zone.dart:1379)
at _Future__propagateToListeners_handleValueCallback.call$0 (future_impl.dart:104)
at Object._Future__propagateToListeners (future_impl.dart:707)
at _Future._complete$1 (future_impl.dart:512)
at Object._cancelAndValue (stream_pipe.dart:63)
at Stream_first_closure.call$1 (stream.dart:1251)
at _EventStreamSubscription_closure.call$1 (html_dart2js.dart:35659)
at invokeClosure (js_helper.dart:2015)
wrapException @ js_helper.dart:1340
call$0 @ async_patch.dart:691
_microtaskLoop @ schedule_microtask.dart:41
_startMicrotaskLoop @ schedule_microtask.dart:50
call$1 @ async_patch.dart:49
invokeClosure @ js_helper.dart:2015
(anonymous) @ js_helper.dart:2047
childList (async)
call$1 @ async_patch.dart:62
_scheduleAsyncCallback @ async_patch.dart:27
_schedulePriorityAsyncCallback @ schedule_microtask.dart:89
_rootHandleUncaughtError @ zone.dart:1110
_Future__propagateToListeners @ zone.dart:1366
_complete$1 @ future_impl.dart:512
_cancelAndValue @ stream_pipe.dart:63
call$1 @ stream.dart:1251
call$1 @ html_dart2js.dart:35659
invokeClosure @ js_helper.dart:2015
(anonymous) @ js_helper.dart:2047
load (async)
_addEventListener$3 @ html_dart2js.dart:15101
_addEventListener$3$x @ main.dart.js:1777
_tryResume$0 @ html_dart2js.dart:15081
_EventStreamSubscription$ @ html_dart2js.dart:35660
listen$4$cancelOnError$onDone$onError @ html_dart2js.dart:35560
get$first @ stream.dart:1249
(anonymous) @ main.dart:28
(anonymous) @ async_patch.dart:305
call$2 @ async_patch.dart:330
_asyncStartSync @ async_patch.dart:235
load @ main.dart:19
(anonymous) @ main.dart:14
(anonymous) @ async_patch.dart:305
call$2 @ async_patch.dart:330
_asyncStartSync @ async_patch.dart:235
$call$body$main_closure @ main.dart:14
call$1 @ main.dart:14
call$1 @ html_dart2js.dart:35659
invokeClosure @ js_helper.dart:2015
(anonymous) @ js_helper.dart:2047
DDC error:
Uncaught TypeError: J.getInterceptor$asx(...).get$length is not a function
at Object.get$length$asx (main.dart.js:1751)
at load_closure.call$1 (main.dart:31)
at _RootZone.runUnary$2$2 (zone.dart:1379)
at _Future__propagateToListeners_handleValueCallback.call$0 (future_impl.dart:104)
at Object._Future__propagateToListeners (future_impl.dart:707)
at _Future._complete$1 (future_impl.dart:512)
at Object._cancelAndValue (stream_pipe.dart:63)
at Stream_first_closure.call$1 (stream.dart:1251)
at _EventStreamSubscription_closure.call$1 (html_dart2js.dart:35659)
at invokeClosure (js_helper.dart:2015)
wrapException @ js_helper.dart:1340
call$0 @ async_patch.dart:691
_microtaskLoop @ schedule_microtask.dart:41
_startMicrotaskLoop @ schedule_microtask.dart:50
call$1 @ async_patch.dart:49
invokeClosure @ js_helper.dart:2015
(anonymous) @ js_helper.dart:2047
childList (async)
call$1 @ async_patch.dart:62
_scheduleAsyncCallback @ async_patch.dart:27
_schedulePriorityAsyncCallback @ schedule_microtask.dart:89
_rootHandleUncaughtError @ zone.dart:1110
_Future__propagateToListeners @ zone.dart:1366
_complete$1 @ future_impl.dart:512
_cancelAndValue @ stream_pipe.dart:63
call$1 @ stream.dart:1251
call$1 @ html_dart2js.dart:35659
invokeClosure @ js_helper.dart:2015
(anonymous) @ js_helper.dart:2047
load (async)
_addEventListener$3 @ html_dart2js.dart:15101
_addEventListener$3$x @ main.dart.js:1777
_tryResume$0 @ html_dart2js.dart:15081
_EventStreamSubscription$ @ html_dart2js.dart:35660
listen$4$cancelOnError$onDone$onError @ html_dart2js.dart:35560
get$first @ stream.dart:1249
(anonymous) @ main.dart:28
(anonymous) @ async_patch.dart:305
call$2 @ async_patch.dart:330
_asyncStartSync @ async_patch.dart:235
load @ main.dart:19
(anonymous) @ main.dart:14
(anonymous) @ async_patch.dart:305
call$2 @ async_patch.dart:330
_asyncStartSync @ async_patch.dart:235
$call$body$main_closure @ main.dart:14
call$1 @ main.dart:14
call$1 @ html_dart2js.dart:35659
invokeClosure @ js_helper.dart:2015
(anonymous) @ js_helper.dart:2047
Thanks for flagging this is still an issue
The runtime error is correct behavior. There is a bug in the code fragment.
The response is a JavaScript ArrayBuffer, which has Dart type ByteBuffer.
ByteBuffer.length is not defined.
The name is lengthInBytes.
This works (updated to use a data URI so that the request succeeds)
import 'dart:html';
void main() {
var xhr = HttpRequest();
xhr.responseType = 'arraybuffer';
xhr.open('GET', 'data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==');
xhr.onLoad.first.then((_) => print(xhr.response.lengthInBytes)); // 13
xhr.send();
}
On the basis of the above investigation it seems everything is working as expected.