Revision: 23185
Author: [email protected]
Date: Tue Aug 19 08:53:38 2014 UTC
Log: Make internalized string parser in JSON.parse GC-safe
SubStringKey::AsHandle is not GC-safe because the string backing store
may move.
[email protected]
Review URL: https://codereview.chromium.org/484703002
http://code.google.com/p/v8/source/detail?r=23185
Modified:
/branches/bleeding_edge/src/factory.cc
/branches/bleeding_edge/src/factory.h
/branches/bleeding_edge/src/objects-inl.h
/branches/bleeding_edge/src/objects.cc
=======================================
--- /branches/bleeding_edge/src/factory.cc Mon Aug 18 14:59:04 2014 UTC
+++ /branches/bleeding_edge/src/factory.cc Tue Aug 19 08:53:38 2014 UTC
@@ -186,7 +186,7 @@
Handle<String> Factory::InternalizeOneByteString(
Handle<SeqOneByteString> string, int from, int length) {
- SubStringKey<uint8_t> key(string, from, length);
+ SeqOneByteSubStringKey key(string, from, length);
return InternalizeStringWithKey(&key);
}
@@ -201,12 +201,6 @@
Handle<String> Factory::InternalizeStringWithKey(StringTableKey* key) {
return StringTable::LookupKey(isolate(), key);
}
-
-
-template Handle<String> Factory::InternalizeStringWithKey<
- SubStringKey<uint8_t> > (SubStringKey<uint8_t>* key);
-template Handle<String> Factory::InternalizeStringWithKey<
- SubStringKey<uint16_t> > (SubStringKey<uint16_t>* key);
MaybeHandle<String> Factory::NewStringFromOneByte(Vector<const uint8_t>
string,
@@ -311,6 +305,17 @@
isolate()->heap()->AllocateOneByteInternalizedString(str,
hash_field),
String);
}
+
+
+MUST_USE_RESULT Handle<String> Factory::NewOneByteInternalizedSubString(
+ Handle<SeqOneByteString> string, int offset, int length,
+ uint32_t hash_field) {
+ CALL_HEAP_FUNCTION(
+ isolate(), isolate()->heap()->AllocateOneByteInternalizedString(
+ Vector<const uint8_t>(string->GetChars() + offset,
length),
+ hash_field),
+ String);
+}
MUST_USE_RESULT Handle<String> Factory::NewTwoByteInternalizedString(
=======================================
--- /branches/bleeding_edge/src/factory.h Tue Aug 12 15:28:20 2014 UTC
+++ /branches/bleeding_edge/src/factory.h Tue Aug 19 08:53:38 2014 UTC
@@ -164,8 +164,11 @@
uint32_t hash_field);
MUST_USE_RESULT Handle<String> NewOneByteInternalizedString(
- Vector<const uint8_t> str,
- uint32_t hash_field);
+ Vector<const uint8_t> str, uint32_t hash_field);
+
+ MUST_USE_RESULT Handle<String> NewOneByteInternalizedSubString(
+ Handle<SeqOneByteString> string, int offset, int length,
+ uint32_t hash_field);
MUST_USE_RESULT Handle<String> NewTwoByteInternalizedString(
Vector<const uc16> str,
=======================================
--- /branches/bleeding_edge/src/objects-inl.h Thu Aug 14 10:24:19 2014 UTC
+++ /branches/bleeding_edge/src/objects-inl.h Tue Aug 19 08:53:38 2014 UTC
@@ -533,21 +533,17 @@
};
-template<class Char>
-class SubStringKey : public HashTableKey {
+class SeqOneByteSubStringKey : public HashTableKey {
public:
- SubStringKey(Handle<String> string, int from, int length)
+ SeqOneByteSubStringKey(Handle<SeqOneByteString> string, int from, int
length)
: string_(string), from_(from), length_(length) {
- if (string_->IsSlicedString()) {
- string_ = Handle<String>(Unslice(*string_, &from_));
- }
- DCHECK(string_->IsSeqString() || string->IsExternalString());
+ DCHECK(string_->IsSeqOneByteString());
}
virtual uint32_t Hash() V8_OVERRIDE {
DCHECK(length_ >= 0);
DCHECK(from_ + length_ <= string_->length());
- const Char* chars = GetChars() + from_;
+ const uint8_t* chars = string_->GetChars() + from_;
hash_field_ = StringHasher::HashSequentialString(
chars, length_, string_->GetHeap()->HashSeed());
uint32_t result = hash_field_ >> String::kHashShift;
@@ -563,17 +559,7 @@
virtual Handle<Object> AsHandle(Isolate* isolate) V8_OVERRIDE;
private:
- const Char* GetChars();
- String* Unslice(String* string, int* offset) {
- while (string->IsSlicedString()) {
- SlicedString* sliced = SlicedString::cast(string);
- *offset += sliced->offset();
- string = sliced->parent();
- }
- return string;
- }
-
- Handle<String> string_;
+ Handle<SeqOneByteString> string_;
int from_;
int length_;
uint32_t hash_field_;
=======================================
--- /branches/bleeding_edge/src/objects.cc Tue Aug 19 08:14:01 2014 UTC
+++ /branches/bleeding_edge/src/objects.cc Tue Aug 19 08:53:38 2014 UTC
@@ -13901,54 +13901,17 @@
}
-template<>
-const uint8_t* SubStringKey<uint8_t>::GetChars() {
- return string_->IsSeqOneByteString()
- ? SeqOneByteString::cast(*string_)->GetChars()
- : ExternalAsciiString::cast(*string_)->GetChars();
-}
-
-
-template<>
-const uint16_t* SubStringKey<uint16_t>::GetChars() {
- return string_->IsSeqTwoByteString()
- ? SeqTwoByteString::cast(*string_)->GetChars()
- : ExternalTwoByteString::cast(*string_)->GetChars();
-}
-
-
-template<>
-Handle<Object> SubStringKey<uint8_t>::AsHandle(Isolate* isolate) {
+Handle<Object> SeqOneByteSubStringKey::AsHandle(Isolate* isolate) {
if (hash_field_ == 0) Hash();
- Vector<const uint8_t> chars(GetChars() + from_, length_);
- return isolate->factory()->NewOneByteInternalizedString(chars,
hash_field_);
+ return isolate->factory()->NewOneByteInternalizedSubString(
+ string_, from_, length_, hash_field_);
}
-template<>
-Handle<Object> SubStringKey<uint16_t>::AsHandle(Isolate* isolate) {
- if (hash_field_ == 0) Hash();
- Vector<const uint16_t> chars(GetChars() + from_, length_);
- return isolate->factory()->NewTwoByteInternalizedString(chars,
hash_field_);
-}
-
-
-template<>
-bool SubStringKey<uint8_t>::IsMatch(Object* string) {
- Vector<const uint8_t> chars(GetChars() + from_, length_);
+bool SeqOneByteSubStringKey::IsMatch(Object* string) {
+ Vector<const uint8_t> chars(string_->GetChars() + from_, length_);
return String::cast(string)->IsOneByteEqualTo(chars);
}
-
-
-template<>
-bool SubStringKey<uint16_t>::IsMatch(Object* string) {
- Vector<const uint16_t> chars(GetChars() + from_, length_);
- return String::cast(string)->IsTwoByteEqualTo(chars);
-}
-
-
-template class SubStringKey<uint8_t>;
-template class SubStringKey<uint16_t>;
// InternalizedStringKey carries a string/internalized-string object as
key.
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.