Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2013 the V8 project authors. All rights reserved. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 2 | // Redistribution and use in source and binary forms, with or without |
| 3 | // modification, are permitted provided that the following conditions are |
| 4 | // met: |
| 5 | // |
| 6 | // * Redistributions of source code must retain the above copyright |
| 7 | // notice, this list of conditions and the following disclaimer. |
| 8 | // * Redistributions in binary form must reproduce the above |
| 9 | // copyright notice, this list of conditions and the following |
| 10 | // disclaimer in the documentation and/or other materials provided |
| 11 | // with the distribution. |
| 12 | // * Neither the name of Google Inc. nor the names of its |
| 13 | // contributors may be used to endorse or promote products derived |
| 14 | // from this software without specific prior written permission. |
| 15 | // |
| 16 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 27 | |
| 28 | // Check that we can traverse very deep stacks of ConsStrings using |
| 29 | // StringCharacterStram. Check that Get(int) works on very deep stacks |
| 30 | // of ConsStrings. These operations may not be very fast, but they |
| 31 | // should be possible without getting errors due to too deep recursion. |
| 32 | |
| 33 | #include "src/v8.h" |
| 34 | |
| 35 | #include "src/objects.h" |
| 36 | #include "src/ostreams.h" |
| 37 | #include "test/cctest/cctest.h" |
| 38 | |
| 39 | using namespace v8::internal; |
| 40 | |
| 41 | |
| 42 | TEST(Create) { |
| 43 | CcTest::InitializeVM(); |
| 44 | Isolate* isolate = CcTest::i_isolate(); |
| 45 | HandleScope scope(isolate); |
| 46 | |
| 47 | const int kNumSymbols = 30; |
| 48 | Handle<Symbol> symbols[kNumSymbols]; |
| 49 | |
| 50 | OFStream os(stdout); |
| 51 | for (int i = 0; i < kNumSymbols; ++i) { |
| 52 | symbols[i] = isolate->factory()->NewSymbol(); |
| 53 | CHECK(symbols[i]->IsName()); |
| 54 | CHECK(symbols[i]->IsSymbol()); |
| 55 | CHECK(symbols[i]->HasHashCode()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 56 | CHECK_GT(symbols[i]->Hash(), 0u); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 57 | os << Brief(*symbols[i]) << "\n"; |
| 58 | #if OBJECT_PRINT |
| 59 | symbols[i]->Print(os); |
| 60 | #endif |
| 61 | #if VERIFY_HEAP |
| 62 | symbols[i]->ObjectVerify(); |
| 63 | #endif |
| 64 | } |
| 65 | |
| 66 | CcTest::heap()->CollectGarbage(i::NEW_SPACE); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 67 | CcTest::heap()->CollectAllGarbage(); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 68 | |
| 69 | // All symbols should be distinct. |
| 70 | for (int i = 0; i < kNumSymbols; ++i) { |
| 71 | CHECK(symbols[i]->SameValue(*symbols[i])); |
| 72 | for (int j = i + 1; j < kNumSymbols; ++j) { |
| 73 | CHECK(!symbols[i]->SameValue(*symbols[j])); |
| 74 | } |
| 75 | } |
| 76 | } |