Skip to content

Commit

Permalink
Enable deserialization of very large serialized values.
Browse files Browse the repository at this point in the history
  • Loading branch information
rayw000 committed Sep 22, 2021
1 parent 5c1adda commit d556d61
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 25 deletions.
27 changes: 3 additions & 24 deletions deps/v8/src/api/api.cc
Expand Up @@ -3260,7 +3260,6 @@ struct ValueDeserializer::PrivateData {
: isolate(i), deserializer(i, data, delegate) {}
i::Isolate* isolate;
i::ValueDeserializer deserializer;
bool has_aborted = false;
bool supports_legacy_wire_format = false;
};

Expand All @@ -3270,16 +3269,9 @@ ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data,

ValueDeserializer::ValueDeserializer(Isolate* isolate, const uint8_t* data,
size_t size, Delegate* delegate) {
if (base::IsValueInRangeForNumericType<int>(size)) {
private_ = new PrivateData(
reinterpret_cast<i::Isolate*>(isolate),
base::Vector<const uint8_t>(data, static_cast<int>(size)), delegate);
} else {
private_ =
new PrivateData(reinterpret_cast<i::Isolate*>(isolate),
base::Vector<const uint8_t>(nullptr, 0), nullptr);
private_->has_aborted = true;
}
private_ = new PrivateData(
reinterpret_cast<i::Isolate*>(isolate),
base::Vector<const uint8_t>(data, size), delegate);
}

ValueDeserializer::~ValueDeserializer() { delete private_; }
Expand All @@ -3289,15 +3281,6 @@ Maybe<bool> ValueDeserializer::ReadHeader(Local<Context> context) {
ENTER_V8_NO_SCRIPT(isolate, context, ValueDeserializer, ReadHeader,
Nothing<bool>(), i::HandleScope);

// We could have aborted during the constructor.
// If so, ReadHeader is where we report it.
if (private_->has_aborted) {
isolate->Throw(*isolate->factory()->NewError(
i::MessageTemplate::kDataCloneDeserializationError));
has_pending_exception = true;
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
}

bool read_header = false;
has_pending_exception = !private_->deserializer.ReadHeader().To(&read_header);
RETURN_ON_FAILED_EXECUTION_PRIMITIVE(bool);
Expand All @@ -3321,12 +3304,10 @@ void ValueDeserializer::SetSupportsLegacyWireFormat(
}

uint32_t ValueDeserializer::GetWireFormatVersion() const {
CHECK(!private_->has_aborted);
return private_->deserializer.GetWireFormatVersion();
}

MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) {
CHECK(!private_->has_aborted);
PREPARE_FOR_EXECUTION(context, ValueDeserializer, ReadValue, Value);
i::MaybeHandle<i::Object> result;
if (GetWireFormatVersion() > 0) {
Expand All @@ -3343,14 +3324,12 @@ MaybeLocal<Value> ValueDeserializer::ReadValue(Local<Context> context) {

void ValueDeserializer::TransferArrayBuffer(uint32_t transfer_id,
Local<ArrayBuffer> array_buffer) {
CHECK(!private_->has_aborted);
private_->deserializer.TransferArrayBuffer(transfer_id,
Utils::OpenHandle(*array_buffer));
}

void ValueDeserializer::TransferSharedArrayBuffer(
uint32_t transfer_id, Local<SharedArrayBuffer> shared_array_buffer) {
CHECK(!private_->has_aborted);
private_->deserializer.TransferArrayBuffer(
transfer_id, Utils::OpenHandle(*shared_array_buffer));
}
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/objects/value-serializer.cc
Expand Up @@ -1117,7 +1117,7 @@ ValueDeserializer::ValueDeserializer(Isolate* isolate,
: isolate_(isolate),
delegate_(delegate),
position_(data.begin()),
end_(data.begin() + data.length()),
end_(data.end()),
id_map_(isolate->global_handles()->Create(
ReadOnlyRoots(isolate_).empty_fixed_array())) {}

Expand Down

0 comments on commit d556d61

Please sign in to comment.