Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Unified Diff: src/value-serializer.cc

Issue 2248893003: Blink-compatible deserialization of old object format. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@vs4
Patch Set: correct to size_t Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/value-serializer.cc
diff --git a/src/value-serializer.cc b/src/value-serializer.cc
index 8e74e91f9652100bc36b196ef9ea2c1c31114384..a6d0c3c2bac7ed620e7de1fd86a61dc05bd944b8 100644
--- a/src/value-serializer.cc
+++ b/src/value-serializer.cc
@@ -327,6 +327,12 @@ Maybe<SerializationTag> ValueDeserializer::PeekTag() const {
return Just(tag);
}
+void ValueDeserializer::ConsumeTag(SerializationTag peeked_tag) {
+ SerializationTag actual_tag = ReadTag().ToChecked();
+ DCHECK(actual_tag == peeked_tag);
+ (void)actual_tag;
Camillo Bruni 2016/08/16 09:04:07 nit: you can use our very pretty USE macro here :)
jbroman 2016/08/16 21:34:14 I was looking for one, but didn't find it. Thanks.
+}
+
Maybe<SerializationTag> ValueDeserializer::ReadTag() {
SerializationTag tag;
do {
@@ -512,9 +518,7 @@ Maybe<uint32_t> ValueDeserializer::ReadJSObjectProperties(
SerializationTag tag;
if (!PeekTag().To(&tag)) return Nothing<uint32_t>();
if (tag == end_tag) {
- SerializationTag consumed_tag = ReadTag().ToChecked();
- (void)consumed_tag;
- DCHECK(tag == consumed_tag);
+ ConsumeTag(end_tag);
return Just(num_properties);
}
@@ -561,5 +565,72 @@ void ValueDeserializer::AddObjectWithID(uint32_t id,
}
}
+static MaybeHandle<JSObject> CreateJSObjectFromKeyValuePairs(
+ Isolate* isolate, Handle<Object>* data, uint32_t num_properties) {
+ Handle<JSObject> object =
+ isolate->factory()->NewJSObject(isolate->object_function());
Camillo Bruni 2016/08/16 09:04:07 Performance Hint: This is a rather slow (but obvio
jbroman 2016/08/16 21:34:14 No problem. I've learned a lot the last couple wee
+ for (unsigned i = 0; i < 2 * num_properties; i += 2) {
+ Handle<Object> key = data[i];
+ Handle<Object> value = data[i + 1];
+ bool success;
+ LookupIterator it = LookupIterator::PropertyOrElement(
+ isolate, object, key, &success, LookupIterator::OWN);
+ if (!success ||
+ JSObject::DefineOwnPropertyIgnoreAttributes(&it, value, NONE).is_null())
+ return MaybeHandle<JSObject>();
Camillo Bruni 2016/08/16 09:04:07 nit: please add braces here, we don't allow traili
jbroman 2016/08/16 21:34:14 OK. As I mentioned in the other review, I couldn't
+ }
+ return object;
+}
+
+MaybeHandle<Object>
+ValueDeserializer::ReadObjectUsingEntireBufferForLegacyFormat() {
+ if (version_ > 0) return MaybeHandle<Object>();
+
+ HandleScope scope(isolate_);
+ std::vector<Handle<Object>> stack;
+ while (position_ < end_) {
+ SerializationTag tag;
+ if (!PeekTag().To(&tag)) break;
+
+ Handle<Object> new_object;
+ switch (tag) {
+ case SerializationTag::kEndJSObject: {
+ ConsumeTag(SerializationTag::kEndJSObject);
+
+ // JS Object: Read the last 2*n values from the stack and use them as
+ // key-value pairs.
+ uint32_t num_properties;
+ if (!ReadVarint<uint32_t>().To(&num_properties) ||
+ stack.size() / 2 < num_properties)
+ return MaybeHandle<Object>();
Camillo Bruni 2016/08/16 09:04:07 nit: missing braces
jbroman 2016/08/16 21:34:14 Done.
+
+ size_t begin_properties = stack.size() - 2 * num_properties;
+ Handle<Object>* data =
+ num_properties ? &stack[begin_properties] : nullptr;
+ if (!CreateJSObjectFromKeyValuePairs(isolate_, data, num_properties)
+ .ToHandle(&new_object))
+ return MaybeHandle<Object>();
Camillo Bruni 2016/08/16 09:04:07 nit: braces
jbroman 2016/08/16 21:34:14 Done.
+
+ stack.resize(begin_properties);
+ break;
+ }
+ default:
+ if (!ReadObject().ToHandle(&new_object)) return MaybeHandle<Object>();
+ break;
+ }
+ stack.push_back(new_object);
+ }
+
+// Nothing remains but padding.
+#ifdef DEBUG
+ while (position_ < end_)
+ DCHECK(*position_++ == static_cast<uint8_t>(SerializationTag::kPadding));
Camillo Bruni 2016/08/16 09:04:07 nit: braces
jbroman 2016/08/16 21:34:14 Done.
+#endif
+ position_ = end_;
+
+ if (stack.size() != 1) return MaybeHandle<Object>();
+ return scope.CloseAndEscape(stack[0]);
+}
+
} // namespace internal
} // namespace v8

Powered by Google App Engine
This is Rietveld 408576698