Commit Graph

115 Commits

Author SHA1 Message Date
davidot
6255ca4a42 LibJS: Add DisposableStack{, Prototype, Constructor}
Since the async parts of the spec are not stage 3 at this point we don't
add AsyncDisposableStack.
2023-01-23 09:56:50 +00:00
davidot
2c87ff2218 LibJS: Add Symbol.dispose 2023-01-23 09:56:50 +00:00
davidot
3353cf68f1 LibJS: Add SuppressedError{, Prototype, Constructor} 2023-01-23 09:56:50 +00:00
Timothy Flynn
3de75f6436 LibJS: Explicitly disallow references in ThrowCompletionOr
This will be disallowed by TRY soon, but the compile error produced by
this requirement will pinpoint the errant line more accurately.
2023-01-13 18:50:47 -05:00
Andreas Kling
3503c658fb LibJS+LibWeb: Move JS::ModuleRequest to its own header file
This allows us to not include LibJS/AST.h in a couple more places.
2022-11-23 16:05:59 +00:00
Andreas Kling
b81816a539 LibJS+LibWeb: Make CyclicModule.h not include AST.h
This led to some fallout as many things in LibJS and LibWeb were pulling
in other things via CyclicModule.h
2022-11-23 16:05:59 +00:00
Andreas Kling
835d7aac96 LibJS: Make FunctionNode::Parameter be a standalone FunctionParameter
This will allow us to forward declare it and avoid including AST.h in a
number of places.
2022-11-23 16:05:59 +00:00
Andreas Kling
65e7c58990 LibJS: Make Script.h not include AST.h 2022-11-23 16:05:59 +00:00
Andreas Kling
e6331031c4 LibJS: Make Parser::Error a standalone ParserError class
This allows us to forward declare it and reduce the number of things
that need to include Parser.h.
2022-11-23 16:05:59 +00:00
Andreas Kling
e0916dbb35 LibJS: Move {Import,Export}Entry out of {Import,Export}Statement
By making these be standalone instead of nested structs, we can forward
declare them. This will allow us to stop including AST.h in some places.
2022-11-23 16:05:59 +00:00
Andreas Kling
1a30e77001 LibJS: Make Interpreter.h not include AST.h 2022-11-23 16:05:59 +00:00
Andreas Kling
9ff02ad42c LibJS: Make AsyncGenerator not include AsyncGeneratorRequest.h 2022-11-23 16:05:59 +00:00
Andreas Kling
b0b022507b LibJS: Reduce AST memory usage by shrink-wrapping source range info
Before this change, each AST node had a 64-byte SourceRange member.
This SourceRange had the following layout:

    filename:       StringView (16 bytes)
    start:          Position (24 bytes)
    end:            Position (24 bytes)

The Position structs have { line, column, offset }, all members size_t.

To reduce memory consumption, AST nodes now only store the following:

    source_code:    NonnullRefPtr<SourceCode> (8 bytes)
    start_offset:   u32 (4 bytes)
    end_offset:     u32 (4 bytes)

SourceCode is a new ref-counted data structure that keeps the filename
and original parsed source code in a single location, and all AST nodes
have a pointer to it.

The start_offset and end_offset can be turned into (line, column) when
necessary by calling SourceCode::range_from_offsets(). This will walk
the source code string and compute line/column numbers on the fly, so
it's not necessarily fast, but it should be rare since this information
is primarily used for diagnostics and exception stack traces.

