From 68960eeb763f93dcedb37d5b663b1019192b7f36 Mon Sep 17 00:00:00 2001 From: jbroman Date: Thu, 23 Feb 2017 05:23:00 -0800 Subject: [PATCH] ValueDeserializer: Make sure that an exception is the legacy path. The entry points to the deserializer are responsible for ensuring that an exception is pending by the time they return. Some failures throw exceptions themselves, while others (like errors in the format) are exceptions caused by the deserializer, not coming from the runtime. Like the non-legacy path, a default deserialization exception should be thrown in such cases. BUG=chromium:693411 Review-Url: https://codereview.chromium.org/2712713002 Cr-Commit-Position: refs/heads/master@{#43390} --- src/value-serializer.cc | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/value-serializer.cc b/src/value-serializer.cc index 7752a47efa..79e2b7382a 100644 --- a/src/value-serializer.cc +++ b/src/value-serializer.cc @@ -1849,6 +1849,20 @@ static Maybe SetPropertiesFromKeyValuePairs(Isolate* isolate, return Just(true); } +namespace { + +// Throws a generic "deserialization failed" exception by default, unless a more +// specific exception has already been thrown. +void ThrowDeserializationExceptionIfNonePending(Isolate* isolate) { + if (!isolate->has_pending_exception()) { + isolate->Throw(*isolate->factory()->NewError( + MessageTemplate::kDataCloneDeserializationError)); + } + DCHECK(isolate->has_pending_exception()); +} + +} // namespace + MaybeHandle ValueDeserializer::ReadObjectUsingEntireBufferForLegacyFormat() { DCHECK_EQ(version_, 0u); @@ -1881,7 +1895,7 @@ ValueDeserializer::ReadObjectUsingEntireBufferForLegacyFormat() { !SetPropertiesFromKeyValuePairs( isolate_, js_object, &stack[begin_properties], num_properties) .FromMaybe(false)) { - DCHECK(isolate_->has_pending_exception()); + ThrowDeserializationExceptionIfNonePending(isolate_); return MaybeHandle(); } @@ -1912,7 +1926,7 @@ ValueDeserializer::ReadObjectUsingEntireBufferForLegacyFormat() { !SetPropertiesFromKeyValuePairs( isolate_, js_array, &stack[begin_properties], num_properties) .FromMaybe(false)) { - DCHECK(isolate_->has_pending_exception()); + ThrowDeserializationExceptionIfNonePending(isolate_); return MaybeHandle(); }