Commit graph

21699 commits

Author SHA1 Message Date
Andreas Kling
bd1a5e282a LibJS: Add AbstractInequals bytecode instruction :^) 2021-06-07 18:11:59 +02:00
Andreas Kling
6ae9346cd3 LibJS: Add basic support for while loops in the bytecode engine
This introduces two new instructions: Jump and JumpIfFalse.
Jumps are made to a Bytecode::Label, which is a simple object that
represents a location in the bytecode stream.

Note that you may not always know the target of a jump when adding the
jump instruction itself, but we can just update the instruction later
on during codegen once we know where the jump target is.

The Bytecode::Interpreter now implements jumping via a jump slot that
gets checked after each instruction to see if a jump is pending.
If not, we just increment the PC as usual.
2021-06-07 18:11:59 +02:00
Andreas Kling
91640d0727 LibJS: Add LessThan bytecode instruction :^) 2021-06-07 18:11:59 +02:00
Andreas Kling
6d66cdc668 LibJS: Print bytecode registers with format "$num" instead of "rnum" 2021-06-07 18:11:59 +02:00
Andreas Kling
4934d16397 LibJS: Make Bytecode::Generator::emit() return the created instruction
This will be useful for instructions that need to be modified later on
during code generation, e.g jumps. :^)
2021-06-07 18:11:59 +02:00
Andreas Kling
0553e0b048 LibJS: Move AST bytecode generation virtuals to separate cpp file
This will hopefully make it a bit more pleasant to edit this, as things
will just get larger and larger.
2021-06-07 18:11:59 +02:00
Andreas Kling
2b9fbd10ed LibJS: Add Sub bytecode instruction (subtract values) 2021-06-07 18:11:59 +02:00
Andreas Kling
23a4448862 LibJS: Add formatting helper for Bytecode::Register 2021-06-07 18:11:59 +02:00
Andreas Kling
37cb70836b LibJS: Some more opcodes for the bytecode VM
- NewString (allocates a new PrimitiveString from the GC heap)
- GetVariable (retrieves a variable in the current scope)
- SetVariable (assigns a variable in the current scope)
2021-06-07 18:11:59 +02:00
Andreas Kling
6da5d17416 LibJS: Add a VM accessor to Bytecode::Interpreter :^) 2021-06-07 18:11:59 +02:00
Andreas Kling
69dddd4ef5 LibJS: Start fleshing out a bytecode for the JavaScript engine :^)
This patch begins the work of implementing JavaScript execution in a
bytecode VM instead of an AST tree-walk interpreter.

It's probably quite naive, but we have to start somewhere.

The basic idea is that you call Bytecode::Generator::generate() on an
AST node and it hands you back a Bytecode::Block filled with
instructions that can then be interpreted by a Bytecode::Interpreter.

This first version only implements two instructions: Load and Add. :^)

Each bytecode block has infinity registers, and the interpreter resizes
its register file to fit the block being executed.

Two new `js` options are added in this patch as well:

`-d` will dump the generated bytecode
`-b` will execute the generated bytecode

