Commit graph

434 commits

Author SHA1 Message Date
Ali Mohammad Pur
ea7ba34a31 AK+LibWasm+LibJS: Disallow Variant.has() on types that aren't contained
Checking for this (and get()'ing it) is always invalid, so let's just
disallow it.
This also finds two bugs where the code is checking for types that can
never actually be in the variant (which was actually a refactor
artifact).
2021-06-02 18:02:47 +02:00
Idan Horowitz
de8d081ca4 LibJS: Add the String.prototype.trim{Left, Right} aliases
These are the same as trim{Start, End} respectively.
2021-06-02 09:42:25 +02:00
Linus Groh
e5c0dbc0d4 LibJS: Fix indendation in CMakeLists.txt 2021-06-02 00:14:53 +01:00
Andreas Kling
12a42edd13 Everywhere: codepoint => code point 2021-06-01 10:01:11 +02:00
Andreas Kling
407d6cd9e4 AK: Rename Utf8CodepointIterator => Utf8CodePointIterator 2021-06-01 09:45:52 +02:00
Idan Horowitz
67a5e9f018 LibJS: Add left shift & right shift operator support for BigIntegers
Based on https://tc39.es/ecma262/#sec-numeric-types-bigint-leftShift
(This commit also includes the matching tests)
2021-05-31 19:50:29 +01:00
Ali Mohammad Pur
724b89f90c LibJS: Make missing variable decls in for..in/of a syntax error
...instead of a hard crash :P
2021-05-30 10:34:44 +01:00
Ali Mohammad Pur
e10006b3fa LibJS: Don't try to parse binding patterns after a syntax error
Otherwise we'd be spinning there forever.
2021-05-30 10:34:44 +01:00
Idan Horowitz
6bfeb87572 LibJS: Add String.prototype.anchor & friends
Adds an implementation of the following StringPrototype methods:
anchor, big, blink, bold, fixed, fontcolor, fontsize, italics, link,
small, strike, sub, sup.
2021-05-30 10:32:05 +01:00
Idan Horowitz
09233b9e41 LibJS: Add Date.prototype.{get, set}Year() 2021-05-29 23:42:08 +01:00
Idan Horowitz
96ee5e36ed LibJS: Replace the broken and unused Date::year getter 2021-05-29 23:42:08 +01:00
Ali Mohammad Pur
827d94939b LibJS: Add tests for destructuring assignments and function parameters 2021-05-29 23:02:23 +04:30
Ali Mohammad Pur
7a00d6d9c8 LibJS: Implement destructuring assignments and function parameters 2021-05-29 23:02:23 +04:30
Andrew Kaster
6aba64b60f LibJS: Instrument HeapBlock cell allocation for ASAN
Mark the entirety of a heap block's storage poisoned at construction.
Unpoison all of a Cell's memory before allocating it, and re-poison as
much as possible on deallocation. Unfortunately, the entirety of the
FreelistEntry must be kept unpoisoned in order for reallocation to work
correctly.

Decreasing the size of FreelistEntry or adding a larger redzone to Cells
would make the instrumentation even better.
2021-05-29 17:47:29 +01:00
Andrew Kaster
81a5dcde84 LibJS: Expose minimum possible cell size of JS::Heap
Use this to avoid creating a 16 byte cell allocator on x86_64, where the
size of FreelistEntry is 24 bytes. Every JS::Cell must be at least the
size of the FreelistEntry or things start crashing, so the 16 byte
allocator was wasted on that platform.
2021-05-29 17:47:29 +01:00
Andrew Kaster
07c62f9f42 LibJS: Remove unused HeapBlock private member function
FreelistEntries are constructed manually in deallocate() instead of
using this helper.
2021-05-29 17:47:29 +01:00
Stephan Unverwerth
10ceeb092f Everywhere: Use s.unverwerth@serenityos.org :^) 2021-05-29 12:30:08 +01:00
Andrew Kaster
1ecf2dad4b LibJS: Poison unused heap blocks until they are re-allocated
This is the coarsest grained ASAN instrumentation possible for the LibJS
heap. Future instrumentation could add red-zones to heap block
allocations, and poison the entire heap block and only un-poison used
cells at the CellAllocator level.
2021-05-28 07:59:41 +02:00
Idan Horowitz
ffaf27e4b6 LibJS: Add inline capacity to BlockAllocator's blocks Vector
There's no need to dynamically allocate a constant sized vector :^)
2021-05-28 00:07:24 +01:00
Andreas Kling
b8fd845885 LibJS: Update mmap name after recycling a HeapBlock :^)
Fixes #7507.
2021-05-27 21:24:58 +02:00
Gunnar Beutner
97d0ebba20 LibJS: Make sure aligned_alloc() doesn't return a null pointer
The previous VERIFY() call checked that aligned_alloc() didn't return
MAP_FAILED. When out of memory aligned_alloc() returns a null pointer
so let's check for that instead.
2021-05-27 21:13:57 +02:00
Andreas Kling
14585a9cba LibJS: Remove unused HeapBlock::operator delete() 2021-05-27 20:07:34 +02:00
Andreas Kling
606b483231 LibJS: Make BlockAllocator use free() on non-Serenity platforms
If we use aligned_alloc() to allocate, we have to use free() to free.
2021-05-27 20:06:47 +02:00
Andreas Kling
9b699bad94 LibJS: Rename Allocator => CellAllocator
Now that we have a BlockAllocator as well, it seems appropriate to name
the allocator-that-allocates-cells something more specific to match.
2021-05-27 19:56:12 +02:00
Andreas Kling
e9081a2644 LibJS: Recycle up to 64 HeapBlocks to improve performance :^)
This patch adds a BlockAllocator to the GC heap where we now cache up to
64 HeapBlock-sized mmap's that get recycled when allocating HeapBlocks.