With this, ASTNode shrinks from 80 bytes to 32 bytes. This gives us a
~23% reduction in memory usage when loading twitter.com/awesomekling
(330 MiB before, 253 MiB after!) :^)
2022-11-22 21:13:35 +01:00
Linus Groh
fc9d587e39 LibJS: Make PromiseCapability GC-allocated
A struct with three raw pointers to other GC'd types is a pretty big
liability, let's just turn this into a Cell itself.
This comes with the additional benefit of being able to capture it in
a lambda effortlessly, without having to create handles for individual
members.
2022-10-02 23:02:27 +01:00
Linus Groh
ed2aa6459d LibJS: Remove two outdated forward declarations 2022-10-02 23:02:27 +01:00
Linus Groh
78eca3ae64 LibJS: Move ConsoleObject construction from GlobalObject to Intrinsics
This will allow us to move the underlying console from GlobalObject to
ConsoleObject without still having to do a 'console' property lookup on
the GlobalObject.
2022-08-28 16:36:56 +01:00
Linus Groh
50428ea8d2 LibJS: Move intrinsics to the realm
Intrinsics, i.e. mostly constructor and prototype objects, but also
things like empty and new object shape now live on a new heap-allocated
JS::Intrinsics object, thus completing the long journey of taking all
the magic away from the global object.
This represents the Realm's [[Intrinsics]] slot in the spec and matches
its existing [[GlobalObject]] / [[GlobalEnv]] slots in terms of
architecture.

In the majority of cases it should now be possibly to fully allocate a
regular object without the global object existing, and in fact that's
what we do now - the realm is allocated before the global object, and
the intrinsics between both :^)
2022-08-27 11:29:10 +01:00
Linus Groh
adc5ac35b7 LibJS: Remove InvalidCharacterError
This a Web API and not part of ECMA-262. Never has been.
2022-08-26 22:26:03 +01:00
Linus Groh
b465f46e00 LibJS: Remove GlobalObject parameter from native functions 2022-08-23 13:58:30 +01:00
Ali Mohammad Pur
f4b26b0cea LibJS: Hook up the 'v' (unicodeSets) RegExp flag 2022-07-20 21:25:59 +01:00
Timothy Flynn
0026e9a4c8 LibJS: Implement a basic Intl mathematical value
The Intl mathematical value is much like ECMA-262's mathematical value
in that it is meant to represent an arbitrarily precise number. The Intl
MV further allows positive/negative infinity, negative zero, and NaN.

This implementation is *not* arbitrarily precise. Rather, it is a
replacement for the use of Value within Intl.NumberFormat. The exact
syntax of the Intl MV is still being worked on, but abstracting this
away into its own class will allow hooking in the finalized Intl MV
more easily, and makes implementing Intl.NumberFormat.formatRange
easier.

Note the methods added here are essentially the same as the static
helpers in Intl/NumberFormat.cpp.
2022-07-20 18:21:24 +01:00
Idan Horowitz
97fe37bcc2 LibJS: Start implementing the stage 3 Intl.DurationFormat proposal 2022-07-01 01:00:05 +03:00
Linus Groh
0c65624a32 LibJS: Add AsyncGenerator / AsyncGeneratorPrototype
Not implementing any prototype functions yet, but stubbing out async
generator infrastructure will allow us to make some progress in that
direction.
2022-05-05 22:40:57 +02:00
Linus Groh
e815d3f9ce LibJS: De-duplicate ClassFieldDefinition Records
This was defined twice, despite being the very same thing:
- ClassElement::ClassFieldDefinition
- ECMAScriptFunctionObject::InstanceField

Move the former to a new header and use it everywhere. Also update the
define_field() AO to take a single field instead of separate name and
initializer arguments.
2022-04-20 00:08:32 +02:00
Linus Groh
bdb13a74b0 LibJS: Describe various kinds of "Duration Records"
This is an editorial change in the Temporal spec.

See: https://github.com/tc39/proposal-temporal/commit/983902e

We already had these defined as structs, but now they're properly
defined in the spec (opposed to the previous anonymous records), and we
don't have to make up our own names anymore :^)

Note that while we're usually not including 'record' in the name, in
this case the 'Duration Record' has a name clash with the Duration
object. Additionally, later editorial changes introduce CreateFooRecord
AOs, so let's just go with FooRecord structs here.
2022-03-10 23:20:39 +01:00
Linus Groh
7676b1b925 LibJS: Remove MarkedValueList in favor of MarkedVector<Value> :^) 2022-02-09 12:25:27 +00:00
Linus Groh
a863363b06 LibJS: Let MarkedVector<T> inherit from Vector and handle Cell* + Value
Note: MarkedVector is still relatively new and has zero users right now,
so these changes don't affect any code other than the class itself.

