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

Side by Side Diff: test/cctest/test-api.cc

Issue 804343006: Version 3.30.33.10 (cherry-pick) (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@3.30
Patch Set: Created 6 years 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 unified diff | Download patch
« no previous file with comments | « src/version.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after
735 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 735 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
736 i::Handle<i::String> isymbol = 736 i::Handle<i::String> isymbol =
737 factory->InternalizeString(istring); 737 factory->InternalizeString(istring);
738 CHECK(isymbol->IsInternalizedString()); 738 CHECK(isymbol->IsInternalizedString());
739 } 739 }
740 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 740 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
741 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 741 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
742 } 742 }
743 743
744 744
745 class DummyResource : public v8::String::ExternalStringResource { 745 class RandomLengthResource : public v8::String::ExternalStringResource {
746 public: 746 public:
747 explicit RandomLengthResource(int length) : length_(length) {}
747 virtual const uint16_t* data() const { return string_; } 748 virtual const uint16_t* data() const { return string_; }
748 virtual size_t length() const { return 1 << 30; } 749 virtual size_t length() const { return length_; }
749 750
750 private: 751 private:
751 uint16_t string_[10]; 752 uint16_t string_[10];
753 int length_;
752 }; 754 };
753 755
754 756
755 class DummyOneByteResource : public v8::String::ExternalOneByteStringResource { 757 class RandomLengthOneByteResource
758 : public v8::String::ExternalOneByteStringResource {
756 public: 759 public:
760 explicit RandomLengthOneByteResource(int length) : length_(length) {}
757 virtual const char* data() const { return string_; } 761 virtual const char* data() const { return string_; }
758 virtual size_t length() const { return 1 << 30; } 762 virtual size_t length() const { return length_; }
759 763
760 private: 764 private:
761 char string_[10]; 765 char string_[10];
766 int length_;
762 }; 767 };
763 768
764 769
765 THREADED_TEST(NewExternalForVeryLongString) { 770 THREADED_TEST(NewExternalForVeryLongString) {
766 { 771 {
767 LocalContext env; 772 LocalContext env;
768 v8::HandleScope scope(env->GetIsolate()); 773 v8::HandleScope scope(env->GetIsolate());
769 v8::TryCatch try_catch; 774 v8::TryCatch try_catch;
770 DummyOneByteResource r; 775 RandomLengthOneByteResource r(1 << 30);
771 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), &r); 776 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), &r);
772 CHECK(str.IsEmpty()); 777 CHECK(str.IsEmpty());
773 CHECK(try_catch.HasCaught()); 778 CHECK(try_catch.HasCaught());
774 String::Utf8Value exception_value(try_catch.Exception()); 779 String::Utf8Value exception_value(try_catch.Exception());
775 CHECK_EQ("RangeError: Invalid string length", *exception_value); 780 CHECK_EQ("RangeError: Invalid string length", *exception_value);
776 } 781 }
777 782
778 { 783 {
779 LocalContext env; 784 LocalContext env;
780 v8::HandleScope scope(env->GetIsolate()); 785 v8::HandleScope scope(env->GetIsolate());
781 v8::TryCatch try_catch; 786 v8::TryCatch try_catch;
782 DummyResource r; 787 RandomLengthResource r(1 << 30);
783 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), &r); 788 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), &r);
784 CHECK(str.IsEmpty()); 789 CHECK(str.IsEmpty());
785 CHECK(try_catch.HasCaught()); 790 CHECK(try_catch.HasCaught());
786 String::Utf8Value exception_value(try_catch.Exception()); 791 String::Utf8Value exception_value(try_catch.Exception());
787 CHECK_EQ("RangeError: Invalid string length", *exception_value); 792 CHECK_EQ("RangeError: Invalid string length", *exception_value);
788 } 793 }
789 } 794 }
790 795
791 796
792 THREADED_TEST(ScavengeExternalString) { 797 THREADED_TEST(ScavengeExternalString) {
(...skipping 23364 matching lines...) Expand 10 before | Expand all | Expand 10 after
24157 char chunk2[] = 24162 char chunk2[] =
24158 "XX\xec\x92\x81r = 13;\n" 24163 "XX\xec\x92\x81r = 13;\n"
24159 " return foob\xec\x92\x81\xec\x92\x81r;\n" 24164 " return foob\xec\x92\x81\xec\x92\x81r;\n"
24160 "}\n"; 24165 "}\n";
24161 chunk1[strlen(chunk1) - 1] = reference[0]; 24166 chunk1[strlen(chunk1) - 1] = reference[0];
24162 chunk2[0] = reference[1]; 24167 chunk2[0] = reference[1];
24163 chunk2[1] = reference[2]; 24168 chunk2[1] = reference[2];
24164 const char* chunks[] = {chunk1, chunk2, "foo();", NULL}; 24169 const char* chunks[] = {chunk1, chunk2, "foo();", NULL};
24165 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8); 24170 RunStreamingTest(chunks, v8::ScriptCompiler::StreamedSource::UTF8);
24166 } 24171 }
24172
24173
24174 TEST(StringConcatOverflow) {
24175 v8::V8::Initialize();
24176 v8::HandleScope scope(CcTest::isolate());
24177 RandomLengthOneByteResource* r =
24178 new RandomLengthOneByteResource(i::String::kMaxLength);
24179 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r);
24180 CHECK(!str.IsEmpty());
24181 v8::TryCatch try_catch;
24182 v8::Local<v8::String> result = v8::String::Concat(str, str);
24183 CHECK(result.IsEmpty());
24184 CHECK(!try_catch.HasCaught());
24185 }
OLDNEW
« no previous file with comments | « src/version.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698