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

Side by Side Diff: vm/dart_api_impl_test.cc

Issue 8342046: Add an imported into list for libraries so that it is possible to lookup (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: '' Created 9 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « vm/dart_api_impl.cc ('k') | vm/isolate.cc » ('j') | vm/object.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 6
7 #include "vm/assert.h" 7 #include "vm/assert.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" 9 #include "vm/dart_api_state.h"
10 #include "vm/unit_test.h" 10 #include "vm/unit_test.h"
(...skipping 1402 matching lines...) Expand 10 before | Expand all | Expand 10 after
1413 number_of_arguments, 1413 number_of_arguments,
1414 dart_arguments); 1414 dart_arguments);
1415 EXPECT(Dart_IsValidResult(result)); 1415 EXPECT(Dart_IsValidResult(result));
1416 retobj = Dart_GetResult(result); 1416 retobj = Dart_GetResult(result);
1417 EXPECT(Dart_ExceptionOccurred(retobj)); */ 1417 EXPECT(Dart_ExceptionOccurred(retobj)); */
1418 } 1418 }
1419 Dart_ExitScope(); // Exit the Dart API scope. 1419 Dart_ExitScope(); // Exit the Dart API scope.
1420 Dart_ShutdownIsolate(); 1420 Dart_ShutdownIsolate();
1421 } 1421 }
1422 1422
1423
1424 static Dart_Result library_handler(Dart_LibraryTag tag,
1425 Dart_Handle library,
1426 Dart_Handle url) {
1427 if (tag == kCanonicalizeUrl) {
1428 return Dart_ResultAsObject(url);
1429 }
1430 return Dart_ResultAsObject(Dart_NewBoolean(true));
1431 }
1432
1433
1434 UNIT_TEST_CASE(ImportLibrary1) {
1435 const char* kScriptChars =
1436 "#import(\"library1.dart\");\n"
Ivan Posva 2011/10/20 08:46:04 This would become a little bit more readable if it
siva 2011/10/20 23:08:47 Done.
1437 "#import(\"library2.dart\");\n"
1438 "var foo; // library2 defines foo, so should be error.\n"
1439 "main() {}\n";
1440 const char* kLibrary1Chars =
1441 "#library(\"library1.dart\");\n"
1442 "#import(\"library2.dart\");\n"
1443 "var foo1;\n";
1444 const char* kLibrary2Chars =
1445 "#library(\"library2.dart\");\n"
1446 "var foo;\n";
1447 Dart_Result result;
1448
1449 Dart_CreateIsolate(NULL, NULL);
1450 {
1451 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1452
1453 // Create a test library and Load up a test script in it.
1454 Dart_Handle url = Dart_NewString(TestCase::url());
1455 Dart_Handle source = Dart_NewString(kScriptChars);
1456 result = Dart_LoadScript(url, source, library_handler);
1457
1458 url = Dart_NewString("library1.dart");
1459 source = Dart_NewString(kLibrary1Chars);
1460 Dart_LoadLibrary(url, source);
1461
1462 url = Dart_NewString("library2.dart");
1463 source = Dart_NewString(kLibrary2Chars);
1464 Dart_LoadLibrary(url, source);
1465
1466 result = Dart_InvokeStatic(Dart_GetResult(result),
1467 Dart_NewString(""),
1468 Dart_NewString("main"),
1469 0,
1470 NULL);
1471 assert(!Dart_IsValidResult(result));
Ivan Posva 2011/10/20 08:46:04 Could you check that there is a complaint about "f
siva 2011/10/20 23:08:47 Done.
1472
1473 Dart_ExitScope(); // Exit the Dart API scope.
1474 }
1475 Dart_ShutdownIsolate();
1476 }
1477
1478
1479 UNIT_TEST_CASE(ImportLibrary2) {
1480 const char* kScriptChars =
1481 "#import(\"library1.dart\");\n"
1482 "var foo;\n"
1483 "main() {}\n";
1484 const char* kLibrary1Chars =
1485 "#library(\"library1.dart\");\n"
1486 "#import(\"library2.dart\");\n"
1487 "var foo1;\n";
1488 const char* kLibrary2Chars =
1489 "#library(\"library2.dart\");\n"
1490 "#import(\"library1.dart\");\n"
1491 "var foo;\n";
1492 Dart_Result result;
1493
1494 Dart_CreateIsolate(NULL, NULL);
1495 {
1496 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1497
1498 // Create a test library and Load up a test script in it.
1499 Dart_Handle url = Dart_NewString(TestCase::url());
1500 Dart_Handle source = Dart_NewString(kScriptChars);
1501 result = Dart_LoadScript(url, source, library_handler);
1502
1503 url = Dart_NewString("library1.dart");
1504 source = Dart_NewString(kLibrary1Chars);
1505 Dart_LoadLibrary(url, source);
1506
1507 url = Dart_NewString("library2.dart");
1508 source = Dart_NewString(kLibrary2Chars);
1509 Dart_LoadLibrary(url, source);
1510
1511 result = Dart_InvokeStatic(Dart_GetResult(result),
1512 Dart_NewString(""),
1513 Dart_NewString("main"),
1514 0,
1515 NULL);
1516 assert(Dart_IsValidResult(result));
1517
1518 Dart_ExitScope(); // Exit the Dart API scope.
1519 }
1520 Dart_ShutdownIsolate();
1521 }
1522
1523
1524 UNIT_TEST_CASE(ImportLibrary3) {
1525 const char* kScriptChars =
1526 "#import(\"library2.dart\");\n"
1527 "#import(\"library1.dart\");\n"
1528 "var foo_top = 10; // foo has dup def. So should be an error.\n"
1529 "main() {}\n";
1530 const char* kLibrary1Chars =
1531 "#library(\"library1.dart\");\n"
1532 "#import(\"library2.dart\");\n"
1533 "var foo;\n";
1534 const char* kLibrary2Chars =
1535 "#library(\"library2.dart\");\n"
1536 "var foo;\n";
1537 Dart_Result result;
1538
1539 Dart_CreateIsolate(NULL, NULL);
1540 {
1541 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1542
1543 // Create a test library and Load up a test script in it.
1544 Dart_Handle url = Dart_NewString(TestCase::url());
1545 Dart_Handle source = Dart_NewString(kScriptChars);
1546 result = Dart_LoadScript(url, source, library_handler);
1547
1548 url = Dart_NewString("library2.dart");
1549 source = Dart_NewString(kLibrary2Chars);
1550 Dart_LoadLibrary(url, source);
1551
1552 url = Dart_NewString("library1.dart");
1553 source = Dart_NewString(kLibrary1Chars);
1554 Dart_LoadLibrary(url, source);
1555
1556 result = Dart_InvokeStatic(Dart_GetResult(result),
1557 Dart_NewString(""),
1558 Dart_NewString("main"),
1559 0,
1560 NULL);
1561 assert(!Dart_IsValidResult(result));
1562
1563 Dart_ExitScope(); // Exit the Dart API scope.
1564 }
1565 Dart_ShutdownIsolate();
1566 }
1567
1568
1569 UNIT_TEST_CASE(ImportLibrary4) {
1570 const char* kScriptChars =
1571 "#import(\"libraryA.dart\");\n"
1572 "#import(\"libraryB.dart\");\n"
1573 "#import(\"libraryD.dart\");\n"
1574 "#import(\"libraryE.dart\");\n"
1575 "var fooApp;\n"
1576 "main() {}\n";
1577 const char* kLibraryAChars =
1578 "#library(\"libraryA.dart\");\n"
1579 "#import(\"libraryC.dart\");\n"
1580 "var fooA;\n";
1581 const char* kLibraryBChars =
1582 "#library(\"library2.dart\");\n"
Ivan Posva 2011/10/20 08:46:04 library2.dart?
siva 2011/10/20 23:08:47 Changed to libraryB.dart On 2011/10/20 08:46:04, I
1583 "#import(\"libraryC.dart\");\n"
1584 "var fooB;\n";
1585 const char* kLibraryCChars =
1586 "#library(\"libraryC.dart\");\n"
1587 "var fooC;\n";
1588 const char* kLibraryDChars =
1589 "#library(\"libraryD.dart\");\n"
1590 "#import(\"libraryF.dart\");\n"
1591 "var fooD;\n";
1592 const char* kLibraryEChars =
1593 "#library(\"libraryE.dart\");\n"
1594 "#import(\"libraryC.dart\");\n"
1595 "#import(\"libraryF.dart\");\n"
1596 "var fooE = 10; //fooC has duplicate def. so should be an error.\n";
1597 const char* kLibraryFChars =
1598 "#library(\"libraryF.dart\");\n"
1599 "var fooC;\n";
1600 Dart_Result result;
1601
1602 Dart_CreateIsolate(NULL, NULL);
1603 {
1604 Dart_EnterScope(); // Start a Dart API scope for invoking API functions.
1605
1606 // Create a test library and Load up a test script in it.
1607 Dart_Handle url = Dart_NewString(TestCase::url());
1608 Dart_Handle source = Dart_NewString(kScriptChars);
1609 result = Dart_LoadScript(url, source, library_handler);
1610
1611 url = Dart_NewString("libraryA.dart");
1612 source = Dart_NewString(kLibraryAChars);
1613 Dart_LoadLibrary(url, source);
1614
1615 url = Dart_NewString("libraryC.dart");
1616 source = Dart_NewString(kLibraryCChars);
1617 Dart_LoadLibrary(url, source);
1618
1619 url = Dart_NewString("libraryB.dart");
1620 source = Dart_NewString(kLibraryBChars);
1621 Dart_LoadLibrary(url, source);
1622
1623 url = Dart_NewString("libraryD.dart");
1624 source = Dart_NewString(kLibraryDChars);
1625 Dart_LoadLibrary(url, source);
1626
1627 url = Dart_NewString("libraryF.dart");
1628 source = Dart_NewString(kLibraryFChars);
1629 Dart_LoadLibrary(url, source);
1630
1631 url = Dart_NewString("libraryE.dart");
1632 source = Dart_NewString(kLibraryEChars);
1633 Dart_LoadLibrary(url, source);
1634
1635 result = Dart_InvokeStatic(Dart_GetResult(result),
1636 Dart_NewString(""),
1637 Dart_NewString("main"),
1638 0,
1639 NULL);
1640 assert(!Dart_IsValidResult(result));
1641
1642 Dart_ExitScope(); // Exit the Dart API scope.
1643 }
1644 Dart_ShutdownIsolate();
1645 }
1646
1423 #endif // TARGET_ARCH_IA32. 1647 #endif // TARGET_ARCH_IA32.
1424 1648
1425 } // namespace dart 1649 } // namespace dart
OLDNEW
« no previous file with comments | « vm/dart_api_impl.cc ('k') | vm/isolate.cc » ('j') | vm/object.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698