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(BranchIfException) { | |
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 | |
1355 Label exception_handler(&m); | |
1356 Callable to_string = CodeFactory::ToString(isolate); | |
1357 Node* string = m.CallStub(to_string, context, to_string_tag); | |
1358 m.BranchIfException(string, &exception_handler); | |
1359 m.Return(string); | |
1360 | |
1361 m.Bind(&exception_handler); | |
1362 m.Return(m.SmiConstant(Smi::FromInt(-1))); | |
1363 | |
1364 Handle<Code> code = m.GenerateCode(); | |
1365 CHECK(!code.is_null()); | |
1366 | |
1367 // Emulate TFJ builtin | |
1368 code->set_flags(Code::ComputeFlags(Code::BUILTIN)); | |
1369 | |
1370 FunctionTester ft(code, 0); | |
1371 MaybeHandle<Object> result = ft.Call(); | |
1372 CHECK_EQ(-1, Handle<Smi>::cast(result.ToHandleChecked())->value()); | |
1373 } | |
1374 | |
1375 TEST(BranchIfException2) { | |
1376 typedef CodeStubAssembler::Label Label; | |
1377 // typedef CodeStubAssembler::Variable Variable; | |
1378 Isolate* isolate(CcTest::InitIsolateOnce()); | |
1379 | |
1380 VoidDescriptor descriptor(isolate); | |
1381 CodeStubAssemblerTester m(isolate, descriptor); | |
1382 | |
1383 Node* context = m.HeapConstant(Handle<Context>(isolate->native_context())); | |
1384 Node* to_string_tag = | |
1385 m.HeapConstant(isolate->factory()->to_string_tag_symbol()); | |
1386 | |
1387 Label exception_handler(&m); | |
1388 Callable to_string = CodeFactory::ToString(isolate); | |
1389 Node* string = m.CallStub(to_string, context, to_string_tag); | |
1390 m.BranchIfException(string, &exception_handler); | |
1391 m.Return(string); | |
1392 | |
1393 m.Bind(&exception_handler); | |
1394 m.Return(string); | |
caitp
2016/08/18 03:08:57
The fact that this test passes is very surprising
| |
1395 | |
1396 Handle<Code> code = m.GenerateCode(); | |
1397 CHECK(!code.is_null()); | |
1398 | |
1399 // Emulate TFJ builtin | |
1400 code->set_flags(Code::ComputeFlags(Code::BUILTIN)); | |
1401 | |
1402 FunctionTester ft(code, 0); | |
1403 Handle<Object> result = ft.Call().ToHandleChecked(); | |
1404 | |
1405 // Should be a TypeError | |
1406 CHECK(result->IsJSObject()); | |
1407 | |
1408 Handle<Object> constructor = | |
1409 Object::GetPropertyOrElement(result, | |
1410 isolate->factory()->constructor_string()) | |
1411 .ToHandleChecked(); | |
1412 CHECK(constructor->SameValue(*isolate->type_error_function())); | |
1413 } | |
1414 | |
1343 } // namespace internal | 1415 } // namespace internal |
1344 } // namespace v8 | 1416 } // namespace v8 |
OLD | NEW |