mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 17:38:12 +00:00
LibWeb: Remove unecessary dependence on Window from assorted classes
These classes only needed Window to get at its realm. Pass a realm directly to construct Crypto, Encoding, HRT, IntersectionObserver, NavigationTiming, Page, RequestIdleCallback, Selection, Streams, URL, and XML classes.
This commit is contained in:
parent
4878a18ee7
commit
4bb6345b2f
30 changed files with 125 additions and 126 deletions
|
@ -8,21 +8,21 @@
|
|||
#include <AK/Random.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <LibJS/Runtime/TypedArray.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/Crypto/Crypto.h>
|
||||
#include <LibWeb/Crypto/SubtleCrypto.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
|
||||
namespace Web::Crypto {
|
||||
|
||||
JS::NonnullGCPtr<Crypto> Crypto::create(HTML::Window& window)
|
||||
JS::NonnullGCPtr<Crypto> Crypto::create(JS::Realm& realm)
|
||||
{
|
||||
return *window.heap().allocate<Crypto>(window.realm(), window);
|
||||
return *realm.heap().allocate<Crypto>(realm, realm);
|
||||
}
|
||||
|
||||
Crypto::Crypto(HTML::Window& window)
|
||||
: PlatformObject(window.realm())
|
||||
Crypto::Crypto(JS::Realm& realm)
|
||||
: PlatformObject(realm)
|
||||
{
|
||||
set_prototype(&window.cached_web_prototype("Crypto"));
|
||||
set_prototype(&Bindings::cached_web_prototype(realm, "Crypto"));
|
||||
}
|
||||
|
||||
Crypto::~Crypto() = default;
|
||||
|
@ -30,7 +30,7 @@ Crypto::~Crypto() = default;
|
|||
void Crypto::initialize(JS::Realm& realm)
|
||||
{
|
||||
Base::initialize(realm);
|
||||
m_subtle = SubtleCrypto::create(global_object());
|
||||
m_subtle = SubtleCrypto::create(realm);
|
||||
}
|
||||
|
||||
JS::NonnullGCPtr<SubtleCrypto> Crypto::subtle() const
|
||||
|
@ -43,16 +43,16 @@ WebIDL::ExceptionOr<JS::Value> Crypto::get_random_values(JS::Value array) const
|
|||
{
|
||||
// 1. If array is not an Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array, then throw a TypeMismatchError and terminate the algorithm.
|
||||
if (!array.is_object() || !(is<JS::Int8Array>(array.as_object()) || is<JS::Uint8Array>(array.as_object()) || is<JS::Uint8ClampedArray>(array.as_object()) || is<JS::Int16Array>(array.as_object()) || is<JS::Uint16Array>(array.as_object()) || is<JS::Int32Array>(array.as_object()) || is<JS::Uint32Array>(array.as_object()) || is<JS::BigInt64Array>(array.as_object()) || is<JS::BigUint64Array>(array.as_object())))
|
||||
return WebIDL::TypeMismatchError::create(global_object(), "array must be one of Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array");
|
||||
return WebIDL::TypeMismatchError::create(realm(), "array must be one of Int8Array, Uint8Array, Uint8ClampedArray, Int16Array, Uint16Array, Int32Array, Uint32Array, BigInt64Array, or BigUint64Array");
|
||||
auto& typed_array = static_cast<JS::TypedArrayBase&>(array.as_object());
|
||||
|
||||
// 2. If the byteLength of array is greater than 65536, throw a QuotaExceededError and terminate the algorithm.
|
||||
if (typed_array.byte_length() > 65536)
|
||||
return WebIDL::QuotaExceededError::create(global_object(), "array's byteLength may not be greater than 65536");
|
||||
return WebIDL::QuotaExceededError::create(realm(), "array's byteLength may not be greater than 65536");
|
||||
|
||||
// IMPLEMENTATION DEFINED: If the viewed array buffer is detached, throw a InvalidStateError and terminate the algorithm.
|
||||
if (typed_array.viewed_array_buffer()->is_detached())
|
||||
return WebIDL::InvalidStateError::create(global_object(), "array is detached");
|
||||
return WebIDL::InvalidStateError::create(realm(), "array is detached");
|
||||
// FIXME: Handle SharedArrayBuffers
|
||||
|
||||
// 3. Overwrite all elements of array with cryptographically strong random values of the appropriate type.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue