diff --git a/Userland/Libraries/LibWeb/Animations/Animation.cpp b/Userland/Libraries/LibWeb/Animations/Animation.cpp index a5e54790b3b..e44c50af5a5 100644 --- a/Userland/Libraries/LibWeb/Animations/Animation.cpp +++ b/Userland/Libraries/LibWeb/Animations/Animation.cpp @@ -424,7 +424,7 @@ void Animation::cancel(ShouldInvalidate should_invalidate) // 1. If animation’s play state is not idle, perform the following steps: if (play_state() != Bindings::AnimationPlayState::Idle) { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm) }; + HTML::TemporaryExecutionContext execution_context { realm }; // 1. Run the procedure to reset an animation’s pending tasks on animation. reset_an_animations_pending_tasks(); @@ -537,7 +537,7 @@ WebIDL::ExceptionOr Animation::finish() } if (should_resolve_ready_promise) { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm()) }; + HTML::TemporaryExecutionContext execution_context { realm() }; WebIDL::resolve_promise(realm(), current_ready_promise(), this); } @@ -1111,7 +1111,7 @@ void Animation::update_finished_state(DidSeek did_seek, SynchronouslyNotify sync return; // 2. Resolve animation’s current finished promise object with animation. - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm) }; + HTML::TemporaryExecutionContext execution_context { realm }; WebIDL::resolve_promise(realm, current_finished_promise(), this); m_is_finished = true; @@ -1178,7 +1178,7 @@ void Animation::update_finished_state(DidSeek did_seek, SynchronouslyNotify sync // 6. If current finished state is false and animation’s current finished promise is already resolved, set // animation’s current finished promise to a new promise in the relevant Realm of animation. if (!current_finished_state && m_is_finished) { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm) }; + HTML::TemporaryExecutionContext execution_context { realm }; m_current_finished_promise = WebIDL::create_promise(realm); m_is_finished = false; } @@ -1266,7 +1266,7 @@ void Animation::run_pending_play_task() } // 4. Resolve animation’s current ready promise with animation. - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm()) }; + HTML::TemporaryExecutionContext execution_context { realm() }; WebIDL::resolve_promise(realm(), current_ready_promise(), this); // 5. Run the procedure to update an animation’s finished state for animation with the did seek flag set to false, @@ -1296,7 +1296,7 @@ void Animation::run_pending_pause_task() m_start_time = {}; // 5. Resolve animation’s current ready promise with animation. - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm()) }; + HTML::TemporaryExecutionContext execution_context { realm() }; WebIDL::resolve_promise(realm(), current_ready_promise(), this); // 6. Run the procedure to update an animation’s finished state for animation with the did seek flag set to false, diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp index ddf57491898..f3f12773149 100644 --- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -464,7 +464,7 @@ ErrorOr initialize_main_thread_vm(HTML::EventLoop::Type type) auto completion = dom_exception_to_throw_completion(main_thread_vm(), url.exception()); // 2. Perform FinishLoadingImportedModule(referrer, moduleRequest, payload, completion). - HTML::TemporaryExecutionContext context { host_defined_environment_settings_object(realm) }; + HTML::TemporaryExecutionContext context { realm }; JS::finish_loading_imported_module(referrer, module_request, payload, completion); // 3. Return. diff --git a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp index 334962c3839..59bd7ac910e 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSStyleSheet.cpp @@ -210,7 +210,7 @@ JS::NonnullGCPtr CSSStyleSheet::replace(String text) // 4. In parallel, do these steps: Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, this, text = move(text), promise = JS::Handle(promise)] { - HTML::TemporaryExecutionContext execution_context { HTML::relevant_settings_object(*this), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // 1. Let rules be the result of running parse a stylesheet’s contents from text. auto context = m_style_sheet_list ? CSS::Parser::ParsingContext { m_style_sheet_list->document() } : CSS::Parser::ParsingContext { realm }; diff --git a/Userland/Libraries/LibWeb/CSS/CSSTransition.cpp b/Userland/Libraries/LibWeb/CSS/CSSTransition.cpp index 4de6f14e322..4075675b05e 100644 --- a/Userland/Libraries/LibWeb/CSS/CSSTransition.cpp +++ b/Userland/Libraries/LibWeb/CSS/CSSTransition.cpp @@ -120,7 +120,7 @@ CSSTransition::CSSTransition(JS::Realm& realm, DOM::Element& element, PropertyID element.associate_with_animation(*this); element.set_transition(m_transition_property, *this); - HTML::TemporaryExecutionContext context(element.document().relevant_settings_object()); + HTML::TemporaryExecutionContext context(realm); play().release_value_but_fixme_should_propagate_errors(); } diff --git a/Userland/Libraries/LibWeb/CSS/FontFace.cpp b/Userland/Libraries/LibWeb/CSS/FontFace.cpp index 20b7e3a2c0d..fd38e5eddcf 100644 --- a/Userland/Libraries/LibWeb/CSS/FontFace.cpp +++ b/Userland/Libraries/LibWeb/CSS/FontFace.cpp @@ -130,7 +130,7 @@ JS::NonnullGCPtr FontFace::construct_impl(JS::Realm& realm, String fam font->m_font_load_promise->when_resolved([font = JS::make_handle(font)](auto const& vector_font) -> ErrorOr { HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), JS::create_heap_function(font->heap(), [font = JS::NonnullGCPtr(*font), vector_font] { - HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*font), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(font->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 1. If the load was successful, font face now represents the parsed font; // fulfill font face’s [[FontStatusPromise]] with font face, and set its status attribute to "loaded". @@ -147,7 +147,7 @@ JS::NonnullGCPtr FontFace::construct_impl(JS::Realm& realm, String fam }); font->m_font_load_promise->when_rejected([font = JS::make_handle(font)](auto const& error) { HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), JS::create_heap_function(font->heap(), [font = JS::NonnullGCPtr(*font), error = Error::copy(error)] { - HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*font), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(font->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 2. Otherwise, reject font face’s [[FontStatusPromise]] with a DOMException named "SyntaxError" // and set font face’s status attribute to "error". font->m_status = Bindings::FontFaceLoadStatus::Error; @@ -356,7 +356,7 @@ void FontFace::load_font_source() // 5. When the load operation completes, successfully or not, queue a task to run the following steps synchronously: auto on_error = [font] { HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), JS::create_heap_function(font->heap(), [font = JS::NonnullGCPtr(*font)] { - HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*font), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(font->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 1. If the attempt to load fails, reject font face’s [[FontStatusPromise]] with a DOMException whose name // is "NetworkError" and set font face’s status attribute to "error". @@ -370,7 +370,7 @@ void FontFace::load_font_source() auto on_load = [font](FontLoader const& loader) { // FIXME: We are assuming that the font loader will live as long as the document! This is an unsafe capture HTML::queue_global_task(HTML::Task::Source::FontLoading, HTML::relevant_global_object(*font), JS::create_heap_function(font->heap(), [font = JS::NonnullGCPtr(*font), &loader] { - HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*font), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(font->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 2. Otherwise, font face now represents the loaded font; fulfill font face’s [[FontStatusPromise]] with font face // and set font face’s status attribute to "loaded". diff --git a/Userland/Libraries/LibWeb/CSS/FontFaceSet.cpp b/Userland/Libraries/LibWeb/CSS/FontFaceSet.cpp index dfed14e74cc..997023ca7e3 100644 --- a/Userland/Libraries/LibWeb/CSS/FontFaceSet.cpp +++ b/Userland/Libraries/LibWeb/CSS/FontFaceSet.cpp @@ -241,7 +241,7 @@ JS::ThrowCompletionOr> FontFaceSet::load(Strin // reject promise with a SyntaxError exception and terminate these steps. auto result = find_matching_font_faces(realm, font_face_set, font, text); if (result.is_error()) { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; WebIDL::reject_promise(realm, promise, Bindings::dom_exception_to_throw_completion(realm.vm(), result.release_error()).release_value().value()); return; } @@ -262,16 +262,16 @@ JS::ThrowCompletionOr> FontFaceSet::load(Strin // 2. Resolve promise with the result of waiting for all of the [[FontStatusPromise]]s of each font face in // the font face list, in order. - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; WebIDL::wait_for_all( realm, promises, [&realm, promise](auto const&) { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; WebIDL::resolve_promise(realm, promise); }, [&realm, promise](auto error) { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; WebIDL::reject_promise(realm, promise, error); }); })); diff --git a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp index 9d3b99eb020..c40849658ab 100644 --- a/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp +++ b/Userland/Libraries/LibWeb/CSS/StyleComputer.cpp @@ -1140,10 +1140,10 @@ static void apply_animation_properties(DOM::Document& document, StyleProperties& if (play_state != effect.last_css_animation_play_state()) { if (play_state == CSS::AnimationPlayState::Running && animation.play_state() == Bindings::AnimationPlayState::Paused) { - HTML::TemporaryExecutionContext context(document.relevant_settings_object()); + HTML::TemporaryExecutionContext context(document.realm()); animation.play().release_value_but_fixme_should_propagate_errors(); } else if (play_state == CSS::AnimationPlayState::Paused && animation.play_state() != Bindings::AnimationPlayState::Paused) { - HTML::TemporaryExecutionContext context(document.relevant_settings_object()); + HTML::TemporaryExecutionContext context(document.realm()); animation.pause().release_value_but_fixme_should_propagate_errors(); } @@ -1561,7 +1561,7 @@ void StyleComputer::compute_cascaded_values(StyleProperties& style, DOM::Element effect->set_target(&element); element.set_cached_animation_name_animation(animation, pseudo_element); - HTML::TemporaryExecutionContext context(m_document->relevant_settings_object()); + HTML::TemporaryExecutionContext context(realm); animation->play().release_value_but_fixme_should_propagate_errors(); } else { // The animation hasn't changed, but some properties of the animation may have diff --git a/Userland/Libraries/LibWeb/Clipboard/Clipboard.cpp b/Userland/Libraries/LibWeb/Clipboard/Clipboard.cpp index 5af85c0e85f..06f9d8d2426 100644 --- a/Userland/Libraries/LibWeb/Clipboard/Clipboard.cpp +++ b/Userland/Libraries/LibWeb/Clipboard/Clipboard.cpp @@ -160,7 +160,7 @@ JS::NonnullGCPtr Clipboard::write_text(String data) // 1. Queue a global task on the permission task source, given realm’s global object, to reject p with // "NotAllowedError" DOMException in realm. queue_global_task(HTML::Task::Source::Permissions, realm.global_object(), JS::create_heap_function(realm.heap(), [&realm, promise]() mutable { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm) }; + HTML::TemporaryExecutionContext execution_context { realm }; WebIDL::reject_promise(realm, promise, WebIDL::NotAllowedError::create(realm, "Clipboard writing is only allowed through user activation"_string)); })); @@ -188,7 +188,7 @@ JS::NonnullGCPtr Clipboard::write_text(String data) write_blobs_and_option_to_clipboard(realm, item_list, move(option)); // 6. Resolve p. - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm) }; + HTML::TemporaryExecutionContext execution_context { realm }; WebIDL::resolve_promise(realm, promise, JS::js_undefined()); })); })); diff --git a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp index 410926a3c87..253e9a24768 100644 --- a/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/SubtleCrypto.cpp @@ -148,7 +148,7 @@ JS::NonnullGCPtr SubtleCrypto::encrypt(AlgorithmIdentifier cons // 6. Return promise and perform the remaining steps in parallel. Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, normalized_algorithm = normalized_algorithm.release_value(), promise, key, data = move(data)]() -> void { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 7. If the following steps or referenced procedures say to throw an error, reject promise with the returned error and then terminate the algorithm. // 8. If the name member of normalizedAlgorithm is not equal to the name attribute of the [[algorithm]] internal slot of key then throw an InvalidAccessError. @@ -205,7 +205,7 @@ JS::NonnullGCPtr SubtleCrypto::decrypt(AlgorithmIdentifier cons // 6. Return promise and perform the remaining steps in parallel. Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, normalized_algorithm = normalized_algorithm.release_value(), promise, key, data = move(data)]() -> void { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 7. If the following steps or referenced procedures say to throw an error, reject promise with the returned error and then terminate the algorithm. // 8. If the name member of normalizedAlgorithm is not equal to the name attribute of the [[algorithm]] internal slot of key then throw an InvalidAccessError. @@ -263,7 +263,7 @@ JS::NonnullGCPtr SubtleCrypto::digest(AlgorithmIdentifier const // 6. Return promise and perform the remaining steps in parallel. Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, algorithm_object = normalized_algorithm.release_value(), promise, data_buffer = move(data_buffer)]() -> void { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 7. If the following steps or referenced procedures say to throw an error, reject promise with the returned error and then terminate the algorithm. // FIXME: Need spec reference to https://webidl.spec.whatwg.org/#reject @@ -303,7 +303,7 @@ JS::ThrowCompletionOr> SubtleCrypto::generate_ // 5. Return promise and perform the remaining steps in parallel. Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, normalized_algorithm = normalized_algorithm.release_value(), promise, extractable, key_usages = move(key_usages)]() -> void { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 6. If the following steps or referenced procedures say to throw an error, reject promise with // the returned error and then terminate the algorithm. @@ -385,7 +385,7 @@ JS::ThrowCompletionOr> SubtleCrypto::import_ke // 8. Return promise and perform the remaining steps in parallel. Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(heap(), [&realm, real_key_data = move(real_key_data), normalized_algorithm = normalized_algorithm.release_value(), promise, format, extractable, key_usages = move(key_usages), algorithm = move(algorithm)]() mutable -> void { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 9. If the following steps or referenced procedures say to throw an error, reject promise with the returned error and then terminate the algorithm. @@ -429,7 +429,7 @@ JS::ThrowCompletionOr> SubtleCrypto::export_ke // 3. Return promise and perform the remaining steps in parallel. Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(heap(), [&realm, key, promise, format]() -> void { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 4. If the following steps or referenced procedures say to throw an error, reject promise with the returned error and then terminate the algorithm. // 5. If the name member of the [[algorithm]] internal slot of key does not identify a registered algorithm that supports the export key operation, @@ -492,7 +492,7 @@ JS::ThrowCompletionOr> SubtleCrypto::sign(Algo // 6. Return promise and perform the remaining steps in parallel. Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, normalized_algorithm = normalized_algorithm.release_value(), promise, key, data = move(data)]() -> void { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 7. If the following steps or referenced procedures say to throw an error, reject promise with the returned error and then terminate the algorithm. // 8. If the name member of normalizedAlgorithm is not equal to the name attribute of the [[algorithm]] internal slot of key then throw an InvalidAccessError. @@ -556,7 +556,7 @@ JS::ThrowCompletionOr> SubtleCrypto::verify(Al // 7. Return promise and perform the remaining steps in parallel. Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, normalized_algorithm = normalized_algorithm.release_value(), promise, key, signature = move(signature), data = move(data)]() -> void { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 8. If the following steps or referenced procedures say to throw an error, reject promise with the returned error and then terminate the algorithm. // 9. If the name member of normalizedAlgorithm is not equal to the name attribute of the [[algorithm]] internal slot of key then throw an InvalidAccessError. @@ -603,7 +603,7 @@ JS::ThrowCompletionOr> SubtleCrypto::derive_bi // 5. Return promise and perform the remaining steps in parallel. Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, normalized_algorithm = normalized_algorithm.release_value(), promise, base_key, length]() -> void { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 6. If the following steps or referenced procedures say to throw an error, reject promise with the returned error and then terminate the algorithm. // 7. If the name member of normalizedAlgorithm is not equal to the name attribute of the [[algorithm]] internal slot of baseKey then throw an InvalidAccessError. @@ -664,7 +664,7 @@ JS::ThrowCompletionOr> SubtleCrypto::derive_ke // 9. Return promise and perform the remaining steps in parallel. Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, &vm, normalized_algorithm = normalized_algorithm.release_value(), promise, normalized_derived_key_algorithm_import = normalized_derived_key_algorithm_import.release_value(), normalized_derived_key_algorithm_length = normalized_derived_key_algorithm_length.release_value(), base_key = move(base_key), extractable, key_usages = move(key_usages)]() -> void { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 10. If the following steps or referenced procedures say to throw an error, reject promise with the returned error and then terminate the algorithm. // 11. If the name member of normalizedAlgorithm is not equal to the name attribute of the [[algorithm]] internal slot of baseKey then throw an InvalidAccessError. diff --git a/Userland/Libraries/LibWeb/Fetch/Body.cpp b/Userland/Libraries/LibWeb/Fetch/Body.cpp index 0e254af3a30..69abea24488 100644 --- a/Userland/Libraries/LibWeb/Fetch/Body.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Body.cpp @@ -190,7 +190,7 @@ WebIDL::ExceptionOr> consume_body(JS::Realm& r // NOTE: `promise` and `realm` is protected by JS::HeapFunction. auto error_steps = JS::create_heap_function(realm.heap(), [promise, &realm](JS::Value error) { // AD-HOC: An execution context is required for Promise's reject function. - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm) }; + HTML::TemporaryExecutionContext execution_context { realm }; WebIDL::reject_promise(realm, promise, error); }); @@ -202,7 +202,7 @@ WebIDL::ExceptionOr> consume_body(JS::Realm& r auto& vm = realm.vm(); // AD-HOC: An execution context is required for Promise's reject function and JSON.parse. - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm) }; + HTML::TemporaryExecutionContext execution_context { realm }; auto value_or_error = Bindings::throw_dom_exception_if_needed(vm, [&]() -> WebIDL::ExceptionOr { return package_data(realm, data, type, object.mime_type_impl()); diff --git a/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp b/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp index a8fd43781ab..4ec827ced5e 100644 --- a/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp +++ b/Userland/Libraries/LibWeb/Fetch/BodyInit.cpp @@ -38,7 +38,7 @@ WebIDL::ExceptionOr safely_extract_body(JS::Realm& // https://fetch.spec.whatwg.org/#concept-bodyinit-extract WebIDL::ExceptionOr extract_body(JS::Realm& realm, BodyInitOrReadableBytes const& object, bool keepalive) { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; auto& vm = realm.vm(); @@ -146,7 +146,7 @@ WebIDL::ExceptionOr extract_body(JS::Realm& realm, // 12. If action is non-null, then run these steps in parallel: if (action) { Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, stream, action = move(action)] { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // 1. Run action. auto bytes = action(); diff --git a/Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp b/Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp index e3b7f6bc216..42679f5e0bf 100644 --- a/Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp +++ b/Userland/Libraries/LibWeb/Fetch/FetchMethod.cpp @@ -87,7 +87,7 @@ JS::NonnullGCPtr fetch(JS::VM& vm, RequestInfo const& input, Re return; // AD-HOC: An execution context is required for Promise functions. - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(relevant_realm) }; + HTML::TemporaryExecutionContext execution_context { relevant_realm }; // 2. If response’s aborted flag is set, then: if (response->aborted()) { @@ -143,7 +143,7 @@ JS::NonnullGCPtr fetch(JS::VM& vm, RequestInfo const& input, Re controller->abort(relevant_realm, request_object->signal()->reason()); // AD-HOC: An execution context is required for Promise functions. - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(relevant_realm) }; + HTML::TemporaryExecutionContext execution_context { relevant_realm }; // 4. Abort the fetch() call with p, request, responseObject, and requestObject’s signal’s abort reason. abort_fetch(relevant_realm, *promise_capability, request, response_object, request_object->signal()->reason()); diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/FetchedDataReceiver.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/FetchedDataReceiver.cpp index af955b9b42d..8540cb1a4e9 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/FetchedDataReceiver.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/FetchedDataReceiver.cpp @@ -66,7 +66,7 @@ void FetchedDataReceiver::on_data_received(ReadonlyBytes bytes) m_fetch_params->controller(), m_fetch_params->task_destination().get>(), JS::create_heap_function(heap(), [this, bytes = MUST(ByteBuffer::copy(bytes))]() mutable { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(m_stream->realm()), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { m_stream->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // 1. Pull from bytes buffer into stream. if (auto result = Streams::readable_stream_pull_from_bytes(m_stream, move(bytes)); result.is_error()) { diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index aa428d39eb2..fa569d02e90 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -723,7 +723,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const } // 7. Otherwise: else { - HTML::TemporaryExecutionContext const execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext const execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // 1. Let transformStream be a new TransformStream. auto transform_stream = realm.heap().allocate(realm, realm); @@ -2232,7 +2232,7 @@ WebIDL::ExceptionOr> nonstandard_resource_load // user-agent-defined limit (or not). However, we will need to fully use stream operations throughout the // fetch process to enable this (e.g. Body::fully_read must use streams for this to work). if (request->buffer_policy() == Infrastructure::Request::BufferPolicy::DoNotBufferResponse) { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // 12. Let stream be a new ReadableStream. auto stream = realm.heap().allocate(realm, realm); @@ -2315,7 +2315,7 @@ WebIDL::ExceptionOr> nonstandard_resource_load }); auto on_complete = JS::create_heap_function(vm.heap(), [&vm, &realm, pending_response, stream](bool success, Optional error_message) { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // 16.1.1.2. Otherwise, if the bytes transmission for response’s message body is done normally and stream is readable, // then close stream, and abort these in-parallel steps. diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp index b77d5ac955f..0037d3548e9 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/HTTP/Bodies.cpp @@ -49,7 +49,7 @@ void Body::visit_edges(Cell::Visitor& visitor) // https://fetch.spec.whatwg.org/#concept-body-clone JS::NonnullGCPtr Body::clone(JS::Realm& realm) { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // To clone a body body, run these steps: // 1. Let « out1, out2 » be the result of teeing body’s stream. @@ -107,7 +107,7 @@ void Body::fully_read(JS::Realm& realm, Web::Fetch::Infrastructure::Body::Proces // https://fetch.spec.whatwg.org/#body-incrementally-read void Body::incrementally_read(ProcessBodyChunkCallback process_body_chunk, ProcessEndOfBodyCallback process_end_of_body, ProcessBodyErrorCallback process_body_error, TaskDestination task_destination) { - HTML::TemporaryExecutionContext const execution_context { Bindings::host_defined_environment_settings_object(m_stream->realm()), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext const execution_context { m_stream->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; VERIFY(task_destination.has>()); // FIXME: 1. If taskDestination is null, then set taskDestination to the result of starting a new parallel queue. diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/IncrementalReadLoopReadRequest.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/IncrementalReadLoopReadRequest.cpp index bae24f26e48..932aaf48040 100644 --- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/IncrementalReadLoopReadRequest.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/IncrementalReadLoopReadRequest.cpp @@ -33,7 +33,7 @@ void IncrementalReadLoopReadRequest::on_chunk(JS::Value chunk) auto bytes = MUST(ByteBuffer::copy(uint8_array.data())); // 2. Set continueAlgorithm to these steps: continue_algorithm = JS::create_heap_function(realm.heap(), [bytes = move(bytes), body = m_body, reader = m_reader, task_destination = m_task_destination, process_body_chunk = m_process_body_chunk, process_end_of_body = m_process_end_of_body, process_body_error = m_process_body_error] { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(reader->realm()), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { reader->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // 1. Run processBodyChunk given bytes. process_body_chunk->function()(move(bytes)); diff --git a/Userland/Libraries/LibWeb/FileAPI/FileReader.cpp b/Userland/Libraries/LibWeb/FileAPI/FileReader.cpp index b4603e18df8..24039eb03b0 100644 --- a/Userland/Libraries/LibWeb/FileAPI/FileReader.cpp +++ b/Userland/Libraries/LibWeb/FileAPI/FileReader.cpp @@ -147,7 +147,7 @@ WebIDL::ExceptionOr FileReader::read_operation(Blob& blob, Type type, Opti // 10. In parallel, while true: Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(heap(), [this, chunk_promise, reader, bytes, is_first_chunk, &realm, type, encoding_name, blobs_type]() mutable { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; Optional progress_timer; while (true) { diff --git a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp index 3dd72c05bfa..0c3d586f9c9 100644 --- a/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp +++ b/Userland/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp @@ -397,7 +397,7 @@ void EventLoop::update_the_rendering() for (auto& document : docs) { if (document->readiness() == HTML::DocumentReadyState::Complete && document->style_computer().number_of_css_font_faces_with_loading_in_progress() == 0) { - HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*document), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(document->realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); document->fonts()->resolve_ready_promise(); } } diff --git a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp index 1f4f108d388..d969fb13993 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLImageElement.cpp @@ -296,7 +296,7 @@ WebIDL::ExceptionOr> HTMLImageElement::decode( return false; auto exception = WebIDL::EncodingError::create(realm, "Node document not fully active"_string); - HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*this)); + HTML::TemporaryExecutionContext context(realm); WebIDL::reject_promise(realm, promise, exception); return true; }; @@ -306,7 +306,7 @@ WebIDL::ExceptionOr> HTMLImageElement::decode( return false; auto exception = WebIDL::EncodingError::create(realm, "Current request state is broken"_string); - HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*this)); + HTML::TemporaryExecutionContext context(realm); WebIDL::reject_promise(realm, promise, exception); return true; }; @@ -354,7 +354,7 @@ WebIDL::ExceptionOr> HTMLImageElement::decode( // (Typically, this would only be violated in low-memory situations that require evicting decoded image data, or when the image is too large // to keep in decoded form for this period of time.) - HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*this)); + HTML::TemporaryExecutionContext context(realm); WebIDL::resolve_promise(realm, promise, JS::js_undefined()); } })); diff --git a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp index b6994bfc056..9d0f67746d3 100644 --- a/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp +++ b/Userland/Libraries/LibWeb/HTML/HTMLMediaElement.cpp @@ -375,7 +375,7 @@ WebIDL::ExceptionOr HTMLMediaElement::pause() WebIDL::ExceptionOr HTMLMediaElement::toggle_playback() { // AD-HOC: An execution context is required for Promise creation hooks. - TemporaryExecutionContext execution_context { document().relevant_settings_object() }; + TemporaryExecutionContext execution_context { realm() }; if (potentially_playing()) TRY(pause()); @@ -1886,7 +1886,7 @@ void HTMLMediaElement::resolve_pending_play_promises(ReadonlySpanrealm(); // AD-HOC: An execution context is required for Promise resolving hooks. - TemporaryExecutionContext execution_context { document().relevant_settings_object() }; + TemporaryExecutionContext execution_context { realm }; // To resolve pending play promises for a media element with a list of promises promises, the user agent // must resolve each promise in promises with undefined. @@ -1900,7 +1900,7 @@ void HTMLMediaElement::reject_pending_play_promises(ReadonlySpanrealm(); // AD-HOC: An execution context is required for Promise rejection hooks. - TemporaryExecutionContext execution_context { document().relevant_settings_object() }; + TemporaryExecutionContext execution_context { realm }; // To reject pending play promises for a media element with a list of promise promises and an exception name // error, the user agent must reject each promise in promises with error. diff --git a/Userland/Libraries/LibWeb/HTML/MessagePort.cpp b/Userland/Libraries/LibWeb/HTML/MessagePort.cpp index d98205ad02c..b53e1257a40 100644 --- a/Userland/Libraries/LibWeb/HTML/MessagePort.cpp +++ b/Userland/Libraries/LibWeb/HTML/MessagePort.cpp @@ -380,7 +380,7 @@ void MessagePort::post_message_task_steps(SerializedTransferRecord& serialize_wi auto& target_vm = target_realm.vm(); // 3. Let deserializeRecord be StructuredDeserializeWithTransfer(serializeWithTransferResult, targetRealm). - TemporaryExecutionContext context { relevant_settings_object(*final_target_port) }; + TemporaryExecutionContext context { relevant_realm(*final_target_port) }; auto deserialize_record_or_error = structured_deserialize_with_transfer(target_vm, serialize_with_transfer_result); if (deserialize_record_or_error.is_error()) { // If this throws an exception, catch it, fire an event named messageerror at finalTargetPort, using MessageEvent, and then return. diff --git a/Userland/Libraries/LibWeb/HTML/Navigation.cpp b/Userland/Libraries/LibWeb/HTML/Navigation.cpp index 4e8aa8b0789..945d243c057 100644 --- a/Userland/Libraries/LibWeb/HTML/Navigation.cpp +++ b/Userland/Libraries/LibWeb/HTML/Navigation.cpp @@ -680,7 +680,7 @@ WebIDL::ExceptionOr Navigation::perform_a_navigation_api_trave // to reject the finished promise for apiMethodTracker with an "InvalidStateError" DOMException. queue_global_task(HTML::Task::Source::NavigationAndTraversal, relevant_global_object(*this), JS::create_heap_function(heap(), [this, api_method_tracker] { auto& reject_realm = relevant_realm(*this); - TemporaryExecutionContext execution_context { relevant_settings_object(*this) }; + TemporaryExecutionContext execution_context { reject_realm }; WebIDL::reject_promise(reject_realm, api_method_tracker->finished_promise, WebIDL::InvalidStateError::create(reject_realm, "Cannot traverse with stale session history entry"_string)); })); @@ -712,7 +712,7 @@ WebIDL::ExceptionOr Navigation::perform_a_navigation_api_trave auto& global = relevant_global_object(*this); if (result == TraversableNavigable::HistoryStepResult::CanceledByBeforeUnload) { queue_global_task(Task::Source::NavigationAndTraversal, global, JS::create_heap_function(heap(), [this, api_method_tracker, &realm] { - TemporaryExecutionContext execution_context { relevant_settings_object(*this) }; + TemporaryExecutionContext execution_context { realm }; reject_the_finished_promise(api_method_tracker, WebIDL::AbortError::create(realm, "Navigation cancelled by beforeunload"_string)); })); } @@ -722,7 +722,7 @@ WebIDL::ExceptionOr Navigation::perform_a_navigation_api_trave // new "SecurityError" DOMException created in navigation's relevant realm. if (result == TraversableNavigable::HistoryStepResult::InitiatorDisallowed) { queue_global_task(Task::Source::NavigationAndTraversal, global, JS::create_heap_function(heap(), [this, api_method_tracker, &realm] { - TemporaryExecutionContext execution_context { relevant_settings_object(*this) }; + TemporaryExecutionContext execution_context { realm }; reject_the_finished_promise(api_method_tracker, WebIDL::SecurityError::create(realm, "Navigation disallowed from this origin"_string)); })); } @@ -904,7 +904,7 @@ void Navigation::notify_about_the_committed_to_entry(JS::NonnullGCPtrcommitted_promise, nhe); } @@ -1088,7 +1088,7 @@ bool Navigation::inner_navigate_event_firing_algorithm( // 31. Prepare to run script given navigation's relevant settings object. // NOTE: There's a massive spec note here - TemporaryExecutionContext execution_context { relevant_settings_object(*this), TemporaryExecutionContext::CallbacksEnabled::Yes }; + TemporaryExecutionContext execution_context { realm, TemporaryExecutionContext::CallbacksEnabled::Yes }; // 32. If event's interception state is not "none": if (event->interception_state() != NavigateEvent::InterceptionState::None) { diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp index 003466d675f..b4bca211cf3 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/ImportMap.cpp @@ -18,7 +18,7 @@ namespace Web::HTML { // https://html.spec.whatwg.org/multipage/webappapis.html#parse-an-import-map-string WebIDL::ExceptionOr parse_import_map_string(JS::Realm& realm, ByteString const& input, URL::URL base_url) { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm) }; + HTML::TemporaryExecutionContext execution_context { realm }; // 1. Let parsed be the result of parsing a JSON string to an Infra value given input. auto parsed = TRY(Infra::parse_json_string_to_javascript_value(realm, input)); diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/TemporaryExecutionContext.cpp b/Userland/Libraries/LibWeb/HTML/Scripting/TemporaryExecutionContext.cpp index 71e2f712153..5acf732ddc4 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/TemporaryExecutionContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/Scripting/TemporaryExecutionContext.cpp @@ -9,20 +9,20 @@ namespace Web::HTML { -TemporaryExecutionContext::TemporaryExecutionContext(EnvironmentSettingsObject& environment_settings, CallbacksEnabled callbacks_enabled) - : m_environment_settings(environment_settings) +TemporaryExecutionContext::TemporaryExecutionContext(JS::Realm& realm, CallbacksEnabled callbacks_enabled) + : m_realm(realm) , m_callbacks_enabled(callbacks_enabled) { - prepare_to_run_script(m_environment_settings->realm()); + prepare_to_run_script(m_realm); if (m_callbacks_enabled == CallbacksEnabled::Yes) - prepare_to_run_callback(m_environment_settings->realm()); + prepare_to_run_callback(m_realm); } TemporaryExecutionContext::~TemporaryExecutionContext() { - clean_up_after_running_script(m_environment_settings->realm()); + clean_up_after_running_script(m_realm); if (m_callbacks_enabled == CallbacksEnabled::Yes) - clean_up_after_running_callback(m_environment_settings->realm()); + clean_up_after_running_callback(m_realm); } } diff --git a/Userland/Libraries/LibWeb/HTML/Scripting/TemporaryExecutionContext.h b/Userland/Libraries/LibWeb/HTML/Scripting/TemporaryExecutionContext.h index dc260b26c5a..de2612cc46b 100644 --- a/Userland/Libraries/LibWeb/HTML/Scripting/TemporaryExecutionContext.h +++ b/Userland/Libraries/LibWeb/HTML/Scripting/TemporaryExecutionContext.h @@ -21,11 +21,11 @@ public: Yes, }; - explicit TemporaryExecutionContext(EnvironmentSettingsObject&, CallbacksEnabled = CallbacksEnabled::No); + explicit TemporaryExecutionContext(JS::Realm&, CallbacksEnabled = CallbacksEnabled::No); ~TemporaryExecutionContext(); private: - JS::NonnullGCPtr m_environment_settings; + JS::NonnullGCPtr m_realm; CallbacksEnabled m_callbacks_enabled { CallbacksEnabled::No }; }; diff --git a/Userland/Libraries/LibWeb/HTML/Window.cpp b/Userland/Libraries/LibWeb/HTML/Window.cpp index daa10a7dc80..ade50005a1f 100644 --- a/Userland/Libraries/LibWeb/HTML/Window.cpp +++ b/Userland/Libraries/LibWeb/HTML/Window.cpp @@ -1126,8 +1126,7 @@ WebIDL::ExceptionOr Window::window_post_message_steps(JS::Value message, W auto& source = verify_cast(incumbent_settings.realm().global_environment().global_this_value()); // 4. Let deserializeRecord be StructuredDeserializeWithTransfer(serializeWithTransferResult, targetRealm). - auto& settings_object = Bindings::host_defined_environment_settings_object(target_realm); - auto temporary_execution_context = TemporaryExecutionContext { settings_object }; + auto temporary_execution_context = TemporaryExecutionContext { target_realm }; auto deserialize_record_or_error = structured_deserialize_with_transfer(vm(), serialize_with_transfer_result); // If this throws an exception, catch it, fire an event named messageerror at targetWindow, using MessageEvent, diff --git a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp index f3804b8cbcd..6a1efc612b3 100644 --- a/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp +++ b/Userland/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp @@ -226,7 +226,7 @@ JS::NonnullGCPtr WindowOrWorkerGlobalScopeMixin::create_image_b // (e.g., a vector graphic with no natural size), then reject p with an "InvalidStateError" DOMException // and abort these steps. auto& realm = relevant_realm(p->promise()); - TemporaryExecutionContext context { relevant_settings_object(p->promise()), TemporaryExecutionContext::CallbacksEnabled::Yes }; + TemporaryExecutionContext context { relevant_realm(p->promise()), TemporaryExecutionContext::CallbacksEnabled::Yes }; WebIDL::reject_promise(realm, *p, WebIDL::InvalidStateError::create(realm, "image does not contain a supported image format"_string)); }; @@ -240,7 +240,7 @@ JS::NonnullGCPtr WindowOrWorkerGlobalScopeMixin::create_image_b auto& realm = relevant_realm(p->promise()); // 5. Resolve p with imageBitmap. - TemporaryExecutionContext context { relevant_settings_object(*image_bitmap), TemporaryExecutionContext::CallbacksEnabled::Yes }; + TemporaryExecutionContext context { relevant_realm(*image_bitmap), TemporaryExecutionContext::CallbacksEnabled::Yes }; WebIDL::resolve_promise(realm, *p, image_bitmap); return {}; }; @@ -253,7 +253,7 @@ JS::NonnullGCPtr WindowOrWorkerGlobalScopeMixin::create_image_b (void)sx; (void)sy; auto error = JS::Error::create(realm, "Not Implemented: createImageBitmap() for non-blob types"sv); - TemporaryExecutionContext context { relevant_settings_object(p->promise()), TemporaryExecutionContext::CallbacksEnabled::Yes }; + TemporaryExecutionContext context { relevant_realm(p->promise()), TemporaryExecutionContext::CallbacksEnabled::Yes }; WebIDL::reject_promise(realm, *p, error); }); @@ -416,7 +416,7 @@ i32 WindowOrWorkerGlobalScopeMixin::run_timer_initialization_steps(TimerHandler // 11. Let completionStep be an algorithm step which queues a global task on the timer task source given global to run task. Function completion_step = [this, task = move(task)]() mutable { queue_global_task(Task::Source::TimerTask, this_impl(), JS::create_heap_function(this_impl().heap(), [this, task] { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(this_impl().realm()), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { this_impl().realm(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; task->function()(); })); }; @@ -587,7 +587,7 @@ void WindowOrWorkerGlobalScopeMixin::queue_the_performance_observer_task() // timeline task source. queue_global_task(Task::Source::PerformanceTimeline, this_impl(), JS::create_heap_function(this_impl().heap(), [this]() { auto& realm = this_impl().realm(); - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // 1. Unset performance observer task queued flag of relevantGlobal. m_performance_observer_task_queued = false; diff --git a/Userland/Libraries/LibWeb/Page/Page.cpp b/Userland/Libraries/LibWeb/Page/Page.cpp index a94efcf11fd..0e2f1eb0e0e 100644 --- a/Userland/Libraries/LibWeb/Page/Page.cpp +++ b/Userland/Libraries/LibWeb/Page/Page.cpp @@ -477,7 +477,7 @@ WebIDL::ExceptionOr Page::toggle_media_play_state() return {}; // AD-HOC: An execution context is required for Promise creation hooks. - HTML::TemporaryExecutionContext execution_context { media_element->document().relevant_settings_object() }; + HTML::TemporaryExecutionContext execution_context { media_element->realm() }; if (media_element->potentially_playing()) TRY(media_element->pause()); @@ -494,7 +494,7 @@ void Page::toggle_media_mute_state() return; // AD-HOC: An execution context is required for Promise creation hooks. - HTML::TemporaryExecutionContext execution_context { media_element->document().relevant_settings_object() }; + HTML::TemporaryExecutionContext execution_context { media_element->realm() }; media_element->set_muted(!media_element->muted()); } @@ -506,7 +506,7 @@ WebIDL::ExceptionOr Page::toggle_media_loop_state() return {}; // AD-HOC: An execution context is required for Promise creation hooks. - HTML::TemporaryExecutionContext execution_context { media_element->document().relevant_settings_object() }; + HTML::TemporaryExecutionContext execution_context { media_element->realm() }; if (media_element->has_attribute(HTML::AttributeNames::loop)) media_element->remove_attribute(HTML::AttributeNames::loop); @@ -522,7 +522,7 @@ WebIDL::ExceptionOr Page::toggle_media_controls_state() if (!media_element) return {}; - HTML::TemporaryExecutionContext execution_context { media_element->document().relevant_settings_object() }; + HTML::TemporaryExecutionContext execution_context { media_element->realm() }; if (media_element->has_attribute(HTML::AttributeNames::controls)) media_element->remove_attribute(HTML::AttributeNames::controls); diff --git a/Userland/Libraries/LibWeb/ServiceWorker/Job.cpp b/Userland/Libraries/LibWeb/ServiceWorker/Job.cpp index e2efcf3530b..b0bfd6b90eb 100644 --- a/Userland/Libraries/LibWeb/ServiceWorker/Job.cpp +++ b/Userland/Libraries/LibWeb/ServiceWorker/Job.cpp @@ -401,8 +401,8 @@ static void update(JS::VM& vm, JS::NonnullGCPtr job) // 16. If runResult is failure or an abrupt completion, then: // 17. Else, invoke Install algorithm with job, worker, and registration as its arguments. if (job->client) { - auto context = HTML::TemporaryExecutionContext(*job->client, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); auto& realm = *vm.current_realm(); + auto context = HTML::TemporaryExecutionContext(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); WebIDL::reject_promise(realm, *job->job_promise, *vm.throw_completion(JS::ErrorType::NotImplemented, "Run Service Worker"sv).value()); finish_job(vm, job); } @@ -428,8 +428,8 @@ static void unregister(JS::VM& vm, JS::NonnullGCPtr job) { // If there's no client, there won't be any promises to resolve if (job->client) { - auto context = HTML::TemporaryExecutionContext(*job->client, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); auto& realm = *vm.current_realm(); + auto context = HTML::TemporaryExecutionContext(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); WebIDL::reject_promise(realm, *job->job_promise, *vm.throw_completion(JS::ErrorType::NotImplemented, "Service Worker unregistration"sv).value()); finish_job(vm, job); } @@ -497,7 +497,7 @@ static void resolve_job_promise(JS::NonnullGCPtr job, Optionalclient) { auto& realm = job->client->realm(); HTML::queue_a_task(HTML::Task::Source::DOMManipulation, job->client->responsible_event_loop(), nullptr, JS::create_heap_function(realm.heap(), [&realm, job, value] { - HTML::TemporaryExecutionContext const context(*job->client, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext const context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // FIXME: Resolve to a ServiceWorkerRegistration platform object // 1. Let convertedValue be null. // 2. If job’s job type is either register or update, set convertedValue to the result of @@ -518,7 +518,7 @@ static void resolve_job_promise(JS::NonnullGCPtr job, Optionalclient->realm(); HTML::queue_a_task(HTML::Task::Source::DOMManipulation, equivalent_job->client->responsible_event_loop(), nullptr, JS::create_heap_function(realm.heap(), [&realm, equivalent_job, value] { - HTML::TemporaryExecutionContext const context(*equivalent_job->client, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext const context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // FIXME: Resolve to a ServiceWorkerRegistration platform object // 1. Let convertedValue be null. // 2. If equivalentJob’s job type is either register or update, set convertedValue to the result of @@ -539,7 +539,7 @@ static void reject_job_promise(JS::NonnullGCPtr job, String message) if (job->client) { auto& realm = job->client->realm(); HTML::queue_a_task(HTML::Task::Source::DOMManipulation, job->client->responsible_event_loop(), nullptr, JS::create_heap_function(realm.heap(), [&realm, job, message] { - HTML::TemporaryExecutionContext const context(*job->client, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext const context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); WebIDL::reject_promise(realm, *job->job_promise, Error::create(realm, message)); })); } @@ -555,7 +555,7 @@ static void reject_job_promise(JS::NonnullGCPtr job, String message) // in equivalentJob’s client's Realm. auto& realm = equivalent_job->client->realm(); HTML::queue_a_task(HTML::Task::Source::DOMManipulation, equivalent_job->client->responsible_event_loop(), nullptr, JS::create_heap_function(realm.heap(), [&realm, equivalent_job, message] { - HTML::TemporaryExecutionContext const context(*equivalent_job->client, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext const context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); WebIDL::reject_promise(realm, *equivalent_job->job_promise, Error::create(realm, message)); })); } diff --git a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp index c1c70f37935..ebab92f276b 100644 --- a/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp +++ b/Userland/Libraries/LibWeb/Streams/AbstractOperations.cpp @@ -402,7 +402,7 @@ public: { // 1. Queue a microtask to perform the following steps: HTML::queue_a_microtask(nullptr, JS::create_heap_function(m_realm->heap(), [this, chunk]() { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(m_realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { m_realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; auto controller1 = m_params->branch1->controller()->get>(); auto controller2 = m_params->branch2->controller()->get>(); @@ -709,7 +709,7 @@ public: { // 1. Queue a microtask to perform the following steps: HTML::queue_a_microtask(nullptr, JS::create_heap_function(m_realm->heap(), [this, chunk]() mutable { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(m_realm) }; + HTML::TemporaryExecutionContext execution_context { m_realm }; auto controller1 = m_params->branch1->controller()->get>(); auto controller2 = m_params->branch2->controller()->get>(); @@ -872,7 +872,7 @@ public: // 1. Queue a microtask to perform the following steps: HTML::queue_a_microtask(nullptr, JS::create_heap_function(m_realm->heap(), [this, chunk = chunk_view]() { - HTML::TemporaryExecutionContext execution_context { Bindings::host_defined_environment_settings_object(m_realm) }; + HTML::TemporaryExecutionContext execution_context { m_realm }; auto byob_controller = m_byob_branch->controller()->get>(); auto other_controller = m_other_branch->controller()->get>(); diff --git a/Userland/Libraries/LibWeb/WebAssembly/WebAssembly.cpp b/Userland/Libraries/LibWeb/WebAssembly/WebAssembly.cpp index f2e3c732b8f..f2f52fed853 100644 --- a/Userland/Libraries/LibWeb/WebAssembly/WebAssembly.cpp +++ b/Userland/Libraries/LibWeb/WebAssembly/WebAssembly.cpp @@ -506,14 +506,14 @@ JS::NonnullGCPtr asynchronously_compile_webassembly_module(JS:: auto promise = WebIDL::create_promise(realm); // 2. Run the following steps in parallel: - Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(vm.heap(), [&vm, bytes = move(bytes), promise, task_source]() mutable { - HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*promise->promise()), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(vm.heap(), [&vm, &realm, bytes = move(bytes), promise, task_source]() mutable { + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 1. Compile the WebAssembly module bytes and store the result as module. auto module_or_error = Detail::compile_a_webassembly_module(vm, move(bytes)); // 2. Queue a task to perform the following steps. If taskSource was provided, queue the task on that task source. - HTML::queue_a_task(task_source, nullptr, nullptr, JS::create_heap_function(vm.heap(), [&vm, promise, module_or_error = move(module_or_error)]() mutable { - HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*promise->promise()), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::queue_a_task(task_source, nullptr, nullptr, JS::create_heap_function(vm.heap(), [&vm, &realm, promise, module_or_error = move(module_or_error)]() mutable { + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); auto& realm = HTML::relevant_realm(*promise->promise()); // 1. If module is error, reject promise with a CompileError exception. @@ -554,8 +554,8 @@ JS::NonnullGCPtr asynchronously_instantiate_webassembly_module( // 4. Run the following steps in parallel: // 1. Queue a task to perform the following steps: Note: Implementation-specific work may be performed here. - HTML::queue_a_task(HTML::Task::Source::Unspecified, nullptr, nullptr, JS::create_heap_function(vm.heap(), [&vm, promise, module, import_object]() { - HTML::TemporaryExecutionContext context(HTML::relevant_settings_object(*promise->promise()), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::queue_a_task(HTML::Task::Source::Unspecified, nullptr, nullptr, JS::create_heap_function(vm.heap(), [&vm, &realm, promise, module, import_object]() { + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); auto& realm = HTML::relevant_realm(*promise->promise()); // 1. Instantiate the core of a WebAssembly module module with imports, and let instance be the result. diff --git a/Userland/Libraries/LibWeb/WebAudio/AudioContext.cpp b/Userland/Libraries/LibWeb/WebAudio/AudioContext.cpp index aaba40d899c..60cfbad55eb 100644 --- a/Userland/Libraries/LibWeb/WebAudio/AudioContext.cpp +++ b/Userland/Libraries/LibWeb/WebAudio/AudioContext.cpp @@ -146,7 +146,7 @@ WebIDL::ExceptionOr> AudioContext::resume() if (!start_rendering_audio_graph()) { // 7.4: In case of failure, queue a media element task to execute the following steps: queue_a_media_element_task(JS::create_heap_function(heap(), [&realm, this]() { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 7.4.1: Reject all promises from [[pending resume promises]] in order, then clear [[pending resume promises]]. for (auto const& promise : m_pending_resume_promises) { @@ -163,7 +163,7 @@ WebIDL::ExceptionOr> AudioContext::resume() // 7.5: queue a media element task to execute the following steps: queue_a_media_element_task(JS::create_heap_function(heap(), [&realm, promise, this]() { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 7.5.1: Resolve all promises from [[pending resume promises]] in order. // 7.5.2: Clear [[pending resume promises]]. Additionally, remove those promises from @@ -233,7 +233,7 @@ WebIDL::ExceptionOr> AudioContext::suspend() // 7.3: queue a media element task to execute the following steps: queue_a_media_element_task(JS::create_heap_function(heap(), [&realm, promise, this]() { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 7.3.1: Resolve promise. WebIDL::resolve_promise(realm, promise, JS::js_undefined()); @@ -288,7 +288,7 @@ WebIDL::ExceptionOr> AudioContext::close() // 5.4: queue a media element task to execute the following steps: queue_a_media_element_task(JS::create_heap_function(heap(), [&realm, promise, this]() { - HTML::TemporaryExecutionContext context(Bindings::host_defined_environment_settings_object(realm), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); + HTML::TemporaryExecutionContext context(realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes); // 5.4.1: Resolve promise. WebIDL::resolve_promise(realm, promise, JS::js_undefined()); diff --git a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp index 8adb98cc0a1..f6314a40c97 100644 --- a/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/ExecuteScript.cpp @@ -340,14 +340,14 @@ void execute_script(HTML::BrowsingContext const& browsing_context, ByteString bo } // AD-HOC: An execution context is required for Promise creation hooks. - HTML::TemporaryExecutionContext execution_context { document->relevant_settings_object(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // 7. Let promise be a new Promise. auto promise = WebIDL::create_promise(realm); // 8. Run the following substeps in parallel: - Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, &browsing_context, promise, document, body = move(body), arguments = move(arguments)]() mutable { - HTML::TemporaryExecutionContext execution_context { document->relevant_settings_object() }; + Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&realm, &browsing_context, promise, body = move(body), arguments = move(arguments)]() mutable { + HTML::TemporaryExecutionContext execution_context { realm }; // 1. Let scriptPromise be the result of promise-calling execute a function body, with arguments body and arguments. auto script_result = execute_a_function_body(browsing_context, body, move(arguments)); @@ -418,15 +418,15 @@ void execute_async_script(HTML::BrowsingContext const& browsing_context, ByteStr } // AD-HOC: An execution context is required for Promise creation hooks. - HTML::TemporaryExecutionContext execution_context { document->relevant_settings_object(), HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; + HTML::TemporaryExecutionContext execution_context { realm, HTML::TemporaryExecutionContext::CallbacksEnabled::Yes }; // 7. Let promise be a new Promise. auto promise_capability = WebIDL::create_promise(realm); JS::NonnullGCPtr promise { verify_cast(*promise_capability->promise()) }; // 8. Run the following substeps in parallel: - Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&vm, &realm, &browsing_context, timer, document, promise_capability, promise, body = move(body), arguments = move(arguments)]() mutable { - HTML::TemporaryExecutionContext execution_context { document->relevant_settings_object() }; + Platform::EventLoopPlugin::the().deferred_invoke(JS::create_heap_function(realm.heap(), [&vm, &realm, &browsing_context, timer, promise_capability, promise, body = move(body), arguments = move(arguments)]() mutable { + HTML::TemporaryExecutionContext execution_context { realm }; // 1. Let resolvingFunctions be CreateResolvingFunctions(promise). auto resolving_functions = promise->create_resolving_functions(); diff --git a/Userland/Services/WebContent/WebDriverConnection.cpp b/Userland/Services/WebContent/WebDriverConnection.cpp index 8229149af55..0d2195fa5f3 100644 --- a/Userland/Services/WebContent/WebDriverConnection.cpp +++ b/Userland/Services/WebContent/WebDriverConnection.cpp @@ -504,7 +504,7 @@ Messages::WebDriverClient::NewWindowResponse WebDriverConnection::new_window(Jso auto* active_window = current_browsing_context().active_window(); VERIFY(active_window); - Web::HTML::TemporaryExecutionContext execution_context { active_window->document()->relevant_settings_object() }; + Web::HTML::TemporaryExecutionContext execution_context { active_window->document()->realm() }; auto [target_navigable, no_opener, window_type] = MUST(active_window->window_open_steps_internal("about:blank"sv, ""sv, "noopener"sv)); // 6. Let handle be the associated window handle of the newly created window. @@ -1175,7 +1175,7 @@ Messages::WebDriverClient::GetElementPropertyResponse WebDriverConnection::get_e Optional result; // 4. Let property be the result of calling the Object.[[GetProperty]](name) on element. - Web::HTML::TemporaryExecutionContext execution_context { current_browsing_context().active_document()->relevant_settings_object() }; + Web::HTML::TemporaryExecutionContext execution_context { current_browsing_context().active_document()->realm() }; if (auto property_or_error = element->get(name.to_byte_string()); !property_or_error.is_throw_completion()) { auto property = property_or_error.release_value(); @@ -2787,7 +2787,7 @@ static ErrorOr json_deserialize(JS::VM& vm, We ErrorOr WebDriverConnection::extract_the_script_arguments_from_a_request(JS::VM& vm, JsonValue const& payload) { // Creating JSON objects below requires an execution context. - Web::HTML::TemporaryExecutionContext execution_context { current_browsing_context().active_document()->relevant_settings_object() }; + Web::HTML::TemporaryExecutionContext execution_context { current_browsing_context().active_document()->realm() }; // 1. Let script be the result of getting a property named script from the parameters. // 2. If script is not a String, return error with error code invalid argument.