Chromium Code Reviews| 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/ic/stub-cache.h" | 6 #include "src/ic/stub-cache.h" |
| 7 #include "src/isolate.h" | 7 #include "src/isolate.h" |
| 8 #include "test/cctest/compiler/code-assembler-tester.h" | 8 #include "test/cctest/compiler/code-assembler-tester.h" |
| 9 #include "test/cctest/compiler/function-tester.h" | 9 #include "test/cctest/compiler/function-tester.h" |
| 10 | 10 |
| (...skipping 1322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1333 queried_existing = true; | 1333 queried_existing = true; |
| 1334 } | 1334 } |
| 1335 | 1335 |
| 1336 Handle<Code> expected_handler(handler, isolate); | 1336 Handle<Code> expected_handler(handler, isolate); |
| 1337 ft.CheckTrue(receiver, name, expected_handler); | 1337 ft.CheckTrue(receiver, name, expected_handler); |
| 1338 } | 1338 } |
| 1339 // Ensure we performed both kind of queries. | 1339 // Ensure we performed both kind of queries. |
| 1340 CHECK(queried_existing && queried_non_existing); | 1340 CHECK(queried_existing && queried_non_existing); |
| 1341 } | 1341 } |
| 1342 | 1342 |
| 1343 TEST(GotoIfException) { | |
| 1344 typedef CodeStubAssembler::Label Label; | |
| 1345 typedef CodeStubAssembler::Variable Variable; | |
| 1346 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 1347 | |
| 1348 VoidDescriptor descriptor(isolate); | |
| 1349 CodeStubAssemblerTester m(isolate, descriptor); | |
| 1350 | |
| 1351 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); | |
| 1352 Node* to_string_tag = | |
| 1353 m.HeapConstant(isolate->factory()->to_string_tag_symbol()); | |
| 1354 Variable exception(&m, MachineRepresentation::kTagged); | |
| 1355 | |
| 1356 Label exception_handler(&m); | |
| 1357 Callable to_string = CodeFactory::ToString(isolate); | |
| 1358 Node* string = m.CallStub(to_string, context, to_string_tag); | |
| 1359 m.GotoIfException(string, &exception_handler, &exception); | |
| 1360 m.Return(string); | |
| 1361 | |
| 1362 m.Bind(&exception_handler); | |
| 1363 m.Return(exception.value()); | |
| 1364 | |
| 1365 Handle<Code> code = m.GenerateCode(); | |
| 1366 CHECK(!code.is_null()); | |
| 1367 | |
| 1368 // Emulate TFJ builtin | |
| 1369 code->set_flags(Code::ComputeFlags(Code::BUILTIN)); | |
| 1370 | |
| 1371 FunctionTester ft(code, 0); | |
| 1372 Handle<Object> result = ft.Call().ToHandleChecked(); | |
| 1373 | |
| 1374 // Should be a TypeError | |
| 1375 CHECK(result->IsJSObject()); | |
| 1376 | |
| 1377 Handle<Object> constructor = | |
| 1378 Object::GetPropertyOrElement(result, | |
| 1379 isolate->factory()->constructor_string()) | |
| 1380 .ToHandleChecked(); | |
| 1381 CHECK(constructor->SameValue(*isolate->type_error_function())); | |
| 1382 } | |
| 1383 | |
| 1384 TEST(GotoIfExceptionMultiple) { | |
| 1385 typedef CodeStubAssembler::Label Label; | |
| 1386 typedef CodeStubAssembler::Variable Variable; | |
| 1387 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 1388 | |
| 1389 VoidDescriptor descriptor(isolate); | |
| 1390 CodeStubAssemblerTester m(isolate, descriptor); | |
| 1391 | |
| 1392 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); | |
| 1393 Node* to_string_tag = | |
| 1394 m.HeapConstant(isolate->factory()->to_string_tag_symbol()); | |
| 1395 | |
| 1396 Label exception_handler(&m); | |
| 1397 Label exception_handler2(&m); | |
| 1398 Variable return_value(&m, MachineRepresentation::kWord32); | |
| 1399 | |
| 1400 return_value.Bind(m.Int32Constant(0)); | |
| 1401 | |
| 1402 Callable to_string = CodeFactory::ToString(isolate); | |
| 1403 Node* string = m.CallStub(to_string, context, to_string_tag); | |
| 1404 m.GotoIfException(string, &exception_handler); | |
| 1405 m.Return(string); | |
| 1406 | |
| 1407 m.Bind(&exception_handler); | |
| 1408 m.DebugBreak(); | |
| 1409 return_value.Bind(m.Int32Constant(7)); | |
| 1410 | |
| 1411 string = m.CallStub(to_string, context, to_string_tag); | |
| 1412 m.GotoIfException(string, &exception_handler2); | |
|
caitp
2016/08/18 16:59:20
There's something weird with the latest refactorin
| |
| 1413 m.Return(m.SmiFromWord32(return_value.value())); | |
| 1414 | |
| 1415 m.Bind(&exception_handler2); | |
| 1416 // Return returnValue & ~2 | |
| 1417 m.DebugBreak(); | |
| 1418 m.Return(m.SmiFromWord32( | |
| 1419 m.Word32And(return_value.value(), | |
| 1420 m.Word32Xor(m.Int32Constant(2), m.Int32Constant(-1))))); | |
| 1421 | |
| 1422 Handle<Code> code = m.GenerateCode(); | |
| 1423 CHECK(!code.is_null()); | |
| 1424 | |
| 1425 // Emulate TFJ builtin | |
| 1426 code->set_flags(Code::ComputeFlags(Code::BUILTIN)); | |
| 1427 | |
| 1428 FunctionTester ft(code, 0); | |
| 1429 CHECK_EQ(7 & ~2, Smi::cast(*ft.Call().ToHandleChecked())->value()); | |
| 1430 } | |
| 1431 | |
| 1432 TEST(GotoIfExceptionNoException) { | |
| 1433 typedef CodeStubAssembler::Label Label; | |
| 1434 typedef CodeStubAssembler::Variable Variable; | |
| 1435 Isolate* isolate(CcTest::InitIsolateOnce()); | |
| 1436 | |
| 1437 VoidDescriptor descriptor(isolate); | |
| 1438 CodeStubAssemblerTester m(isolate, descriptor); | |
| 1439 | |
| 1440 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); | |
| 1441 Node* undefined = m.HeapConstant(isolate->factory()->undefined_value()); | |
| 1442 Variable exception(&m, MachineRepresentation::kTagged); | |
| 1443 | |
| 1444 Label exception_handler(&m); | |
| 1445 Callable to_string = CodeFactory::ToString(isolate); | |
| 1446 Node* string = m.CallRuntime(Runtime::kToString, context, undefined); | |
| 1447 m.GotoIfException(string, &exception_handler, &exception); | |
| 1448 m.Return(string); | |
| 1449 | |
| 1450 m.Bind(&exception_handler); | |
| 1451 m.Return(m.SmiConstant(Smi::FromInt(-1))); | |
| 1452 | |
| 1453 Handle<Code> code = m.GenerateCode(); | |
| 1454 CHECK(!code.is_null()); | |
| 1455 | |
| 1456 // Emulate TFJ builtin | |
| 1457 code->set_flags(Code::ComputeFlags(Code::BUILTIN)); | |
| 1458 | |
| 1459 FunctionTester ft(code, 0); | |
| 1460 Handle<String> result = Handle<String>::cast(ft.Call().ToHandleChecked()); | |
| 1461 CHECK(result->IsOneByteEqualTo(OneByteVector("undefined"))); | |
| 1462 } | |
| 1463 | |
| 1343 } // namespace internal | 1464 } // namespace internal |
| 1344 } // namespace v8 | 1465 } // namespace v8 |
| OLD | NEW |