[Fetch] Body.json() method should reject promise when parsing body fail

RESOLVED FIXED in mozilla38

Status

()

RESOLVED FIXED
4 years ago
4 years ago

People

(Reporter: crimsteam, Assigned: nsm)

Tracking

36 Branch
mozilla38
x86_64
Windows 7
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

4 years ago
User Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0
Build ID: 20141125180439

Steps to reproduce:

Per "consume body" algorithm:
https://fetch.spec.whatwg.org/#concept-body-consume-body

[Let JSON be the result of invoking the initial value of the parse property of the JSON object with the result of running utf-8 decode on bytes as argument.
If that threw an exception, reject p with that exception.
Otherwise, resolve p with JSON.]

Now, when JSON.parse() faild, Firefox resolve p (but should reject p) and throw to Console: SyntaxError: JSON.parse.

Small test:

<script>

	var request1 = new Request("");

	request1.json().then(function(data){
	
		// Parsing body faild but this function was invoke
		// data is undefined 
		// and we get in Console
		// SyntaxError: JSON.parse: unexpected end of data at line 1 column 1 of the JSON data
	
		document.write("Resolve Promies:" + "<br>" + data);
	 
	}, function(e){
		// This should be invoke
		document.write("Reject Promies:" + "<br>" + e);
	});
	
</script>
This is a known bug. Bug dom-fetch-api is blocked on 2 AutoJSAPI fixes (Bug 1072144, Bug 1107777) that are required to fix the issue.
Assignee: nobody → nsm.nikhil
Blocks: 1039846
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
It is possible to implement Body.json() correctly using just the autoJSAPIOwnsErrorReporting flag that landed in Bug 1107777.
Created attachment 8550451 [details] [diff] [review]
Fix Body.json() error rejection

This relies on the stack class introduced in Bug 1121682.
Attachment #8550451 - Flags: review?(amarchesini)
Attachment #8550451 - Flags: review?(amarchesini) → review+
https://hg.mozilla.org/mozilla-central/rev/a1791566f721
Status: ASSIGNED → RESOLVED
Last Resolved: 4 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla38
You need to log in before you can comment on or make changes to this bug.