aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/gpu.rs
diff options
context:
space:
mode:
authorKunal Mohan <kunalmohan99@gmail.com>2020-08-02 12:45:22 +0530
committerKunal Mohan <kunalmohan99@gmail.com>2020-08-02 12:45:22 +0530
commitcd8d9162e66b9cdf03918fc3c24d855e6938edb7 (patch)
treec74ad16bd2128ef5adf68d85ac7bf7a30ffa0cfe /components/script/dom/gpu.rs
parent8cb5fad8286d87f2e852d870581d4f867afaf435 (diff)
downloadservo-cd8d9162e66b9cdf03918fc3c24d855e6938edb7.tar.gz
servo-cd8d9162e66b9cdf03918fc3c24d855e6938edb7.zip
Error handling for promise returning operations
Diffstat (limited to 'components/script/dom/gpu.rs')
-rw-r--r--components/script/dom/gpu.rs25
1 files changed, 13 insertions, 12 deletions
diff --git a/components/script/dom/gpu.rs b/components/script/dom/gpu.rs
index 2839ed94835..eea21c1b988 100644
--- a/components/script/dom/gpu.rs
+++ b/components/script/dom/gpu.rs
@@ -41,7 +41,7 @@ impl GPU {
}
pub trait AsyncWGPUListener {
- fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>);
+ fn handle_response(&self, response: WebGPUResponseResult, promise: &Rc<Promise>);
}
struct WGPUResponse<T: AsyncWGPUListener + DomObject> {
@@ -53,13 +53,7 @@ impl<T: AsyncWGPUListener + DomObject> WGPUResponse<T> {
#[allow(unrooted_must_root)]
fn response(self, response: WebGPUResponseResult) {
let promise = self.trusted.root();
- match response {
- Ok(response) => self.receiver.root().handle_response(response, &promise),
- Err(error) => promise.reject_error(Error::Type(format!(
- "Received error from WebGPU thread: {}",
- error
- ))),
- }
+ self.receiver.root().handle_response(response, &promise);
}
}
@@ -134,13 +128,13 @@ impl GPUMethods for GPU {
}
impl AsyncWGPUListener for GPU {
- fn handle_response(&self, response: WebGPUResponse, promise: &Rc<Promise>) {
+ fn handle_response(&self, response: WebGPUResponseResult, promise: &Rc<Promise>) {
match response {
- WebGPUResponse::RequestAdapter {
+ Ok(WebGPUResponse::RequestAdapter {
adapter_name,
adapter_id,
channel,
- } => {
+ }) => {
let adapter = GPUAdapter::new(
&self.global(),
channel,
@@ -150,7 +144,14 @@ impl AsyncWGPUListener for GPU {
);
promise.resolve_native(&adapter);
},
- _ => promise.reject_error(Error::Operation),
+ Err(e) => {
+ warn!("Could not get GPUAdapter ({:?})", e);
+ promise.resolve_native(&None::<GPUAdapter>);
+ },
+ _ => {
+ warn!("GPU received wrong WebGPUResponse");
+ promise.reject_error(Error::Operation);
+ },
}
}
}