| 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/builtins/builtins-promise.h" | 6 #include "src/builtins/builtins-promise.h" |
| 7 #include "src/code-factory.h" | 7 #include "src/code-factory.h" |
| 8 #include "src/code-stub-assembler.h" | 8 #include "src/code-stub-assembler.h" |
| 9 #include "src/compiler/node.h" | 9 #include "src/compiler/node.h" |
| 10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 173 for (int i = 0; i < 5; ++i) { | 173 for (int i = 0; i < 5; ++i) { |
| 174 Handle<FixedArray> test = handle(FixedArray::cast(test_cases->get(i))); | 174 Handle<FixedArray> test = handle(FixedArray::cast(test_cases->get(i))); |
| 175 Handle<Object> obj = handle(test->get(0), isolate); | 175 Handle<Object> obj = handle(test->get(0), isolate); |
| 176 Handle<String> expected = handle(String::cast(test->get(1))); | 176 Handle<String> expected = handle(String::cast(test->get(1))); |
| 177 Handle<Object> result = ft.Call(obj).ToHandleChecked(); | 177 Handle<Object> result = ft.Call(obj).ToHandleChecked(); |
| 178 CHECK(result->IsString()); | 178 CHECK(result->IsString()); |
| 179 CHECK(String::Equals(Handle<String>::cast(result), expected)); | 179 CHECK(String::Equals(Handle<String>::cast(result), expected)); |
| 180 } | 180 } |
| 181 } | 181 } |
| 182 | 182 |
| 183 TEST(FlattenString) { | |
| 184 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 185 const int kNumParams = 1; | |
| 186 CodeAssemblerTester data(isolate, kNumParams); | |
| 187 CodeStubAssembler m(data.state()); | |
| 188 m.Return(m.FlattenString(m.Parameter(0))); | |
| 189 | |
| 190 Handle<Code> code = data.GenerateCode(); | |
| 191 FunctionTester ft(code, kNumParams); | |
| 192 | |
| 193 Handle<FixedArray> test_cases(isolate->factory()->NewFixedArray(4)); | |
| 194 Handle<String> expected( | |
| 195 isolate->factory()->InternalizeUtf8String("hello, world!")); | |
| 196 test_cases->set(0, *expected); | |
| 197 | |
| 198 Handle<String> string( | |
| 199 isolate->factory()->InternalizeUtf8String("filler hello, world! filler")); | |
| 200 Handle<String> sub_string( | |
| 201 isolate->factory()->NewProperSubString(string, 7, 20)); | |
| 202 test_cases->set(1, *sub_string); | |
| 203 | |
| 204 Handle<String> hello(isolate->factory()->InternalizeUtf8String("hello,")); | |
| 205 Handle<String> world(isolate->factory()->InternalizeUtf8String(" world!")); | |
| 206 Handle<String> cons_str( | |
| 207 isolate->factory()->NewConsString(hello, world).ToHandleChecked()); | |
| 208 test_cases->set(2, *cons_str); | |
| 209 | |
| 210 Handle<String> empty(isolate->factory()->InternalizeUtf8String("")); | |
| 211 Handle<String> fake_cons_str( | |
| 212 isolate->factory()->NewConsString(expected, empty).ToHandleChecked()); | |
| 213 test_cases->set(3, *fake_cons_str); | |
| 214 | |
| 215 for (int i = 0; i < 4; ++i) { | |
| 216 Handle<String> test = handle(String::cast(test_cases->get(i))); | |
| 217 Handle<Object> result = ft.Call(test).ToHandleChecked(); | |
| 218 CHECK(result->IsString()); | |
| 219 CHECK(Handle<String>::cast(result)->IsFlat()); | |
| 220 CHECK(String::Equals(Handle<String>::cast(result), expected)); | |
| 221 } | |
| 222 } | |
| 223 | |
| 224 TEST(TryToName) { | 183 TEST(TryToName) { |
| 225 typedef CodeAssemblerLabel Label; | 184 typedef CodeAssemblerLabel Label; |
| 226 typedef CodeAssemblerVariable Variable; | 185 typedef CodeAssemblerVariable Variable; |
| 227 Isolate* isolate(CcTest::InitIsolateOnce()); | 186 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 228 | 187 |
| 229 const int kNumParams = 3; | 188 const int kNumParams = 3; |
| 230 CodeAssemblerTester data(isolate, kNumParams); | 189 CodeAssemblerTester data(isolate, kNumParams); |
| 231 CodeStubAssembler m(data.state()); | 190 CodeStubAssembler m(data.state()); |
| 232 | 191 |
| 233 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; | 192 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; |
| 234 { | 193 { |
| 235 Node* key = m.Parameter(0); | 194 Node* key = m.Parameter(0); |
| 236 Node* expected_result = m.Parameter(1); | 195 Node* expected_result = m.Parameter(1); |
| 237 Node* expected_arg = m.Parameter(2); | 196 Node* expected_arg = m.Parameter(2); |
| 238 | 197 |
| 239 Label passed(&m), failed(&m); | 198 Label passed(&m), failed(&m); |
| 240 Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m); | 199 Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m); |
| 241 Variable var_index(&m, MachineType::PointerRepresentation()); | 200 { |
| 201 Variable var_index(&m, MachineType::PointerRepresentation()); |
| 202 Variable var_unique(&m, MachineRepresentation::kTagged); |
| 242 | 203 |
| 243 m.TryToName(key, &if_keyisindex, &var_index, &if_keyisunique, &if_bailout); | 204 m.TryToName(key, &if_keyisindex, &var_index, &if_keyisunique, &var_unique, |
| 205 &if_bailout); |
| 244 | 206 |
| 245 m.Bind(&if_keyisindex); | 207 m.Bind(&if_keyisindex); |
| 246 m.GotoUnless( | 208 m.GotoUnless(m.WordEqual(expected_result, |
| 247 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kKeyIsIndex))), | 209 m.SmiConstant(Smi::FromInt(kKeyIsIndex))), |
| 248 &failed); | 210 &failed); |
| 249 m.Branch(m.WordEqual(m.SmiUntag(expected_arg), var_index.value()), &passed, | 211 m.Branch(m.WordEqual(m.SmiUntag(expected_arg), var_index.value()), |
| 250 &failed); | 212 &passed, &failed); |
| 251 | 213 |
| 252 m.Bind(&if_keyisunique); | 214 m.Bind(&if_keyisunique); |
| 253 m.GotoUnless( | 215 m.GotoUnless(m.WordEqual(expected_result, |
| 254 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kKeyIsUnique))), | 216 m.SmiConstant(Smi::FromInt(kKeyIsUnique))), |
| 255 &failed); | 217 &failed); |
| 256 m.Branch(m.WordEqual(expected_arg, key), &passed, &failed); | 218 m.Branch(m.WordEqual(expected_arg, var_unique.value()), &passed, &failed); |
| 219 } |
| 257 | 220 |
| 258 m.Bind(&if_bailout); | 221 m.Bind(&if_bailout); |
| 259 m.Branch( | 222 m.Branch( |
| 260 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))), | 223 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))), |
| 261 &passed, &failed); | 224 &passed, &failed); |
| 262 | 225 |
| 263 m.Bind(&passed); | 226 m.Bind(&passed); |
| 264 m.Return(m.BooleanConstant(true)); | 227 m.Return(m.BooleanConstant(true)); |
| 265 | 228 |
| 266 m.Bind(&failed); | 229 m.Bind(&failed); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 342 Handle<String> key = isolate->factory()->NewStringFromAsciiChecked("153"); | 305 Handle<String> key = isolate->factory()->NewStringFromAsciiChecked("153"); |
| 343 CHECK(!key->HasHashCode()); | 306 CHECK(!key->HasHashCode()); |
| 344 ft.CheckTrue(key, expect_bailout); | 307 ft.CheckTrue(key, expect_bailout); |
| 345 } | 308 } |
| 346 | 309 |
| 347 { | 310 { |
| 348 // TryToName(<non-internalized string>) => bailout. | 311 // TryToName(<non-internalized string>) => bailout. |
| 349 Handle<Object> key = isolate->factory()->NewStringFromAsciiChecked("test"); | 312 Handle<Object> key = isolate->factory()->NewStringFromAsciiChecked("test"); |
| 350 ft.CheckTrue(key, expect_bailout); | 313 ft.CheckTrue(key, expect_bailout); |
| 351 } | 314 } |
| 315 |
| 316 { |
| 317 // TryToName(<thin string>) => internalized version. |
| 318 Handle<String> s = isolate->factory()->NewStringFromAsciiChecked("foo"); |
| 319 Handle<String> internalized = isolate->factory()->InternalizeString(s); |
| 320 ft.CheckTrue(s, expect_unique, internalized); |
| 321 } |
| 322 |
| 323 { |
| 324 // TryToName(<thin two-byte string>) => internalized version. |
| 325 uc16 array1[] = {2001, 2002, 2003}; |
| 326 Vector<const uc16> str1(array1); |
| 327 Handle<String> s = |
| 328 isolate->factory()->NewStringFromTwoByte(str1).ToHandleChecked(); |
| 329 Handle<String> internalized = isolate->factory()->InternalizeString(s); |
| 330 ft.CheckTrue(s, expect_unique, internalized); |
| 331 } |
| 352 } | 332 } |
| 353 | 333 |
| 354 namespace { | 334 namespace { |
| 355 | 335 |
| 356 template <typename Dictionary> | 336 template <typename Dictionary> |
| 357 void TestEntryToIndex() { | 337 void TestEntryToIndex() { |
| 358 Isolate* isolate(CcTest::InitIsolateOnce()); | 338 Isolate* isolate(CcTest::InitIsolateOnce()); |
| 359 | 339 |
| 360 const int kNumParams = 1; | 340 const int kNumParams = 1; |
| 361 CodeAssemblerTester data(isolate, kNumParams); | 341 CodeAssemblerTester data(isolate, kNumParams); |
| (...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2477 m.Return(m.SmiConstant(0)); | 2457 m.Return(m.SmiConstant(0)); |
| 2478 | 2458 |
| 2479 Handle<Code> code = data.GenerateCode(); | 2459 Handle<Code> code = data.GenerateCode(); |
| 2480 CHECK(!code.is_null()); | 2460 CHECK(!code.is_null()); |
| 2481 FunctionTester ft(code, kNumParams); | 2461 FunctionTester ft(code, kNumParams); |
| 2482 CHECK_EQ(1, Handle<Smi>::cast(ft.Call().ToHandleChecked())->value()); | 2462 CHECK_EQ(1, Handle<Smi>::cast(ft.Call().ToHandleChecked())->value()); |
| 2483 } | 2463 } |
| 2484 | 2464 |
| 2485 } // namespace internal | 2465 } // namespace internal |
| 2486 } // namespace v8 | 2466 } // namespace v8 |
| OLD | NEW |