Commit graph

32 commits

Author SHA1 Message Date
Tim Ledbetter
48a3a02238 LibCrypto: Make constructing a BigInteger from string fallible
Previously, constructing a `UnsignedBigInteger::from_base()` could
produce an incorrect result if the input string contained a valid
Base36 digit that was out of range of the given base. The same method
would also crash if the input string contained an invalid Base36 digit.
An error is now returned in both these cases.

Constructing a BigFraction from string is now also fallible, so that we
can handle the case where we are given an input string with invalid
digits.
2024-01-13 19:01:35 -07:00
Timothy Flynn
9258d7b98a LibJS+LibWeb: Implement resizable ArrayBuffer support for TypedArray
This is (part of) a normative change in the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/a9ae96e
2023-12-26 11:16:10 +01:00
Timothy Flynn
c7fec9424c LibJS+LibWeb: Implement resizable ArrayBuffer support for DataView
This is (part of) a normative change in the ECMA-262 spec. See:
https://github.com/tc39/ecma262/commit/a9ae96e
2023-12-26 11:16:10 +01:00
Andrew Kaster
c0f50b12a4 LibWeb: Post all MessagePort messages over their LocalSockets
This is to allow future changes to do cross-process MessagePorts in an
implementation-agnostic way. Add some tests for this behavior.

Delivering messages that were posted to a MessagePort just before it was
transferred is not yet implemented still.
2023-12-20 12:25:40 -07:00
Andrew Kaster
6e3b816763 LibWeb: Represent transferred objects as an empty object
This matches the behavior of the three major engines.
2023-12-20 12:25:40 -07:00
Andrew Kaster
f68c67bf3f LibWeb: Implement MessagePort.postMessage closer to the spec
Use a LocalSocket to represent the connection between two message ports.

The concept of the port message queue is still missing, however. When
that concept is implemented, the "steps" in step 7 of the message port
transfer steps will need to send the serialized data over the connected
socketpair and run in the event loop of the process that holds onto the
other side of the message port. Doing this should allow centralizing the
behavior of postMessage for Window, MessagePorts and Workers.
2023-12-19 21:08:05 +01:00
Andrew Kaster
d361221657 LibJS+LibWeb: Add JS::Value constructor for `JS::Handle<T>`
Similar to the constructors for ``JS::{Nonnull}GCPtr<T>``, this helper
avoids unnecessary .ptr() clutter when we want to construct Values.
2023-12-19 09:21:55 -07:00
Ali Mohammad Pur
5e1499d104 Everywhere: Rename {Deprecated => Byte}String
This commit un-deprecates DeprecatedString, and repurposes it as a byte
string.
As the null state has already been removed, there are no other
particularly hairy blockers in repurposing this type as a byte string
(what it _really_ is).

This commit is auto-generated:
  $ xs=$(ack -l \bDeprecatedString\b\|deprecated_string AK Userland \
    Meta Ports Ladybird Tests Kernel)
  $ perl -pie 's/\bDeprecatedString\b/ByteString/g;
    s/deprecated_string/byte_string/g' $xs
  $ clang-format --style=file -i \
    $(git diff --name-only | grep \.cpp\|\.h)
  $ gn format $(git ls-files '*.gn' '*.gni')
