summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp
AgeCommit message (Collapse)Author
2021-10-31LibWeb: Convert throw_dom_exception_if_needed() to ThrowCompletionOrTimothy Flynn
This changes Web::Bindings::throw_dom_exception_if_needed() to return a JS::ThrowCompletionOr instead of an Optional. This allows callers to wrap the invocation with a TRY() macro instead of making a follow-up call to should_return_empty(). Further, this removes all invocations to vm.exception() in the generated bindings.
2021-10-31LibWeb: Convert the Window object to ThrowCompletionOrTimothy Flynn
2021-10-23AK+Everywhere: Make Base64 decoding fallibleBen Wiederhake
2021-10-20LibJS: Rename define_native_function => define_old_native_functionIdan Horowitz
This method will eventually be removed once all native functions are converted to ThrowCompletionOr
2021-10-20LibJS: Add ThrowCompletionOr versions of the JS native function macrosIdan Horowitz
The old versions were renamed to JS_DECLARE_OLD_NATIVE_FUNCTION and JS_DEFINE_OLD_NATIVE_FUNCTION, and will be eventually removed once all native functions were converted to the new format.
2021-10-20LibJS: Replace usages of JS_{DECLARE, DEFINE}_NATIVE_GETTERIdan Horowitz
These macros are equivalent to JS_{DECLARE, DEFINE}_NATIVE_FUNCTION and were only sometimes used, so let's just get rid of them altogether.
2021-10-18LibJS: Convert to_i32() to ThrowCompletionOrIdan Horowitz
2021-10-17LibJS: Convert to_double() to ThrowCompletionOrIdan Horowitz
2021-10-13LibJS: Convert to_object() to ThrowCompletionOrLinus Groh
2021-10-13LibJS: Convert to_string() to ThrowCompletionOrLinus Groh
Also update get_function_name() to use ThrowCompletionOr, but this is not a standard AO and should be refactored out of existence eventually.
2021-10-11LibWeb: Replace heycam.github.io/webidl URLs with webidl.spec.whatwg.orgLinus Groh
Web IDL is now a WHATWG standard and the specification was moved accordingly: https://twitter.com/annevk/status/1445311275026821120 The old URLs now redirect, but let's use canonical ones.
2021-10-11LibWeb: Stub out a basic Selection interfaceAndreas Kling
This patch establishes scaffolding for the Selection API.
2021-10-08LibWeb: Add CSS.escape() JS functionSam Atkins
This is the `CSS` namespace defined in IDL here: https://www.w3.org/TR/cssom-1/#namespacedef-css , not to be confused with our `Web::CSS` namespace. Words are hard. `CSS.escape()` lets you escape identifiers that can then be used to create a CSS string. I've also stubbed out the `CSS.supports()` function.
2021-10-04LibWeb: Make WindowObject::clear_interval() call correct functionAndreas Kling
This was incorrectly calling DOM::Window::clear_timeout(). In practice, these functions are interchangeable, but let's have things looking correct regardless.
2021-10-04LibWeb: Add basic support for script string argument to setInterval()Linus Groh
Instead of passing a function it is also possible to pass a string, which is then evaluated as a classic script.
2021-10-04LibWeb: Add basic support for script string argument to setTimeout()Linus Groh
Instead of passing a function it is also possible to pass a string, which is then evaluated as a classic script. This means we now support the following example from the "timer initialization steps", step 16 - except that it runs the timers in reverse order, so the `log` result is `"TWO ONE "`. https://html.spec.whatwg.org/multipage/timers-and-user-prompts.html#timer-initialisation-steps var log = ''; function logger(s) { log += s + ' '; } setTimeout({ toString: function () { setTimeout("logger('ONE')", 100); return "logger('TWO')"; } }, 100);
2021-10-03LibJS: Convert Object::set() to ThrowCompletionOrLinus Groh
2021-10-03LibJS: Convert Object::get() to ThrowCompletionOrLinus Groh
To no one's surprise, this patch is pretty big - this is possibly the most used AO of all of them. Definitely worth it though.
2021-10-02LibJS+LibWeb: Use Object::set_prototype() in more placesLinus Groh
2021-09-30LibWeb: Add the Web::Crypto namespace, built-in, and getRandomValuesIdan Horowitz
Since we don't support IDL typedefs or unions yet, the responsibility of verifying the type of the argument is temporarily moved from the generated Wrapper to the implementation.
2021-09-29LibJS: Convert internal_set_prototype_of() to ThrowCompletionOrLinus Groh
2021-09-29LibWeb: Support window.screen{X,Y,Left,Top}Andreas Kling
Some sites query these properties for whatever reason, so let's support them. (But let's always pretend the screen coordinates are (0, 0))
2021-09-27LibWeb: Support window.devicePixelRatioAndreas Kling
This always returns 1 for now. I've added a FIXME about returning 2 in HiDPI mode.
2021-09-26LibWeb: Make WindowObject's prototype immutableLuke Wilde
While I was implementing IDL special operations, I noticed that for global platform objects (e.g. WindowObject), the IDL spec makes their prototype immutable. https://heycam.github.io/webidl/#platform-object-setprototypeof
2021-09-26LibWeb: Implement window.queueMicrotask(callback)Andreas Kling
This API allows authors to schedule a serialized JS callback that will get invoked at the next spec-allowed opportunity.
2021-09-25LibWeb: Move window.scroll{X,Y} from wrapper into DOM::WindowAndreas Kling
The less we do in WindowObject, the easier it will be to eventually auto-generate the entire thing.
2021-09-24LibWeb: Return undefined from event handler setters, not an empty valueLinus Groh
2021-09-22LibWeb: Expose the GlobalEventHandlers mixin on the Window objectAndreas Kling
We now expose all the `onfoo` event handler attributes on the window object. This makes `window.onload = ...` actually work. :^)
2021-09-12LibWeb: Implement window.matchMedia()Linus Groh
2021-09-12LibWeb: Expose the location object via Document.locationLuke Wilde
Both Window.location and Document.location use the same instance of the Location object. Some sites use it via Window, some via Document.
2021-09-12LibWeb: Implement window.event as a [Replaceable] propertyLinus Groh
This is the result of debugging React DOM, which would throw a TypeError when assigning to window.event in strict mode and then not complete rendering - here: https://github.com/facebook/react/blob/cae6350/packages/shared/invokeGuardedCallbackImpl.js#L134 With this change, the following minimal React example now works! <div id="app"></div> <script src="react.development.js"></script> <script src="react-dom.development.js"></script> <script> ReactDOM.render( React.createElement("h1", null, "Hello World"), document.getElementById("app") ); </script>
2021-09-12LibWeb: Add the History object and stub pushState and replaceStateLuke Wilde
The spec allows us to optionally return from these for any reason. Our reason is that we don't have all the infrastructure in place yet to implement them.
2021-09-12LibWeb: Use ErrorType::NotAnObjectOfType instead of NotATimothy Flynn
2021-09-11LibWeb: Implement Window.scroll() and Window.scrollBy() JS methodsSam Atkins
... and `Window.scrollTo()`, which is an alias for `scroll()`. There is still work that needs to be done here, regarding bringing the scroll position calculation in line with the spec. Currently we get the viewport rect from outside, and treat it as if it was the result of calculating steps 5-9 of the `scroll()` method. But it works. :^)
2021-09-11LibWeb: Implement Window.scroll{X,Y} JS propertiesSam Atkins
...and pageXOffset/pageYOffset too, since those are just aliases for the same thing.
2021-09-11LibWeb: Stub out a dummy window.getComputedStyle()Andreas Kling
This just returns an empty CSSStyleDeclaration for now. The real thing needs to be a live object that provides a view onto the computed style of a given element. This is far from that, but it's something. :^)
2021-09-09LibWeb: Rename DOM::Window::document() => associated_document()Andreas Kling
Match the spec nomenclature.
2021-09-09LibWeb: Rename BrowsingContext::document() => active_document()Andreas Kling
This better matches the spec nomenclature. Note that we don't yet *retrieve* the active document according to spec.
2021-07-26LibWeb: Fix that non-member calls to window gave the wrong this_valuedavidot
We treat all NativeFunctions as strict mode and thus window function which were called in a global context (i.e. `setTimeout(f, 0)`) got a null this_value. But we really need to treat all functions not defined by the ECMAScript specification as non-strict. In most cases this won't matter however since Window is also the global_object we have an extra bit of logic. To fix this more correctly we would need to track the strictness of NativeFunctions.
2021-07-06LibJS: Remove the default length & attributes from define_native_*Idan Horowitz
These are usually incorrect, and people sometimes forget to add the correct values as a result of them being optional, so they should just be specified explicitly.
2021-07-06LibJS: Add define_direct_property and remove the define_property helperIdan Horowitz
This removes all usages of the non-standard define_property helper method and replaces all it's usages with the specification required alternative or with define_direct_property where appropriate.
2021-07-05LibWeb: Replace usage of native properties with accessors in WindowIdan Horowitz
This is required by the WebIDL specification.
2021-07-04LibJS: Rewrite most of Object for spec compliance :^)Linus Groh
This is a huge patch, I know. In hindsight this perhaps could've been done slightly more incremental, but I started and then fixed everything until it worked, and here we are. I tried splitting of some completely unrelated changes into separate commits, however. Anyway. This is a rewrite of most of Object, and by extension large parts of Array, Proxy, Reflect, String, TypedArray, and some other things. What we already had worked fine for about 90% of things, but getting the last 10% right proved to be increasingly difficult with the current code that sort of grew organically and is only very loosely based on the spec - this became especially obvious when we started fixing a large number of test262 failures. Key changes include: - 1:1 matching function names and parameters of all object-related functions, to avoid ambiguity. Previously we had things like put(), which the spec doesn't have - as a result it wasn't always clear which need to be used. - Better separation between object abstract operations and internal methods - the former are always the same, the latter can be overridden (and are therefore virtual). The internal methods (i.e. [[Foo]] in the spec) are now prefixed with 'internal_' for clarity - again, it was previously not always clear which AO a certain method represents, get() could've been both Get and [[Get]] (I don't know which one it was closer to right now). Note that some of the old names have been kept until all code relying on them is updated, but they are now simple wrappers around the closest matching standard abstract operation. - Simplifications of the storage layer: functions that write values to storage are now prefixed with 'storage_' to make their purpose clear, and as they are not part of the spec they should not contain any steps specified by it. Much functionality is now covered by the layers above it and was removed (e.g. handling of accessors, attribute checks). - PropertyAttributes has been greatly simplified, and is being replaced by PropertyDescriptor - a concept similar to the current implementation, but more aligned with the actual spec. See the commit message of the previous commit where it was introduced for details. - As a bonus, and since I had to look at the spec a whole lot anyway, I introduced more inline comments with the exact steps from the spec - this makes it super easy to verify correctness. - East-const all the things. As a result of all of this, things are much more correct but a bit slower now. Retaining speed wasn't a consideration at all, I have done no profiling of the new code - there might be low hanging fruits, which we can then harvest separately. Special thanks to Idan for helping me with this by tracking down bugs, updating everything outside of LibJS to work with these changes (LibWeb, Spreadsheet, HackStudio), as well as providing countless patches to fix regressions I introduced - there still are very few (we got it down to 5), but we also get many new passing test262 tests in return. :^) Co-authored-by: Idan Horowitz <idan.horowitz@gmail.com>
2021-06-27LibJS: Rename Function => FunctionObjectAndreas Kling
2021-06-09LibJS: Add the Set built-in objectIdan Horowitz
2021-05-31LibWeb: Return null in Window.{top,parent} if browsing context is nullLuke
We were asserting that it exists, but the spec says to return null in this case. Top: https://html.spec.whatwg.org/multipage/browsers.html#dom-top Parent: https://html.spec.whatwg.org/multipage/browsers.html#dom-parent
2021-05-30LibWeb: Rename Web::Frame to Web::BrowsingContextAndreas Kling
Our "frame" concept very closely matches what the web specs call a "browsing context", so let's rename it to that. :^) The "main frame" becomes the "top-level browsing context", and "sub-frames" are now "nested browsing contexts".
2021-05-26LibWeb: Implement a very basic WebAssembly JS APIAli Mohammad Pur
This impl is *extremely* simple, and is missing a lot of things, it's also not particularly spec-compliant in some places, but it's definitely a start :^)
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-12LibWeb: Add Window.parent and fix Window.top attributesLuke
This returns the parent frame of the current frame. If it's the main frame, it returns itself. Also fixes the attributes of Window.top, as they were accidentally being passed in as the setter. Required by Web Platform Tests.