aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/window.rs
diff options
context:
space:
mode:
authorTaym Haddadi <haddadi.taym@gmail.com>2024-08-12 09:58:00 +0200
committerGitHub <noreply@github.com>2024-08-12 07:58:00 +0000
commitdf8ccafa7c01c162bebd00aefe557a1bfc0f300b (patch)
tree74e4d06db6f4b49dc0580ed8be93d437dbf8e819 /components/script/dom/window.rs
parenta797969efed10c46c7cf93e5eb7a03b52d6ca7bc (diff)
downloadservo-df8ccafa7c01c162bebd00aefe557a1bfc0f300b.tar.gz
servo-df8ccafa7c01c162bebd00aefe557a1bfc0f300b.zip
Fix: Return error and avoid panicking in SetOpener function (#33002)
* Fix: Return error and avoid panicking in SetOpener function Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * eturn JSFailed onstead of InvalidState Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> * Update wpt test result Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com> --------- Signed-off-by: Bentaimia Haddadi <haddadi.taym@gmail.com>
Diffstat (limited to 'components/script/dom/window.rs')
-rw-r--r--components/script/dom/window.rs28
1 files changed, 15 insertions, 13 deletions
diff --git a/components/script/dom/window.rs b/components/script/dom/window.rs
index 90ba17a9cbf..a9d3dd3c16b 100644
--- a/components/script/dom/window.rs
+++ b/components/script/dom/window.rs
@@ -702,41 +702,43 @@ impl WindowMethods for Window {
}
// https://html.spec.whatwg.org/multipage/#dom-opener
- fn Opener(&self, cx: JSContext, in_realm_proof: InRealm) -> JSVal {
+ fn GetOpener(&self, cx: JSContext) -> Fallible<JSVal> {
// Step 1, Let current be this Window object's browsing context.
let current = match self.window_proxy.get() {
Some(proxy) => proxy,
// Step 2, If current is null, then return null.
- None => return NullValue(),
+ None => return Ok(NullValue()),
};
// Still step 2, since the window's BC is the associated doc's BC,
// see https://html.spec.whatwg.org/multipage/#window-bc
// and a doc's BC is null if it has been discarded.
// see https://html.spec.whatwg.org/multipage/#concept-document-bc
if current.is_browsing_context_discarded() {
- return NullValue();
+ return Ok(NullValue());
}
// Step 3 to 5.
- current.opener(*cx, in_realm_proof)
+ Ok(current.opener(*cx))
}
#[allow(unsafe_code)]
// https://html.spec.whatwg.org/multipage/#dom-opener
- fn SetOpener(&self, cx: JSContext, value: HandleValue) {
+ fn SetOpener(&self, cx: JSContext, value: HandleValue) -> ErrorResult {
// Step 1.
if value.is_null() {
- return self.window_proxy().disown();
+ self.window_proxy().disown();
+ return Ok(());
}
// Step 2.
let obj = self.reflector().get_jsobject();
unsafe {
- assert!(JS_DefineProperty(
- *cx,
- obj,
- c"opener".as_ptr(),
- value,
- JSPROP_ENUMERATE as u32
- ));
+ let result =
+ JS_DefineProperty(*cx, obj, c"opener".as_ptr(), value, JSPROP_ENUMERATE as u32);
+
+ if result {
+ Ok(())
+ } else {
+ Err(Error::JSFailed)
+ }
}
}