Commit Graph

5138 Commits

Author SHA1 Message Date
Andreas Kling
b61f198d22 LibJS: Rename Bytecode::ExecutionUnit => Bytecode::Executable 2021-06-09 09:24:32 +02:00
Luke
597e0d95fe LibJS: Only set element in array literal to an empty value if it's null
This avoids an unnecessary empty load that immediately gets overridden.

For example, `[1,,]` would appear as:
[   0] EnterScope
[  10] LoadImmediate value:<empty>
[  28] LoadImmediate value:1
[  40] Store dst:$1
[  48] LoadImmediate value:<empty>
[  60] Store dst:$2
[  68] NewArray, elements:[$1,$2]

But now appears as:
[   0] EnterScope
[  10] LoadImmediate value:1
[  28] Store dst:$1
[  30] LoadImmediate value:<empty>
[  48] Store dst:$2
[  50] NewArray, elements:[$1,$2]
2021-06-09 09:14:40 +02:00
Ali Mohammad Pur
01e8f0889a LibJS: Generate bytecode in basic blocks instead of one big block
This limits the size of each block (currently set to 1K), and gets us
closer to a canonical, more easily analysable bytecode format.
As a result of this, "Labels" are now simply entries to basic blocks.
Since there is no more 'conditional' jump (as all jumps are always
taken), JumpIf{True,False} are unified to JumpConditional, and
JumpIfNullish is renamed to JumpNullish.
Also fixes #7914 as a result of reimplementing the loop logic.
2021-06-09 09:07:29 +02:00
brapru
d7a25cdb82 Utilities: Do not allow creating users with existing usernames
Previously useradd would not check if a username already existed on the
system, and would instead add the user anyway and just increment the
uid. useradd should instead return an error when the user attempts to
create already existing users.
2021-06-09 09:00:31 +02:00
Matthew Olsson
f286cf1792 LibJS: Fix not executing the expression of a return statement 2021-06-09 01:33:38 +02:00
Gunnar Beutner
a1e5711a27 LibJS: Generate bytecode for array expressions 2021-06-09 01:27:18 +02:00
Andreas Kling
b8a5ea1f8d Revert "LibJS: Add bytecode instruction handles"
This reverts commit a01bd35c67.

This broke simple programs like:

function sum(a, b) { return a + b; }
console.log(sum(1, 2));
2021-06-09 00:50:42 +02:00
Matthew Olsson
a01bd35c67 LibJS: Add bytecode instruction handles
This change removes the mmap inside of Block in favor of a growing
vector of bytes. This is favorable for two reasons:
  - We don't take more space than we need
  - There is no limit to the growth of the vector (previously, if
    the Block overstepped its 64kb boundary, it would just crash)

However, if that vector happens to resize, any pointer pointing into
that vector would become invalid. To avoid this, this commit adds an
InstructionHandle<Op> class which just stores a block and an offset
into that block.
2021-06-09 00:37:17 +02:00
Linus Groh
83be39c91a LibJS: Handle Proxy with Array target in IsArray() abstract operation
This was missing from Value::is_array(), which is equivalent to the
spec's IsArray() abstract operation - it treats a Proxy value with an
Array target object as being an Array.
It can throw, so needs both the global object and an exception check
now.
2021-06-08 23:53:13 +02:00
Linus Groh
9b35231453 LibJS: Implement Proxy.revocable() 2021-06-08 23:53:13 +02:00
Linus Groh
e39dd65cf0 LibJS: Remove Proxy() argument count check
Let's just treat missing arguments as undefined and throw with
'target/handler must be object' - this is more JavaScript-y.
2021-06-08 23:53:13 +02:00
Gunnar Beutner
5ff85abe8c LibJS: Make sure loop results are initialized
This ensures that "while", do...while, "for" expressions have a
properly initialized result value even if the user terminated
the loop body via break or the loop body wasn't executed at all.
2021-06-08 21:49:52 +01:00
Marcin Gasperowicz
624ceec04f LibJS: Make SwitchStatement::execute() return undefined for empty blocks
Previously SwitchStatement::execute() would return <empty> when hitting
break, continue or empty consequent block. This was not in line with
the standard.
2021-06-08 21:41:46 +01:00
Andreas Kling
949ceedaed LibJS: Remove the seal/unseal of Bytecode::Block again
This partially reverts c6ce7c9326.
The munmap part of that change was good, but we can't seal the blocks
since that breaks NewString and other ops that have String members.
2021-06-08 21:39:50 +02:00
Matthew Olsson
9bed2e4f4a LibJS: Introduce an accumulator register to Bytecode::Interpreter
This commit introduces the concept of an accumulator register to
LibJS's bytecode interpreter. The accumulator register is always
register 0, and most simple instructions use it for reading and
writing.

Not only does this slim down the AST, but it also simplifies a lot of
the code. For example, the generate_bytecode methods no longer need
to return an Optional<Register>, as any opcode which has a "return"
value will always put it into the accumulator.

