Commit graph

2115 commits

Author SHA1 Message Date
Andreas Kling
8249280500 LibJS: Use HashMap::ensure_capacity() in enter_scope()
Preallocate some space in the scope variable map. This avoids a bunch
of incremental rehashing in the common case.
2020-04-13 17:27:25 +02:00
Stephan Unverwerth
8f82f6c574 LibJS: Add more number test cases for #1680 2020-04-13 17:23:22 +02:00
Andreas Kling
062d6af16e LibJS: Remove Interpreter::declare_variable()
Since declarations are now hoisted and handled on scope entry, the job
of a VariableDeclaration becomes to actually initialize variables.

As such, we can remove the part where we insert variables into the
nearest relevant scope. Less work == more speed! :^)
2020-04-13 17:22:24 +02:00
Andreas Kling
ac7459cb40 LibJS: Hoist variable declarations to the nearest relevant scope
"var" declarations are hoisted to the nearest function scope, while
"let" and "const" are hoisted to the nearest block scope.

This is done by the parser, which keeps two scope stacks, one stack
for the current var scope and one for the current let/const scope.

When the interpreter enters a scope, we walk all of the declarations
and insert them into the variable environment.

We don't support the temporal dead zone for let/const yet.
2020-04-13 17:22:23 +02:00
Linus Groh
b9415dc0e9 LibJS: Use assertNotReached() in tests 2020-04-13 16:28:50 +02:00
Linus Groh
92a9fe0e49 LibJS: Fix test files indentation (4 spaces) 2020-04-13 16:28:50 +02:00
Andreas Kling
94647fa4ab LibThread: Simplify the userspace Lock to remove CAS on unlock()
Instead of using a separate synchronization variable, just use the lock
holder TID for synchronization. This way, we only need to CAS when
first acquiring a lock.
2020-04-13 12:33:42 +02:00
Andreas Kling
d1ffdea550 LibC: Fix truncated strncpy() in getlogin() 2020-04-13 12:27:05 +02:00
Andreas Kling
dda9ffe906 LibC: Fix truncated strncpy() in /etc/group parsing 2020-04-13 12:27:05 +02:00
Andreas Kling
e3df925e48 LibC: Fix strncpy() overflow in /etc/passwd parsing 2020-04-13 12:27:05 +02:00
Andreas Kling
c1607dc41f LibC: Fix strncpy() overflow in gethostbyname() 2020-04-13 12:27:05 +02:00
Andreas Kling
038fdc2017 LibC: Simplify ASSERT() to reduce code size
Instead of pushing the message, file name, line# and function name
separately, we now mash the message, file name and line# into a string
constant and pass that.

This means that the failure path only has to push a single address onto
the stack, reducing the code size and causing the compiler to inline
many more functions containing an assertions (e.g RefPtr::operator*())

Obviously if you wanted minimal size, you could turn assertions off
entirely, but I really like running with assertions, so let's make
a little effort to reduce their impact. :^)
2020-04-13 12:27:05 +02:00
AnotherTest
8ebee4bce6 LibLine: Update display when deleting forward 2020-04-13 12:26:43 +02:00
Brian Gianforcaro
2a65db7c12
LibJS: Implement Error.prototype.name setter (#1776)
The MDN example for creating a custom error type in javascript uses:

    function CustomError(foo, message, fileName, lineNumber) {
        var instance = new Error(message, fileName, lineNumber);
        instance.name = 'CustomError';
        instance.foo = foo;
        Object.setPrototypeOf(instance, Object.getPrototypeOf(this));
        return instance;
    }

The name property on the Error prototype needs to be settable for
this to work properly.
2020-04-13 11:19:53 +02:00
Stephan Unverwerth
984c290ec0 LibJS: Do not execute scripts with parse errors
This adds missing checks in several LibJS consumers.
2020-04-13 10:42:25 +02:00
Andreas Kling
a0592912c3 LibC: Simplify the gettid() cache by just clearing the cache in fork()
It's hilarious how much better this is.

Thanks to Sergey for suggesting it! :^)
2020-04-13 10:27:14 +02:00
Stephan Unverwerth
bbd592cb6c LibJS: Tweak FunctionPrototype::to_string and constructors
The output of FunctionPrototype::to_string is now more in line
with the output in Firefox. The builtin constructors have been
extended to include their function name in the output.
2020-04-13 01:14:21 +02:00
Brian Gianforcaro
0d41e542b7 LibJS: Throw on assignment of an const variable
Was stubbed out as an assert, should be handled with a runtime exception.
2020-04-13 01:12:31 +02:00
Itamar
50fd2cabff ptrace: Report error in PT_PEEK via errno
The syscall wrapper for ptrace needs to return the peeked value when
using  PT_PEEK.
Because of this, the user has to check errno to detect an error in
PT_PEEK.

