Commit graph

17 commits

Author SHA1 Message Date
ayeteadoe
3df8e00d91 LibWeb: Enable EXPLICIT_SYMBOL_EXPORT 2025-08-23 16:04:36 -06:00
CountBleck
d0d5bffb2d LibWeb: Implement resizable ArrayBuffers for Wasm memories
This commit adds the toResizableBuffer() and toFixedLengthBuffer()
methods to WebAssembly.Memory. This includes the necessary hook to
HostResizeArrayBuffer. Some modifications to function signatures in
LibWeb/WebAssembly/Memory.h were also made (changing the return type
from WebIDL::ExceptionOr to JS::ThrowCompletionOr) to allow the use of
some code in the aforementioned hook.

Note: the hook for HostGrowSharedArrayBuffer isn't implemented, since
LibJS doesn't seem to have complete support for growable
SharedArrayBuffers; the relevant methods/getters don't even exist on
the prototype, let alone HostGrowSharedArrayBuffer!

This should help pass the WebAssembly.Memory WPT tests included in
Interop 2025, except those pertaining to growable SharedArrayBuffers.
2025-08-23 08:26:23 +02:00
CountBleck
f2a170bcfb LibWeb: Implement the WebAssembly "Memory object cache" + other changes
This cache is referenced by a few parts of the JS API spec, including
the threads spec (such as in toFixedLengthBuffer), as well as the
"refresh the Memory buffer" algorithm, which was implemented as a method
of Memory before this change.

Now, this algorithm can be implemented in a spec-like fashion (though it
mostly seems to add extra complexity). This change also fixes a bug
where memories that were re-exported from an imported WebAssembly.Memory
were given a distinct WebAssembly.Memory object, since the caching that
existed in Instance.cpp was instance-local, not global to the realm.

We also make Memory::m_buffer non-lazy, since we have to implement
"initialize a memory object" correctly anyway.
2025-08-23 08:26:23 +02:00
Timothy Flynn
70db474cf0 LibJS+LibWeb: Port interned bytecode strings to UTF-16
This was almost a no-op, except we intern JS exception messages. So the
bulk of this patch is porting exception messages to UTF-16.
2025-08-14 10:27:08 +02:00
Luke Wilde
4d34095b0a LibWeb/Wasm: Return Hash{Map,Table} caches by const reference
When loading Infiltrating the Airship in Ruffle, the copying of these
hash maps/tables were at least 10% of the runtime. This disappears when
returning them by const reference.
2025-08-08 16:30:37 +02:00
Ali Mohammad Pur
1ef536194d LibWeb/WebAssembly: Avoid scanning all externs when resolving references
This was very hot on a profile of ruffle.
2025-08-08 12:54:06 +02:00
Timothy Flynn
0efa98a57a LibJS+LibWeb+WebContent: Port JS::PropertyKey to UTF-16
This has quite a lot of fall out. But the majority of it is just type or
UDL substitution, where the changes just fall through to other function
calls.

By changing property key storage to UTF-16, the main affected areas are:
* NativeFunction names must now be UTF-16
* Bytecode identifiers must now be UTF-16
* Module/binding names must now be UTF-16
2025-08-05 07:07:15 -04:00
Timothy Flynn
27d139e817 LibWeb: Define Wasm native errors correctly
Some checks are pending
CI / macOS, arm64, Sanitizer, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
1. Fix typos in some macro invocations of these error types. We now use
   a single xmacro to instantiate error definitions to prevent such
   errors in the future.

2. Use the "WebAssembly." prefix as needed.

3. Allocate the error constructors and prototypes with `realm.create`
   rather than `heap.allocate`. The latter does not invoke `initialize`
   methods. This exposed the next issue:

4. Use the correct intrinsic prototype in the error constructor. We were
   using the base native error prototype. We unfortunately cannot invoke
   OrdinaryCreateFromConstructor from LibJS directly with the correct
   prototype, so an implementation was added here.

5. Use intrinsic accessors to create the constructors. I don't think
   this one was actually a fix, but it makes the setup look more like
   other built-ins.
2025-07-19 16:48:01 -04:00
Luke Wilde
0cff47828d LibWeb/CSP: Implement the script-src directive 2025-07-09 15:52:54 -06:00
Timothy Flynn
7280ed6312 Meta: Enforce newlines around namespaces
This has come up several times during code review, so let's just enforce
it using a new clang-format 20 option.
2025-05-14 02:01:59 -06:00
Ali Mohammad Pur
333ba93d49 LibWeb/WebAssembly: Define the hacky 'native' errors given in the spec
These cannot be implemented "correctly" as the set of native errors as
defined by ecma262 is closed, but we can get pretty close.
2025-05-08 03:35:11 -06:00
Andreas Kling
5290dcf650 LibJS: Don't create a GC::Function for every JS::NativeFunction
Instead, let JS::NativeFunction store the AK::Function directly, and
take care of conservatively marking its captured data.

This avoids an extra GC allocation for every JS::NativeFunction.
2025-04-20 18:43:11 +02:00
Andreas Kling
46a5710238 LibJS: Use FlyString in PropertyKey instead of DeprecatedFlyString
This required dealing with *substantial* fallout.
2025-03-24 22:27:17 +00:00
Andrew Kaster
44e3817219 LibWeb: Add WebAssembly.Global and exports support for global instances 2024-12-24 15:20:28 +01:00
Ali Mohammad Pur
e32a9b2c6f LibWeb/WebAssembly: Use wasm funcaddr of exported functions on import
Previously this was proxying the call through javascript, which lead to
unexpected crashes when functions returned things that js-api did not
like.
This commit also adds in the spec comments and fixes a few inaccuracies
that were present in the process.
2024-12-21 20:16:12 +01:00
Shannon Booth
f87041bf3a LibGC+Everywhere: Factor out a LibGC from LibJS
Resulting in a massive rename across almost everywhere! Alongside the
namespace change, we now have the following names:

 * JS::NonnullGCPtr -> GC::Ref
 * JS::GCPtr -> GC::Ptr
 * JS::HeapFunction -> GC::Function
 * JS::CellImpl -> GC::Cell
 * JS::Handle -> GC::Root
2024-11-15 14:49:20 +01:00
Timothy Flynn
93712b24bf Everywhere: Hoist the Libraries folder to the top-level 2024-11-10 12:50:45 +01:00
Renamed from Userland/Libraries/LibWeb/WebAssembly/WebAssembly.h (Browse further)