Commit 1dbe6148 authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[web snapshot] Implement WriteByte

Bug: v8:11525
Change-Id: I227f0bb852e56551ec0333db52061842664c47c9
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3706963
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81259}
parent 1de7e249
...@@ -384,6 +384,13 @@ Maybe<bool> ValueSerializer::ExpandBuffer(size_t required_capacity) { ...@@ -384,6 +384,13 @@ Maybe<bool> ValueSerializer::ExpandBuffer(size_t required_capacity) {
} }
} }
void ValueSerializer::WriteByte(uint8_t value) {
uint8_t* dest;
if (ReserveRawBytes(sizeof(uint8_t)).To(&dest)) {
*dest = value;
}
}
void ValueSerializer::WriteUint32(uint32_t value) { void ValueSerializer::WriteUint32(uint32_t value) {
WriteVarint<uint32_t>(value); WriteVarint<uint32_t>(value);
} }
...@@ -1337,6 +1344,13 @@ Maybe<base::Vector<const uint8_t>> ValueDeserializer::ReadRawBytes( ...@@ -1337,6 +1344,13 @@ Maybe<base::Vector<const uint8_t>> ValueDeserializer::ReadRawBytes(
return Just(base::Vector<const uint8_t>(start, size)); return Just(base::Vector<const uint8_t>(start, size));
} }
bool ValueDeserializer::ReadByte(uint8_t* value) {
if (static_cast<size_t>(end_ - position_) < sizeof(uint8_t)) return false;
*value = *position_;
position_++;
return true;
}
bool ValueDeserializer::ReadUint32(uint32_t* value) { bool ValueDeserializer::ReadUint32(uint32_t* value) {
return ReadVarint<uint32_t>().To(value); return ReadVarint<uint32_t>().To(value);
} }
......
...@@ -84,6 +84,7 @@ class ValueSerializer { ...@@ -84,6 +84,7 @@ class ValueSerializer {
void WriteUint64(uint64_t value); void WriteUint64(uint64_t value);
void WriteRawBytes(const void* source, size_t length); void WriteRawBytes(const void* source, size_t length);
void WriteDouble(double value); void WriteDouble(double value);
void WriteByte(uint8_t value);
/* /*
* Indicate whether to treat ArrayBufferView objects as host objects, * Indicate whether to treat ArrayBufferView objects as host objects,
...@@ -239,6 +240,7 @@ class ValueDeserializer { ...@@ -239,6 +240,7 @@ class ValueDeserializer {
bool ReadUint64(uint64_t* value) V8_WARN_UNUSED_RESULT; bool ReadUint64(uint64_t* value) V8_WARN_UNUSED_RESULT;
bool ReadDouble(double* value) V8_WARN_UNUSED_RESULT; bool ReadDouble(double* value) V8_WARN_UNUSED_RESULT;
bool ReadRawBytes(size_t length, const void** data) V8_WARN_UNUSED_RESULT; bool ReadRawBytes(size_t length, const void** data) V8_WARN_UNUSED_RESULT;
bool ReadByte(uint8_t* value) V8_WARN_UNUSED_RESULT;
private: private:
friend class WebSnapshotDeserializer; friend class WebSnapshotDeserializer;
......
...@@ -110,7 +110,7 @@ void WebSnapshotSerializerDeserializer::IterateBuiltinObjects( ...@@ -110,7 +110,7 @@ void WebSnapshotSerializerDeserializer::IterateBuiltinObjects(
static_assert(kBuiltinObjectCount == 12); static_assert(kBuiltinObjectCount == 12);
} }
uint32_t WebSnapshotSerializerDeserializer::FunctionKindToFunctionFlags( uint8_t WebSnapshotSerializerDeserializer::FunctionKindToFunctionFlags(
FunctionKind kind) { FunctionKind kind) {
// TODO(v8:11525): Support more function kinds. // TODO(v8:11525): Support more function kinds.
switch (kind) { switch (kind) {
...@@ -147,7 +147,7 @@ uint32_t WebSnapshotSerializerDeserializer::FunctionKindToFunctionFlags( ...@@ -147,7 +147,7 @@ uint32_t WebSnapshotSerializerDeserializer::FunctionKindToFunctionFlags(
// TODO(v8:11525): Optionally, use an enum instead. // TODO(v8:11525): Optionally, use an enum instead.
FunctionKind WebSnapshotSerializerDeserializer::FunctionFlagsToFunctionKind( FunctionKind WebSnapshotSerializerDeserializer::FunctionFlagsToFunctionKind(
uint32_t flags) { uint8_t flags) {
FunctionKind kind; FunctionKind kind;
if (IsFunctionOrMethod(flags)) { if (IsFunctionOrMethod(flags)) {
if (ArrowFunctionBitField::decode(flags) && MethodBitField::decode(flags)) { if (ArrowFunctionBitField::decode(flags) && MethodBitField::decode(flags)) {
...@@ -215,7 +215,7 @@ FunctionKind WebSnapshotSerializerDeserializer::FunctionFlagsToFunctionKind( ...@@ -215,7 +215,7 @@ FunctionKind WebSnapshotSerializerDeserializer::FunctionFlagsToFunctionKind(
return kind; return kind;
} }
bool WebSnapshotSerializerDeserializer::IsFunctionOrMethod(uint32_t flags) { bool WebSnapshotSerializerDeserializer::IsFunctionOrMethod(uint8_t flags) {
uint32_t mask = AsyncFunctionBitField::kMask | uint32_t mask = AsyncFunctionBitField::kMask |
GeneratorFunctionBitField::kMask | GeneratorFunctionBitField::kMask |
ArrowFunctionBitField::kMask | MethodBitField::kMask | ArrowFunctionBitField::kMask | MethodBitField::kMask |
...@@ -223,21 +223,21 @@ bool WebSnapshotSerializerDeserializer::IsFunctionOrMethod(uint32_t flags) { ...@@ -223,21 +223,21 @@ bool WebSnapshotSerializerDeserializer::IsFunctionOrMethod(uint32_t flags) {
return (flags & mask) == flags; return (flags & mask) == flags;
} }
bool WebSnapshotSerializerDeserializer::IsConstructor(uint32_t flags) { bool WebSnapshotSerializerDeserializer::IsConstructor(uint8_t flags) {
uint32_t mask = ClassConstructorBitField::kMask | uint32_t mask = ClassConstructorBitField::kMask |
DefaultConstructorBitField::kMask | DefaultConstructorBitField::kMask |
DerivedConstructorBitField::kMask; DerivedConstructorBitField::kMask;
return ClassConstructorBitField::decode(flags) && (flags & mask) == flags; return ClassConstructorBitField::decode(flags) && (flags & mask) == flags;
} }
uint32_t WebSnapshotSerializerDeserializer::GetDefaultAttributeFlags() { uint8_t WebSnapshotSerializerDeserializer::GetDefaultAttributeFlags() {
auto flags = ReadOnlyBitField::encode(false) | auto flags = ReadOnlyBitField::encode(false) |
ConfigurableBitField::encode(true) | ConfigurableBitField::encode(true) |
EnumerableBitField::encode(true); EnumerableBitField::encode(true);
return flags; return flags;
} }
uint32_t WebSnapshotSerializerDeserializer::AttributesToFlags( uint8_t WebSnapshotSerializerDeserializer::AttributesToFlags(
PropertyDetails details) { PropertyDetails details) {
auto flags = ReadOnlyBitField::encode(details.IsReadOnly()) | auto flags = ReadOnlyBitField::encode(details.IsReadOnly()) |
ConfigurableBitField::encode(details.IsConfigurable()) | ConfigurableBitField::encode(details.IsConfigurable()) |
...@@ -246,7 +246,7 @@ uint32_t WebSnapshotSerializerDeserializer::AttributesToFlags( ...@@ -246,7 +246,7 @@ uint32_t WebSnapshotSerializerDeserializer::AttributesToFlags(
} }
PropertyAttributes WebSnapshotSerializerDeserializer::FlagsToAttributes( PropertyAttributes WebSnapshotSerializerDeserializer::FlagsToAttributes(
uint32_t flags) { uint8_t flags) {
int attributes = ReadOnlyBitField::decode(flags) * READ_ONLY + int attributes = ReadOnlyBitField::decode(flags) * READ_ONLY +
!ConfigurableBitField::decode(flags) * DONT_DELETE + !ConfigurableBitField::decode(flags) * DONT_DELETE +
!EnumerableBitField::decode(flags) * DONT_ENUM; !EnumerableBitField::decode(flags) * DONT_ENUM;
...@@ -614,7 +614,7 @@ void WebSnapshotSerializer::SerializeMap(Handle<Map> map) { ...@@ -614,7 +614,7 @@ void WebSnapshotSerializer::SerializeMap(Handle<Map> map) {
DCHECK(!map->is_dictionary_map()); DCHECK(!map->is_dictionary_map());
int first_custom_index = -1; int first_custom_index = -1;
std::vector<Handle<Name>> keys; std::vector<Handle<Name>> keys;
std::vector<uint32_t> attributes; std::vector<uint8_t> attributes;
keys.reserve(map->NumberOfOwnDescriptors()); keys.reserve(map->NumberOfOwnDescriptors());
attributes.reserve(map->NumberOfOwnDescriptors()); attributes.reserve(map->NumberOfOwnDescriptors());
for (InternalIndex i : map->IterateOwnDescriptors()) { for (InternalIndex i : map->IterateOwnDescriptors()) {
...@@ -646,12 +646,12 @@ void WebSnapshotSerializer::SerializeMap(Handle<Map> map) { ...@@ -646,12 +646,12 @@ void WebSnapshotSerializer::SerializeMap(Handle<Map> map) {
map_serializer_.WriteUint32(static_cast<uint32_t>(keys.size())); map_serializer_.WriteUint32(static_cast<uint32_t>(keys.size()));
uint32_t default_flags = GetDefaultAttributeFlags(); uint8_t default_flags = GetDefaultAttributeFlags();
for (size_t i = 0; i < keys.size(); ++i) { for (size_t i = 0; i < keys.size(); ++i) {
if (keys[i]->IsString()) { if (keys[i]->IsString()) {
WriteStringMaybeInPlace(Handle<String>::cast(keys[i]), map_serializer_); WriteStringMaybeInPlace(Handle<String>::cast(keys[i]), map_serializer_);
} else if (keys[i]->IsSymbol()) { } else if (keys[i]->IsSymbol()) {
map_serializer_.WriteUint32(ValueType::SYMBOL_ID); map_serializer_.WriteByte(ValueType::SYMBOL_ID);
map_serializer_.WriteUint32(GetSymbolId(Symbol::cast(*keys[i]))); map_serializer_.WriteUint32(GetSymbolId(Symbol::cast(*keys[i])));
} else { } else {
// This error should've been recognized in the discovery phase. // This error should've been recognized in the discovery phase.
...@@ -659,9 +659,9 @@ void WebSnapshotSerializer::SerializeMap(Handle<Map> map) { ...@@ -659,9 +659,9 @@ void WebSnapshotSerializer::SerializeMap(Handle<Map> map) {
} }
if (first_custom_index >= 0) { if (first_custom_index >= 0) {
if (static_cast<int>(i) < first_custom_index) { if (static_cast<int>(i) < first_custom_index) {
map_serializer_.WriteUint32(default_flags); map_serializer_.WriteByte(default_flags);
} else { } else {
map_serializer_.WriteUint32(attributes[i - first_custom_index]); map_serializer_.WriteByte(attributes[i - first_custom_index]);
} }
} }
} }
...@@ -783,8 +783,7 @@ void WebSnapshotSerializer::SerializeFunctionInfo(Handle<JSFunction> function, ...@@ -783,8 +783,7 @@ void WebSnapshotSerializer::SerializeFunctionInfo(Handle<JSFunction> function,
serializer.WriteUint32( serializer.WriteUint32(
function->shared().internal_formal_parameter_count_without_receiver()); function->shared().internal_formal_parameter_count_without_receiver());
serializer.WriteUint32( serializer.WriteByte(FunctionKindToFunctionFlags(function->shared().kind()));
FunctionKindToFunctionFlags(function->shared().kind()));
if (function->has_prototype_slot() && function->has_instance_prototype()) { if (function->has_prototype_slot() && function->has_instance_prototype()) {
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
...@@ -1442,7 +1441,7 @@ template <typename T> ...@@ -1442,7 +1441,7 @@ template <typename T>
void WebSnapshotSerializer::SerializeObjectPropertiesWithDictionaryMap(T dict) { void WebSnapshotSerializer::SerializeObjectPropertiesWithDictionaryMap(T dict) {
DisallowGarbageCollection no_gc; DisallowGarbageCollection no_gc;
std::vector<uint32_t> attributes; std::vector<uint8_t> attributes;
attributes.reserve(dict->NumberOfElements()); attributes.reserve(dict->NumberOfElements());
HandleScope scope(isolate_); HandleScope scope(isolate_);
int first_custom_index = -1; int first_custom_index = -1;
...@@ -1464,7 +1463,7 @@ void WebSnapshotSerializer::SerializeObjectPropertiesWithDictionaryMap(T dict) { ...@@ -1464,7 +1463,7 @@ void WebSnapshotSerializer::SerializeObjectPropertiesWithDictionaryMap(T dict) {
: PropertyAttributesType::CUSTOM); : PropertyAttributesType::CUSTOM);
object_serializer_.WriteUint32(dict->NumberOfElements()); object_serializer_.WriteUint32(dict->NumberOfElements());
uint32_t default_flags = GetDefaultAttributeFlags(); uint8_t default_flags = GetDefaultAttributeFlags();
for (InternalIndex index : dict->IterateEntries()) { for (InternalIndex index : dict->IterateEntries()) {
Object key = dict->KeyAt(index); Object key = dict->KeyAt(index);
if (!dict->IsKey(roots, key)) { if (!dict->IsKey(roots, key)) {
...@@ -1474,9 +1473,9 @@ void WebSnapshotSerializer::SerializeObjectPropertiesWithDictionaryMap(T dict) { ...@@ -1474,9 +1473,9 @@ void WebSnapshotSerializer::SerializeObjectPropertiesWithDictionaryMap(T dict) {
WriteValue(handle(dict->ValueAt(index), isolate_), object_serializer_); WriteValue(handle(dict->ValueAt(index), isolate_), object_serializer_);
if (first_custom_index >= 0) { if (first_custom_index >= 0) {
if (index.as_int() < first_custom_index) { if (index.as_int() < first_custom_index) {
object_serializer_.WriteUint32(default_flags); object_serializer_.WriteByte(default_flags);
} else { } else {
object_serializer_.WriteUint32( object_serializer_.WriteByte(
attributes[index.as_int() - first_custom_index]); attributes[index.as_int() - first_custom_index]);
} }
} }
...@@ -1627,7 +1626,7 @@ void WebSnapshotSerializer::SerializeElements(Handle<JSObject> object, ...@@ -1627,7 +1626,7 @@ void WebSnapshotSerializer::SerializeElements(Handle<JSObject> object,
} }
} }
} }
uint32_t WebSnapshotSerializerDeserializer::ArrayBufferKindToFlags( uint8_t WebSnapshotSerializerDeserializer::ArrayBufferKindToFlags(
Handle<JSArrayBuffer> array_buffer) { Handle<JSArrayBuffer> array_buffer) {
return DetachedBitField::encode(array_buffer->was_detached()) | return DetachedBitField::encode(array_buffer->was_detached()) |
SharedBitField::encode(array_buffer->is_shared()) | SharedBitField::encode(array_buffer->is_shared()) |
...@@ -1647,7 +1646,7 @@ void WebSnapshotSerializer::SerializeArrayBuffer( ...@@ -1647,7 +1646,7 @@ void WebSnapshotSerializer::SerializeArrayBuffer(
Throw("Too large array buffer"); Throw("Too large array buffer");
return; return;
} }
array_buffer_serializer_.WriteUint32(ArrayBufferKindToFlags(array_buffer)); array_buffer_serializer_.WriteByte(ArrayBufferKindToFlags(array_buffer));
array_buffer_serializer_.WriteUint32(static_cast<uint32_t>(byte_length)); array_buffer_serializer_.WriteUint32(static_cast<uint32_t>(byte_length));
if (array_buffer->is_resizable()) { if (array_buffer->is_resizable()) {
...@@ -1663,7 +1662,7 @@ void WebSnapshotSerializer::SerializeArrayBuffer( ...@@ -1663,7 +1662,7 @@ void WebSnapshotSerializer::SerializeArrayBuffer(
byte_length); byte_length);
} }
uint32_t WebSnapshotSerializerDeserializer::ArrayBufferViewKindToFlags( uint8_t WebSnapshotSerializerDeserializer::ArrayBufferViewKindToFlags(
Handle<JSArrayBufferView> array_buffer_view) { Handle<JSArrayBufferView> array_buffer_view) {
return LengthTrackingBitField::encode( return LengthTrackingBitField::encode(
array_buffer_view->is_length_tracking()); array_buffer_view->is_length_tracking());
...@@ -1710,8 +1709,7 @@ void WebSnapshotSerializer::SerializeTypedArray( ...@@ -1710,8 +1709,7 @@ void WebSnapshotSerializer::SerializeTypedArray(
ExternalArrayTypeToTypedArrayType(typed_array->type()); ExternalArrayTypeToTypedArrayType(typed_array->type());
typed_array_serializer_.WriteUint32(typed_array_type); typed_array_serializer_.WriteUint32(typed_array_type);
WriteValue(typed_array->GetBuffer(), typed_array_serializer_); WriteValue(typed_array->GetBuffer(), typed_array_serializer_);
// TODO(v8:11525): Implement WriteByte. typed_array_serializer_.WriteByte(ArrayBufferViewKindToFlags(typed_array));
typed_array_serializer_.WriteUint32(ArrayBufferViewKindToFlags(typed_array));
if (typed_array->byte_offset() > std::numeric_limits<uint32_t>::max()) { if (typed_array->byte_offset() > std::numeric_limits<uint32_t>::max()) {
Throw("Too large byte offset in TypedArray"); Throw("Too large byte offset in TypedArray");
return; return;
...@@ -1751,20 +1749,20 @@ void WebSnapshotSerializer::SerializeExport(Handle<Object> object, ...@@ -1751,20 +1749,20 @@ void WebSnapshotSerializer::SerializeExport(Handle<Object> object,
void WebSnapshotSerializer::WriteValue(Handle<Object> object, void WebSnapshotSerializer::WriteValue(Handle<Object> object,
ValueSerializer& serializer) { ValueSerializer& serializer) {
if (object->IsSmi()) { if (object->IsSmi()) {
serializer.WriteUint32(ValueType::INTEGER); serializer.WriteByte(ValueType::INTEGER);
serializer.WriteZigZag<int32_t>(Smi::cast(*object).value()); serializer.WriteZigZag<int32_t>(Smi::cast(*object).value());
return; return;
} }
uint32_t id; uint32_t id;
if (GetExternalId(HeapObject::cast(*object), &id)) { if (GetExternalId(HeapObject::cast(*object), &id)) {
serializer.WriteUint32(ValueType::EXTERNAL_ID); serializer.WriteByte(ValueType::EXTERNAL_ID);
serializer.WriteUint32(id); serializer.WriteUint32(id);
return; return;
} }
if (GetBuiltinObjectId(HeapObject::cast(*object), id)) { if (GetBuiltinObjectId(HeapObject::cast(*object), id)) {
serializer.WriteUint32(ValueType::BUILTIN_OBJECT_ID); serializer.WriteByte(ValueType::BUILTIN_OBJECT_ID);
serializer.WriteUint32(id); serializer.WriteUint32(id);
return; return;
} }
...@@ -1775,46 +1773,46 @@ void WebSnapshotSerializer::WriteValue(Handle<Object> object, ...@@ -1775,46 +1773,46 @@ void WebSnapshotSerializer::WriteValue(Handle<Object> object,
case ODDBALL_TYPE: case ODDBALL_TYPE:
switch (Oddball::cast(*heap_object).kind()) { switch (Oddball::cast(*heap_object).kind()) {
case Oddball::kFalse: case Oddball::kFalse:
serializer.WriteUint32(ValueType::FALSE_CONSTANT); serializer.WriteByte(ValueType::FALSE_CONSTANT);
return; return;
case Oddball::kTrue: case Oddball::kTrue:
serializer.WriteUint32(ValueType::TRUE_CONSTANT); serializer.WriteByte(ValueType::TRUE_CONSTANT);
return; return;
case Oddball::kNull: case Oddball::kNull:
serializer.WriteUint32(ValueType::NULL_CONSTANT); serializer.WriteByte(ValueType::NULL_CONSTANT);
return; return;
case Oddball::kUndefined: case Oddball::kUndefined:
serializer.WriteUint32(ValueType::UNDEFINED_CONSTANT); serializer.WriteByte(ValueType::UNDEFINED_CONSTANT);
return; return;
case Oddball::kTheHole: case Oddball::kTheHole:
serializer.WriteUint32(ValueType::NO_ELEMENT_CONSTANT); serializer.WriteByte(ValueType::NO_ELEMENT_CONSTANT);
return; return;
default: default:
UNREACHABLE(); UNREACHABLE();
} }
case HEAP_NUMBER_TYPE: case HEAP_NUMBER_TYPE:
// TODO(v8:11525): Handle possible endianness mismatch. // TODO(v8:11525): Handle possible endianness mismatch.
serializer.WriteUint32(ValueType::DOUBLE); serializer.WriteByte(ValueType::DOUBLE);
serializer.WriteDouble(HeapNumber::cast(*heap_object).value()); serializer.WriteDouble(HeapNumber::cast(*heap_object).value());
break; break;
case JS_FUNCTION_TYPE: case JS_FUNCTION_TYPE:
serializer.WriteUint32(ValueType::FUNCTION_ID); serializer.WriteByte(ValueType::FUNCTION_ID);
serializer.WriteUint32(GetFunctionId(JSFunction::cast(*heap_object))); serializer.WriteUint32(GetFunctionId(JSFunction::cast(*heap_object)));
break; break;
case JS_CLASS_CONSTRUCTOR_TYPE: case JS_CLASS_CONSTRUCTOR_TYPE:
serializer.WriteUint32(ValueType::CLASS_ID); serializer.WriteByte(ValueType::CLASS_ID);
serializer.WriteUint32(GetClassId(JSFunction::cast(*heap_object))); serializer.WriteUint32(GetClassId(JSFunction::cast(*heap_object)));
break; break;
case JS_OBJECT_TYPE: case JS_OBJECT_TYPE:
serializer.WriteUint32(ValueType::OBJECT_ID); serializer.WriteByte(ValueType::OBJECT_ID);
serializer.WriteUint32(GetObjectId(JSObject::cast(*heap_object))); serializer.WriteUint32(GetObjectId(JSObject::cast(*heap_object)));
break; break;
case JS_ARRAY_TYPE: case JS_ARRAY_TYPE:
serializer.WriteUint32(ValueType::ARRAY_ID); serializer.WriteByte(ValueType::ARRAY_ID);
serializer.WriteUint32(GetArrayId(JSArray::cast(*heap_object))); serializer.WriteUint32(GetArrayId(JSArray::cast(*heap_object)));
break; break;
case SYMBOL_TYPE: case SYMBOL_TYPE:
serializer.WriteUint32(ValueType::SYMBOL_ID); serializer.WriteByte(ValueType::SYMBOL_ID);
serializer.WriteUint32(GetSymbolId(Symbol::cast(*heap_object))); serializer.WriteUint32(GetSymbolId(Symbol::cast(*heap_object)));
break; break;
case JS_REG_EXP_TYPE: { case JS_REG_EXP_TYPE: {
...@@ -1823,7 +1821,7 @@ void WebSnapshotSerializer::WriteValue(Handle<Object> object, ...@@ -1823,7 +1821,7 @@ void WebSnapshotSerializer::WriteValue(Handle<Object> object,
Throw("Unsupported RegExp map"); Throw("Unsupported RegExp map");
return; return;
} }
serializer.WriteUint32(ValueType::REGEXP); serializer.WriteByte(ValueType::REGEXP);
Handle<String> pattern = handle(regexp->source(), isolate_); Handle<String> pattern = handle(regexp->source(), isolate_);
WriteStringId(pattern, serializer); WriteStringId(pattern, serializer);
Handle<String> flags_string = Handle<String> flags_string =
...@@ -1834,14 +1832,14 @@ void WebSnapshotSerializer::WriteValue(Handle<Object> object, ...@@ -1834,14 +1832,14 @@ void WebSnapshotSerializer::WriteValue(Handle<Object> object,
case JS_ARRAY_BUFFER_TYPE: { case JS_ARRAY_BUFFER_TYPE: {
Handle<JSArrayBuffer> array_buffer = Handle<JSArrayBuffer> array_buffer =
Handle<JSArrayBuffer>::cast(heap_object); Handle<JSArrayBuffer>::cast(heap_object);
serializer.WriteUint32(ValueType::ARRAY_BUFFER_ID); serializer.WriteByte(ValueType::ARRAY_BUFFER_ID);
serializer.WriteUint32(GetArrayBufferId(*array_buffer)); serializer.WriteUint32(GetArrayBufferId(*array_buffer));
break; break;
} }
case JS_TYPED_ARRAY_TYPE: { case JS_TYPED_ARRAY_TYPE: {
Handle<JSTypedArray> typed_array = Handle<JSTypedArray> typed_array =
Handle<JSTypedArray>::cast(heap_object); Handle<JSTypedArray>::cast(heap_object);
serializer.WriteUint32(ValueType::TYPED_ARRAY_ID); serializer.WriteByte(ValueType::TYPED_ARRAY_ID);
serializer.WriteUint32(GetTypedArrayId(*typed_array)); serializer.WriteUint32(GetTypedArrayId(*typed_array));
break; break;
} }
...@@ -1862,10 +1860,10 @@ void WebSnapshotSerializer::WriteStringMaybeInPlace( ...@@ -1862,10 +1860,10 @@ void WebSnapshotSerializer::WriteStringMaybeInPlace(
bool in_place = false; bool in_place = false;
uint32_t id = GetStringId(string, in_place); uint32_t id = GetStringId(string, in_place);
if (in_place) { if (in_place) {
serializer.WriteUint32(ValueType::IN_PLACE_STRING_ID); serializer.WriteByte(ValueType::IN_PLACE_STRING_ID);
SerializeString(string, serializer); SerializeString(string, serializer);
} else { } else {
serializer.WriteUint32(ValueType::STRING_ID); serializer.WriteByte(ValueType::STRING_ID);
serializer.WriteUint32(id); serializer.WriteUint32(id);
} }
} }
...@@ -2401,8 +2399,8 @@ void WebSnapshotDeserializer::DeserializeMaps() { ...@@ -2401,8 +2399,8 @@ void WebSnapshotDeserializer::DeserializeMaps() {
} }
PropertyAttributes attributes = PropertyAttributes::NONE; PropertyAttributes attributes = PropertyAttributes::NONE;
if (has_custom_property_attributes) { if (has_custom_property_attributes) {
uint32_t flags; uint8_t flags;
if (!deserializer_->ReadUint32(&flags)) { if (!deserializer_->ReadByte(&flags)) {
Throw("Malformed property attributes"); Throw("Malformed property attributes");
return; return;
} }
...@@ -2636,7 +2634,7 @@ Handle<ScopeInfo> WebSnapshotDeserializer::CreateScopeInfo( ...@@ -2636,7 +2634,7 @@ Handle<ScopeInfo> WebSnapshotDeserializer::CreateScopeInfo(
Handle<JSFunction> WebSnapshotDeserializer::CreateJSFunction( Handle<JSFunction> WebSnapshotDeserializer::CreateJSFunction(
int shared_function_info_index, uint32_t start_position, uint32_t length, int shared_function_info_index, uint32_t start_position, uint32_t length,
uint32_t parameter_count, uint32_t flags, uint32_t context_id) { uint32_t parameter_count, uint8_t flags, uint32_t context_id) {
// TODO(v8:11525): Deduplicate the SFIs for class methods. // TODO(v8:11525): Deduplicate the SFIs for class methods.
FunctionKind kind = FunctionFlagsToFunctionKind(flags); FunctionKind kind = FunctionFlagsToFunctionKind(flags);
Handle<SharedFunctionInfo> shared = factory()->NewSharedFunctionInfo( Handle<SharedFunctionInfo> shared = factory()->NewSharedFunctionInfo(
...@@ -2781,11 +2779,11 @@ void WebSnapshotDeserializer::DeserializeFunctions() { ...@@ -2781,11 +2779,11 @@ void WebSnapshotDeserializer::DeserializeFunctions() {
uint32_t start_position; uint32_t start_position;
uint32_t length; uint32_t length;
uint32_t parameter_count; uint32_t parameter_count;
uint32_t flags; uint8_t flags;
if (!deserializer_->ReadUint32(&start_position) || if (!deserializer_->ReadUint32(&start_position) ||
!deserializer_->ReadUint32(&length) || !deserializer_->ReadUint32(&length) ||
!deserializer_->ReadUint32(&parameter_count) || !deserializer_->ReadUint32(&parameter_count) ||
!deserializer_->ReadUint32(&flags)) { !deserializer_->ReadByte(&flags)) {
Throw("Malformed function"); Throw("Malformed function");
return; return;
} }
...@@ -2843,11 +2841,11 @@ void WebSnapshotDeserializer::DeserializeClasses() { ...@@ -2843,11 +2841,11 @@ void WebSnapshotDeserializer::DeserializeClasses() {
uint32_t start_position; uint32_t start_position;
uint32_t length; uint32_t length;
uint32_t parameter_count; uint32_t parameter_count;
uint32_t flags; uint8_t flags;
if (!deserializer_->ReadUint32(&start_position) || if (!deserializer_->ReadUint32(&start_position) ||
!deserializer_->ReadUint32(&length) || !deserializer_->ReadUint32(&length) ||
!deserializer_->ReadUint32(&parameter_count) || !deserializer_->ReadUint32(&parameter_count) ||
!deserializer_->ReadUint32(&flags)) { !deserializer_->ReadByte(&flags)) {
Throw("Malformed class"); Throw("Malformed class");
return; return;
} }
...@@ -2972,8 +2970,8 @@ void WebSnapshotDeserializer::DeserializeObjectPropertiesWithDictionaryMap( ...@@ -2972,8 +2970,8 @@ void WebSnapshotDeserializer::DeserializeObjectPropertiesWithDictionaryMap(
Handle<Object> value(std::get<0>(ReadValue()), isolate_); Handle<Object> value(std::get<0>(ReadValue()), isolate_);
PropertyAttributes attributes = PropertyAttributes::NONE; PropertyAttributes attributes = PropertyAttributes::NONE;
if (has_custom_property_attributes) { if (has_custom_property_attributes) {
uint32_t flags; uint8_t flags;
if (!deserializer_->ReadUint32(&flags)) { if (!deserializer_->ReadByte(&flags)) {
Throw("Malformed property attributes"); Throw("Malformed property attributes");
return; return;
} }
...@@ -3285,9 +3283,9 @@ void WebSnapshotDeserializer::DeserializeArrayBuffers() { ...@@ -3285,9 +3283,9 @@ void WebSnapshotDeserializer::DeserializeArrayBuffers() {
array_buffers_ = *array_buffers_handle_; array_buffers_ = *array_buffers_handle_;
for (; current_array_buffer_count_ < array_buffer_count_; for (; current_array_buffer_count_ < array_buffer_count_;
++current_array_buffer_count_) { ++current_array_buffer_count_) {
uint32_t flags; uint8_t flags;
uint32_t byte_length; uint32_t byte_length;
if (!deserializer_->ReadUint32(&flags) || if (!deserializer_->ReadByte(&flags) ||
!deserializer_->ReadUint32(&byte_length) || !deserializer_->ReadUint32(&byte_length) ||
byte_length > static_cast<size_t>(deserializer_->end_ - byte_length > static_cast<size_t>(deserializer_->end_ -
deserializer_->position_)) { deserializer_->position_)) {
...@@ -3393,8 +3391,8 @@ void WebSnapshotDeserializer::DeserializeTypedArrays() { ...@@ -3393,8 +3391,8 @@ void WebSnapshotDeserializer::DeserializeTypedArrays() {
Handle<JSArrayBuffer> array_buffer( Handle<JSArrayBuffer> array_buffer(
JSArrayBuffer::cast(std::get<0>(ReadValue())), isolate_); JSArrayBuffer::cast(std::get<0>(ReadValue())), isolate_);
uint32_t byte_offset = 0; uint32_t byte_offset = 0;
uint32_t flags = 0; uint8_t flags = 0;
if (!deserializer_->ReadUint32(&flags) || if (!deserializer_->ReadByte(&flags) ||
!deserializer_->ReadUint32(&byte_offset)) { !deserializer_->ReadUint32(&byte_offset)) {
Throw("Malformed typed array"); Throw("Malformed typed array");
return; return;
...@@ -3555,9 +3553,8 @@ void WebSnapshotDeserializer::DeserializeExports(bool skip_exports) { ...@@ -3555,9 +3553,8 @@ void WebSnapshotDeserializer::DeserializeExports(bool skip_exports) {
std::tuple<Object, bool> WebSnapshotDeserializer::ReadValue( std::tuple<Object, bool> WebSnapshotDeserializer::ReadValue(
Handle<HeapObject> container, uint32_t container_index, Handle<HeapObject> container, uint32_t container_index,
InternalizeStrings internalize_strings) { InternalizeStrings internalize_strings) {
uint32_t value_type; uint8_t value_type;
// TODO(v8:11525): Consider adding a ReadByte. if (!deserializer_->ReadByte(&value_type)) {
if (!deserializer_->ReadUint32(&value_type)) {
Throw("Malformed variable"); Throw("Malformed variable");
// Return a placeholder "value" so that the "keep on trucking" error // Return a placeholder "value" so that the "keep on trucking" error
// handling won't fail. // handling won't fail.
......
...@@ -96,19 +96,19 @@ class WebSnapshotSerializerDeserializer { ...@@ -96,19 +96,19 @@ class WebSnapshotSerializerDeserializer {
enum PropertyAttributesType : uint8_t { DEFAULT, CUSTOM }; enum PropertyAttributesType : uint8_t { DEFAULT, CUSTOM };
uint32_t FunctionKindToFunctionFlags(FunctionKind kind); uint8_t FunctionKindToFunctionFlags(FunctionKind kind);
FunctionKind FunctionFlagsToFunctionKind(uint32_t flags); FunctionKind FunctionFlagsToFunctionKind(uint8_t flags);
bool IsFunctionOrMethod(uint32_t flags); bool IsFunctionOrMethod(uint8_t flags);
bool IsConstructor(uint32_t flags); bool IsConstructor(uint8_t flags);
uint32_t GetDefaultAttributeFlags(); uint8_t GetDefaultAttributeFlags();
uint32_t AttributesToFlags(PropertyDetails details); uint8_t AttributesToFlags(PropertyDetails details);
PropertyAttributes FlagsToAttributes(uint32_t flags); PropertyAttributes FlagsToAttributes(uint8_t flags);
uint32_t ArrayBufferViewKindToFlags( uint8_t ArrayBufferViewKindToFlags(
Handle<JSArrayBufferView> array_buffer_view); Handle<JSArrayBufferView> array_buffer_view);
uint32_t ArrayBufferKindToFlags(Handle<JSArrayBuffer> array_buffer); uint8_t ArrayBufferKindToFlags(Handle<JSArrayBuffer> array_buffer);
// The maximum count of items for each value type (strings, objects etc.) // The maximum count of items for each value type (strings, objects etc.)
static constexpr uint32_t kMaxItemCount = static constexpr uint32_t kMaxItemCount =
...@@ -135,7 +135,7 @@ class WebSnapshotSerializerDeserializer { ...@@ -135,7 +135,7 @@ class WebSnapshotSerializerDeserializer {
// Encode JSArrayBufferFlags, including was_detached, is_shared, is_resizable. // Encode JSArrayBufferFlags, including was_detached, is_shared, is_resizable.
// DetachedBitField indicates whether the ArrayBuffer was detached. // DetachedBitField indicates whether the ArrayBuffer was detached.
using DetachedBitField = base::BitField<bool, 0, 1>; using DetachedBitField = base::BitField<bool, 0, 1, uint8_t>;
// SharedBitField indicates whether the ArrayBuffer is SharedArrayBuffer. // SharedBitField indicates whether the ArrayBuffer is SharedArrayBuffer.
using SharedBitField = DetachedBitField::Next<bool, 1>; using SharedBitField = DetachedBitField::Next<bool, 1>;
// ResizableBitField indicates whether the ArrayBuffer is ResizableArrayBuffer // ResizableBitField indicates whether the ArrayBuffer is ResizableArrayBuffer
...@@ -147,7 +147,7 @@ class WebSnapshotSerializerDeserializer { ...@@ -147,7 +147,7 @@ class WebSnapshotSerializerDeserializer {
// LengthTrackingBitField indicates whether the ArrayBufferView should track // LengthTrackingBitField indicates whether the ArrayBufferView should track
// the length of the backing buffer, that is whether the ArrayBufferView is // the length of the backing buffer, that is whether the ArrayBufferView is
// constructed without the specified length argument. // constructed without the specified length argument.
using LengthTrackingBitField = base::BitField<bool, 0, 1>; using LengthTrackingBitField = base::BitField<bool, 0, 1, uint8_t>;
private: private:
WebSnapshotSerializerDeserializer(const WebSnapshotSerializerDeserializer&) = WebSnapshotSerializerDeserializer(const WebSnapshotSerializerDeserializer&) =
...@@ -155,9 +155,7 @@ class WebSnapshotSerializerDeserializer { ...@@ -155,9 +155,7 @@ class WebSnapshotSerializerDeserializer {
WebSnapshotSerializerDeserializer& operator=( WebSnapshotSerializerDeserializer& operator=(
const WebSnapshotSerializerDeserializer&) = delete; const WebSnapshotSerializerDeserializer&) = delete;
// Keep most common function kinds in the 7 least significant bits to make the using AsyncFunctionBitField = base::BitField<bool, 0, 1, uint8_t>;
// flags fit in 1 byte.
using AsyncFunctionBitField = base::BitField<bool, 0, 1>;
using GeneratorFunctionBitField = AsyncFunctionBitField::Next<bool, 1>; using GeneratorFunctionBitField = AsyncFunctionBitField::Next<bool, 1>;
using ArrowFunctionBitField = GeneratorFunctionBitField::Next<bool, 1>; using ArrowFunctionBitField = GeneratorFunctionBitField::Next<bool, 1>;
using MethodBitField = ArrowFunctionBitField::Next<bool, 1>; using MethodBitField = ArrowFunctionBitField::Next<bool, 1>;
...@@ -166,7 +164,7 @@ class WebSnapshotSerializerDeserializer { ...@@ -166,7 +164,7 @@ class WebSnapshotSerializerDeserializer {
using DefaultConstructorBitField = ClassConstructorBitField::Next<bool, 1>; using DefaultConstructorBitField = ClassConstructorBitField::Next<bool, 1>;
using DerivedConstructorBitField = DefaultConstructorBitField::Next<bool, 1>; using DerivedConstructorBitField = DefaultConstructorBitField::Next<bool, 1>;
using ReadOnlyBitField = base::BitField<bool, 0, 1>; using ReadOnlyBitField = base::BitField<bool, 0, 1, uint8_t>;
using ConfigurableBitField = ReadOnlyBitField::Next<bool, 1>; using ConfigurableBitField = ReadOnlyBitField::Next<bool, 1>;
using EnumerableBitField = ConfigurableBitField::Next<bool, 1>; using EnumerableBitField = ConfigurableBitField::Next<bool, 1>;
}; };
...@@ -464,7 +462,7 @@ class V8_EXPORT WebSnapshotDeserializer ...@@ -464,7 +462,7 @@ class V8_EXPORT WebSnapshotDeserializer
bool has_inlined_local_names); bool has_inlined_local_names);
Handle<JSFunction> CreateJSFunction(int index, uint32_t start, Handle<JSFunction> CreateJSFunction(int index, uint32_t start,
uint32_t length, uint32_t parameter_count, uint32_t length, uint32_t parameter_count,
uint32_t flags, uint32_t context_id); uint8_t flags, uint32_t context_id);
void DeserializeFunctionData(uint32_t count, uint32_t current_count); void DeserializeFunctionData(uint32_t count, uint32_t current_count);
void DeserializeFunctions(); void DeserializeFunctions();
void DeserializeClasses(); void DeserializeClasses();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment