LibWeb/HTML: Fix Origin.from(value) for Window objects
I had completely managed to forget about the special case of Window where a WindowProxy is what is received over IDL. This was caught by the origin-from-window WPT test, but unfortunately this cannot be imported as it relies on a web server running and other surroundsing WPT infrastructure.
This commit is contained in:
parent
45ab134de9
commit
865b2b88b0
3 changed files with 17 additions and 0 deletions
|
|
@ -8,6 +8,8 @@
|
|||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Bindings/OriginPrototype.h>
|
||||
#include <LibWeb/DOMURL/Origin.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/HTML/WindowProxy.h>
|
||||
|
||||
namespace Web::DOMURL {
|
||||
|
||||
|
|
@ -39,6 +41,10 @@ WebIDL::ExceptionOr<GC::Ref<Origin>> Origin::from(JS::VM& vm, JS::Value value)
|
|||
{
|
||||
auto& realm = *vm.current_realm();
|
||||
|
||||
// NB: IDL only ever sees HTML::WindowProxy but we want to use HTML::Window.
|
||||
if (auto* window_proxy = value.as_if<HTML::WindowProxy>())
|
||||
value = window_proxy->window();
|
||||
|
||||
// 1. If value is a platform object:
|
||||
if (auto* object = value.as_if<Bindings::PlatformObject>()) {
|
||||
// 1. Let origin be the result of executing value's extract an origin operation.
|
||||
|
|
|
|||
2
Tests/LibWeb/Text/expected/HTML/origin-from-window.txt
Normal file
2
Tests/LibWeb/Text/expected/HTML/origin-from-window.txt
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
[object Origin]
|
||||
true
|
||||
9
Tests/LibWeb/Text/input/HTML/origin-from-window.html
Normal file
9
Tests/LibWeb/Text/input/HTML/origin-from-window.html
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<!DOCTYPE html>
|
||||
<script src="../include.js"></script>
|
||||
<script>
|
||||
test(() => {
|
||||
const origin = Origin.from(window);
|
||||
println(origin);
|
||||
println(origin.isSameOrigin(Origin.from(window)));
|
||||
});
|
||||
</script>
|
||||
Loading…
Reference in a new issue