mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
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>
This commit is contained in:
parent
a797969efe
commit
df8ccafa7c
5 changed files with 22 additions and 21 deletions
|
@ -36,7 +36,7 @@
|
||||||
// Note that this can return null in the case that the browsing context has been discarded.
|
// Note that this can return null in the case that the browsing context has been discarded.
|
||||||
// https://github.com/whatwg/html/issues/2115
|
// https://github.com/whatwg/html/issues/2115
|
||||||
[LegacyUnforgeable, CrossOriginReadable] readonly attribute WindowProxy? top;
|
[LegacyUnforgeable, CrossOriginReadable] readonly attribute WindowProxy? top;
|
||||||
[CrossOriginReadable] attribute any opener;
|
[Throws, CrossOriginReadable] attribute any opener;
|
||||||
// Note that this can return null in the case that the browsing context has been discarded.
|
// Note that this can return null in the case that the browsing context has been discarded.
|
||||||
// https://github.com/whatwg/html/issues/2115
|
// https://github.com/whatwg/html/issues/2115
|
||||||
[Replaceable, CrossOriginReadable] readonly attribute WindowProxy? parent;
|
[Replaceable, CrossOriginReadable] readonly attribute WindowProxy? parent;
|
||||||
|
|
|
@ -702,41 +702,43 @@ impl WindowMethods for Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-opener
|
// 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.
|
// Step 1, Let current be this Window object's browsing context.
|
||||||
let current = match self.window_proxy.get() {
|
let current = match self.window_proxy.get() {
|
||||||
Some(proxy) => proxy,
|
Some(proxy) => proxy,
|
||||||
// Step 2, If current is null, then return null.
|
// 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,
|
// Still step 2, since the window's BC is the associated doc's BC,
|
||||||
// see https://html.spec.whatwg.org/multipage/#window-bc
|
// see https://html.spec.whatwg.org/multipage/#window-bc
|
||||||
// and a doc's BC is null if it has been discarded.
|
// and a doc's BC is null if it has been discarded.
|
||||||
// see https://html.spec.whatwg.org/multipage/#concept-document-bc
|
// see https://html.spec.whatwg.org/multipage/#concept-document-bc
|
||||||
if current.is_browsing_context_discarded() {
|
if current.is_browsing_context_discarded() {
|
||||||
return NullValue();
|
return Ok(NullValue());
|
||||||
}
|
}
|
||||||
// Step 3 to 5.
|
// Step 3 to 5.
|
||||||
current.opener(*cx, in_realm_proof)
|
Ok(current.opener(*cx))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-opener
|
// 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.
|
// Step 1.
|
||||||
if value.is_null() {
|
if value.is_null() {
|
||||||
return self.window_proxy().disown();
|
self.window_proxy().disown();
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
// Step 2.
|
// Step 2.
|
||||||
let obj = self.reflector().get_jsobject();
|
let obj = self.reflector().get_jsobject();
|
||||||
unsafe {
|
unsafe {
|
||||||
assert!(JS_DefineProperty(
|
let result =
|
||||||
*cx,
|
JS_DefineProperty(*cx, obj, c"opener".as_ptr(), value, JSPROP_ENUMERATE as u32);
|
||||||
obj,
|
|
||||||
c"opener".as_ptr(),
|
if result {
|
||||||
value,
|
Ok(())
|
||||||
JSPROP_ENUMERATE as u32
|
} else {
|
||||||
));
|
Err(Error::JSFailed)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -418,7 +418,7 @@ impl WindowProxy {
|
||||||
|
|
||||||
#[allow(unsafe_code)]
|
#[allow(unsafe_code)]
|
||||||
// https://html.spec.whatwg.org/multipage/#dom-opener
|
// https://html.spec.whatwg.org/multipage/#dom-opener
|
||||||
pub fn opener(&self, cx: *mut JSContext, in_realm_proof: InRealm) -> JSVal {
|
pub fn opener(&self, cx: *mut JSContext) -> JSVal {
|
||||||
if self.disowned.get() {
|
if self.disowned.get() {
|
||||||
return NullValue();
|
return NullValue();
|
||||||
}
|
}
|
||||||
|
@ -436,8 +436,11 @@ impl WindowProxy {
|
||||||
opener_id,
|
opener_id,
|
||||||
) {
|
) {
|
||||||
Some(opener_top_id) => {
|
Some(opener_top_id) => {
|
||||||
let global_to_clone_from =
|
let in_realm_proof =
|
||||||
unsafe { GlobalScope::from_context(cx, in_realm_proof) };
|
AlreadyInRealm::assert_for_cx(unsafe { SafeJSContext::from_ptr(cx) });
|
||||||
|
let global_to_clone_from = unsafe {
|
||||||
|
GlobalScope::from_context(cx, InRealm::Already(&in_realm_proof))
|
||||||
|
};
|
||||||
let creator =
|
let creator =
|
||||||
CreatorBrowsingContextInfo::from(parent_browsing_context, None);
|
CreatorBrowsingContextInfo::from(parent_browsing_context, None);
|
||||||
WindowProxy::new_dissimilar_origin(
|
WindowProxy::new_dissimilar_origin(
|
||||||
|
|
|
@ -1,2 +0,0 @@
|
||||||
[window-opener-unconfigurable.window.html]
|
|
||||||
expected: CRASH
|
|
|
@ -1,2 +0,0 @@
|
||||||
[window-opener-unconfigurable.window.html]
|
|
||||||
expected: CRASH
|
|
Loading…
Add table
Add a link
Reference in a new issue