Note that unless `-d` and/or `-b` are specified, none of the bytecode
related stuff in LibJS runs at all. This is implemented in parallel
with the existing AST interpreter. :^)
2021-06-07 18:11:59 +02:00
Idan Horowitz
f9395efaac LibJS: Use ToPropertyKey in Object.getOwnPropertyDescriptor
The specification requires this. (And the current usage of
PropertyName::from_value is invalid since integers are not allowed in
this context)
2021-06-07 16:51:09 +01:00
Idan Horowitz
1c51edb639 LibJS: Add missing length field to Symbol.prototype[Symbol.ToPrimitive]
Since the argument was missing Attribute::Configurable was used as the
length, which resulted in incorrect attributes being applied.
2021-06-07 16:51:09 +01:00
Ali Mohammad Pur
71b4433b0d LibWeb+LibSyntax: Implement nested syntax highlighters
And use them to highlight javascript in HTML source.
This commit also changes how TextDocumentSpan::data is interpreted,
as it used to be an opaque pointer, but everyone stuffed an enum value
inside it, which made the values not unique to each highlighter;
that field is now a u64 serial id.
The syntax highlighters don't need to change their ways of stuffing
token types into that field, but a highlighter that calls another
nested highlighter needs to register the nested types for use with
token pairs.
2021-06-07 14:45:49 +04:30
Gunnar Beutner
3bac14e19e Kernel: Remove incorrect VERIFY() in Thread::relock_process
Turns are there are legitimate cases where the thread state isn't
Thread::Running.
2021-06-07 14:45:38 +04:30
Andreas Kling
cb295ab644 WindowServer+Magnifier: Make Magnifier buttery smooth :^)
This patch moves the magnifier rect computation over to the server side
to ensure that the mouse cursor position and the screen image never get
out of sync.
2021-06-07 10:22:25 +02:00
Andreas Kling
0ea1fd2d54 Magnifier: Use a GUI::DisplayLink to drive the screen captures
This ensures that we don't try to update more often than the screen
is updated. It also avoids doing synchronous IPC in paint_event().
2021-06-07 10:22:25 +02:00
Andreas Kling
61c56e75f4 LibJS: Flatten Shape::property_table()
In the common case, we take the early return in ensure_property_table()
so let's make sure it gets inlined into property_table().
2021-06-07 10:22:25 +02:00
Andreas Kling
d24f4462c7 LibJS: Add VM::dump_backtrace()
This is just a simple helper that dumps the current VM call stack
to the debug console. I find myself rewriting this function over and
over, so let's just have it in the tree.
2021-06-07 10:22:25 +02:00
Gunnar Beutner
988dfa7f33 Toolchain+Ports: Fix building binutils on FreeBSD
This imports the upstream patch from
https://sourceware.org/bugzilla/show_bug.cgi?id=27382

Fixes #7407.
2021-06-07 09:51:12 +02:00
Gunnar Beutner
2d38d56e29 Documentation: Add ccache and rsync to the packages to install
These aren't hard dependencies but make building and working with
SerenityOS significantly faster.
2021-06-07 09:50:26 +02:00
Brian Gianforcaro
77f4f6e0de Kernel: Fix error propagation if Thread::WaitBlocker constructor fails
There is logic at the end of the constructor that sets m_should_block
to false if we encountered errors. We were missing this step due to the
erroneous early return, the code then ended up waiting and then
asserting on unblock since the WaitBlocker is in a invalid state.

This fix is to not return early, and let normal control flow handle it.

Fixes: #7857

