Closed Bug 1109742 Opened 10 years ago Closed 9 years ago

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

Categories

(Core :: DOM: Core & HTML, defect)

36 Branch
x86_64
Windows 7
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla38

People

(Reporter: crimsteam, Assigned: nsm)

References

Details

Attachments

(1 file)

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
Status: UNCONFIRMED → ASSIGNED
Ever confirmed: true
It is possible to implement Body.json() correctly using just the autoJSAPIOwnsErrorReporting flag that landed in Bug 1107777.
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
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla38
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: