summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Bindings/MainThreadVM.cpp
AgeCommit message (Collapse)Author
2023-01-29LibJS+Everywhere: Propagate Cell::initialize errors from Heap::allocateTimothy Flynn
Callers that are already in a fallible context will now TRY to allocate cells. Callers in infallible contexts get a FIXME.
2023-01-18LibWeb: Convert the Location object to IDLLinus Groh
This includes: - Moving it from Bindings/ to HTML/ - Renaming it from LocationObject to Location - Removing the manual definitions of the constructor and prototype - Removing special handling of the Location interface from the bindings generator - Converting the JS_DEFINE_NATIVE_FUNCTIONs to regular functions returning DeprecatedString instead of PrimitiveString - Adding missing (no-op) setters for the various attributes, which are expected to exist by the bindings generator
2023-01-10LibWeb: Generate exposed Window/Worker interfaces as lazy objectsTimothy Flynn
We now lazily create these instances on-demand rather than all at once when a Window/Worker object is created.
2022-12-15LibJS: Convert Heap::allocate{,_without_realm}() to NonnullGCPtrLinus Groh
2022-12-14LibJS: Convert Object::create() to NonnullGCPtrLinus Groh
2022-12-14LibJS: Convert Array::create{,_from}() to NonnullGCPtrLinus Groh
2022-12-06AK+Everywhere: Rename String to DeprecatedStringLinus Groh
We have a new, improved string type coming up in AK (OOM aware, no null state), and while it's going to use UTF-8, the name UTF8String is a mouthful - so let's free up the String name by renaming the existing class. Making the old one have an annoying name will hopefully also help with quick adoption :^)
2022-11-23LibJS+LibWeb: Move JS::ModuleRequest to its own header fileAndreas Kling
This allows us to not include LibJS/AST.h in a couple more places.
2022-11-23LibJS+LibWeb: Make Runtime/AbstractOperations.h not include AST.hAndreas Kling
This led to considerable fallout and many files had to be patched with now-missing include statements.
2022-11-19Everywhere: Remove unnecessary mutable attributes from lambdasMacDue
These lambdas were marked mutable as they captured a Ptr wrapper class by value, which then only returned const-qualified references to the value they point from the previous const pointer operators. Nothing is actually mutating in the lambdas state here, and now that the Ptr operators don't add extra const qualifiers these can be removed.
2022-10-25LibWeb: Remove old assertion in host_enqueue_promise_job context hackLuke Wilde
We no longer need to pull a global object from somewhere to push an execution context onto the stack, so the assertion no longer makes sense.
2022-10-24LibWeb: Implement recent changes to module script fetchingnetworkException
This patch implements all changes to the specification touching the subset of module script fetching we support. Notably it adds parts of the specification for supporting import maps. With this we are also able to get rid of a non standard workaround for a spec issue we discovered while initially implementing module scripts :^)
2022-10-24LibWeb: Teach MainThreadVM about module scriptsLinus Groh
2022-10-20LibWeb: Hang on to the internal realm with a JS::HandleAndreas Kling
This fixes an issue where GC would kill the internal realm if it ran at the wrong time during startup. Found by aggressively GC'ing between every allocation.
2022-10-20LibWeb: Prevent GC from running during intrinsics allocationAndreas Kling
Due to the way we lazily construct prototypes and constructors for web platform interfaces, it's possible for nested GC allocation to occur while GC objects have been allocated but not fully constructed. If the garbage collector ends up running in this state, it may attempt to call JS::Cell::visit_edges() on an object whose vtable pointer hasn't been set up yet. This patch works around the issue by deferring GC while intrinsics are being brought up. Furthermore, we also create a dummy global object for the internal realm, and populate it with intrinsics. This works around the same issue happening when allocating something (like the default UA stylesheets) in the internal realm. These solutions are pretty hacky and sad, so I've left FIXMEs about finding a nicer way.
2022-10-20LibWeb: Don't store JS::Handle<JS::Promise> in EnvironmentSettingsObjectAndreas Kling
Now that the ESO is a JS::Cell, we can just store them as NonnullGCPtr and mark them in visit_edges().
2022-10-15WebContent+LibWeb+LibJS: Report exceptions to the JS consolePavel
Print exceptions passed to `HTML::report_exception` in the JS console Refactored `ExceptionReporter`: in order to report exception now you need to pass the relevant realm in it. For passed `JS::Value` we now create `JS::Error` object to print value as the error message.
2022-10-06LibWeb: Implement two module related host hooksnetworkException
This patch adds support for the HostGetSupportedImportAssertions and HostResolveImportedModule host hooks. Co-authored-by: davidot <davidot@serenityos.org>
2022-10-05LibWeb: Prepare to run callback in host_enqueue_promise_job()Linus Groh
...and clean up afterwards, of course. Additionally to preparing to run a script, we also prepare to run a callback here. This matches WebIDL's invoke_callback() / call_user_object_operation() functions, and prevents a crash in host_make_job_callback() when getting the incumbent settings object. Running the following JS no longer crashes after this change: ```js new Promise((resolve) => { setTimeout(resolve, 0); }).then(() => { return Promise.reject(); }); ``` See further discussion/investigation here: https://discord.com/channels/830522505605283862/830525031720943627/995019647214694511 https://discord.com/channels/830522505605283862/830525031720943627/1026824624358576158 https://discord.com/channels/830522505605283862/830525031720943627/1026922985581457458 Many thanks to Luke for doing the hard work here, tracking this down, and suggesting the fix! Co-authored-by: Luke Wilde <lukew@serenityos.org>
2022-10-01LibWeb: Remove the internal window object from WebEngineCustomDataAndrew Kaster
Now that no one needs a Window just to create prototypes, we can remove the internal window Object from the main thread VM and get rid of the HTML::Window include for it. This finally solves the reference binding to nullptr error in ladybird that shows up when compiling it with ASAN.
2022-10-01LibWeb: Remove unecessary dependence on Window from HTML classesAndrew Kaster
These classes only needed Window to get at its realm. Pass a realm directly to construct HTML classes.
2022-10-01LibWeb: Move Web prototypes and constructors to new Intrinsics objectAndrew Kaster
This Intrinsics object hangs off of a new HostDefined struct that takes the place of EnvironmentSettingsObject as the true [[HostDefined]] slot on JS::Realm objects created by LibWeb. This gets the intrinsics off of the GlobalObject, Window, similar to the previous refactor of LibJS to move the intrinsics into the Realm's [[Intrinics]] internal slot. A side effect of this change is that we cannot fully initialize a Window object until the [[HostDefined]] slot has been installed into the realm, which happens with the creation of the WindowEnvironmentSettingsObject. As such, any Window usage that has not been funned through a WindowESO will not have any cached Web prototyped or constructors, and will not have Window APIs available to javascript code. Currently this seems limited to usage of Window in the CSS parser, but a subsequent commit will clean those up to take Realm as well. However, this commit compiles so let's cut it off here :^).
2022-09-24LibWeb: Move WindowProxy from Bindings/ to HTML/Linus Groh
2022-09-24LibWeb: Move IDLAbstractOperations from Bindings/ to WebIDL/Linus Groh
2022-09-24LibWeb: Remove unused capture in queue_a_microtask()Andreas Kling
2022-09-24LibWeb: Remove now-unnecessary JS::Handles in microtask capture listsAndreas Kling
2022-09-24LibWeb: Remove now-unnecessary JS::Handles in HTML task capture listsAndreas Kling
JS::SafeFunction will protect anything captures for HTML tasks now.
2022-09-08LibJS+LibWeb: Spin event loop via VM::CustomData abstractionAndreas Kling
Instead of calling Core::EventLoop directly, LibJS now has a virtual function on VM::CustomData for customizing this behavior. We use this in LibWeb to plumb the spin request through to the PlatformEventPlugin.
2022-09-06LibJS: Make Script and Module GC-allocatedAndreas Kling
This ensures that code currently in any active or saved execution stack always stays alive.
2022-09-06LibWeb: Make MutationObserver GC-allocatedAndreas Kling
2022-09-06LibWeb: Make MutationRecord GC-allocatedAndreas Kling
2022-09-06LibWeb+LibJS: Make the EventTarget hierarchy (incl. DOM) GC-allocatedAndreas Kling
This is a monster patch that turns all EventTargets into GC-allocated PlatformObjects. Their C++ wrapper classes are removed, and the LibJS garbage collector is now responsible for their lifetimes. There's a fair amount of hacks and band-aids in this patch, and we'll have a lot of cleanup to do after this.
2022-09-06LibWeb: Make DOM::Event and all its subclasses GC-allocatedAndreas Kling
2022-09-06LibWeb: Add an "internal" JS realm & window objectAndreas Kling
These will be used to host JS objects that don't belong in one of the web-facing global objects.
2022-08-27LibWeb: Implement the HostEnsureCanAddPrivateElement JS hookdavidot
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.
2022-08-26LibWeb: Intentionally leak the main thread JS VMAndreas Kling
This way we avoid doing an expensive full GC on exit.
2022-08-23LibWeb: Replace GlobalObject with Realm in wrapper functionsLinus Groh
Similar to create() in LibJS, wrap() et al. are on a low enough level to warrant passing a Realm directly instead of relying on the current realm from the VM, as a wrapper may need to be allocated while no JS is being executed.
2022-08-23LibJS: Replace GlobalObject with VM in common AOs [Part 18/19]Linus Groh
2022-08-23LibJS: Replace GlobalObject with VM in Promise AOs [Part 8/19]Linus Groh
2022-08-23LibJS: Remove GlobalObject from VM::throw_completion()Linus Groh
This is a continuation of the previous five commits. A first big step into the direction of no longer having to pass a realm (or currently, a global object) trough layers upon layers of AOs! Unlike the create() APIs we can safely assume that this is only ever called when a running execution context and therefore current realm exists. If not, you can always manually allocate the Error and put it in a Completion :^) In the spec, throw exceptions implicitly use the current realm's intrinsics as well: https://tc39.es/ecma262/#sec-throw-an-exception
2022-08-23LibJS+LibWeb: Replace GlobalObject with Realm in create() functionsLinus Groh
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.
2022-08-06LibJS+LibWeb: Restore type safety of Realm::set_global_object()Linus Groh
The changes from 8a03b17 to allow any JS::Value aren't a good fit, as shown by the excessive amount of verify_cast needed :^)
2022-08-05LibWeb: Start implementing "create and initialize a Document" from HTMLAndreas Kling
The way we've been creating DOM::Document has been pretty far from what the spec tells us to do, and this is a first big step towards getting us closer to spec. The new Document::create_and_initialize() is called by FrameLoader after loading a "text/html" resource. We create the JS Realm and the Window object when creating the Document (previously, we'd do it on first access to Document::interpreter().) The realm execution context is owned by the Environment Settings Object.
2022-08-05LibWeb: Always put a dummy execution context on the main thread VM stackAndreas Kling
A lot of code assumes that there's a current execution context. By setting up a dummy context right after creating the main thread VM, we ensure that such code can always run.
2022-07-11LibWeb: Introduce Mutation{Record,Observer} and observer microtasksLuke Wilde
2022-06-29LibWeb: Use CSO if running script is null in HostPromiseRejectionTrackerLuke Wilde
2022-03-18LibJS: Add infallible variant of VM::push_execution_context()Linus Groh
It makes no sense to require passing a global object and doing a stack space check in some cases where running out of stack is highly unlikely, we can't recover from errors, and currently ignore the result anyway. This is most commonly in constructors and when setting things up, rather than regular function calls.
2022-03-08LibWeb: Move Window from DOM directory & namespace to HTMLLinus Groh
The Window object is part of the HTML spec. :^) https://html.spec.whatwg.org/multipage/window-object.html
2022-02-09LibJS: Replace uses of MarkedValueList with MarkedVector<Value>Linus Groh
This is effectively a drop-in replacement.
2022-02-08LibWeb: Implement the JS host hooks for promises, job callbacks and moreLuke Wilde
This overrides the JS host hooks to follow the spec for queuing promises, making/calling job callbacks, unhandled promise rejection handling and FinalizationRegistry queuing. This also allows us to drop the on_call_stack_emptied hook in Document::interpreter().