diff options
Diffstat (limited to 'src/3rdparty/v8/test/cctest/test-strings.cc')
-rw-r--r-- | src/3rdparty/v8/test/cctest/test-strings.cc | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/src/3rdparty/v8/test/cctest/test-strings.cc b/src/3rdparty/v8/test/cctest/test-strings.cc index d86886f..5a9ccbb 100644 --- a/src/3rdparty/v8/test/cctest/test-strings.cc +++ b/src/3rdparty/v8/test/cctest/test-strings.cc @@ -1,4 +1,4 @@ -// Copyright 2011 the V8 project authors. All rights reserved. +// Copyright 2012 the V8 project authors. All rights reserved. // Check that we can traverse very deep stacks of ConsStrings using // StringInputBuffer. Check that Get(int) works on very deep stacks @@ -11,6 +11,7 @@ #include "api.h" #include "factory.h" +#include "objects.h" #include "cctest.h" #include "zone-inl.h" @@ -82,6 +83,7 @@ static void InitializeBuildingBlocks( Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]) { // A list of pointers that we don't have any interest in cleaning up. // If they are reachable from a root then leak detection won't complain. + Zone* zone = Isolate::Current()->runtime_zone(); for (int i = 0; i < NUMBER_OF_BUILDING_BLOCKS; i++) { int len = gen() % 16; if (len > 14) { @@ -113,11 +115,11 @@ static void InitializeBuildingBlocks( break; } case 2: { - uc16* buf = ZONE->NewArray<uc16>(len); + uc16* buf = zone->NewArray<uc16>(len); for (int j = 0; j < len; j++) { buf[j] = gen() % 65536; } - Resource* resource = new Resource(Vector<const uc16>(buf, len)); + Resource* resource = new(zone) Resource(Vector<const uc16>(buf, len)); building_blocks[i] = FACTORY->NewExternalStringFromTwoByte(resource); for (int j = 0; j < len; j++) { CHECK_EQ(buf[j], building_blocks[i]->Get(j)); @@ -233,7 +235,7 @@ TEST(Traverse) { InitializeVM(); v8::HandleScope scope; Handle<String> building_blocks[NUMBER_OF_BUILDING_BLOCKS]; - ZoneScope zone(Isolate::Current(), DELETE_ON_EXIT); + ZoneScope zone(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); InitializeBuildingBlocks(building_blocks); Handle<String> flat = ConstructBalanced(building_blocks); FlattenString(flat); @@ -348,10 +350,11 @@ TEST(Utf8Conversion) { TEST(ExternalShortStringAdd) { - ZoneScope zone(Isolate::Current(), DELETE_ON_EXIT); + ZoneScope zonescope(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); InitializeVM(); v8::HandleScope handle_scope; + Zone* zone = Isolate::Current()->runtime_zone(); // Make sure we cover all always-flat lengths and at least one above. static const int kMaxLength = 20; @@ -365,25 +368,25 @@ TEST(ExternalShortStringAdd) { // Generate short ascii and non-ascii external strings. for (int i = 0; i <= kMaxLength; i++) { - char* ascii = ZONE->NewArray<char>(i + 1); + char* ascii = zone->NewArray<char>(i + 1); for (int j = 0; j < i; j++) { ascii[j] = 'a'; } // Terminating '\0' is left out on purpose. It is not required for external // string data. AsciiResource* ascii_resource = - new AsciiResource(Vector<const char>(ascii, i)); + new(zone) AsciiResource(Vector<const char>(ascii, i)); v8::Local<v8::String> ascii_external_string = v8::String::NewExternal(ascii_resource); ascii_external_strings->Set(v8::Integer::New(i), ascii_external_string); - uc16* non_ascii = ZONE->NewArray<uc16>(i + 1); + uc16* non_ascii = zone->NewArray<uc16>(i + 1); for (int j = 0; j < i; j++) { non_ascii[j] = 0x1234; } // Terminating '\0' is left out on purpose. It is not required for external // string data. - Resource* resource = new Resource(Vector<const uc16>(non_ascii, i)); + Resource* resource = new(zone) Resource(Vector<const uc16>(non_ascii, i)); v8::Local<v8::String> non_ascii_external_string = v8::String::NewExternal(resource); non_ascii_external_strings->Set(v8::Integer::New(i), @@ -438,7 +441,7 @@ TEST(CachedHashOverflow) { // We incorrectly allowed strings to be tagged as array indices even if their // values didn't fit in the hash field. // See http://code.google.com/p/v8/issues/detail?id=728 - ZoneScope zone(Isolate::Current(), DELETE_ON_EXIT); + ZoneScope zone(Isolate::Current()->runtime_zone(), DELETE_ON_EXIT); InitializeVM(); v8::HandleScope handle_scope; @@ -672,3 +675,43 @@ TEST(RobustSubStringStub) { CompileRun("var slice = long.slice(1, 15);"); CheckException("%_SubString(slice, 0, 17);"); } + + +TEST(RegExpOverflow) { + // Result string has the length 2^32, causing a 32-bit integer overflow. + InitializeVM(); + HandleScope scope; + LocalContext context; + v8::V8::IgnoreOutOfMemoryException(); + v8::Local<v8::Value> result = CompileRun( + "var a = 'a'; " + "for (var i = 0; i < 16; i++) { " + " a += a; " + "} " + "a.replace(/a/g, a); "); + CHECK(result.IsEmpty()); + CHECK(context->HasOutOfMemoryException()); +} + + +TEST(StringReplaceAtomTwoByteResult) { + InitializeVM(); + HandleScope scope; + LocalContext context; + v8::Local<v8::Value> result = CompileRun( + "var subject = 'ascii~only~string~'; " + "var replace = '\x80'; " + "subject.replace(/~/g, replace); "); + CHECK(result->IsString()); + Handle<String> string = v8::Utils::OpenHandle(v8::String::Cast(*result)); + CHECK(string->IsSeqTwoByteString()); + + v8::Local<v8::String> expected = v8_str("ascii\x80only\x80string\x80"); + CHECK(expected->Equals(result)); +} + + +TEST(IsAscii) { + CHECK(String::IsAscii(static_cast<char*>(NULL), 0)); + CHECK(String::IsAscii(static_cast<uc16*>(NULL), 0)); +} |