mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-08 09:09:43 +00:00
LibWeb: Add method for "is CORS-same-origin"
This commit is contained in:
parent
ae943965dc
commit
a4db7e9e23
Notes:
github-actions[bot]
2024-12-22 11:31:10 +00:00
Author: https://github.com/AtkinsSJ
Commit: a4db7e9e23
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/2998
3 changed files with 16 additions and 3 deletions
|
@ -201,6 +201,20 @@ GC::Ref<Response> Response::unsafe_response()
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-same-origin
|
||||||
|
bool Response::is_cors_same_origin() const
|
||||||
|
{
|
||||||
|
// A response whose type is "basic", "cors", or "default" is CORS-same-origin. [FETCH]
|
||||||
|
switch (type()) {
|
||||||
|
case Type::Basic:
|
||||||
|
case Type::CORS:
|
||||||
|
case Type::Default:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-cross-origin
|
// https://html.spec.whatwg.org/multipage/urls-and-fetching.html#cors-cross-origin
|
||||||
bool Response::is_cors_cross_origin() const
|
bool Response::is_cors_cross_origin() const
|
||||||
{
|
{
|
||||||
|
|
|
@ -116,6 +116,7 @@ public:
|
||||||
|
|
||||||
[[nodiscard]] GC::Ref<Response> unsafe_response();
|
[[nodiscard]] GC::Ref<Response> unsafe_response();
|
||||||
|
|
||||||
|
[[nodiscard]] bool is_cors_same_origin() const;
|
||||||
[[nodiscard]] bool is_cors_cross_origin() const;
|
[[nodiscard]] bool is_cors_cross_origin() const;
|
||||||
|
|
||||||
[[nodiscard]] bool is_fresh() const;
|
[[nodiscard]] bool is_fresh() const;
|
||||||
|
|
|
@ -750,9 +750,7 @@ GC::Ref<WebIDL::Promise> compile_potential_webassembly_response(JS::VM& vm, GC::
|
||||||
}
|
}
|
||||||
|
|
||||||
// 6. If response is not CORS-same-origin, reject returnValue with a TypeError and abort these substeps.
|
// 6. If response is not CORS-same-origin, reject returnValue with a TypeError and abort these substeps.
|
||||||
// https://html.spec.whatwg.org/#cors-same-origin
|
if (!response->is_cors_same_origin()) {
|
||||||
auto type = response_object.type();
|
|
||||||
if (type != Bindings::ResponseType::Basic && type != Bindings::ResponseType::Cors && type != Bindings::ResponseType::Default) {
|
|
||||||
WebIDL::reject_promise(realm, return_value, *vm.throw_completion<JS::TypeError>("Response is not CORS-same-origin"sv).value());
|
WebIDL::reject_promise(realm, return_value, *vm.throw_completion<JS::TypeError>("Response is not CORS-same-origin"sv).value());
|
||||||
return JS::js_undefined();
|
return JS::js_undefined();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue