/
githubmirror
/
node
Обзор
Документация
Войти
/
githubmirror
/
node
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
deps/v8/src/objects/name.tq
134 строки
4 KB
Joyee Cheung
build,test: test array index hash collision
24 апр 2026, 19:01
Не верифицирован
24 апр 2026, 19:01
fff9a8a
Код
Авторство
О чём код?
// Copyright 2019 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @abstract @cppObjectLayoutDefinition extern class Name extends PrimitiveHeapObject { raw_hash_field: NameHash; } bitfield struct NameHash extends uint32 { hash_field_type: HashFieldType: 2 bit; array_index_value: uint32: 24 bit; array_index_length: uint32: 6 bit; } // This is the same as Name, but with the information that there are no other // kinds of names. type AnyName = PrivateSymbol|PublicSymbol|String; extern enum PrivateSymbolKind extends uint8 { kPublic, kInternal, kFieldName, kBrand } bitfield struct SymbolFlags extends uint32 { private_symbol_kind: PrivateSymbolKind: 2 bit; is_well_known_symbol: bool: 1 bit; is_in_public_symbol_table: bool: 1 bit; is_interesting_symbol: bool: 1 bit; } @cppObjectLayoutDefinition extern class Symbol extends Name { flags: SymbolFlags; description: String|Undefined; } type PublicSymbol extends Symbol; type PrivateSymbol extends Symbol; const kMaxCachedArrayIndexLength: constexpr uint32 generates 'Name::kMaxCachedArrayIndexLength'; const kMaxArrayIndexSize: constexpr uint32 generates 'Name::kMaxArrayIndexSize'; const kNofHashBitFields: constexpr int31 generates 'Name::HashFieldTypeBits::kSize'; const kArrayIndexValueBits: constexpr int31 generates 'Name::kArrayIndexValueBits'; const kDoesNotContainCachedArrayIndexMask: constexpr uint32 generates 'Name::kDoesNotContainCachedArrayIndexMask'; const kNameEmptyHashField: NameHash = NameHash{ hash_field_type: HashFieldType::kEmpty, array_index_value: 0, array_index_length: 0 }; macro ContainsCachedArrayIndex(hash: uint32): bool { return (hash & kDoesNotContainCachedArrayIndexMask) == 0; } @if(V8_ENABLE_SEEDED_ARRAY_INDEX_HASH) extern macro SeedArrayIndexValue(uint32): uint32; @if(V8_ENABLE_SEEDED_ARRAY_INDEX_HASH) extern macro UnseedArrayIndexValue(uint32): uint32; const kArrayIndexValueBitsShift: uint32 = kNofHashBitFields; const kArrayIndexLengthBitsShift: uint32 = kNofHashBitFields + kArrayIndexValueBits; macro TenToThe(exponent: uint32): uint32 { dcheck(exponent <= 9); let answer: int32 = 1; for (let i: int32 = 0; i < Signed(exponent); i++) { answer = answer * 10; } return Unsigned(answer); } macro IsIntegerIndex(hash: NameHash): bool { return hash.hash_field_type == HashFieldType::kIntegerIndex; } // This is in sync with the private StringHasher::MakeArrayIndexHash without // seeding. Do not call directly, use the @export MakeArrayIndexHash wrapper // below. macro MakeArrayIndexHashRaw(value: uint32, length: uint32): NameHash { dcheck(length <= kMaxArrayIndexSize); const one: uint32 = 1; dcheck(TenToThe(kMaxCachedArrayIndexLength) < (one << kArrayIndexValueBits)); let rawHash: uint32 = value; rawHash = (rawHash << kArrayIndexValueBitsShift) | (length << kArrayIndexLengthBitsShift); dcheck( (length <= kMaxCachedArrayIndexLength) == ContainsCachedArrayIndex(rawHash)); const hash: NameHash = %RawDownCast<NameHash>(rawHash); dcheck(IsIntegerIndex(hash)); return hash; } // This is in sync with the private StringHasher::DecodeArrayIndexFromHashField // without seeding. Do not call directly, use the @export // DecodeArrayIndexFromHashField wrapper below. macro DecodeArrayIndexFromHashFieldRaw(rawHashField: uint32): uint32 { const hash: NameHash = %RawDownCast<NameHash>(rawHashField); dcheck(ContainsCachedArrayIndex(rawHashField) || IsIntegerIndex(hash)); return hash.array_index_value; } // Mirror C++ public StringHasher::MakeArrayIndexHash. @export macro MakeArrayIndexHash(value: uint32, length: uint32): NameHash { @if(V8_ENABLE_SEEDED_ARRAY_INDEX_HASH) { return MakeArrayIndexHashRaw(SeedArrayIndexValue(value), length); } @ifnot(V8_ENABLE_SEEDED_ARRAY_INDEX_HASH) { return MakeArrayIndexHashRaw(value, length); } } // Mirror C++ public StringHasher::DecodeArrayIndexFromHashField. @export macro DecodeArrayIndexFromHashField(rawHashField: uint32): uint32 { const value: uint32 = DecodeArrayIndexFromHashFieldRaw(rawHashField); @if(V8_ENABLE_SEEDED_ARRAY_INDEX_HASH) { return UnseedArrayIndexValue(value); } @ifnot(V8_ENABLE_SEEDED_ARRAY_INDEX_HASH) { return value; } }