1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 06:44:57 +00:00
Commit graph

1589 commits

Author SHA1 Message Date
Brian Gianforcaro
12024aeda9 LibJS: Use ElapsedTimer::start_new(); 2021-09-12 17:24:44 +00:00
Linus Groh
c5bd382524 LibJS: Leave NativeFunction's Realm unset if VM has no Interpreter
There's currently a fallback at the call site where the Realm is needed
(due to a slightly incorrect implementation of [[Call]] / [[Construct]])
so this is better than crashing (in LibWeb, currently).
2021-09-12 15:18:25 +02:00
Linus Groh
7b92889e6b LibJS: Change Interpreter::create_with_existing_{global_object => realm}
We need both a GlobalObject and Realm now, but can get the former from
the latter (once initialized).
This also fixes JS execution in LibWeb, as we failed to set the Realm of
the newly created Interpreter in this function.
2021-09-12 15:18:25 +02:00
Linus Groh
106f295916 LibJS+LibWeb: Make JS::Script and Web::HTML::ClassicScript use Realms
The spec wants Script Records to have a Realm, not a GlobalObject.
2021-09-12 15:18:25 +02:00
Timothy Flynn
673fc02ac5 LibJS: Move locale_relevant_extension_keys to Intl.Locale 2021-09-12 12:57:17 +01:00
Timothy Flynn
7769cd2cab LibJS: Move number_format_relevant_extension_keys to Intl.NumberFormat
This method represents the Intl.NumberFormat's [[RelevantExtensionKeys]]
internal slot, so it makes more sense for this to be directly in the
class itself.
2021-09-12 12:57:17 +01:00
Timothy Flynn
94a5a0437c LibJS: Move Intl.NumberFormat's AOs to its object file 2021-09-12 12:57:17 +01:00
Timothy Flynn
0b08201fec LibJS: Move Intl.ListFormat's AOs to its object file
To be consistent with the style in Temporal, let's move all AOs in Intl
to their object file, rather than splitting the AOs between prototype
and constructor files.
2021-09-12 12:57:17 +01:00
Timothy Flynn
ae7b5280c2 LibJS: Make "options" objects const references in NumberFormat's AOs 2021-09-12 12:57:17 +01:00
Timothy Flynn
7f700bd84e LibJS: Make GetNumberOption's "options" object a const reference 2021-09-12 12:57:17 +01:00
Timothy Flynn
aa2af06c84 LibJS: Store Intl.Locale's "tag" argument as a plain string 2021-09-12 12:57:17 +01:00
Timothy Flynn
4411e16798 LibJS: Change GetOption AO to accept the options as a concrete Object
This was being verified at runtime anyways, so let the compiler ensure
it. This also matches the GetOption AO in Temporal now.
2021-09-12 12:57:17 +01:00
Timothy Flynn
ada56981dc LibJS: Sort Intl AbstractOperation declarations by spec ID
The definitions in the .cpp file are already sorted this way.
2021-09-12 12:57:17 +01:00
Timothy Flynn
094c390fb1 LibJS: Move CanonicalCodeForDisplayNames to Intl.DisplayNames
Intl.DisplayNames was the first Intl object implemented, and at that
point all AOs were just put into the main Intl AO header. But AOs that
belong to specific objects belong in that object's header. So this moves
CanonicalCodeForDisplayNames to the Intl.DisplayNames header.
2021-09-12 12:57:17 +01:00
Linus Groh
80e58dab9a LibJS: Make get_function_realm() actually return a Realm 2021-09-12 11:10:20 +01:00
Linus Groh
06e89311fa LibJS: Set the callee context's realm in prepare_for_ordinary_call()
This includes making FunctionObject::realm() actually return a Realm,
instead of a GlobalObject.
2021-09-12 11:10:20 +01:00
Linus Groh
332946ab4f LibJS: Prepare ExecutionContext to store the current Realm Record
Also add VM::current_realm() to retrieve it, similar to all the other
getters (running_execution_context() et al.).
2021-09-12 11:10:20 +01:00
Linus Groh
15c33477e4 LibJS: Make prepare_for_ordinary_call() new_target parameter an Object*
This got changed in the spec at some point, replacing the assertion in
step 1 with "... and newTarget (an Object or undefined)" in the
parameter description.
Subsequently, there's now one step less, so the numbers all change.
2021-09-12 11:10:20 +01:00
Linus Groh
f29a82dd84 LibJS: Move the GlobalEnvironment from GlobalObject to Realm
This is where the spec wants to have it. Requires a couple of hacks as
currently everything that needs a Realm actually has a GlobalObject, so
we need to go via the Interpreter.
2021-09-12 11:10:20 +01:00
Linus Groh
1e79934acf LibJS: Add [[GlobalThisValue]] internal slot to GlobalEnvironment
Instead of hardcoding the environment's global object as the return
value of GlobalEnvironment::global_this_value(), it now stores an Object
reference which is passed to the constructor for this purpose.

