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

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

Issue 735763002: v8::String::Concat must not throw. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years, 1 month 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/api.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 23432 matching lines...) Expand 10 before | Expand all | Expand 10 after
24225 } 24230 }
24226 24231
24227 24232
24228 TEST(InvalidCacheData) { 24233 TEST(InvalidCacheData) {
24229 v8::V8::Initialize(); 24234 v8::V8::Initialize();
24230 v8::HandleScope scope(CcTest::isolate()); 24235 v8::HandleScope scope(CcTest::isolate());
24231 LocalContext context; 24236 LocalContext context;
24232 TestInvalidCacheData(v8::ScriptCompiler::kConsumeParserCache); 24237 TestInvalidCacheData(v8::ScriptCompiler::kConsumeParserCache);
24233 TestInvalidCacheData(v8::ScriptCompiler::kConsumeCodeCache); 24238 TestInvalidCacheData(v8::ScriptCompiler::kConsumeCodeCache);
24234 } 24239 }
24240
24241
24242 TEST(StringConcatOverflow) {
24243 v8::V8::Initialize();
24244 v8::HandleScope scope(CcTest::isolate());
24245 RandomLengthOneByteResource* r =
24246 new RandomLengthOneByteResource(i::String::kMaxLength);
24247 v8::Local<v8::String> str = v8::String::NewExternal(CcTest::isolate(), r);
24248 CHECK(!str.IsEmpty());
24249 v8::TryCatch try_catch;
24250 v8::Local<v8::String> result = v8::String::Concat(str, str);
24251 CHECK(result.IsEmpty());
24252 CHECK(!try_catch.HasCaught());
24253 }
OLDNEW
« no previous file with comments | « src/api.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698