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 // TODO(jochen): Remove this after the setting is turned on globally. | 5 // TODO(jochen): Remove this after the setting is turned on globally. |
6 #define V8_IMMINENT_DEPRECATION_WARNINGS | 6 #define V8_IMMINENT_DEPRECATION_WARNINGS |
7 | 7 |
8 #include "src/v8.h" | 8 #include "src/v8.h" |
9 | 9 |
10 #include "src/ast.h" | 10 #include "src/ast.h" |
(...skipping 1401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1412 | 1412 |
1413 | 1413 |
1414 TEST(BadLiteral) { | 1414 TEST(BadLiteral) { |
1415 CHECK_FUNC_ERROR( | 1415 CHECK_FUNC_ERROR( |
1416 "function bar() { return true | 0; }\n" | 1416 "function bar() { return true | 0; }\n" |
1417 "function foo() { bar(); }", | 1417 "function foo() { bar(); }", |
1418 "asm: line 39: illegal literal\n"); | 1418 "asm: line 39: illegal literal\n"); |
1419 } | 1419 } |
1420 | 1420 |
1421 | 1421 |
| 1422 TEST(MismatchedReturnTypeLiteral) { |
| 1423 CHECK_FUNC_ERROR( |
| 1424 "function bar() { if(1) { return 1; } return 1.0; }\n" |
| 1425 "function foo() { bar(); }", |
| 1426 "asm: line 39: return type does not match function signature\n"); |
| 1427 } |
| 1428 |
| 1429 |
| 1430 TEST(MismatchedReturnTypeExpression) { |
| 1431 CHECK_FUNC_ERROR( |
| 1432 "function bar() {\n" |
| 1433 " var x = 1; var y = 1.0; if(1) { return x; } return +y; }\n" |
| 1434 "function foo() { bar(); }", |
| 1435 "asm: line 40: return type does not match function signature\n"); |
| 1436 } |
| 1437 |
| 1438 |
1422 TEST(ForeignFunction) { | 1439 TEST(ForeignFunction) { |
1423 CHECK_FUNC_TYPES_BEGIN( | 1440 CHECK_FUNC_TYPES_BEGIN( |
1424 "var baz = foreign.baz;\n" | 1441 "var baz = foreign.baz;\n" |
1425 "function bar() { return baz(1, 2)|0; }\n" | 1442 "function bar() { return baz(1, 2)|0; }\n" |
1426 "function foo() { bar(); }") { | 1443 "function foo() { bar(); }") { |
1427 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { | 1444 CHECK_EXPR(FunctionLiteral, FUNC_I_TYPE) { |
1428 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { | 1445 CHECK_EXPR(BinaryOperation, Bounds(cache.kAsmSigned)) { |
1429 CHECK_EXPR(Call, Bounds(Type::Number(zone))) { | 1446 CHECK_EXPR(Call, Bounds(Type::Number(zone))) { |
1430 CHECK_VAR(baz, Bounds(Type::Any())); | 1447 CHECK_VAR(baz, Bounds(Type::Any())); |
1431 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); | 1448 CHECK_EXPR(Literal, Bounds(cache.kAsmFixnum)); |
(...skipping 30 matching lines...) Expand all Loading... |
1462 HandleAndZoneScope handles; | 1479 HandleAndZoneScope handles; |
1463 Zone* zone = handles.main_zone(); | 1480 Zone* zone = handles.main_zone(); |
1464 ZoneVector<ExpressionTypeEntry> types(zone); | 1481 ZoneVector<ExpressionTypeEntry> types(zone); |
1465 CHECK_EQ("asm: line 40: non-function in function table\n", | 1482 CHECK_EQ("asm: line 40: non-function in function table\n", |
1466 Validate(zone, test_function, &types)); | 1483 Validate(zone, test_function, &types)); |
1467 } | 1484 } |
1468 | 1485 |
1469 | 1486 |
1470 TEST(TypeConsistency) { | 1487 TEST(TypeConsistency) { |
1471 v8::V8::Initialize(); | 1488 v8::V8::Initialize(); |
1472 // HandleAndZoneScope handles; | |
1473 // Zone* zone = handles.main_zone(); | |
1474 TypeCache cache; | 1489 TypeCache cache; |
| 1490 // Check the consistency of each of the main Asm.js types. |
| 1491 CHECK(cache.kAsmFixnum->Is(cache.kAsmFixnum)); |
| 1492 CHECK(cache.kAsmFixnum->Is(cache.kAsmSigned)); |
| 1493 CHECK(cache.kAsmFixnum->Is(cache.kAsmUnsigned)); |
| 1494 CHECK(cache.kAsmFixnum->Is(cache.kAsmInt)); |
| 1495 CHECK(!cache.kAsmFixnum->Is(cache.kAsmFloat)); |
| 1496 CHECK(!cache.kAsmFixnum->Is(cache.kAsmDouble)); |
1475 | 1497 |
| 1498 CHECK(cache.kAsmSigned->Is(cache.kAsmSigned)); |
| 1499 CHECK(cache.kAsmSigned->Is(cache.kAsmInt)); |
| 1500 CHECK(!cache.kAsmSigned->Is(cache.kAsmFixnum)); |
| 1501 CHECK(!cache.kAsmSigned->Is(cache.kAsmUnsigned)); |
| 1502 CHECK(!cache.kAsmSigned->Is(cache.kAsmFloat)); |
| 1503 CHECK(!cache.kAsmSigned->Is(cache.kAsmDouble)); |
1476 | 1504 |
1477 CHECK(!cache.kAsmSigned->Is(cache.kAsmDouble)); | 1505 CHECK(cache.kAsmUnsigned->Is(cache.kAsmUnsigned)); |
1478 CHECK(!cache.kAsmSigned->Is(cache.kAsmFloat)); | 1506 CHECK(cache.kAsmUnsigned->Is(cache.kAsmInt)); |
1479 CHECK(!cache.kAsmSigned->Is(cache.kAsmUnsigned)); | 1507 CHECK(!cache.kAsmUnsigned->Is(cache.kAsmSigned)); |
| 1508 CHECK(!cache.kAsmUnsigned->Is(cache.kAsmFixnum)); |
| 1509 CHECK(!cache.kAsmUnsigned->Is(cache.kAsmFloat)); |
| 1510 CHECK(!cache.kAsmUnsigned->Is(cache.kAsmDouble)); |
| 1511 |
| 1512 CHECK(cache.kAsmInt->Is(cache.kAsmInt)); |
| 1513 CHECK(!cache.kAsmInt->Is(cache.kAsmUnsigned)); |
| 1514 CHECK(!cache.kAsmInt->Is(cache.kAsmSigned)); |
| 1515 CHECK(!cache.kAsmInt->Is(cache.kAsmFixnum)); |
| 1516 CHECK(!cache.kAsmInt->Is(cache.kAsmFloat)); |
| 1517 CHECK(!cache.kAsmInt->Is(cache.kAsmDouble)); |
| 1518 |
| 1519 CHECK(cache.kAsmFloat->Is(cache.kAsmFloat)); |
| 1520 CHECK(!cache.kAsmFloat->Is(cache.kAsmInt)); |
| 1521 CHECK(!cache.kAsmFloat->Is(cache.kAsmUnsigned)); |
| 1522 CHECK(!cache.kAsmFloat->Is(cache.kAsmSigned)); |
| 1523 CHECK(!cache.kAsmFloat->Is(cache.kAsmFixnum)); |
| 1524 CHECK(!cache.kAsmFloat->Is(cache.kAsmDouble)); |
| 1525 |
| 1526 CHECK(cache.kAsmDouble->Is(cache.kAsmDouble)); |
| 1527 CHECK(!cache.kAsmDouble->Is(cache.kAsmInt)); |
| 1528 CHECK(!cache.kAsmDouble->Is(cache.kAsmUnsigned)); |
1480 CHECK(!cache.kAsmDouble->Is(cache.kAsmSigned)); | 1529 CHECK(!cache.kAsmDouble->Is(cache.kAsmSigned)); |
1481 CHECK(cache.kAsmSigned->Is(cache.kAsmInt)); | 1530 CHECK(!cache.kAsmDouble->Is(cache.kAsmFixnum)); |
1482 CHECK(!cache.kAsmSigned->Is(cache.kAsmDouble)); | 1531 CHECK(!cache.kAsmDouble->Is(cache.kAsmFloat)); |
1483 } | 1532 } |
OLD | NEW |