Reasons for this are the rather limited API:

- Despite the name and unlike MarkedValueList, MarkedVector isn't
  actually a Vector, it *wraps* a Vector. This means that plenty of
  convenient APIs are unavailable and have to be exported on the class
  separately and forwarded to the internal Vector, or need to go through
  the exposed Span - both not great options.
- Exposing append(Cell*) and prepend(Cell*) on the base class means that
  it was possible to append any Cell type, not just T! All the strong
  typing guarantees are basically gone, and MarkedVector doesn't do much
  more than casting Cells to the appropriate type through the exposed
  Span.

All of this combined means that MarkedVector - in its current form -
doesn't provide much value over MarkedValueList, and that we have to
maintain two separate, yet almost identical classes.

Let's fix this!

The updated MarkedVector steals various concepts from the existing
MarkedValueList, especially the ability to copy. On the other hand, it
remains generic enough to handle both Cell* and Value for T, making
MarkedValueList effectively redundant :^)

Additionally, by inheriting from Vector we get all the current and
future APIs without having to select and expose them separately.

MarkedVectorBase remains and takes care of communicating creation and
destruction of the class to the heap. Visiting the contained values is
handled via a pure virtual method gather_roots(), which is being called
by the Heap's function of the same name; much like the VM has one.
From there, values are added to the roots HashTable if they are cells
for T = Value, and unconditionally for any other T.

As a small additional improvement the template now also takes an
inline_capacity parameter, defaulting to 32, and forwards it to the
Vector template; allowing for possible future optimizations of current
uses of MarkedValueList, which hard-codes it to 32.
2022-02-09 12:25:27 +00:00
Luke Wilde
f71f404e0c LibWeb: Introduce the Environment Settings Object
The environment settings object is effectively the context a piece of
script is running under, for example, it contains the origin,
responsible document, realm, global object and event loop for the
current context. This effectively replaces ScriptExecutionContext, but
it cannot be removed in this commit as EventTarget still depends on it.

https://html.spec.whatwg.org/multipage/webappapis.html#environment-settings-object
2022-02-08 17:47:44 +00:00
davidot
9264f9d24e LibJS+Everywhere: Remove VM::exception() and most related functions
This commit removes all exception related code:
Remove VM::exception(), VM::throw_exception() etc. Any leftover
throw_exception calls are moved to throw_completion.
The one method left is clear_exception() which is now a no-op. Most of
these calls are just to clear whatever exception might have been thrown
when handling a Completion. So to have a cleaner commit this will be
removed in a next commit.

It also removes the actual Exception and TemporaryClearException classes
since these are no longer used.

In any spot where the exception was actually used an attempt was made to
preserve that behavior. However since it is no longer tracked by the VM
we cannot access exceptions which were thrown in previous calls.
There are two such cases which might have different behavior:
- In Web::DOM::Document::interpreter() the on_call_stack_emptied hook
  used to print any uncaught exception but this is now no longer
  possible as the VM does not store uncaught exceptions.
- In js the code used to be interruptable by throwing an exception on
  the VM. This is no longer possible but was already somewhat fragile
  before as you could happen to throw an exception just before a VERIFY.
