mirror of
https://github.com/servo/servo.git
synced 2025-06-20 23:28:59 +01:00
Auto merge of #20450 - ysimonson:fix-13464, r=jdm
Properly rethrow any exceptions from parsing JSON in Body mixin's `Json()` This fixes #13464 by rethrowing exceptions from parsing JSON. - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [X] These changes fix #__ (github issue number if applicable). - [X] There are tests for these changes <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20450) <!-- Reviewable:end -->
This commit is contained in:
commit
25dcd0ecfd
2 changed files with 8 additions and 18 deletions
|
@ -16,8 +16,10 @@ use js::jsapi::Heap;
|
|||
use js::jsapi::JSContext;
|
||||
use js::jsapi::JSObject;
|
||||
use js::jsapi::JS_ClearPendingException;
|
||||
use js::jsapi::JS_GetPendingException;
|
||||
use js::jsapi::JS_ParseJSON;
|
||||
use js::jsapi::Value as JSValue;
|
||||
use js::jsval::JSVal;
|
||||
use js::jsval::UndefinedValue;
|
||||
use js::typedarray::{ArrayBuffer, CreateWith};
|
||||
use mime::{Mime, TopLevel, SubLevel};
|
||||
|
@ -42,6 +44,7 @@ pub enum FetchedData {
|
|||
BlobData(DomRoot<Blob>),
|
||||
FormData(DomRoot<FormData>),
|
||||
ArrayBuffer(RootedTraceableBox<Heap<*mut JSObject>>),
|
||||
JSException(RootedTraceableBox<Heap<JSVal>>)
|
||||
}
|
||||
|
||||
// https://fetch.spec.whatwg.org/#concept-body-consume-body
|
||||
|
@ -90,7 +93,8 @@ pub fn consume_body_with_promise<T: BodyOperations + DomObject>(object: &T,
|
|||
FetchedData::Json(j) => promise.resolve_native(&j),
|
||||
FetchedData::BlobData(b) => promise.resolve_native(&b),
|
||||
FetchedData::FormData(f) => promise.resolve_native(&f),
|
||||
FetchedData::ArrayBuffer(a) => promise.resolve_native(&a)
|
||||
FetchedData::ArrayBuffer(a) => promise.resolve_native(&a),
|
||||
FetchedData::JSException(e) => promise.reject_native(&e.handle()),
|
||||
};
|
||||
},
|
||||
Err(err) => promise.reject_error(err),
|
||||
|
@ -133,9 +137,10 @@ fn run_json_data_algorithm(cx: *mut JSContext,
|
|||
json_text.as_ptr(),
|
||||
json_text.len() as u32,
|
||||
rval.handle_mut()) {
|
||||
rooted!(in(cx) let mut exception = UndefinedValue());
|
||||
assert!(JS_GetPendingException(cx, exception.handle_mut()));
|
||||
JS_ClearPendingException(cx);
|
||||
// TODO: See issue #13464. Exception should be thrown instead of cleared.
|
||||
return Err(Error::Type("Failed to parse JSON".to_string()));
|
||||
return Ok(FetchedData::JSException(RootedTraceableBox::from_box(Heap::boxed(exception.get()))));
|
||||
}
|
||||
let rooted_heap = RootedTraceableBox::from_box(Heap::boxed(rval.get()));
|
||||
Ok(FetchedData::Json(rooted_heap))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue