Commit graph

5156 commits

Author SHA1 Message Date
Andreas Kling
845f2826aa LibJS: Reset Bytecode::Interpreter's m_return_value when leaving run()
Otherwise it will cause complete unwind since all parent run() loops
will see the same m_return_value being non-empty and break out.
2021-06-07 18:11:59 +02:00
Andreas Kling
9330163b0b LibJS: Make sure the global CallFrame doesn't go out of scope
The Bytecode::Interpreter will push a global call frame if needed,
and it needs to make sure that call frame survives until the end
of the Interpreter::run() function.
2021-06-07 18:11:59 +02:00
Andreas Kling
0cc9d47e1b LibJS: Add AbstractEquals bytecode instruction for == comparison :^) 2021-06-07 18:11:59 +02:00
Andreas Kling
4bdfe73895 LibJS: Add basic support for "continue" in the bytecode VM
Unlike the convoluted unwind-until-scope-type mechanism in the AST
interpreter, "continue" maps to a simple Bytecode::Op::Jump here. :^)

We know where to jump based on a stack of "continuable scopes" that
we now maintain on the Bytecode::Generator as we go.

Note that this only supports bare "continue", not continue-with-label.
2021-06-07 18:11:59 +02:00
Andreas Kling
79eac08f5b LibJS: Add basic "if" statement support to the bytecode VM :^)
This also required making Bytecode::Op::Jump support lazy linking
to a target label.

I left a FIXME here about having the "if" statement return the result
value from the taken branch statement. That's what the AST interpreter
does but I'm not sure if it's actually required.
2021-06-07 18:11:59 +02:00
Andreas Kling
80b1604b0a LibJS: Compile ScriptFunctions into bytecode and run them that way :^)
If there's a current Bytecode::Interpreter in action, ScriptFunction
will now compile itself into bytecode and execute in that context.

This patch also adds the Return bytecode instruction so that we can
actually return values from called functions. :^)

Return values are propagated from callee to caller via the caller's
$0 register. Bytecode::Interpreter now keeps a stack of register
"windows". These are not very efficient, but it should be pretty
straightforward to convert them to e.g a sliding register window
architecture later on.

This is pretty dang cool! :^)
2021-06-07 18:11:59 +02:00
Andreas Kling
b609fc6d51 js: Exit the program after dumping and/or running bytecode
Otherwise we'd run the same program again in the AST interpreter.
2021-06-07 18:11:59 +02:00
Andreas Kling
dc63958478 LibJS: Support basic function calls in the bytecode world :^)
This patch adds the Call bytecode instruction which is emitted for the
CallExpression AST node.

It's pretty barebones and doesn't handle 'this' values properly, etc.
But it can perform basic function calls! :^)

Note that the called function will *not* execute as bytecode, but will
simply fall back into the old codepath and use the AST interpreter.
2021-06-07 18:11:59 +02:00
Andreas Kling
1eafaf67fe LibJS: Add a new EnterScope bytecode instruction
This is intended to perform the same duties as enter_scope() does in
the AST tree-walk interpreter:

- Hoisted function declaration processing
- Hoisted variable declaration processing
- ... maybe more

This first cut only implements the function declaration processing.
2021-06-07 18:11:59 +02:00
Andreas Kling
2316a084bf LibJS: Create a global/outermost CallFrame for Bytecode::Interpreter
Note that we don't yet support nested calls using bytecode.
2021-06-07 18:11:59 +02:00
Andreas Kling
32561bb90d LibJS: Add GetById bytecode instruction for object property retrieval
Same as PutById but in the other direction. :^)
2021-06-07 18:11:59 +02:00
Andreas Kling
14cfc44855 LibJS: Add PutById bytecode instruction for object property assignment
Note that this is only used for non-computed accesses. Computed access
is not yet implemented. :^)
2021-06-07 18:11:59 +02:00
Andreas Kling
bea6e31ddc LibJS: Add a NewObject bytecode instruction for ObjectExpression :^) 2021-06-07 18:11:59 +02:00
Andreas Kling
f2863b5a89 LibJS: Generate bytecode for do...while statements :^)
This was quite straightforward using the same label/jump machinery that
we added for while statements.

The main addition here is a new JumpIfTrue bytecode instruction.
2021-06-07 18:11:59 +02:00
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
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
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
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
Linus Groh
b661363dfe LibJS: Implement String.prototype[@@toPrimitive]() 2021-06-06 19:34:43 +02:00
Linus Groh
e9a0759b16 LibJS: Add String.prototype.valueOf()
It should have its own and not inherit from the Object prototype.
2021-06-06 19:34:43 +02:00
Linus Groh
8d7ec28924 LibJS: Remove String.prototype.length
A string's length property is supposed to be a regular non-writable,
non-enumerable, non-configurable property on the StringObject instead.
2021-06-06 19:34:43 +02:00
Linus Groh
fc2673d111 LibJS: Replace SymbolPrototype's typed_this() with this_symbol_value()
This brings the code close to the spec with no trade-offs, which is
always valuable.

No functionality change.
2021-06-06 19:34:43 +02:00
Linus Groh
6f96f01171 LibJS: Replace StringPrototype's typed_this() with this_string_value()
This brings the code close to the spec with no trade-offs, which is
always valuable.

No functionality change.
2021-06-06 19:34:43 +02:00
Linus Groh
68d669443f LibJS: Replace bigint_object_from() with this_bigint_value()
This brings the code close to the spec with no trade-offs, which is
always valuable.

No functionality change.
2021-06-06 19:34:43 +02:00
Linus Groh
d255e6892b LibJS: Update NumberPrototype's this_number_value() to take a Value
This is now about as close to the spec as it gets - instead of querying
the |this| value inside of the function, we now pass it in from the
outside.
Also get rid of the oddly specific error messages, they're nice but
pretty inconsistent with most others. Let's prefer consistency and
simplicity for now.

Other than that, no functionality change.
2021-06-06 19:34:43 +02:00
Linus Groh
3cfd9f51f7 LibJS: Replace some is_nullish() checks with require_object_coercible() 2021-06-06 19:34:43 +02:00
Linus Groh
cd12b2aa57 LibJS: Implement the RequireObjectCoercible abstract operation
Throws an exception if the given value is nullish, returns it otherwise.
We can now gradually replace such manual checks with this function where
applicable.

This also has the advantage that the somewhat useless "ToObject on null
or undefined" will be replaced with "null cannot be converted to an
object" or "undefined cannot be converted to an object". :^)
2021-06-06 19:34:43 +02:00
Andreas Kling
4c47b3951d Clipboard: Tighten pledge promises a bit earlier :^) 2021-06-06 17:56:34 +02:00
FalseHonesty
db20f7b6d8 Userland: Add matroska program to test parsing Matroska container files 2021-06-06 17:47:00 +02:00
FalseHonesty
403bb07443 LibVideo: Scaffold LibVideo and implement simplistic Matroska parser
This commit initializes the LibVideo library and implements parsing
basic Matroska container files. Currently, it will only parse audio
and video tracks.
2021-06-06 17:47:00 +02:00
Max Wipfli
30cdebfa9e LibProtocol: Use URL class in RequestClient::start_request argument
This changes the RequestClient::start_request() method to take a URL
object instead of a URL string as argument. All callers of the method
already had a URL object anyway, and start_request() in turn parses the
URL string back into a URL object. This removes this unnecessary
conversion.
2021-06-06 16:00:11 +02:00
Max Wipfli
5b5f7bc360 LibProtocol: Change RequestClient.{cpp,h} to use east const style 2021-06-06 16:00:11 +02:00
Eugene Barnett
cab2ee5ea2 Magnifier: Add desktop display scale awareness
Continues to magnify correctly at the most current
desktop scale.
2021-06-06 15:56:43 +02:00
Eugene Barnett
4ef85de9dc WindowServer: Add a GetDesktopDisplayScale IPC request
Tells you which scale factor is configured in window manager.
2021-06-06 15:56:43 +02:00
Andreas Kling
f290048662 LibJS: Pass unwinding target labels a bit more efficiently
Use const reference or move semantics when passing these labels.
2021-06-06 11:45:52 +02:00
dylanbobb
e24f1dfbe1 LibGUI: Don't delete within a line if the line is empty 2021-06-06 11:25:59 +02:00
Tom
2c8309c841 WindowServer: Simplify determining transparent/opaque occlusions
By moving the logic to determine what window areas (shadow, frame,
content) into WindowFrame::opaque/transparent_render_rects we can
simplify the occlusion calculation and properly handle more
arbitrary opaque/transparent areas.

This also solves the problem where we would render the entire
window frame as transparency only because the frame had a window
shadow.
2021-06-06 09:37:27 +01:00
Linus Groh
939da41fa1 LibRegex: Fix compilation errors on my host machine
I have no idea *why*, but this stopped working suddenly:

    return { { .code_point = '-', .is_character_class = false } };

Fails with:

    error: could not convert ‘{{'-', false}}’ from
    ‘<brace-enclosed initializer list>’ to
    ‘AK::Optional<regex::CharClassRangeElement>

Might be related to 66f15c2 somehow, going one past that commit makes
the build work again, however reverting the commit doesn't. Not sure
what's up with that.

Consider this patch a band-aid until we can find the reason and an
actual fix...

Compiler version:
gcc (GCC) 11.1.1 20210531 (Red Hat 11.1.1-3)
2021-06-06 09:26:07 +01:00
Linus Groh
887852f36d LibJS: Make Number.prototype.toString() radix coercion spec compliant
This should use the ToIntegerOrInfinity() abstract operation.
2021-06-06 07:03:12 +01:00
Linus Groh
adc3de4480 LibJS: Implement Number.prototype.valueOf() 2021-06-06 06:56:08 +01:00
Idan Horowitz
0bf597e99d LibJS: Uncomment and add parseInt tests
Added another test that checks radices > 16, as well as uncommented
several "FIXME" tests that are now working.
2021-06-06 01:34:22 +01:00
Idan Horowitz
aa5b144f90 LibJS: Correct modulo behaviour in to_i32 to match the specification 2021-06-06 01:34:22 +01:00
Idan Horowitz
bbf75d0bea LibJS: Trim initial whitespace in parseFloat 2021-06-06 01:34:22 +01:00
Idan Horowitz
bda32e9440 LibJS: Parse digits with parse_ascii_base36_digit in parseInt
This was accidentally replaced with parse_ascii_hex_digit in
bc8d16ad28 which caused radices above
16 (hex) to fail.
2021-06-06 01:34:22 +01:00
Idan Horowitz
26a0dbdd9e LibJS: Set the length property of parseInt to 2
The method takes 2 arguments
2021-06-06 01:34:22 +01:00
NonStdModel
0e4dc5f7a1 LibKeyboard: Use correct filename in debug message 2021-06-06 00:21:12 +01:00
NonStdModel
484ec94624 KeyboardMapper: Add GUI alert in case load from file fails
Previously there was no visual clue letting the user know that loading
from file failed.
2021-06-06 00:21:12 +01:00
Tobias Christiansen
b253b63bb4 LibWeb: Resolve flex: shorthand correctly
This patch removes some FIXMEs from the StyleResolver, specifically
adding the proper float-parsing to the flex: shorthand. The
functionality was already there it just didn't get plumbed in before.
2021-06-06 00:16:27 +01:00
Idan Horowitz
2a8f4f097c LibJS: Throw TypeError on write to non-writable property in strict mode 2021-06-05 23:54:08 +01:00
Tobias Christiansen
31534055e4 LibWeb: Implement FlexBox Layout Algorithm 2021-06-06 01:46:06 +04:30
Tobias Christiansen
c51dbb4372 LibWeb: Expose size calculation of BlockFormattingContext
This is a hack for the FlexFormattingContext
2021-06-06 01:46:06 +04:30
Tobias Christiansen
ce7c8e215f LibWeb: Parse and resolve flex: shorthand 2021-06-06 01:46:06 +04:30
Tobias Christiansen
ae61e9ded2 LibWeb: Add flex-grow and flex-shrink
They get parsed and are available to the programmer of Layouts :^)
2021-06-06 01:46:06 +04:30
Tobias Christiansen
af4d80af4d LibWeb: Add parsing for NumericStyleValue
This StyleValue can hold an arbitrary float value.
2021-06-06 01:46:06 +04:30
Tobias Christiansen
ae3e6510d6 LibWeb: Parse flex-basis
Flex-basis accepts either 'content' or a Length.
2021-06-06 01:46:06 +04:30
Tobias Christiansen
27704f5f9e LibWeb: Add support for 'definite size' determination
This is pretty naive and there are more nuances in the spec but should
be enough for now.
2021-06-06 01:46:06 +04:30
Tobias Christiansen
ead864acf3 LibWeb: Parse and resolve flex-flow property 2021-06-06 01:46:06 +04:30
Tobias Christiansen
e6545d5259 LibWeb: Add parsing for flex-wrap property 2021-06-06 01:46:06 +04:30
Tobias Christiansen
72d5394b8c LibWeb: Flex-items aren't affected by float nor clear
There are a few other things to notice, but they don't seem to be
implemented yet.
2021-06-06 01:46:06 +04:30
Tobias Christiansen
7f81c8fba2 LibWeb: LayoutNodes know whether they are flex-items
This is useful for debugging when dumping the layout tree.
2021-06-06 01:46:06 +04:30
dylanbobb
2205239d9a LibWeb: Change BlockBox to not want mouse events 2021-06-05 22:35:22 +02:00
Tim Schumacher
1618cffb75 LibVT: Don't return a history size if alternate buffer is used
The line history is unavailable if the alternate screen buffer is
currently enabled. However, since TerminalWidget uses the history size
to offset its line numbers when rendering, it will try to render
inaccessible lines once the history is not empty anymore.
2021-06-05 22:12:18 +02:00
Ali Mohammad Pur
51c2c69357 AK+Everywhere: Disallow constructing Functions from incompatible types
Previously, AK::Function would accept _any_ callable type, and try to
call it when called, first with the given set of arguments, then with
zero arguments, and if all of those failed, it would simply not call the
function and **return a value-constructed Out type**.
This lead to many, many, many hard to debug situations when someone
forgot a `const` in their lambda argument types, and many cases of
people taking zero arguments in their lambdas to ignore them.
This commit reworks the Function interface to not include any such
surprising behaviour, if your function instance is not callable with
the declared argument set of the Function, it can simply not be
assigned to that Function instance, end of story.
2021-06-06 00:27:30 +04:30
Maciej Zygmanowski
104dc93220 ifconfig: Use shorter argument names
The previous argument names were so long that they won't fit
into the terminal, making help message unreadable.
2021-06-05 23:51:08 +04:30
Timothy Flynn
f8f36effc9 LibSQL: Limit the allowed depth of an expression tree
According to the definition at https://sqlite.org/lang_expr.html, SQL
expressions could be infinitely deep. For practicality, SQLite enforces
a maxiumum expression tree depth of 1000. Apply the same limit in
LibSQL to avoid stack overflow in the expression parser.

Fixes https://crbug.com/oss-fuzz/34859.
2021-06-05 23:48:18 +04:30
Idan Horowitz
442ef63008 LibJS: Add the global escape() & unescape() methods 2021-06-05 18:55:08 +01:00
Idan Horowitz
e2fb7943f7 LibJS: Correctly handle NaN and negative infinity in Math.atan2
The current implementation was missing an early return on a NaN
argument and mixed up a couple of the positive/negative infinity early
returns.
2021-06-05 14:56:58 +01:00
Idan Horowitz
57a52094d1 LibJS: Rewrite Math.hypot to handle exceptions, NaNs, Infinity properly
The specification requires that we immediately return Infinity during
the iteration over the arguments if positive or negative infinity is
encountered, and return a NaN if it is encountered and no Infinity was
found. The specification also requires all arguments to be coerced into
numbers before the operation starts, or else a number conversion
exception could be missed due to the Infinity/NaN early return.
2021-06-05 14:56:58 +01:00
Idan Horowitz
03255c1c53 LibJS: Handle NaN/Infinity/Zero edge cases in Math.pow()
This commit replaces the current simple call to LibM's pow with the
full implementation of 6.1.6.1.3 Number::exponentiate:
https://tc39.es/ecma262/#sec-numeric-types-number-exponentiate
2021-06-05 14:56:58 +01:00
Idan Horowitz
7507999230 LibJS: Rewrite Math.{max, min} to handle exceptions and NaNs properly
The specification requires that we immediately return a NaN during the
iteration over the arguments if one is encountered. It also requires
all arguments to be coerced into numbers before the operation starts,
or else a number conversion exception could be missed due to the NaN
early return.
2021-06-05 14:56:58 +01:00
Idan Horowitz
24ffe91b16 LibJS: Handle negative zero and negative infinity in Math.abs()
As required by the specification:
3. If n is -0, return +0.
4. If n is -∞, return +∞.
2021-06-05 14:56:58 +01:00
Idan Horowitz
9d2e90d569 LibJS: Add Math.imul() 2021-06-05 14:56:58 +01:00
Idan Horowitz
de10f0dc6c LibJS: Support symbol keys in Object.prototype.propertyIsEnumerable 2021-06-05 14:15:28 +01:00
Idan Horowitz
eb0b1c432a LibJS: Replace StringOrSymbol::from_value with Value::to_property_key
This is a more specification compliant implementation of the
abstract operation 7.1.19 ToPropertyKey which should handle boxed
symbols correctly.
2021-06-05 14:15:28 +01:00
Andreas Kling
42fcc2219d LibJS: Use PropertyName::as_string() in Object::get()
After we've already checked is_string(), we can use as_string() to
avoid a temporary String.
2021-06-05 13:00:34 +02:00
Sahan Fernando
d02e7b3811 LibWasm: Move Wasm::BytecodeInterpreter into its own header 2021-06-05 14:31:54 +04:30
Marcus Nilsson
94551149d1 TreeView: Don't try to move cursor with invalid index
When clicking on the TreeView in profiler without selecting a node and
then pressing up or pgup, cursor_index was in an invalid state. Instead
select the first node in the index.
2021-06-05 11:27:05 +02:00
Tim Schumacher
f295ac3c0b rm: Allow empty paths if -f is specified
On most (if not all) systems rm ignores an empty paths array if -f or
--force is specified. This helps with scripts that may pass an empty
variable where the file paths are supposed to go.
2021-06-05 10:56:58 +02:00
Gunnar Beutner
4cd45f5875 LibC: Let setlocale() pretend that setting the locale succeeded
By returning nullptr we're telling the caller that setlocale() failed.
Some programs expect setlocale() to succeed so let's pretend that it
did.
2021-06-05 10:56:37 +02:00
Idan Horowitz
0f8ed6183b LibJS: Add the Number.{MAX, MIN}_VALUE constants 2021-06-05 02:38:37 +01:00
Timothy Flynn
f73bb164ad LibCards: Draw card stack background when the entire stack is moving
The stack background should be painted when the entire stack is being
dragged, rather than just the top card.

Fixes #7786. Regressed in 2b762ef940.
2021-06-04 23:48:25 +02:00
Max Wipfli
ec2f0fc8eb LibCpp: Fix off-by-one error in SyntaxHighlighter
This changes the C++ SyntaxHighlighter to conform to the now-fixed
rendering of syntax highlighting spans in GUI::TextEditor.

Contrary to other syntax highlighters, for this one the change has been
made to the SyntaxHighlighter rather than the Lexer. This is due to the
fact that the Parser also uses the same Lexer. I'm soure there is some
more elegant way to do this, but this patch at least unbreaks the C++
syntax highlighting.
2021-06-05 00:32:28 +04:30
Max Wipfli
617c54a00b LibCpp: Do not emit empty whitespace token after include statement
If an include statement didn't contain whitespace between the word
"include" and the '<' or '"', the lexer would previous emit an empty
whitespace token. This has been changed now.
2021-06-05 00:32:28 +04:30
Max Wipfli
2aa0cbaf22 LibCpp: Use CharacterTypes.h and constexpr functions in Lexer 2021-06-05 00:32:28 +04:30
Max Wipfli
d57d7bea1c LibCpp: Use east const style in Lexer and SyntaxHighlighter 2021-06-05 00:32:28 +04:30
Max Wipfli
282a623853 LibWeb: Change a few source end positions in HTMLTokenizer
This patch aims to fix wrong highlighting for some cases in HTML's
syntax highlighter. The values were somewhat experimentally determined
are are subject to change. Regardless, it should be more correct with
this patch than without it. :^)
2021-06-05 00:32:28 +04:30
Max Wipfli
44c438d0ca LibWeb: Fix off-by-one error in SyntaxHighlighter
This changes the HTML SyntaxHighlighter to conform to the now-fixed
rendering of syntax highlighting spans in GUI::TextEditor. It also
avoids emitting tokens if they have a zero or negative length.