This commit changes the actual syscall's interface (only for PT_PEEK) to
allow the syscall wrapper to detect an error and change errno.
2020-04-13 00:53:22 +02:00
Itamar
9e51e295cf ptrace: Add PT_SETREGS
PT_SETTREGS sets the regsiters of the traced thread. It can only be
used when the tracee is stopped.

Also, refactor ptrace.
The implementation was getting long and cluttered the alraedy large
Process.cpp file.

This commit moves the bulk of the implementation to Kernel/Ptrace.cpp,
and factors out peek & poke to separate methods of the Process class.
2020-04-13 00:53:22 +02:00
Itamar
b306ac9b2b ptrace: Add PT_POKE
PT_POKE writes a single word to the tracee's address space.

Some caveats:
- If the user requests to write to an address in a read-only region, we
temporarily change the page's protections to allow it.

- If the user requests to write to a region that's backed by a
SharedInodeVMObject, we replace the vmobject with a PrivateIndoeVMObject.
2020-04-13 00:53:22 +02:00
Itamar
984ff93406 ptrace: Add PT_PEEK
PT_PEEK reads a single word from the tracee's address space and returns
it to the tracer.
2020-04-13 00:53:22 +02:00
Itamar
77f671b462 CPU: Handle breakpoint trap
Also, start working on the debugger app.
2020-04-13 00:53:22 +02:00
AnotherTest
364dbe28d6 LibLine: Remove unused cut_mismatching_chars() function
This is superceded by the suggest() mechanism
2020-04-13 00:49:24 +02:00
AnotherTest
fa0525b8bf LibLine: Autocomplete single suggestions
`cd /h<tab>` -> `cd /home/`, pressing tab after that would
descend into `/home/' and show `/home/anon/`
2020-04-13 00:49:24 +02:00
Linus Groh
62d0fa5af8 LibWeb: Use specific error classes when throwing exceptions
Generally:

- interpreter.throw_exception<JS::Error>("TypeError", "Message");
+ interpreter.throw_exception<JS::TypeError>("Message");
2020-04-13 00:47:53 +02:00
Stephan Unverwerth
f8f65053bd LibJS: Parse "this" as ThisExpression 2020-04-13 00:45:25 +02:00
Andreas Kling
110ca6b0b6 LibJS: Cache a FlyString for "this" to speed up variable lookup
We were hitting strcmp() in every variable lookup to see if the lookup
was for "this". Caching a FlyString("this") turns that check into one
pointer comparison instead. :^)
2020-04-12 20:40:02 +02:00
Andreas Kling
c84b8e597a LibC: Cache the result of gettid() to avoid syscalls
We now use minherit(MAP_INHERIT_ZERO) to create a gettid() cache that
is automatically invalidated on fork(). This is needed since the TID
will be different in a forked child, and so we can't have a stale
cached TID lying around.

This is a gigantic speedup for LibJS (and everyone else too) :^)
2020-04-12 20:24:34 +02:00
Andreas Kling
c19b56dc99 Kernel+LibC: Add minherit() and MAP_INHERIT_ZERO
This patch adds the minherit() syscall originally invented by OpenBSD.
Only the MAP_INHERIT_ZERO mode is supported for now. If set on an mmap
region, that region will be zeroed out on fork().
2020-04-12 20:22:26 +02:00
Andreas Kling
dd00175ae2 LibWeb: Use an AffineTransform for CanvasRenderingContext2D :^)
This will allow us to support complex 2D transforms.
2020-04-12 19:23:39 +02:00
Andreas Kling
6f2c63000d LibGfx: Add a basic AffineTransform class
We can now perform some basic 2D transforms through an affine matrix.
This patch adds translate() and scale() :^)
2020-04-12 19:23:39 +02:00
Andreas Kling
5c780c9ef7 LibGfx: Allow constructing Float{Rect,Point,Size} from integer buddies 2020-04-12 19:23:39 +02:00
Linus Groh
dd7796515f LibJS: Add console.{debug,info,warn,error}() 2020-04-12 18:42:42 +02:00
Hüseyin ASLITÜRK
8e9d031cb3 LibGfx: Add Bitmap::rotated and Bitmap::flipped 2020-04-12 18:08:11 +02:00
Hüseyin ASLITÜRK
c6944f8cc2 LibGUI: Use parrent window icon for MessageBox dialog icon 2020-04-12 18:08:11 +02:00
Andreas Kling
235ae80e5e LibGUI: Make TableView ignore custom colors for selected rows
This allows them to look selected instead.
2020-04-12 15:23:24 +02:00
Linus Groh
97de93eed1 LibJS: Add js_negative_infinity()
Value(-js_infinity().as_double()) is kind of awkward.
2020-04-12 14:39:38 +02:00
Linus Groh
f226746394 LibJS: Handle Infinity in Value::to_number() 2020-04-12 14:39:38 +02:00
Andreas Kling
e880e4c2d2 LibX86: Add a way for Instruction::to_string() to symbolicate addresses
This patch adds a pure virtual X86::SymbolProvider that can be passed
to Instruction::to_string(). If the instruction contains what appears
to be a program address, stringification will try to symbolicate that
address via the SymbolProvider.

This makes it possible (and very flexible) to add symbolication to
clients of the disassembler. :^)
2020-04-12 14:20:04 +02:00
Andreas Kling
5390d53a80 LibGUI: Remove debug spam in AbstractView::did_update_model() 2020-04-12 14:20:04 +02:00
Andreas Kling
8e4751a963 LibGUI: Add a way for models to update without invalidating indexes
This is really just a workaround to keep SystemMonitor's process table
working right wrt selection retention during resorts (while also doing
full index invalidation on things like ProfileViewer inversion.)

It's starting to feel like the model abstraction is not super great
and we'll need a better approach if we want to actually build some more
dynamic functionality into our views.
2020-04-12 12:03:33 +02:00
Andreas Kling
ff33c5b286 LibJS: Let's show a few more decimals when stringifying numeric values
I'm not sure what the correct behavior is supposed to be, but at least
this makes printing numbers show some more interesting detail for now.
2020-04-12 10:59:29 +02:00
Brendan Coles
2d699cd5da LibWeb: Add port blacklist for ResourceLoader::load
`ResourceLoader::load` now rejects URLs which specify a `port`
associated with network services known to be vulnerable to
inter-protocol exploitation.

Fixes #1735
2020-04-12 10:33:35 +02:00
Andreas Kling
34d07e35bd LibX86: Decode RDRAND instruction
I was looking at Kernel::get_good_random_bytes() and wondering where
the RDRAND instruction was. :^)
2020-04-11 23:37:00 +02:00
Andreas Kling
8daddcfa0a LibX86: Fix duplicate '+' in SIB byte disassembly
For SIB bytes with base but no index, we were emitting two '+' chars
which looked very off.
2020-04-11 23:11:10 +02:00
Andrew Kaster
827e375297 LibELF: Validate the mapped file in DynamicLoader constructor
ELF::DynamicLoader now validates the ELF header and the program headers
in its constructor. The requested program interpreter from the
PT_INTERP program header is now avaiable via a getter. The dynamic
loader program will want to check that this matches its name, for extra
shenanigans checking.
2020-04-11 22:41:05 +02:00
Andrew Kaster
61acca223f LibELF: Move validation methods to their own file
These validate_elf_* methods really had no business being static
methods of ELF::Image. Now that the ELF namespace exists, it makes
sense to just move them to be free functions in the namespace.
2020-04-11 22:41:05 +02:00
Andrew Kaster
21b5909dc6 LibELF: Move ELF classes into namespace ELF
This is for consistency with other namespace changes that were made
a while back to the other libraries :)
2020-04-11 22:41:05 +02:00
Brendan Coles
6b0f47683c LibWeb: Prevent http:// URLs loading scripts sourced from file:// URLs
Fixes #1616
2020-04-11 21:10:50 +02:00