aboutsummaryrefslogtreecommitdiffstats
path: root/components/script
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2018-03-27 22:44:32 -0400
committerGitHub <noreply@github.com>2018-03-27 22:44:32 -0400
commit25dcd0ecfd4cb7a844f00696730cb0d3ab4b198c (patch)
tree4222bb70484dd0fc28688715a1d4f105c35a53b2 /components/script
parent339146ae1566fc35e47ccc4fba1471a9123d039d (diff)
parentac1e02405d062f1f1051e27321306a140e9aad9f (diff)
downloadservo-25dcd0ecfd4cb7a844f00696730cb0d3ab4b198c.tar.gz
servo-25dcd0ecfd4cb7a844f00696730cb0d3ab4b198c.zip
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 -->
Diffstat (limited to 'components/script')
-rw-r--r--components/script/body.rs11
1 files changed, 8 insertions, 3 deletions
diff --git a/components/script/body.rs b/components/script/body.rs
index 35ee2dae2c6..1ae05e4b043 100644
--- a/components/script/body.rs
+++ b/components/script/body.rs
@@ -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))