mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 06:27:45 +00:00
LibJS+LibWeb: Replace GlobalObject with Realm in create() functions
This is a continuation of the previous two commits. As allocating a JS cell already primarily involves a realm instead of a global object, and we'll need to pass one to the allocate() function itself eventually (it's bridged via the global object right now), the create() functions need to receive a realm as well. The plan is for this to be the highest-level function that actually receives a realm and passes it around, AOs on an even higher level will use the "current realm" concept via VM::current_realm() as that's what the spec assumes; passing around realms (or global objects, for that matter) on higher AO levels is pointless and unlike for allocating individual objects, which may happen outside of regular JS execution, we don't need control over the specific realm that is being used there.
This commit is contained in:
parent
5dd5896588
commit
b99cc7d050
178 changed files with 883 additions and 609 deletions
|
@ -18,6 +18,7 @@ namespace Web::Crypto {
|
|||
JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object> const& data)
|
||||
{
|
||||
auto& global_object = wrapper()->global_object();
|
||||
auto& realm = *global_object.associated_realm();
|
||||
|
||||
// 1. Let algorithm be the algorithm parameter passed to the digest() method.
|
||||
|
||||
|
@ -25,7 +26,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
|
|||
auto data_buffer_or_error = Bindings::IDL::get_buffer_source_copy(*data.cell());
|
||||
if (data_buffer_or_error.is_error()) {
|
||||
auto* error = wrap(wrapper()->global_object(), DOM::OperationError::create("Failed to copy bytes from ArrayBuffer"));
|
||||
auto* promise = JS::Promise::create(global_object);
|
||||
auto* promise = JS::Promise::create(realm);
|
||||
promise->reject(error);
|
||||
return promise;
|
||||
}
|
||||
|
@ -46,13 +47,13 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
|
|||
// 4. If an error occurred, return a Promise rejected with normalizedAlgorithm.
|
||||
else {
|
||||
auto* error = wrap(wrapper()->global_object(), DOM::NotSupportedError::create(String::formatted("Invalid hash function '{}'", algorithm)));
|
||||
auto* promise = JS::Promise::create(global_object);
|
||||
auto* promise = JS::Promise::create(realm);
|
||||
promise->reject(error);
|
||||
return promise;
|
||||
}
|
||||
|
||||
// 5. Let promise be a new Promise.
|
||||
auto* promise = JS::Promise::create(global_object);
|
||||
auto* promise = JS::Promise::create(realm);
|
||||
|
||||
// 6. Return promise and perform the remaining steps in parallel.
|
||||
// FIXME: We don't have a good abstraction for this yet, so we do it in sync.
|
||||
|
@ -71,7 +72,7 @@ JS::Promise* SubtleCrypto::digest(String const& algorithm, JS::Handle<JS::Object
|
|||
return promise;
|
||||
}
|
||||
|
||||
auto* result = JS::ArrayBuffer::create(global_object, result_buffer.release_value());
|
||||
auto* result = JS::ArrayBuffer::create(realm, result_buffer.release_value());
|
||||
|
||||
// 9. Resolve promise with result.
|
||||
promise->fulfill(result);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue