ladybird/Userland/Libraries/LibJS/Runtime/ValueTraits.h
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

46 lines
1.6 KiB
C++

/*
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2020-2022, Idan Horowitz <idan.horowitz@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <LibJS/Runtime/BigInt.h>
#include <LibJS/Runtime/PrimitiveString.h>
#include <LibJS/Runtime/Value.h>
namespace JS {
struct ValueTraits : public Traits<Value> {
static unsigned hash(Value value)
{
VERIFY(!value.is_empty());
if (value.is_string()) {
// FIXME: Propagate this error.
return value.as_string().byte_string().hash();
}
if (value.is_bigint())
return value.as_bigint().big_integer().hash();
if (value.is_negative_zero())
value = Value(0);
// In the IEEE 754 standard a NaN value is encoded as any value from 0x7ff0000000000001 to 0x7fffffffffffffff,
// with the least significant bits (referred to as the 'payload') carrying some kind of diagnostic information
// indicating the source of the NaN. Since ECMA262 does not differentiate between different kinds of NaN values,
// Sets and Maps must not differentiate between them either.
// This is achieved by replacing any NaN value by a canonical qNaN.
else if (value.is_nan())
value = js_nan();
return u64_hash(value.encoded()); // FIXME: Is this the best way to hash pointers, doubles & ints?
}
static bool equals(const Value a, const Value b)
{
return same_value_zero(a, b);
}
};
}