From ba5bcb67a56389c8949e7691eb112527ee52946f Mon Sep 17 00:00:00 2001 From: davidot Date: Sat, 27 Aug 2022 14:35:54 +0200 Subject: [PATCH] LibWeb: Implement the HostEnsureCanAddPrivateElement JS hook Also added a local test for ensuring this behavior since it is unique to browsers. Since we don't actually use WindowProxy anywhere yet we just test on location for now. --- Base/res/html/misc/private-element-test.html | 63 +++++++++++++++++++ Base/res/html/misc/welcome.html | 1 + .../LibWeb/Bindings/MainThreadVM.cpp | 34 ++++++---- 3 files changed, 87 insertions(+), 11 deletions(-) create mode 100644 Base/res/html/misc/private-element-test.html diff --git a/Base/res/html/misc/private-element-test.html b/Base/res/html/misc/private-element-test.html new file mode 100644 index 0000000000..1a9d669298 --- /dev/null +++ b/Base/res/html/misc/private-element-test.html @@ -0,0 +1,63 @@ + + + If passed, the text below should say: "Passed" And the iframe should have loaded +
Starting up
+ + + diff --git a/Base/res/html/misc/welcome.html b/Base/res/html/misc/welcome.html index 0ff3d086e8..e3462f0cde 100644 --- a/Base/res/html/misc/welcome.html +++ b/Base/res/html/misc/welcome.html @@ -170,6 +170,7 @@
  • Basic test for async functions and their integration with the LibWeb event loop
  • Workers
  • Web Storage API
  • +
  • Test for rejecting private elements on special objects
  • Canvas

  • canvas 2D test
  • canvas rotate()
  • diff --git a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp index a78434db19..91c269c46c 100644 --- a/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp +++ b/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp @@ -12,9 +12,11 @@ #include #include #include +#include #include #include #include +#include #include #include #include @@ -58,9 +60,19 @@ JS::VM& main_thread_vm() static_cast(vm->custom_data())->event_loop.set_vm(*vm); - // FIXME: Implement 8.1.5.1 HostEnsureCanCompileStrings(callerRealm, calleeRealm), https://html.spec.whatwg.org/multipage/webappapis.html#hostensurecancompilestrings(callerrealm,-calleerealm) + // 8.1.5.1 HostEnsureCanAddPrivateElement(O), https://html.spec.whatwg.org/multipage/webappapis.html#the-hostensurecanaddprivateelement-implementation + vm->host_ensure_can_add_private_element = [](JS::Object const& object) -> JS::ThrowCompletionOr { + // 1. If O is a WindowProxy object, or implements Location, then return Completion { [[Type]]: throw, [[Value]]: a new TypeError }. + if (is(object) || is(object)) + return vm->throw_completion("Cannot add private elements to window or location object"); - // 8.1.5.2 HostPromiseRejectionTracker(promise, operation), https://html.spec.whatwg.org/multipage/webappapis.html#the-hostpromiserejectiontracker-implementation + // 2. Return NormalCompletion(unused). + return {}; + }; + + // FIXME: Implement 8.1.5.2 HostEnsureCanCompileStrings(callerRealm, calleeRealm), https://html.spec.whatwg.org/multipage/webappapis.html#hostensurecancompilestrings(callerrealm,-calleerealm) + + // 8.1.5.3 HostPromiseRejectionTracker(promise, operation), https://html.spec.whatwg.org/multipage/webappapis.html#the-hostpromiserejectiontracker-implementation vm->host_promise_rejection_tracker = [](JS::Promise& promise, JS::Promise::RejectionOperation operation) { // 1. Let script be the running script. // The running script is the script in the [[HostDefined]] field in the ScriptOrModule component of the running JavaScript execution context. @@ -132,7 +144,7 @@ JS::VM& main_thread_vm() } }; - // 8.1.5.3.1 HostCallJobCallback(callback, V, argumentsList), https://html.spec.whatwg.org/multipage/webappapis.html#hostcalljobcallback + // 8.1.5.4.1 HostCallJobCallback(callback, V, argumentsList), https://html.spec.whatwg.org/multipage/webappapis.html#hostcalljobcallback vm->host_call_job_callback = [](JS::JobCallback& callback, JS::Value this_value, JS::MarkedVector arguments_list) { auto& callback_host_defined = verify_cast(*callback.custom_data); @@ -162,7 +174,7 @@ JS::VM& main_thread_vm() return result; }; - // 8.1.5.3.2 HostEnqueueFinalizationRegistryCleanupJob(finalizationRegistry), https://html.spec.whatwg.org/multipage/webappapis.html#hostenqueuefinalizationregistrycleanupjob + // 8.1.5.4.2 HostEnqueueFinalizationRegistryCleanupJob(finalizationRegistry), https://html.spec.whatwg.org/multipage/webappapis.html#hostenqueuefinalizationregistrycleanupjob vm->host_enqueue_finalization_registry_cleanup_job = [](JS::FinalizationRegistry& finalization_registry) mutable { // 1. Let global be finalizationRegistry.[[Realm]]'s global object. auto& global = finalization_registry.realm().global_object(); @@ -191,7 +203,7 @@ JS::VM& main_thread_vm() }); }; - // 8.1.5.3.3 HostEnqueuePromiseJob(job, realm), https://html.spec.whatwg.org/multipage/webappapis.html#hostenqueuepromisejob + // 8.1.5.4.3 HostEnqueuePromiseJob(job, realm), https://html.spec.whatwg.org/multipage/webappapis.html#hostenqueuepromisejob vm->host_enqueue_promise_job = [](Function()> job, JS::Realm* realm) { // 1. If realm is not null, then let job settings be the settings object for realm. Otherwise, let job settings be null. HTML::EnvironmentSettingsObject* job_settings { nullptr }; @@ -257,7 +269,7 @@ JS::VM& main_thread_vm() }); }; - // 8.1.5.3.4 HostMakeJobCallback(callable), https://html.spec.whatwg.org/multipage/webappapis.html#hostmakejobcallback + // 8.1.5.4.4 HostMakeJobCallback(callable), https://html.spec.whatwg.org/multipage/webappapis.html#hostmakejobcallback vm->host_make_job_callback = [](JS::FunctionObject& callable) -> JS::JobCallback { // 1. Let incumbent settings be the incumbent settings object. auto& incumbent_settings = HTML::incumbent_settings_object(); @@ -283,12 +295,12 @@ JS::VM& main_thread_vm() return { JS::make_handle(&callable), move(host_defined) }; }; - // FIXME: Implement 8.1.5.4.1 HostGetImportMetaProperties(moduleRecord), https://html.spec.whatwg.org/multipage/webappapis.html#hostgetimportmetaproperties - // FIXME: Implement 8.1.5.4.2 HostImportModuleDynamically(referencingScriptOrModule, moduleRequest, promiseCapability), https://html.spec.whatwg.org/multipage/webappapis.html#hostimportmoduledynamically(referencingscriptormodule,-modulerequest,-promisecapability) - // FIXME: Implement 8.1.5.4.3 HostResolveImportedModule(referencingScriptOrModule, moduleRequest), https://html.spec.whatwg.org/multipage/webappapis.html#hostresolveimportedmodule(referencingscriptormodule,-modulerequest) - // FIXME: Implement 8.1.5.4.4 HostGetSupportedImportAssertions(), https://html.spec.whatwg.org/multipage/webappapis.html#hostgetsupportedimportassertions + // FIXME: Implement 8.1.5.5.1 HostGetImportMetaProperties(moduleRecord), https://html.spec.whatwg.org/multipage/webappapis.html#hostgetimportmetaproperties + // FIXME: Implement 8.1.5.5.2 HostImportModuleDynamically(referencingScriptOrModule, moduleRequest, promiseCapability), https://html.spec.whatwg.org/multipage/webappapis.html#hostimportmoduledynamically(referencingscriptormodule,-modulerequest,-promisecapability) + // FIXME: Implement 8.1.5.5.3 HostResolveImportedModule(referencingScriptOrModule, moduleRequest), https://html.spec.whatwg.org/multipage/webappapis.html#hostresolveimportedmodule(referencingscriptormodule,-modulerequest) + // FIXME: Implement 8.1.5.5.4 HostGetSupportedImportAssertions(), https://html.spec.whatwg.org/multipage/webappapis.html#hostgetsupportedimportassertions - vm->host_resolve_imported_module = [&](JS::ScriptOrModule, JS::ModuleRequest const&) -> JS::ThrowCompletionOr> { + vm->host_resolve_imported_module = [](JS::ScriptOrModule, JS::ModuleRequest const&) -> JS::ThrowCompletionOr> { return vm->throw_completion(JS::ErrorType::NotImplemented, "Modules in the browser"); };