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

Unified Diff: src/value-serializer.cc

Issue 2262013002: Blink-compatible serialization of RegExp objects. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@vs-value
Patch Set: Merge branch 'vs-value' into vs-regexp 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 32f41e925efb7fc522cae66f63cd57707d2853ec..0af4838abf27fae8afa123c49d790e6cac45370b 100644
--- a/src/value-serializer.cc
+++ b/src/value-serializer.cc
@@ -79,6 +79,9 @@ enum class SerializationTag : uint8_t {
kNumberObject = 'n',
// String object, UTF-8 encoding. byteLength:uint32_t, then raw data.
kStringObject = 's',
+ // Regular expression, UTF-8 encoding. byteLength:uint32_t, raw data,
+ // flags:uint32_t.
+ kRegExp = 'R',
};
ValueSerializer::ValueSerializer(Isolate* isolate)
@@ -283,6 +286,9 @@ Maybe<bool> ValueSerializer::WriteJSReceiver(Handle<JSReceiver> receiver) {
return Just(true);
case JS_VALUE_TYPE:
return WriteJSValue(Handle<JSValue>::cast(receiver));
+ case JS_REGEXP_TYPE:
+ WriteJSRegExp(JSRegExp::cast(*receiver));
+ return Just(true);
default:
UNIMPLEMENTED();
break;
@@ -400,6 +406,17 @@ Maybe<bool> ValueSerializer::WriteJSValue(Handle<JSValue> value) {
return Just(true);
}
+void ValueSerializer::WriteJSRegExp(JSRegExp* regexp) {
+ WriteTag(SerializationTag::kRegExp);
+ v8::Local<v8::String> api_string =
+ Utils::ToLocal(handle(regexp->Pattern(), isolate_));
+ uint32_t utf8_length = api_string->Utf8Length();
+ WriteVarint(utf8_length);
+ api_string->WriteUtf8(reinterpret_cast<char*>(ReserveRawBytes(utf8_length)),
+ utf8_length, nullptr, v8::String::NO_NULL_TERMINATION);
+ WriteVarint(static_cast<uint32_t>(regexp->GetFlags()));
+}
+
Maybe<uint32_t> ValueSerializer::WriteJSObjectProperties(
Handle<JSObject> object, Handle<FixedArray> keys) {
uint32_t properties_written = 0;
@@ -587,6 +604,8 @@ MaybeHandle<Object> ValueDeserializer::ReadObject() {
case SerializationTag::kNumberObject:
case SerializationTag::kStringObject:
return ReadJSValue(tag);
+ case SerializationTag::kRegExp:
+ return ReadJSRegExp();
default:
return MaybeHandle<Object>();
}
@@ -767,6 +786,21 @@ MaybeHandle<JSValue> ValueDeserializer::ReadJSValue(SerializationTag tag) {
return value;
}
+MaybeHandle<JSRegExp> ValueDeserializer::ReadJSRegExp() {
+ uint32_t id = next_id_++;
+ Handle<String> pattern;
+ uint32_t raw_flags;
+ Handle<JSRegExp> regexp;
+ if (!ReadUtf8String().ToHandle(&pattern) ||
+ !ReadVarint<uint32_t>().To(&raw_flags) ||
+ !JSRegExp::New(pattern, static_cast<JSRegExp::Flags>(raw_flags))
+ .ToHandle(&regexp)) {
+ return MaybeHandle<JSRegExp>();
+ }
+ AddObjectWithID(id, regexp);
+ return regexp;
+}
+
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