dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.31k stars 1.59k forks source link

Fetch response.json() returns native js object instead of Map #34923

Open mnordine opened 6 years ago

mnordine commented 6 years ago

I was just testing out fetch with DDC (webdev serve) and noticed response.json() returns a native JS object, when I would think it should return a Dart Map:

final fetch = WorkerGlobalScope.instance.fetch;

final response = await fetch('https://api.github.com/users/mnordine');
final json = await response.json();
print(json.runtimeType);

Output: NativeJavaScriptObject

An obvious workaround is to json.decode(await response.text())

A bigger issue I ran into was this throws a runtime error when doing webdev build, but it doesn't with webdev build --no-release

Update: I've filed another issue for the runtime error here: https://github.com/dart-lang/sdk/issues/34924

kevmoo commented 6 years ago

CC @terrylucas RE his latest updates to these APIs

mnordine commented 5 years ago

Also, response above should be a Stream, since it's a ReadableStream in JS

Analyzer thinks it's dynamic
https://api.dartlang.org/stable/2.2.0/dart-html/Window/fetch.html