diff options
author | Kenneth Myhra <kennethmyhra@gmail.com> | 2023-02-23 18:58:56 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2023-02-24 19:24:39 +0100 |
commit | a8cef1fa06624ea215bded432c60925716135b2c (patch) | |
tree | b39bbe7b930e06a81eb0c12f8cd9042d057f2adb | |
parent | 450ffbe612985b14fe24104ce933df921052a1c6 (diff) | |
download | serenity-a8cef1fa06624ea215bded432c60925716135b2c.zip |
LibWeb: Port Crypto to new String
-rw-r--r-- | Userland/Libraries/LibWeb/Crypto/Crypto.cpp | 16 | ||||
-rw-r--r-- | Userland/Libraries/LibWeb/Crypto/Crypto.h | 2 |
2 files changed, 10 insertions, 8 deletions
diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp index 7797876daf..139c6bf2ed 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.cpp +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.cpp @@ -68,8 +68,10 @@ WebIDL::ExceptionOr<JS::Value> Crypto::get_random_values(JS::Value array) const } // https://w3c.github.io/webcrypto/#dfn-Crypto-method-randomUUID -DeprecatedString Crypto::random_uuid() const +WebIDL::ExceptionOr<String> Crypto::random_uuid() const { + auto& vm = realm().vm(); + // 1. Let bytes be a byte sequence of length 16. u8 bytes[16]; @@ -111,12 +113,12 @@ DeprecatedString Crypto::random_uuid() const ยป. */ StringBuilder builder; - builder.appendff("{:02x}{:02x}{:02x}{:02x}-", bytes[0], bytes[1], bytes[2], bytes[3]); - builder.appendff("{:02x}{:02x}-", bytes[4], bytes[5]); - builder.appendff("{:02x}{:02x}-", bytes[6], bytes[7]); - builder.appendff("{:02x}{:02x}-", bytes[8], bytes[9]); - builder.appendff("{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15]); - return builder.to_deprecated_string(); + TRY_OR_THROW_OOM(vm, builder.try_appendff("{:02x}{:02x}{:02x}{:02x}-", bytes[0], bytes[1], bytes[2], bytes[3])); + TRY_OR_THROW_OOM(vm, builder.try_appendff("{:02x}{:02x}-", bytes[4], bytes[5])); + TRY_OR_THROW_OOM(vm, builder.try_appendff("{:02x}{:02x}-", bytes[6], bytes[7])); + TRY_OR_THROW_OOM(vm, builder.try_appendff("{:02x}{:02x}-", bytes[8], bytes[9])); + TRY_OR_THROW_OOM(vm, builder.try_appendff("{:02x}{:02x}{:02x}{:02x}{:02x}{:02x}", bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15])); + return TRY_OR_THROW_OOM(vm, builder.to_string()); } void Crypto::visit_edges(Cell::Visitor& visitor) diff --git a/Userland/Libraries/LibWeb/Crypto/Crypto.h b/Userland/Libraries/LibWeb/Crypto/Crypto.h index 7811736aaa..bbef73827e 100644 --- a/Userland/Libraries/LibWeb/Crypto/Crypto.h +++ b/Userland/Libraries/LibWeb/Crypto/Crypto.h @@ -23,7 +23,7 @@ public: JS::NonnullGCPtr<SubtleCrypto> subtle() const; WebIDL::ExceptionOr<JS::Value> get_random_values(JS::Value array) const; - DeprecatedString random_uuid() const; + WebIDL::ExceptionOr<String> random_uuid() const; protected: virtual JS::ThrowCompletionOr<void> initialize(JS::Realm&) override; |