Timothy Flynn
134bb44ca0
LibJS: Implement Iterator.prototype.forEach
2023-06-26 10:39:07 +02:00
Timothy Flynn
35380b2aef
LibJS: Implement Iterator.prototype.toArray
2023-06-26 10:39:07 +02:00
Timothy Flynn
acc05480e8
LibJS: Implement Iterator.prototype.reduce
2023-06-26 10:39:07 +02:00
Timothy Flynn
ad42b4ea67
LibJS: Implement Iterator.prototype.flatMap
...
This prototype is a bit tricky in that we need to maintain the iteration
state of the mapped iterator's inner iterator as we return values to the
caller. To do this, we create a FlatMapIterator helper to perform the
steps that apply to the current iteration state.
2023-06-26 10:39:07 +02:00
Timothy Flynn
67028ee3a3
LibJS: Implement Iterator.prototype.drop
2023-06-26 10:39:07 +02:00
Timothy Flynn
0e2f9f006d
LibJS: Implement Iterator.prototype.take
2023-06-26 10:39:07 +02:00
Timothy Flynn
7e0083fb65
LibJS: Rename ErrorType::IntlNumberIsNaN to ErrorType::NumberIsNaN
...
It will be used outside of the Intl namespace, so give it a less overly
specific name.
2023-06-26 10:39:07 +02:00
Timothy Flynn
deeee65e37
LibJS: Implement Iterator.prototype.filter
2023-06-26 10:39:07 +02:00
Timothy Flynn
3eb2e4e08a
LibJS: Implement Iterator.prototype.map
...
This uses a new Iterator type called IteratorHelper. This does not
implement IteratorHelper.prototype.return as that relies on generator
objects (i.e. the internal slots of JS::GeneratorObject), which are not
hooked up here.
2023-06-26 10:39:07 +02:00
Timothy Flynn
7ff6b472c0
LibJS: Implement Iterator.prototype [ @@toStringTag ]
2023-06-26 10:39:07 +02:00
Timothy Flynn
d9d245faa7
LibJS: Implement Iterator.from and the WrapForValidIteratorPrototype
...
Iterator.from creates an Iterator from either an existing iterator or
an iterator-like object. In the latter case, it sets the prototype of
the returned iterator to WrapForValidIteratorPrototype to wrap around
the iterator-like object's iteration methods.
2023-06-26 10:39:07 +02:00
Timothy Flynn
5736b53013
LibJS: Add an Iterator constructor and object
...
The Iterator object cannot be constructed directly but can be subclassed
or created with `Iterator.from` (not implemented here).
2023-06-26 10:39:07 +02:00
Timothy Flynn
428109e709
LibJS: Forward declare IteratorRecord and remove inclusion from VM.h
...
This drastically reduces the amount of compilation required when
Iterator.h is changed.
2023-06-26 10:39:07 +02:00
Timothy Flynn
4977000fa0
LibJS: Rename JS::Iterator to JS::IteratorRecord
...
This is in preparation for an upcoming implementation of the Iterator
Helpers proposal. That proposal will require a JS::Object type named
"Iterator", so this rename is to avoid conflicts.
2023-06-26 10:39:07 +02:00
Luke Wilde
c5f3b3ae02
LibJS/Bytecode: Return the proper result for iteration statements
2023-06-26 04:58:27 +02:00
Luke Wilde
b162c9117e
LibJS/Bytecode: Set accumulator to undefined at start of catch blocks
...
Otherwise we leak the error value through to the result.
2023-06-26 04:58:27 +02:00
Andreas Kling
a4a1d1b84a
LibJS/Bytecode: Transfer object expression property names to functions
...
2 new passes on test262. :^)
2023-06-25 20:39:29 +02:00
Andreas Kling
ad15a1e3e2
LibJS/Bytecode: Don't assert on eval() without arguments
...
3 new passes on test262. :^)
2023-06-25 19:41:53 +02:00
Andreas Kling
ceb5199225
LibJS/Bytecode: Don't clobber accumulator in Put/Delete instructions
...
The fact that side effects clobbers the accumulator isn't just annoying
inside the instruction handler, but also really counter-intuitive in
the bytecode program itself.
17 new passes on test262. :^)
2023-06-25 19:14:30 +02:00
Andreas Kling
8450948458
LibJS: Make class definition evaluation work in bytecode mode
...
Instead of assuming that there's an active AST interpreter, this code
now takes VM& everywhere and invokes the appropriate interpreter.
92 new passes on test262. :^)
2023-06-25 18:28:44 +02:00
Andreas Kling
66936a0d61
LibJS/Bytecode: Fix non-string keys not being excluded in rest object
...
By converting the excluded names to PropertyKey before filtering, we
ensure that non-string keys get excluded as needed.
14 new passes on test262. :^)
2023-06-25 18:02:37 +02:00
Andreas Kling
6f0952c358
LibJS/Bytecode: Handle object destructuring to member expression
...
19 new passes on test262. :^)
2023-06-25 17:00:29 +02:00
Hendiadyoin1
7005a91a1e
LibJS: Replace invalid escapes in TemplateLiterals with undefined in BC
...
Also adds a big FIXME, to outline what is still wrong
2023-06-25 16:41:50 +02:00
Andreas Kling
77f1e91e9d
LibJS: Make $262.evalScript() work in bytecode mode
...
29 new passes on test262. :^)
2023-06-25 13:13:19 +02:00
Andreas Kling
1932f7e6b6
LibJS/Bytecode: Transfer binding pattern aliases to function names
...
60 new passes on test262. :^)
2023-06-25 11:59:51 +02:00
Andreas Kling
8873bf5016
LibJS/Bytecode: Use ToString instead of generic add() in ConcatString
...
This avoids invoking valueOf() on the values, which is observable.
48 new passes on test262. :^)
2023-06-25 11:20:05 +02:00
Andreas Kling
8021048bc9
LibJS/Bytecode: Throw on destructuring object assignment to nullish LHS
...
24 new passes on test262. :^)
2023-06-25 09:19:53 +02:00
Andreas Kling
1f95a40780
LibJS/Bytecode: Actually exit switch
statement's lexical scope
...
95 new passes on test262. :^)
2023-06-25 08:09:39 +02:00
Andreas Kling
4fd71e3c3a
LibJS/Bytecode: Support destructuring in try..catch
...
112 new passes in test262.
2023-06-24 21:10:07 +02:00
Aliaksandr Kalenik
331f6a9e60
LibJS: Invalidate cached environment coordinate after delete in global
...
Fixes the bug in interpreter when cached environment coordinate is not
invalidated after `delete` operator usage on global `this`.
2023-06-24 18:33:44 +02:00
Andreas Kling
06ac768c8b
LibJS/Bytecode: Add some basic codegen for ExportStatement
...
This is by no means complete, but at least a bunch of test-js and
test262 tests start working. :^)
2023-06-24 17:13:30 +02:00
Andreas Kling
5d79431859
LibJS/Bytecode: Actually generate & run bytecode for SourceTextModule
2023-06-24 17:13:30 +02:00
Andreas Kling
8a5e71256d
LibJS/Bytecode: Add codegen for ImportCall
...
Also moved most of the AST ImportCall::execute() into a helper so we can
share the code.
2023-06-24 17:13:30 +02:00
Andreas Kling
eb9298b54e
LibJS/Bytecode: Support destructuring function parameters
...
To reduce code duplication, I've added new VM::execute_ast_node()
helper that handles bytecode compilation if needed.
918 new passes on test262. :^)
2023-06-24 08:38:54 +02:00
Andreas Kling
b3a3c53007
LibJS: Fix bad indentation when dumping FunctionNode AST nodes
2023-06-24 08:38:54 +02:00
Luke Wilde
95d619943e
LibJS/Bytecode: Support private identifiers in optional chaining
...
Fixes 4 test262 tests :^)
2023-06-23 21:05:18 +02:00
Timothy Flynn
32502fceed
LibJS: Update spec numbers/steps for RegExp unicode sets flag proposal
...
This proposal has been merged into the main ECMA-262 spec. See:
26b2369
2023-06-23 20:22:45 +02:00
Timothy Flynn
9407e05a3c
LibJS: Update RegExp spec numbers to match re-ordering within the spec
...
This is an editorial change in the ECMA-262 spec. See:
abee2e6
77256bf
2023-06-23 20:22:45 +02:00
Andreas Kling
99b23fe2ad
LibJS/Bytecode: Emit GetPrivateById for private member expressions
...
This makes it possible to call private member functions.
347 new passes on test262. :^)
2023-06-23 17:51:04 +02:00
Andreas Kling
85a3a1c085
LibJS/Bytecode: Add codegen for "named evaluation if anonymous function"
...
This gives anonymous functions the name from the LHS they are being
assigned to.
171 new passes on test262. :^)
2023-06-23 16:09:33 +02:00
Andreas Kling
e5c7d8407b
LibJS/Bytecode: Support private class fields
...
This is accomplished with two new instructions:
- GetPrivateById
- PutPrivateById
Looks like 1616 new passes on test262. :^)
2023-06-23 08:53:10 +02:00
Andreas Kling
467ea86179
LibJS: Use bytecode for generator function default parameters
...
Otherwise there's a mismatch between which interpreter we use.
This fixes a regression in the AST interpreter score on test262.
2023-06-23 08:09:50 +02:00
Andreas Kling
cd08515957
LibJS/Bytecode: Support named evaluation of anonymous functions
2023-06-22 21:16:17 +02:00
Andreas Kling
f4fe9f09a1
LibJS/Bytecode: Perform ShadowRealm evaluations in bytecode when enabled
2023-06-22 21:16:17 +02:00
Andreas Kling
6537ed8fff
LibJS/Bytecode: Simplify Bytecode::Interpreter lifetime model
...
The JS::VM now owns the one Bytecode::Interpreter. We no longer have
multiple bytecode interpreters, and there is no concept of a "current"
bytecode interpreter.
If you ask for VM::bytecode_interpreter_if_exists(), it will return null
if we're not running the program in "bytecode enabled" mode.
If you ask for VM::bytecode_interpreter(), it will return a bytecode
interpreter in all modes. This is used for situations where even the AST
interpreter switches to bytecode mode (generators, etc.)
2023-06-22 21:16:17 +02:00
Timothy Flynn
396655d145
LibJS: Begin implementing console.dir
...
The intent of the spec is that the output of console.dir is interactable
within the console. Our Printer implementation currently just prints the
provided object as a string, and doesn't check the provided `options`
argument. But having console.dir defined prevents exceptions from being
thrown on real websites.
2023-06-22 06:46:27 +02:00
Timothy Flynn
9f8e5f0b1c
LibJS: Sort Console methods in spec order
...
Easier to compare to the spec side-by-side when everything is in the
same order.
2023-06-22 06:46:27 +02:00
MacDue
130ec7e5b4
LibJS: Align HeapBlock cell storage to __BIGGEST_ALIGNMENT__
...
alignas(Cell) is just the alignment requirement for the base class
(which resolves to 8-bytes). This does not necessarily hold for all
subclasses.
2023-06-19 21:59:35 +02:00
Kenneth Myhra
ce2b88e7cc
LibJS: Use copy_data_block_bytes() instead of overwrite() and copy_to()
...
Replaces usage of ByteBuffer::overwrite() and combinations of
Span::slice() + Span::copy_to() with AO CopyDataBlockBytes.
2023-06-19 17:43:18 +02:00
Kenneth Myhra
f3fb005653
LibJS: Partially implement AO CopyDataBlockBytes
...
Currently we do not support Shared Data Block so that part is not yet
implemented.
2023-06-19 17:43:18 +02:00