Verified with `stress-ng --yield=10` locally.
2021-06-07 09:43:30 +02:00
Brian Gianforcaro
9fccbde371 Kernel: Switch Process to InstrusiveList from InlineLinkedList 2021-06-07 09:42:55 +02:00
Brian Gianforcaro
252e98761a Kernel: Remove unnecessary cast to int during ensure capacity 2021-06-07 09:42:55 +02:00
Brian Gianforcaro
f5e04759cc AK: Add IntrusiveList::size_slow() to match InlineLinkedList
The functionality is needed to replace InlineLinkedList with
IntrusiveList in the Kernel Process class.
2021-06-07 09:42:55 +02:00
Linus Groh
3dfd450f2d LibJS: Use Array::create() length arg in favor of set_array_like_size()
This way we don't bypass the maximum length check.
2021-06-06 23:27:47 +01:00
Linus Groh
1c906b07a4 LibJS: Add length parameter to Array::create()
This is now a bit closer to the spec's 10.4.2.2 ArrayCreate - it will
throw a RangeError if the requested length exceeds 2^32 - 1, so anyone
passing in a custom value (defaults to zero for same behaviour as
before) will need an exception check at the call site.
2021-06-06 23:25:33 +01:00
Linus Groh
e7bfd34ea7 LibJS: Add dbgln() to Heap::allocator_for_size() before crashing
If we can't get a CellAllocator for the requested cell size, at least
print a debug message before dying.
2021-06-06 23:08:15 +01:00
Ali Mohammad Pur
7700ee2722 LibLine: Actually remove the two levels of deferred_invoke
4d5cdcc893 partially reverted the changes
from d8c5eeceab, but it reverted too much
and reintroduced the bug.
This commit finally fixes the actual bug.
The author hasn't been in his best committing state today.
2021-06-07 02:22:40 +04:30
Ali Mohammad Pur
4d5cdcc893 LibLine: Partially revert d8c5eec and remove unrelated code
This is a partial revert of d8c5eeceab
as it contained unrelated code that was committed accidentally,
which broke history on LibLine.
2021-06-07 02:08:17 +04:30
Gunnar Beutner
64754ba985 Utilities: Add support for testing null deferencing a RefPtr
This adds the new flag -R for the crash utility which tests what
happens when we dereference a null RefPtr. This is useful for testing
the output of the assertion message.
2021-06-06 22:16:11 +02:00
Gunnar Beutner
89a38b72b7 LibC+LibELF: Implement dladdr()
This implements the dladdr() function which lets the caller look up
the symbol name, symbol address as well as library name and library
base address for an arbitrary address.
2021-06-06 22:16:11 +02:00
Ali Mohammad Pur
f82aa87d14 LibLine: Keep the CSI bytes alive across read events
Otherwise we would lose the CSI parameters and intermediates if the
whole sequence was split between two reads.
Fixes #7835.
2021-06-06 23:55:20 +04:30
Ali Mohammad Pur
d8c5eeceab LibLine: Stop registering the Notifier as a child Object
We're already keeping it alive via `m_notifier`.
This makes the event loop quitting logic simpler by making less
deferred calls and removes a race condition where the notifier would be
deleted before the second deferred_invoke() would be invoked, leading
to a nullptr dereference.
Fixes #7822.
2021-06-06 23:55:20 +04:30
FalseHonesty
73ff571d24 Userland: Fix matroska utility displaying invalid track data 2021-06-06 23:46:59 +04:30
Gunnar Beutner
6591d423d4 Ports: Install launcher for Freeciv 2021-06-06 20:31:38 +02:00
Idan Horowitz
f65cb63aab LibJS: Check dates are below the time_clip threshold 2021-06-06 19:14:11 +01:00
Idan Horowitz
c4530e95f4 LibJS: Add Date.prototype.toJSON() 2021-06-06 19:14:11 +01:00
Idan Horowitz
ed7eb403fe LibJS: Add Date.prototype[@@toPrimitive]() 2021-06-06 19:14:11 +01:00
Idan Horowitz
60e70e5ee4 LibJS: Add Date.setUTC{Date, Month, Hours, ...}() aliases
These are a bit hacky, since they are supposed to be separate methods,
but since serenity only supports UTC currently, they are equivalent.
2021-06-06 19:14:11 +01:00
Idan Horowitz
46214f0657 LibJS: Store Date milliseconds as signed to support negative offsets
We need to support the range of -999 to 999.
2021-06-06 19:14:11 +01:00
Idan Horowitz
17afe015a5 LibJS: Add Date.prototype.setTime() 2021-06-06 19:14:11 +01:00
Idan Horowitz
a93b1c7ea0 LibJS: Add Date.prototype.setMonth() 2021-06-06 19:14:11 +01:00
Idan Horowitz
59034554a4 LibJS: Account for differences in month representations (0-11 vs 1-12)
Since DateTime stores months as 1 to 12, while JS accepts months as
0 to 11, we have to account for the difference (by subtracting or
adding 1) where appropriate.
2021-06-06 19:14:11 +01:00
Idan Horowitz
b893963651 LibJS: Add Date.prototype.setDate() 2021-06-06 19:14:11 +01:00
Idan Horowitz
3eb05d9413 LibJS: Stub out Date.prototype.getTimezoneOffset()
We only support UTC currently, so this always returns 0 as long as the
date is not invalid.
2021-06-06 19:14:11 +01:00
Idan Horowitz
44926b3f80 LibJS: Ignore arguments in Date's constructor when called as a function
Since theres no way to drop the arguments before the call to the
constructor (or to signal to the constructor that it was not called
directly), we simply reuse the code for the no arguments provided
special case. (And to prevent code duplication, the code was extracted
into the separate static function Date::now(GlobalObject&).
2021-06-06 19:14:11 +01:00
Linus Groh
ba9d3bc38c LibJS: Create 1970-01-01 00:00:00 local time Date for invalid ctor call
When using Core::DateTime::from_timestamp(0) the resulting Date is
1970-01-01 00:00:00 in UTC, which might be something different in local
time - this is incorrect and relevant as invalid Dates can be made valid
later on.
2021-06-06 19:34:43 +02:00
Linus Groh
ff5aa3ca70 LibJS: Make it so that Date.prototype.toGMTString === .toUTCString 2021-06-06 19:34:43 +02:00
Linus Groh
60aace8400 LibJS: Remove unused includes from SymbolPrototype.cpp 2021-06-06 19:34:43 +02:00