This improves test-js runtime performance by ~35%, pretty cool! :^)
2021-05-27 19:56:04 +02:00
Ali Mohammad Pur
6af596d9e8 LibJS+LibWeb: Make Uint8ClampedArray use TypedArray
Instead of being its own separate unrelated class.
This automatically makes typed array properties available to it,
as well as making it available to the runtime.
2021-05-26 15:34:13 +04:30
Ali Mohammad Pur
4fd43a8f96 LibJS: Allow ArrayBuffer to not own its backing data buffer as well
This is implemented as a ByteBuffer* in a variant, so its size should
only be increased by an index.
2021-05-26 15:34:13 +04:30
Andreas Kling
cfe3895991 LibJS: Fix broken dbgln_if(HEAP_DEBUG) 2021-05-25 19:44:32 +02:00
Andreas Kling
2de9139532 LibJS: Fix clang-tidy warnings about redundant types in Heap.cpp 2021-05-25 19:04:15 +02:00
Andreas Kling
679fc3066c LibJS: Fix clang-tidy warnings about unnecessary move()s in VM.cpp 2021-05-25 18:52:00 +02:00
Andreas Kling
47a4b2ba9f LibJS: Make Value::as_cell() return a Cell& 2021-05-25 18:48:11 +02:00
Andreas Kling
0de954e86b LibJS: Make Cell::Visitor::visit_impl() take a Cell&
Passing a null cell pointer is not supported.
2021-05-25 18:39:01 +02:00
Andreas Kling
789d20ebb7 LibJS: Replace Cell live bit with a cell state
So far we only have two states: Live and Dead. In the future, we can
add additional states to support incremental sweeping and/or multi-
stage cell destruction.
2021-05-25 18:37:37 +02:00
Andreas Kling
91656d63c7 LibJS: Inline Cell::Visitor::visit() functions
This allows the calls to MarkingVisitor::visit_impl() during GC to be
devirtualized in Heap::mark_live_cells().
2021-05-25 18:18:48 +02:00
Andreas Kling
de395a3df2 AK+Everywhere: Consolidate String::index_of() and String::find()
We had two functions for doing mostly the same thing. Combine both
of them into String::find() and use that everywhere.

Also add some tests to cover basic behavior.
2021-05-24 11:59:18 +02:00
Luke
4d34802f74 LibJS: Expose TypedArray.prototype.byteOffset 2021-05-21 22:52:35 +01:00
Luke
58afd71ad2 LibJS: Expose TypedArray.prototype.byteLength 2021-05-21 22:52:35 +01:00
Luke
8004a2dc77 LibJS: Expose TypedArray.prototype.buffer 2021-05-21 22:52:35 +01:00
Luke
6f1688279a LibJS: Expose BYTES_PER_ELEMENT on each TypedArray 2021-05-21 22:52:35 +01:00
Linus Groh
3a4cbbf01c LibJS: Fix indexed access of TypedArray with byte offset
By doing the offset calculation in {get,put}_by_index() we would
delegate these operations to Object for any index >= (array length -
byte offset). By doing the offset calculation in data() instead, we can
just use the unaltered property index for indexing the returned Span.
In other words: data()[0] now returns the same value as indexing the
TypedArray at index 0 in JS.

