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

Side by Side Diff: test/cctest/test-code-stub-assembler.cc

Issue 2247353005: [builtins] support exception handling in TFJ builtins (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: rebased Created 4 years, 4 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
« no previous file with comments | « src/isolate.cc ('k') | 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 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
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 const int kNumParams = 1;
1349 CodeStubAssemblerTester m(isolate, kNumParams);
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, kNumParams);
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 const int kNumParams = 4; // receiver, first, second, third
1390 CodeStubAssemblerTester m(isolate, kNumParams);
1391
1392 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context()));
1393 Node* first_value = m.Parameter(0);
1394 Node* second_value = m.Parameter(1);
1395 Node* third_value = m.Parameter(2);
1396
1397 Label exception_handler1(&m);
1398 Label exception_handler2(&m);
1399 Label exception_handler3(&m);
1400 Variable return_value(&m, MachineRepresentation::kWord32);
1401 Variable error(&m, MachineRepresentation::kTagged);
1402
1403 return_value.Bind(m.Int32Constant(0));
1404
1405 // try { return ToString(param1) } catch (e) { ... }
1406 Callable to_string = CodeFactory::ToString(isolate);
1407 Node* string = m.CallStub(to_string, context, first_value);
1408 m.GotoIfException(string, &exception_handler1, &error);
1409 m.Return(string);
1410
1411 // try { ToString(param2); return 7 } catch (e) { ... }
1412 m.Bind(&exception_handler1);
1413 return_value.Bind(m.Int32Constant(7));
1414 error.Bind(m.UndefinedConstant());
1415 string = m.CallStub(to_string, context, second_value);
1416 m.GotoIfException(string, &exception_handler2, &error);
1417 m.Return(m.SmiFromWord32(return_value.value()));
1418
1419 // try { ToString(param3); return 7 & ~2; } catch (e) { return e; }
1420 m.Bind(&exception_handler2);
1421 // Return returnValue & ~2
1422 error.Bind(m.UndefinedConstant());
1423 string = m.CallStub(to_string, context, third_value);
1424 m.GotoIfException(string, &exception_handler3, &error);
1425 m.Return(m.SmiFromWord32(
1426 m.Word32And(return_value.value(),
1427 m.Word32Xor(m.Int32Constant(2), m.Int32Constant(-1)))));
1428
1429 m.Bind(&exception_handler3);
1430 m.Return(error.value());
1431
1432 Handle<Code> code = m.GenerateCode();
1433 CHECK(!code.is_null());
1434
1435 // Emulate TFJ builtin
1436 code->set_flags(Code::ComputeFlags(Code::BUILTIN));
1437
1438 FunctionTester ft(code, kNumParams);
1439
1440 Handle<Object> result;
1441 // First handler does not throw, returns result of first value
1442 result = ft.Call(isolate->factory()->undefined_value(),
1443 isolate->factory()->to_string_tag_symbol())
1444 .ToHandleChecked();
1445 CHECK(String::cast(*result)->IsOneByteEqualTo(OneByteVector("undefined")));
1446
1447 // First handler returns a number
1448 result = ft.Call(isolate->factory()->to_string_tag_symbol(),
1449 isolate->factory()->undefined_value())
1450 .ToHandleChecked();
1451 CHECK_EQ(7, Smi::cast(*result)->value());
1452
1453 // First handler throws, second handler returns a number
1454 result = ft.Call(isolate->factory()->to_string_tag_symbol(),
1455 isolate->factory()->to_primitive_symbol())
1456 .ToHandleChecked();
1457 CHECK_EQ(7 & ~2, Smi::cast(*result)->value());
1458
1459 // First handler throws, second handler throws, third handler returns thrown
1460 // value.
1461 result = ft.Call(isolate->factory()->to_string_tag_symbol(),
1462 isolate->factory()->to_primitive_symbol(),
1463 isolate->factory()->unscopables_symbol())
1464 .ToHandleChecked();
1465
1466 // Should be a TypeError
1467 CHECK(result->IsJSObject());
1468
1469 Handle<Object> constructor =
1470 Object::GetPropertyOrElement(result,
1471 isolate->factory()->constructor_string())
1472 .ToHandleChecked();
1473 CHECK(constructor->SameValue(*isolate->type_error_function()));
1474 }
1475
1343 } // namespace internal 1476 } // namespace internal
1344 } // namespace v8 1477 } // namespace v8
OLDNEW
« no previous file with comments | « src/isolate.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698