This fixes a bug where single-character tokens were not highlighted
properly.
2021-06-05 00:32:28 +04:30
Max Wipfli
932161e581 LibWeb: Be more forgiving when adding source positions in HTMLTokenizer
This patch changes HTMLTokenizer::nth_last_position to not fail if the
requested position is not available. Rather, it will just return (0-0).

While this is not the correct solution, it prevents the tokenizer from
crashing just because it cannot find a source position. This should only
affect SyntaxHighlighter.
2021-06-05 00:32:28 +04:30
Max Wipfli
93d830b5cc LibWeb: Add debugging statements in SyntaxHighlighter
This also changes SyntaxHighlighter.{h,cpp} to use east const style.
2021-06-05 00:32:28 +04:30
Max Wipfli
04897f6842 LibSQL: Fix off-by-one error in SyntaxHighlighter
This changes the SQL SyntaxHighlighter to conform to the now-fixed
rendering of syntax highlighting spans in GUI::TextEditor.
2021-06-05 00:32:28 +04:30
Max Wipfli
a9378ce5c2 LibSQL: Clean up SyntaxHighlighter code
This changes SyntaxHighlighter.{cpp,h} to use east const style. It also
removes two unused headers and simplifies a loop.
2021-06-05 00:32:28 +04:30
Max Wipfli
261f233060 Shell: Fix off-by-one error in SyntaxHighlighter
This changes the Shell syntax highlighter to conform to the now-fixed
rendering of syntax highlighting spans in GUI::TextEditor.

This also adds some debug output to make debugging easier.
2021-06-05 00:32:28 +04:30
Max Wipfli
cb5a50d3f7 LibGUI: Fix off-by-one error in Lexer tokens
This changes the INI and GML lexers to conform to the now-fixed
rendering of syntax highlighting spans in GUI::TextEditor.

The other user of GMLToken::m_end, GMLAutocompleteProvider, has been
modified to take into account that end position columns have been
incremented by one.
2021-06-05 00:32:28 +04:30
Max Wipfli
e7b5dbe1ac LibGUI: Use CharacterTypes.h and constexpr functions in {INI,GML}Lexer 2021-06-05 00:32:28 +04:30
Max Wipfli
e10278402f LibGUI: Use east const style in {INI,GML}Lexer.{cpp,h} 2021-06-05 00:32:28 +04:30
Max Wipfli
106ad6ba09 LibJS: Fix off-by-one error in SyntaxHighlighter
This changes the JS syntax highlighter to conform to the now-fixed
rendering of syntax highlighting spans in GUI::TextEditor.
2021-06-05 00:32:28 +04:30
Max Wipfli
a819f98956 LibGUI: Fix off-by-one error in rendering of highlighted text
This fixes an off-by-one error in TextEditor's rendering of the syntax
highlighting as generated by Syntax::Highlighter and its subclasses.

Before, a single character span was e.g. (0-3) to (0-3), but this was
considered invalid by GUI::TextRange. Now, a single character span would
be e.g. (0-3) to (0-4).