This also fixes a bug in the js REPL which would not consider the byte
offset and subsequently access the underlying ArrayBuffer data with a
wrong index.
2021-05-21 19:29:23 +01:00
Linus Groh
d60ebbbba6 Revert "Userland: static vs non-static constexpr variables"
This reverts commit 800ea8ea96.

Booting the system no longer worked after these changes.
2021-05-21 10:30:52 +01:00
Lenny Maiorani
800ea8ea96 Userland: static vs non-static constexpr variables
Problem:
- `static` variables consume memory and sometimes are less
  optimizable.
- `static const` variables can be `constexpr`, usually.
- `static` function-local variables require an initialization check
  every time the function is run.

Solution:
- If a global `static` variable is only used in a single function then
  move it into the function and make it non-`static` and `constexpr`.
- Make all global `static` variables `constexpr` instead of `const`.
- Change function-local `static const[expr]` variables to be just
  `constexpr`.
2021-05-21 10:07:06 +01:00
Andreas Kling
3ee092cd0c LibJS: Implement Object.hasOwn() :^)
This is currently a TC39 Stage 2 proposal, but let's go for it!

https://github.com/tc39/proposal-accessible-object-hasownproperty

I wrote the C++, @linusg found bugs and wrote the test.
2021-05-18 11:18:19 +02:00
Linus Groh
63e8477a6b LibJS: Handle OOB access in GenericIndexedPropertyStorage::take_last()
We already do this for the SimpleIndexedPropertyStorage, so for indexed
properties with GenericIndexedPropertyStorage this would previously
crash. Since overwriting the array-like size with a larger value won't
magically insert values at previously unset indices, we need to handle
such an out of bounds access gracefully and just return an empty value.

Fixes #7043.
2021-05-17 23:20:29 +01:00
Linus Groh
c15121fef7 LibJS: Make length_setter_generic_storage_threshold a global constant
This was a bit hard to find as a local variable - rename it to uppercase
LENGTH_SETTER_GENERIC_STORAGE_THRESHOLD and move it to the top (next to
SPARSE_ARRAY_HOLE_THRESHOLD) for good visibility.
2021-05-17 23:15:18 +01:00
Andreas Kling
e0493c509e LibJS: Make the forward transition chain weakly cached
Before this patch, every shape would permanently remember every other
shape it had ever transitioned to. This could lead to pathological
accumulation of unused shape objects in some cases.

Fix this by using WeakPtr instead of a strongly visited Shape* in the
the forward transition chain map. This means that we will now miss out
on some shape sharing opportunities, but since this is not required
for correctness it doesn't matter.

Note that the backward transition chain is still strongly cached,
as it's necessary for the reification of property tables.

An interesting future optimization could be to allow property tables
to get garbage collected (by detaching them from the shape object)
and then reconstituted from the backwards transition chain (if needed.)
2021-05-17 21:40:18 +02:00
Andreas Kling
751ad19c86 LibJS: Don't consider cells in the lazy freelist in conservative scan
Cells after the lazy freelist bump index are guaranteed to not be
valid cell pointers, so ignore them during the conservative scan.
2021-05-17 19:57:40 +02:00
Andreas Kling
aa857bcdeb LibJS: Always prefer freelist over lazy freelist if possible
If we're able to allocate cells from a freelist, we should always
prefer that over the lazy freelist, since this may further defer
faulting in additional memory for the HeapBlock.

Thanks to @gunnarbeutner for pointing this out. :^)
2021-05-17 19:53:00 +02:00
Andreas Kling
6714cf3631 LibJS: Move Cell.{cpp,h} from Runtime/ to Heap/ 2021-05-17 19:53:00 +02:00
Andreas Kling
c2d9cd8d53 LibJS: Implement lazy freelist allocation for cells
HeapBlock now implements the same lazy freelist as LibC malloc() does,
where new blocks start out in a "bump allocator" mode that gets used
until we've bump-allocated all the way to the end of the block.

Then we fall back to the old freelist style as before.

This means we don't have to pre-initialize the freelist on HeapBlock
construction. This defers page faults and reduces memory usage for
blocks where all cells don't get used. :^)
2021-05-17 19:30:12 +02:00