OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/base/utils/random-number-generator.h" | 5 #include "src/base/utils/random-number-generator.h" |
6 #include "src/code-factory.h" | 6 #include "src/code-factory.h" |
7 #include "src/code-stub-assembler.h" | 7 #include "src/code-stub-assembler.h" |
8 #include "src/compiler/node.h" | 8 #include "src/compiler/node.h" |
9 #include "src/ic/stub-cache.h" | 9 #include "src/ic/stub-cache.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 for (int i = 0; i < 5; ++i) { | 168 for (int i = 0; i < 5; ++i) { |
169 Handle<FixedArray> test = handle(FixedArray::cast(test_cases->get(i))); | 169 Handle<FixedArray> test = handle(FixedArray::cast(test_cases->get(i))); |
170 Handle<Object> obj = handle(test->get(0), isolate); | 170 Handle<Object> obj = handle(test->get(0), isolate); |
171 Handle<String> expected = handle(String::cast(test->get(1))); | 171 Handle<String> expected = handle(String::cast(test->get(1))); |
172 Handle<Object> result = ft.Call(obj).ToHandleChecked(); | 172 Handle<Object> result = ft.Call(obj).ToHandleChecked(); |
173 CHECK(result->IsString()); | 173 CHECK(result->IsString()); |
174 CHECK(String::Equals(Handle<String>::cast(result), expected)); | 174 CHECK(String::Equals(Handle<String>::cast(result), expected)); |
175 } | 175 } |
176 } | 176 } |
177 | 177 |
| 178 TEST(FlattenString) { |
| 179 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 180 const int kNumParams = 1; |
| 181 CodeStubAssemblerTester m(isolate, kNumParams); |
| 182 m.Return(m.FlattenString(m.Parameter(0))); |
| 183 |
| 184 Handle<Code> code = m.GenerateCode(); |
| 185 FunctionTester ft(code, kNumParams); |
| 186 |
| 187 Handle<FixedArray> test_cases(isolate->factory()->NewFixedArray(4)); |
| 188 Handle<String> expected( |
| 189 isolate->factory()->InternalizeUtf8String("hello, world!")); |
| 190 test_cases->set(0, *expected); |
| 191 |
| 192 Handle<String> string( |
| 193 isolate->factory()->InternalizeUtf8String("filler hello, world! filler")); |
| 194 Handle<String> sub_string( |
| 195 isolate->factory()->NewProperSubString(string, 7, 20)); |
| 196 test_cases->set(1, *sub_string); |
| 197 |
| 198 Handle<String> hello(isolate->factory()->InternalizeUtf8String("hello,")); |
| 199 Handle<String> world(isolate->factory()->InternalizeUtf8String(" world!")); |
| 200 Handle<String> cons_str( |
| 201 isolate->factory()->NewConsString(hello, world).ToHandleChecked()); |
| 202 test_cases->set(2, *cons_str); |
| 203 |
| 204 Handle<String> empty(isolate->factory()->InternalizeUtf8String("")); |
| 205 Handle<String> fake_cons_str( |
| 206 isolate->factory()->NewConsString(expected, empty).ToHandleChecked()); |
| 207 test_cases->set(3, *fake_cons_str); |
| 208 |
| 209 for (int i = 0; i < 4; ++i) { |
| 210 Handle<String> test = handle(String::cast(test_cases->get(i))); |
| 211 Handle<Object> result = ft.Call(test).ToHandleChecked(); |
| 212 CHECK(result->IsString()); |
| 213 CHECK(Handle<String>::cast(result)->IsFlat()); |
| 214 CHECK(String::Equals(Handle<String>::cast(result), expected)); |
| 215 } |
| 216 } |
| 217 |
178 TEST(TryToName) { | 218 TEST(TryToName) { |
179 typedef CodeStubAssembler::Label Label; | 219 typedef CodeStubAssembler::Label Label; |
180 typedef CodeStubAssembler::Variable Variable; | 220 typedef CodeStubAssembler::Variable Variable; |
181 Isolate* isolate(CcTest::InitIsolateOnce()); | 221 Isolate* isolate(CcTest::InitIsolateOnce()); |
182 | 222 |
183 const int kNumParams = 3; | 223 const int kNumParams = 3; |
184 CodeStubAssemblerTester m(isolate, kNumParams); | 224 CodeStubAssemblerTester m(isolate, kNumParams); |
185 | 225 |
186 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; | 226 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; |
187 { | 227 { |
(...skipping 1434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1622 .ToHandleChecked()); | 1662 .ToHandleChecked()); |
1623 VERIFY(result, object->map(), object->properties(), object->elements()); | 1663 VERIFY(result, object->map(), object->properties(), object->elements()); |
1624 #ifdef VERIFY_HEAP | 1664 #ifdef VERIFY_HEAP |
1625 isolate->heap()->Verify(); | 1665 isolate->heap()->Verify(); |
1626 #endif | 1666 #endif |
1627 } | 1667 } |
1628 } | 1668 } |
1629 | 1669 |
1630 } // namespace internal | 1670 } // namespace internal |
1631 } // namespace v8 | 1671 } // namespace v8 |
OLD | NEW |