2023-12-17 18:25:10 +03:30
Andrew Kaster
84ac6a454f LibWeb: Use `Vector<Handle<Object>>` in transfer variants of serialize
Also trap the invalid object index inserted for transferred values in
deserialization. In the future we should avoid inserting that
placeholder value in the data stream at all.
2023-12-14 08:36:11 -07:00
Andrew Kaster
bab9e75a96 LibWeb: Implement Structured{De}SerializeWithTransfer for transferables
This first cut at these APIs only works for platform objects that
implement the Transferable interface from Bindings.
2023-12-09 21:52:28 +01:00
Idan Horowitz
20734ac335 LibWeb: Support [de]serialization for {Map, Set, Object, Array} objects 2023-11-11 22:18:41 +01:00
Idan Horowitz
4e89ec7fd5 LibWeb: Throw more specific serialization errors for some object types 2023-11-11 22:18:41 +01:00
Idan Horowitz
1d24e08934 LibWeb: Support [de]serialization for Error objects 2023-11-11 22:18:41 +01:00
Tobias Soppa
9267e24741 LibJS+LibWeb: Track SharedArrayBuffers' shared state
ArrayBuffer no longer stores a plain ByteBuffer internally, but a
DataBlock instead, which encapsulated the ByteBuffer together with
information if it is shared or not.
2023-09-17 16:29:21 -06:00
Andrew Kaster
5ae9b2fdaf LibWeb: Add {de}serialization steps for TypedArrayBuffers and DataViews 2023-09-13 08:49:09 +02:00
Andrew Kaster
bddf3fbf2d LibWeb: Make StructuredSerialize/Deserialize friendlier to recursion
Make the internal calls take objects by reference, and take writable
spans into data rather than const& to the underlying vector type.
2023-09-13 08:49:09 +02:00
Andrew Kaster
642802d339 LibWeb: Add {de}serialization steps for ArrayBuffers 2023-09-12 22:14:39 +02:00
Andrew Kaster
a527f55768 LibWeb: Create StructuredSerialize helpers for Bytes
Call them from the helpers for strings. We'll have other object classes
soon that need to serialize ByteBuffers, so let's take advantage of the
encoding scheme we are already using for Strings.
2023-09-12 22:14:39 +02:00
Andrew Kaster
267074cd81 LibWeb: Add {de}serialization steps for RegExpObjects
We skip serializing any of the internal state of the Regex<ECMA262>
object, because that state is all computable from the input pattern
and flags. If it turns out that this is really, really slow, we can add
some optimizations to serialize more of the regex parse result.
2023-09-12 22:14:39 +02:00
Andrew Kaster
3a74bd2509 LibWeb: Don't try to deserialize past length of strings
If we serialize a string followed by some other object, the deserialize
helper would just happily keep appending bytes to the string until the
end of the serialization buffer. Avoid doing that by checking the string
length for figuring out when the string actually ends.
2023-09-12 22:14:39 +02:00
Shannon Booth
41928c2902 LibWeb: Port DOMException interface from DeprecatedString to String 2023-09-06 11:44:45 -04:00
Andrew Kaster
b3bd232a5e LibWeb: Implement StructuredSerialize for BigIntObject and Symbol 2023-08-22 13:08:08 +02:00
Andrew Kaster
f3cf7496a1 LibWeb: Add spec steps to StructuredSerialize
In preparation for serializing more types, let's move the implementation
closer to the steps in the spec.
2023-08-22 13:08:08 +02:00
Andreas Kling
72c9f56c66 LibJS: Make Heap::allocate<T>() infallible
Stop worrying about tiny OOMs. Work towards #20449.

While going through these, I also changed the function signature in many
places where returning ThrowCompletionOr<T> is no longer necessary.
2023-08-13 15:38:42 +02:00
Andreas Kling
c084269e5f LibJS: Make PrimitiveString::utf8_string() infallible
Work towards #20449.
2023-08-09 17:09:16 +02:00
Kenneth Myhra
cf2c2cb4d7 LibWeb: Make sure we fallback to "Unsupported type" if type unrecognized
If we do not recognize the Type being serialized make sure we always
fallback to setting m_error to "Unsupported type".
2023-08-02 14:52:37 +02:00
Kenneth Myhra
7da055e3e1 LibWeb: Remove unused headers in StructuredSerialize.cpp 2023-07-31 10:41:38 +02:00
Kenneth Myhra
9a007ccdbe LibWeb: Serialize strings into a more storage efficient format
This patch changes the way StructuredSerializeInternal() serialize
strings by storing four bytes into a 32-bit entry, instead of one code
point per 32-bit entry.

StructuredDeserialize() has also been changed to deserialize strings by
the same ruleset.
2023-07-31 10:41:38 +02:00
Kenneth Myhra
77e339022b LibWeb: Serialize and deserialize standard built-in objects
This adds support for serializing and deserializing standard built-in
objects:
- Boolean object
- Number object
- String object
- Date object
2023-07-29 17:24:39 +02:00
Kenneth Myhra
8c88e8f896 LibWeb: Add primitive support to Structured{Serialize,Deserialize}
This adds support for Undefined, Null, Boolean, BigInt, and String to
AOs StructuredSerializeInternal and StructuredDeserialize.
2023-07-23 06:37:14 +02:00
Ali Mohammad Pur
06c6c40df9 LibWeb+LibJS: Move some code around to make CSS/Parser parse faster
This makes it possible to include fewer full definitions of things,
which makes the file about 30% faster to compile.
2023-07-11 09:38:37 +03:30
Daniel Ehrenberg
09841f56ed LibWeb: Add initial implementation of structured clone
This implementation only works for cloning Numbers, and does not try to
do all the spec steps for structured serialize and deserialize.

Co-Authored-By: Andrew Kaster <akaster@serenityos.org>
2022-11-26 00:47:23 +01:00