From the spec (https://tc39.es/ecma262/#sec-global-environment-records):

[[GlobalThisValue]] | Object | The value returned by this in global
scope. Hosts may provide any ECMAScript Object value.
2021-09-12 11:10:20 +01:00
Linus Groh
2b8d5696ab LibJS: Allocate a Realm next to GlobalObject in Interpreter::create()
Also pass a Realm reference to the Bytecode::Interpreter constructor,
just like we pass the GlobalObject.
2021-09-12 11:10:20 +01:00
Linus Groh
d9c3bafcd9 LibJS: Start adding a JS::Realm class (spec's "Realm Record") 2021-09-12 11:10:20 +01:00
Timothy Flynn
f5c988b3ce LibJS: Convert MapIterator.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
77efecadf7 LibJS: Convert Map.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
9e57ea71af LibJS: Convert GeneratorObject.prototype to be a PrototypeObject
The added #include in GeneratorObject.h is to resolve usage of
Bytecode::RegisterWindow.
2021-09-12 01:40:56 +02:00
Timothy Flynn
43e4cec3e2 LibJS: Convert FinalizationRegistry.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
94f076a774 LibJS: Convert Date.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
8bfb665b72 LibJS: Convert DataView.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
4d1d0f05a9 LibJS: Convert ArrayIterator.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
bd4c116d08 LibJS: Convert ArrayBuffer.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
696967d7b6 LibJS: Convert WeakSet.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
777ae53615 LibJS: Convert WeakRef.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
966f4faae4 LibJS: Convert WeakMap.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
be0880fb2c LibJS: Convert StringIterator.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
f195cb41a8 LibJS: Convert SetIterator.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
75d5c17aec LibJS: Convert Set.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
a41d0d23f9 LibJS: Convert Promise.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
b749194e70 LibJS: Convert RegExpStringIterator.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
65b0c26c44 LibJS: Convert RegExp.prototype to be a PrototypeObject 2021-09-12 01:40:56 +02:00
Timothy Flynn
1078d5e58a LibJS: Create a class to provide common methods for object prototypes
Almost every JS prototype class defines a static "typed_this" helper to
return the current "this" value as the analogous object type. This adds
a PrototypeObject class to be inserted between the prototype object and
the base Object class to define these methods on the prototype's behalf.

Note that the generated "display_name" method must be defined static
because the callers of typed_this are also static.
2021-09-12 01:40:56 +02:00
Timothy Flynn
6d55e0572d LibJS: Remove ErrorType::NotA and ErrorType::NotAn 2021-09-12 00:16:39 +02:00
Timothy Flynn
470262c8ab LibJS: Use ErrorType::NotAnObjectOfType instead of NotA 2021-09-12 00:16:39 +02:00
Timothy Flynn
fd8ec1fffa LibJS: Add a variant of ErrorType::NotA named NotAnObjectOfType
This is a clearer name. Subsequent commits will convert files to use the
new name, then the old name will be deleted.
2021-09-12 00:16:39 +02:00
Timothy Flynn
76589d6728 LibJS: Change wording of ErrorType::NotA to be independent of context
Currently, we have NotA and NotAn, to be used dependent on whether the
following word begins with a vowel or not. To avoid this, change the
wording on NotA to be independent of this context.
2021-09-12 00:16:39 +02:00
Andreas Kling
935075c26e LibJS: Specify right base for PromiseResolvingElementFunction subclasses 2021-09-11 22:26:53 +02:00
Andreas Kling
971dc44ed3 LibJS: Don't use MarkedValueList in PromiseValueList
Instead, override visit_edges() and mark the values like any other Cell
subclass would.

This makes PromiseValueList play nice with zombification.
2021-09-11 22:16:30 +02:00
Andreas Kling
0d2c3f62d3 LibJS: Use move semantics more when creating Reference objects
Turns a bunch of FlyString copies into moves.
2021-09-11 20:38:45 +02:00
Idan Horowitz
6704961c82 AK: Replace the mutable String::replace API with an immutable version
This removes the awkward String::replace API which was the only String
API which mutated the String and replaces it with a new immutable
version that returns a new String with the replacements applied. This
also fixes a couple of UAFs that were caused by the use of this API.

As an optimization an equivalent StringView::replace API was also added
to remove an unnecessary String allocations in the format of:
`String { view }.replace(...);`
2021-09-11 20:36:43 +03:00
Idan Horowitz
b92871f7ef LibJS: Visit WeakMap's values as long as their keys were not collected
While the WeakMap only holds a weak reference to its keys, their
accompanying values should be kept alive as long as they're accessible.
2021-09-11 18:27:56 +02:00
Idan Horowitz
073a1dec16 LibJS: Visit OrdinaryFunctionObject's owning realm 2021-09-11 18:27:56 +02:00