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

Unified Diff: src/value-serializer.cc

Issue 2255973005: Blink-compatible serialization of dates. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: forgot the decode tests 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
« no previous file with comments | « src/value-serializer.h ('k') | test/unittests/value-serializer-unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/value-serializer.cc
diff --git a/src/value-serializer.cc b/src/value-serializer.cc
index 29ebb8f1508ff4af7562803cbe1e454c2255bdcd..0c2a61b472046a00cd3a30b8d2bc4535c130db35 100644
--- a/src/value-serializer.cc
+++ b/src/value-serializer.cc
@@ -70,6 +70,8 @@ enum class SerializationTag : uint8_t {
kBeginDenseJSArray = 'A',
// End of a dense JS array. numProperties:uint32_t length:uint32_t
kEndDenseJSArray = '$',
+ // Date. millisSinceEpoch:double
+ kDate = 'D',
};
ValueSerializer::ValueSerializer(Isolate* isolate)
@@ -268,6 +270,9 @@ Maybe<bool> ValueSerializer::WriteJSReceiver(Handle<JSReceiver> receiver) {
case JS_OBJECT_TYPE:
case JS_API_OBJECT_TYPE:
return WriteJSObject(Handle<JSObject>::cast(receiver));
+ case JS_DATE_TYPE:
+ WriteJSDate(JSDate::cast(*receiver));
+ return Just(true);
default:
UNIMPLEMENTED();
break;
@@ -353,6 +358,11 @@ Maybe<bool> ValueSerializer::WriteJSArray(Handle<JSArray> array) {
return Just(true);
}
+void ValueSerializer::WriteJSDate(JSDate* date) {
+ WriteTag(SerializationTag::kDate);
+ WriteDouble(date->value()->Number());
+}
+
Maybe<uint32_t> ValueSerializer::WriteJSObjectProperties(
Handle<JSObject> object, Handle<FixedArray> keys) {
uint32_t properties_written = 0;
@@ -533,6 +543,8 @@ MaybeHandle<Object> ValueDeserializer::ReadObject() {
return ReadSparseJSArray();
case SerializationTag::kBeginDenseJSArray:
return ReadDenseJSArray();
+ case SerializationTag::kDate:
+ return ReadJSDate();
default:
return MaybeHandle<Object>();
}
@@ -661,6 +673,19 @@ MaybeHandle<JSArray> ValueDeserializer::ReadDenseJSArray() {
return scope.CloseAndEscape(array);
}
+MaybeHandle<JSDate> ValueDeserializer::ReadJSDate() {
+ double value;
+ if (!ReadDouble().To(&value)) return MaybeHandle<JSDate>();
+ uint32_t id = next_id_++;
+ Handle<JSDate> date;
+ if (!JSDate::New(isolate_->date_function(), isolate_->date_function(), value)
+ .ToHandle(&date)) {
+ return MaybeHandle<JSDate>();
+ }
+ AddObjectWithID(id, date);
+ return date;
+}
+
Maybe<uint32_t> ValueDeserializer::ReadJSObjectProperties(
Handle<JSObject> object, SerializationTag end_tag) {
for (uint32_t num_properties = 0;; num_properties++) {
« no previous file with comments | « src/value-serializer.h ('k') | test/unittests/value-serializer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698