summaryrefslogtreecommitdiff
path: root/deps/v8/test/cctest/test-strings.cc
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/cctest/test-strings.cc')
-rw-r--r--deps/v8/test/cctest/test-strings.cc48
1 files changed, 45 insertions, 3 deletions
diff --git a/deps/v8/test/cctest/test-strings.cc b/deps/v8/test/cctest/test-strings.cc
index 837d42669a..f070118bd8 100644
--- a/deps/v8/test/cctest/test-strings.cc
+++ b/deps/v8/test/cctest/test-strings.cc
@@ -1393,6 +1393,49 @@ TEST(InternalizeExternal) {
CcTest::CollectGarbage(i::OLD_SPACE);
}
+TEST(Regress1402187) {
+ CcTest::InitializeVM();
+ i::Isolate* isolate = CcTest::i_isolate();
+ Factory* factory = isolate->factory();
+ // This won't leak; the external string mechanism will call Dispose() on it.
+ const char ext_string_content[] = "prop-1234567890asdf";
+ OneByteVectorResource* resource =
+ new OneByteVectorResource(v8::base::Vector<const char>(
+ ext_string_content, strlen(ext_string_content)));
+ const uint32_t fake_hash =
+ String::CreateHashFieldValue(4711, String::HashFieldType::kHash);
+ {
+ v8::HandleScope scope(CcTest::isolate());
+ // Internalize a string with the same hash to ensure collision.
+ Handle<String> intern = isolate->factory()->NewStringFromAsciiChecked(
+ "internalized1234567", AllocationType::kOld);
+ intern->set_raw_hash_field(fake_hash);
+ factory->InternalizeName(intern);
+ CHECK(intern->IsInternalizedString());
+
+ v8::Local<v8::String> ext_string =
+ v8::String::NewFromUtf8Literal(CcTest::isolate(), ext_string_content);
+ ext_string->MakeExternal(resource);
+ Handle<String> string = v8::Utils::OpenHandle(*ext_string);
+ string->set_raw_hash_field(fake_hash);
+ CHECK(string->IsExternalString());
+ CHECK(!StringShape(*string).IsUncachedExternal());
+ CHECK(!string->IsInternalizedString());
+ CHECK(!String::Equals(isolate, string, intern));
+ CHECK_EQ(string->hash(), intern->hash());
+ CHECK_EQ(string->length(), intern->length());
+
+ CHECK_EQ(isolate->string_table()->TryStringToIndexOrLookupExisting(
+ isolate, string->ptr()),
+ Smi::FromInt(ResultSentinel::kNotFound).ptr());
+ string = factory->InternalizeString(string);
+ CHECK(string->IsExternalString());
+ CHECK(string->IsInternalizedString());
+ }
+ CcTest::CollectGarbage(i::OLD_SPACE);
+ CcTest::CollectGarbage(i::OLD_SPACE);
+}
+
TEST(SliceFromExternal) {
if (!v8_flags.string_slices) return;
CcTest::InitializeVM();
@@ -1682,8 +1725,8 @@ TEST(FormatMessage) {
Handle<String> arg1 = isolate->factory()->NewStringFromAsciiChecked("arg1");
Handle<String> arg2 = isolate->factory()->NewStringFromAsciiChecked("arg2");
Handle<String> result =
- MessageFormatter::Format(isolate, MessageTemplate::kPropertyNotFunction,
- arg0, arg1, arg2)
+ MessageFormatter::TryFormat(
+ isolate, MessageTemplate::kPropertyNotFunction, arg0, arg1, arg2)
.ToHandleChecked();
Handle<String> expected = isolate->factory()->NewStringFromAsciiChecked(
"'arg0' returned for property 'arg1' of object 'arg2' is not a function");
@@ -1893,7 +1936,6 @@ TEST(Regress876759) {
// The grandparent string becomes one-byte, but the child strings are still
// two-byte.
CHECK(grandparent->IsOneByteRepresentation());
- CHECK(parent->IsTwoByteRepresentation());
CHECK(sliced->IsTwoByteRepresentation());
// The *Underneath version returns the correct representation.
CHECK(String::IsOneByteRepresentationUnderneath(*sliced));