This fix requires all Syntax::Highlighter subclasses to be adjusted, as
they all relied on the previous implementation. This will then also fix
a bug where single-character HTML tags wouldn't be highlighted.
2021-06-05 00:32:28 +04:30
Gunnar Beutner
fab9b2f068 Hearts: Don't destroy the animation handler while running it 2021-06-04 19:32:25 +02:00
Itamar
fdaec58f59 HackStudio: Add comment about lexicographical insertion to ClassView 2021-06-04 19:29:22 +02:00
Itamar
c1b2003687 HackStudio: Use Node's name when inserting to the ClassView tree
Previously, when traversing the ClassView tree to find the parent of a
new node, we used the name of the node's declaration to find the path
to the parent in the tree.

However, some nodes in the tree do not have a matching declaration,
which caused a VERIFY failure.

To fix this, we now use the node's name when walking the tree.
We can do this because the node's name should be identical to the name
of its declaration.

Closes #7702.
2021-06-04 19:29:22 +02:00
Timothy Flynn
2b762ef940 Solitaire+LibCards: Draw card stacks with rounded corners
Now that the cards have rounded corners, draw the stack box behind the
cards with rounded corners as well. This way, the corner of the stack
box doesn't peek out from behind the cards.

The caveat here is that the "play" card stack now needs to hold a
reference to the "waste" stack beneath it so it knows when not to draw
its background on top of the waste stack. To faciliate that, the array
of card stacks is now a NonnullRefPtrVector so the play stack can store
a smart pointer to the waste stack (instead of a raw pointer or
reference).
2021-06-04 19:11:45 +02:00
Timothy Flynn
4903186cc5 LibGfx: Add helper for painting a rounded rect with equal corner radii 2021-06-04 19:11:45 +02:00
Maciej Zygmanowski
bee1e06055 hostname: Handle 'sethostname' errors 2021-06-04 19:11:27 +02:00
Gunnar Beutner
d840608a51 Taskbar: Make sure LibGUI/Desktop.h is usable in ports
Now that Desktop.h includes Services/Taskbar/TaskbarWindow.h we have
to install Taskbar's header files so that Desktop.h can be used in
ports or when building software in-target.
2021-06-04 19:11:13 +02:00
Ryan Chandler
c66b281856 LibJS: Fix functions binding this to global object in strict mode
This fixes an issue where this would be bound to the global object
by default when operating in strict mode.

According to the specification, the expected value for |this| when
no binding is provided is undefined.
2021-06-04 13:00:37 +01:00
Ali Mohammad Pur
1b083392fa LibWasm+wasm: Switch to east-const to comply with project style
Against my better judgement, this change is mandated by the project code
style rules, even if it's not actually enforced.
2021-06-04 16:07:42 +04:30
Ali Mohammad Pur
23fd8bfd69 Userland/wasm: Replace manual noop export with an automatic one
Instead of manually specifying the types and names of imports to stub
out, `--export-noop` can be used to export stub functions for any
unresolved function import.
This makes running and debugging random wasm files much easier.
2021-06-04 16:07:42 +04:30
Ali Mohammad Pur
be62e4d1d7 LibWasm: Load and instantiate tables
This commit is a fairly large refactor, mainly because it unified the
two different ways that existed to represent references.
Now Reference values are also a kind of value.
It also implements a printer for values/references instead of copying
the implementation everywhere.
2021-06-04 16:07:42 +04:30
Ali Mohammad Pur
c392a0cf7f LibWasm: Implement the br.table instruction
Unlike its name, this instruction has nothing to do with tables, it's
just a very simple switch-case instruction.
2021-06-04 16:07:42 +04:30
Ali Mohammad Pur
9db418e1fb LibWasm: Read from and write to memory as little-endian
The spec says so, we must do so.
2021-06-04 16:07:42 +04:30
Ali Mohammad Pur
09cf1040ef LibJS/Tests: Catch exceptions in describe() itself
Otherwise exceptions thrown in that state would simply terminate the
test.
2021-06-04 16:07:42 +04:30
Jelle Raaijmakers
e483de93ce LibC: Define MSG_OOB 2021-06-04 10:39:41 +02:00