2022-02-08 09:12:42 +00:00
Idan Horowitz
6c26a02aa8 LibJS: Start implementing Intl Segment Iterator objects 2022-01-30 19:47:01 +00:00
Idan Horowitz
bbacea255f LibJS: Start implementing Intl Segments objects 2022-01-30 19:47:01 +00:00
Idan Horowitz
a3bc06bb23 LibJS: Start implementing Intl.Segmenter 2022-01-30 19:47:01 +00:00
Timothy Flynn
4a3e142d55 LibJS: Implement a nearly empty Intl.Collator object
This adds plumbing for the Intl.Collator object, constructor, and
prototype.
2022-01-29 20:27:24 +00:00
Timothy Flynn
0087804d10 LibJS: Implement a nearly empty Intl.PluralRules object
This adds plumbing for the Intl.PluralRules object, constructor, and
prototype.
2022-01-28 19:38:47 +00:00
Timothy Flynn
79fdec85de LibJS: Implement a nearly empty Intl.RelativeTimeFormat object
This adds plumbing for the Intl.RelativeTimeFormat object, constructor,
and prototype.
2022-01-25 19:02:59 +00:00
davidot
be9d478d92 LibJS: Add host layering point related to modules to VM
Also make HostResolveImportedModule fail on the browser to prevent
module loading for now.
2022-01-22 01:21:18 +00:00
davidot
57c5a59cab LibJS: Add ScriptOrModule to execution context and track it everywhere 2022-01-22 01:21:18 +00:00
Linus Groh
4ed49e05a9 LibJS: Rename GeneratorObjectPrototype to GeneratorPrototype
Given we usually call objects Foo{Object,Constructor,Prototype} or
Foo{,Constructor,Prototype}, this name was an odd choice.
The new one matches the spec better, which calls it the "Generator
Prototype Object", so we simply omit the Object suffix as usual as it's
implied.
2022-01-16 14:50:22 +01:00
Andreas Kling
8bb9fe63b7 LibJS: Add MarkedVector<T>
This abstracts a vector of Cell* with a strongly typed span() accessor
that gives you Span<T*> instead of Span<Cell*>.

It is intended to replace MarkedValueList in situations where you only
need to store pointers to Cell (or an even more specific type of Cell).

The API can definitely be improved, it's just the bare basics for now.
2021-12-16 22:48:17 +01:00
Timothy Flynn
75b2a09a2f LibJS: Implement a nearly empty Intl.DateTimeFormat object
This adds plumbing for the Intl.DateTimeFormat object, constructor, and
prototype.

Note that unlike other Intl objects, the Intl.DateTimeFormat object has
a LibUnicode structure as a base. This is to prevent wild amounts of
code duplication between LibUnicode, Intl.DateTimeFormat, and other
not-yet-defined Intl structures, because there's 12 fields shared
between them.
2021-11-29 22:48:46 +00:00
davidot
064c8be627 LibJS: Add AsyncFromSyncIteratorPrototype and Async-From-Sync instances
Until we have actual iterator records we have to store the sync iterator
as the raw object.
2021-11-29 15:20:07 +00:00
davidot
7fd38eac98 LibJS: Add AsyncIteratorPrototype 2021-11-29 15:20:07 +00:00
davidot
0982a73d1d LibJS: Parse async generator functions 2021-11-21 21:46:39 +00:00
Idan Horowitz
681787de76 LibJS: Add support for async functions
This commit adds support for the most bare bones version of async
functions, support for async generator functions, async arrow functions
and await expressions are TODO.
2021-11-10 08:48:27 +00:00
Idan Horowitz
2eaed880b1 LibJS: Remove old Native Functions
Now that all the usages were updated to the new ThrowCompletionOr based
version we can remove the legacy version.
2021-10-31 18:20:37 +02:00
Andreas Kling
398c181c79 LibJS: Rename PropertyName to PropertyKey
Let's use the same name as the spec. :^)
2021-10-24 17:18:07 +02:00
Idan Horowitz
20163c0584 LibJS: Add ThrowCompletionOr versions of the JS native function macros
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-20 12:27:19 +01:00
Idan Horowitz
3355b52cca LibJS: Remove unused JS_{DECLARE,DEFINE}_NATIVE_{GETTER,SETTER} macros 2021-10-20 12:27:19 +01:00
Linus Groh
d40331ef69 LibJS: Start implementing ShadowRealm
This commit adds the ShadowRealm object itself, its constructor, and
prototype (currently empty).
2021-10-14 00:41:41 +01:00
Linus Groh
50f8755792 LibJS: Implement Wrapped Function Exotic Objects
This is a new concept from the ShadowRealm API stage 3 proposal:
https://tc39.es/proposal-shadowrealm/#sec-wrapped-function-exotic-objects
2021-10-14 00:41:41 +01:00