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

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

Issue 150213002: Make sure we delete[] what we got from new[], not one byte after it. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | 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 470 matching lines...) Expand 10 before | Expand all | Expand 10 after
481 } 481 }
482 private: 482 private:
483 uint16_t* data_; 483 uint16_t* data_;
484 size_t length_; 484 size_t length_;
485 int* counter_; 485 int* counter_;
486 }; 486 };
487 487
488 488
489 class TestAsciiResource: public String::ExternalAsciiStringResource { 489 class TestAsciiResource: public String::ExternalAsciiStringResource {
490 public: 490 public:
491 explicit TestAsciiResource(const char* data, int* counter = NULL) 491 TestAsciiResource(const char* data, int* counter = NULL, size_t offset = 0)
492 : data_(data), length_(strlen(data)), counter_(counter) { } 492 : orig_data_(data),
493 data_(data + offset),
494 length_(strlen(data) - offset),
495 counter_(counter) { }
493 496
494 ~TestAsciiResource() { 497 ~TestAsciiResource() {
495 i::DeleteArray(data_); 498 i::DeleteArray(orig_data_);
496 if (counter_ != NULL) ++*counter_; 499 if (counter_ != NULL) ++*counter_;
497 } 500 }
498 501
499 const char* data() const { 502 const char* data() const {
500 return data_; 503 return data_;
501 } 504 }
502 505
503 size_t length() const { 506 size_t length() const {
504 return length_; 507 return length_;
505 } 508 }
509
506 private: 510 private:
511 const char* orig_data_;
507 const char* data_; 512 const char* data_;
508 size_t length_; 513 size_t length_;
509 int* counter_; 514 int* counter_;
510 }; 515 };
511 516
512 517
513 THREADED_TEST(ScriptUsingStringResource) { 518 THREADED_TEST(ScriptUsingStringResource) {
514 int dispose_count = 0; 519 int dispose_count = 0;
515 const char* c_source = "1 + 2 * 3"; 520 const char* c_source = "1 + 2 * 3";
516 uint16_t* two_byte_source = AsciiToTwoByteString(c_source); 521 uint16_t* two_byte_source = AsciiToTwoByteString(c_source);
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
726 731
727 // Trigger GCs so that the newly allocated string moves to old gen. 732 // Trigger GCs so that the newly allocated string moves to old gen.
728 SimulateFullSpace(CcTest::heap()->old_pointer_space()); 733 SimulateFullSpace(CcTest::heap()->old_pointer_space());
729 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now 734 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in survivor space now
730 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now 735 CcTest::heap()->CollectGarbage(i::NEW_SPACE); // in old gen now
731 736
732 // Turn into external string with unaligned resource data. 737 // Turn into external string with unaligned resource data.
733 int dispose_count = 0; 738 int dispose_count = 0;
734 const char* c_cons = "_abcdefghijklmnopqrstuvwxyz"; 739 const char* c_cons = "_abcdefghijklmnopqrstuvwxyz";
735 bool success = cons->MakeExternal( 740 bool success = cons->MakeExternal(
736 new TestAsciiResource(i::StrDup(c_cons) + 1, &dispose_count)); 741 new TestAsciiResource(i::StrDup(c_cons), &dispose_count, 1));
737 CHECK(success); 742 CHECK(success);
738 const char* c_slice = "_bcdefghijklmnopqrstuvwxyz"; 743 const char* c_slice = "_bcdefghijklmnopqrstuvwxyz";
739 success = slice->MakeExternal( 744 success = slice->MakeExternal(
740 new TestAsciiResource(i::StrDup(c_slice) + 1, &dispose_count)); 745 new TestAsciiResource(i::StrDup(c_slice), &dispose_count, 1));
741 CHECK(success); 746 CHECK(success);
742 747
743 // Trigger GCs and force evacuation. 748 // Trigger GCs and force evacuation.
744 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags); 749 CcTest::heap()->CollectAllGarbage(i::Heap::kNoGCFlags);
745 CcTest::heap()->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask); 750 CcTest::heap()->CollectAllGarbage(i::Heap::kReduceMemoryFootprintMask);
746 } 751 }
747 752
748 753
749 THREADED_TEST(UsingExternalString) { 754 THREADED_TEST(UsingExternalString) {
750 i::Factory* factory = CcTest::i_isolate()->factory(); 755 i::Factory* factory = CcTest::i_isolate()->factory();
(...skipping 21082 matching lines...) Expand 10 before | Expand all | Expand 10 after
21833 context->Global()->Set(v8_str("P"), templ->NewInstance()); 21838 context->Global()->Set(v8_str("P"), templ->NewInstance());
21834 CompileRun( 21839 CompileRun(
21835 "function C1() {" 21840 "function C1() {"
21836 " this.x = 23;" 21841 " this.x = 23;"
21837 "};" 21842 "};"
21838 "C1.prototype = P;" 21843 "C1.prototype = P;"
21839 "for (var i = 0; i < 4; i++ ) {" 21844 "for (var i = 0; i < 4; i++ ) {"
21840 " new C1();" 21845 " new C1();"
21841 "}"); 21846 "}");
21842 } 21847 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698