This also renames the old Op::Load to Op::LoadImmediate, and uses
Op::Load to load from a register into the accumulator. There is
also an Op::Store to put the value in the accumulator into another
register.
2021-06-08 21:00:12 +02:00
Linus Groh
6c256bb400 LibJS: Add @@toStringTag to Reflect 2021-06-08 19:13:14 +01:00
Linus Groh
b377777208 LibJS: Add @@toStringTag to Promise.prototype 2021-06-08 19:13:14 +01:00
Linus Groh
ed64a69fb2 LibJS: Replace two instances of 'global_object.vm()' with just 'vm' 2021-06-08 19:13:14 +01:00
Gunnar Beutner
75a12bc2b7 LibJS: Generate bytecode for template literals 2021-06-08 19:47:32 +02:00
Sam Atkins
0b2bf3d73a gron: Handle invalid input gracefully
Print an error and return 1, instead of asserting.
2021-06-08 19:15:12 +02:00
Sam Atkins
d09fb8f599 gron: Make gron read from stdin if no file is provided 2021-06-08 19:15:12 +02:00
Ali Mohammad Pur
7ac196974d Everywhere: Replace Vector<T*> with nonnull entries with Vector<T&> 2021-06-08 19:14:24 +02:00
Timothy Flynn
c7cd81bce8 LibSQL: Limit the number of nested subqueries
SQLite hasn't documented a limit on https://www.sqlite.org/limits.html
for the maximum number of nested subqueries. However, its parser is
generated with Yacc and has an internal limit of 100 for general nested
statements.

Fixes https://crbug.com/oss-fuzz/35022.
2021-06-08 19:08:13 +02:00
Gunnar Beutner
ac9dbcda97 LibM: Implement nearbyint, nearbyintl and nearbyintf
These are used by the ultima engine for scummvm.
2021-06-08 17:29:57 +02:00
Gunnar Beutner
d2662df57c LibC+AK: Remove our custom macros from <assert.h>
Other software might not expect these to be defined and behave
differently if they _are_ defined, e.g. scummvm which checks if
the TODO macro is defined and fails to build if it is.
2021-06-08 17:29:57 +02:00
Leon Albrecht
c6ce7c9326
LibJS: Seal Bytecode Blocks and munmap them (#7919) 2021-06-08 17:21:48 +02:00
Idan Horowitz
064ed8279e LibJS: Support deleting local variables with operator delete
To make this cleaner i also moved the logic into Reference::delete_.
2021-06-08 15:31:46 +01:00
Idan Horowitz
af58779def LibJS: Return undefined from a with statement if no value was generated
Co-authored-by: Linus Groh <mail@linusgroh.de>
2021-06-08 15:31:46 +01:00
Idan Horowitz
98897ff676 LibJS: Return the last value from a with statement 2021-06-08 15:31:46 +01:00
Linus Groh
68ce69db88 LibJS: Add for loop bytecode generation 2021-06-08 11:59:32 +02:00
Gunnar Beutner
50ece3dd1b LibJS: Implement bytecode generation for BigInts 2021-06-08 10:57:28 +01:00
Gunnar Beutner
0975e08285 LibJS: Make if yield undefined for the else branch if it is missing 2021-06-08 11:38:48 +02:00
Gunnar Beutner
d9989fd259 LibJS: Remove redundant jump for IfStatements 2021-06-08 11:38:48 +02:00
Gunnar Beutner
ef83872f62 LibJS: Make JumpIf{True,False,Nullish} inherit from Jump
This saves a few lines in LogicalExpression::generate_bytecode.
2021-06-08 11:38:48 +02:00
Jelle Raaijmakers
afbbcde150 Utilities: Make xargs stop parsing options on first non-option 2021-06-08 11:30:58 +02:00
Jelle Raaijmakers
3c7ddf383a Utilities: Make watch stop parsing options on first non-option 2021-06-08 11:30:58 +02:00
Jelle Raaijmakers
fb6d141601 Utilities: Make strace stop parsing options on first non-option 2021-06-08 11:30:58 +02:00
Jelle Raaijmakers
00fc0a6cf0 Shell: Make time stop parsing options on first non-option 2021-06-08 11:30:58 +02:00
Jelle Raaijmakers
a32fe8df33 UserspaceEmulator: Stop parsing options on first non-option 2021-06-08 11:30:58 +02:00
Jelle Raaijmakers
001c81b1be Userland: Let env parse options up to first non-option 2021-06-08 11:30:58 +02:00
Jelle Raaijmakers
d7126fbbc2 LibCore/ArgsParser: Learn how to stop on first non-option
We need this for utilities like `env`, that do not gain anything by
parsing the options passed to the command they are supposed to
execute.
2021-06-08 11:30:58 +02:00
Jelle Raaijmakers
250f8eccf3 LibCore: Support fine-grained failure behavior for ArgsParser 2021-06-08 11:30:58 +02:00
Luke
1dc31842cb LibJS: Add sequence expression bytecode generation 2021-06-08 11:20:10 +02:00
Luke
de3ee701ce LibJS: Add conditional expression bytecode generation
Or, by its more common name, the ternary operator :^)
2021-06-08 09:53:56 +01:00
Gunnar Beutner
6da587b59b LibJS: Implement bytecode ops for logical expressions 2021-06-08 10:42:45 +02:00
Gunnar Beutner
216d27d4c1 LibJS: Convert values to boolean for JumpIfTrue/JumpIfFalse
Value::as_bool() might fail if the underlying value isn't already a
boolean value.
2021-06-08 10:42:45 +02:00
Idan Horowitz
aefb7995f1 LibJS: Add the Symbol.species getter to the appropriate built-ins 2021-06-08 09:09:51 +01:00
Linus Groh
39c3aefe5d LibJS: Use to_property_key() a bunch in ReflectObject
Yay for correctness. :^)
2021-06-07 23:11:08 +01:00
Linus Groh
7565bf0590 LibJS: Remove redundant exception checks 2021-06-07 23:09:06 +01:00
Linus Groh
3fdad563e2 LibJS: Never omit setter/getter attributes in accessor descriptor object
These should not be omitted, an accessor with out getter or setter still
yields an undefined for the attribute in its descriptor object.
2021-06-07 23:07:13 +01:00