| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "platform/assert.h" | 6 #include "platform/assert.h" |
| 7 #include "platform/json.h" | 7 #include "platform/json.h" |
| 8 #include "platform/utils.h" | 8 #include "platform/utils.h" |
| 9 #include "vm/class_finalizer.h" | 9 #include "vm/class_finalizer.h" |
| 10 #include "vm/dart_api_impl.h" | 10 #include "vm/dart_api_impl.h" |
| (...skipping 5635 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5646 Dart_Handle result = Dart_LoadLibrary(url, source); | 5646 Dart_Handle result = Dart_LoadLibrary(url, source); |
| 5647 EXPECT(Dart_IsError(result)); | 5647 EXPECT(Dart_IsError(result)); |
| 5648 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); | 5648 EXPECT(strstr(Dart_GetError(result), "unexpected token ')'")); |
| 5649 } | 5649 } |
| 5650 | 5650 |
| 5651 | 5651 |
| 5652 TEST_CASE(LoadSource) { | 5652 TEST_CASE(LoadSource) { |
| 5653 const char* kLibrary1Chars = | 5653 const char* kLibrary1Chars = |
| 5654 "library library1_name;"; | 5654 "library library1_name;"; |
| 5655 const char* kSourceChars = | 5655 const char* kSourceChars = |
| 5656 "// Something innocuous"; | 5656 "part of library1_name;\n// Something innocuous"; |
| 5657 const char* kBadSourceChars = | 5657 const char* kBadSourceChars = |
| 5658 ")"; | 5658 ")"; |
| 5659 Dart_Handle error = Dart_Error("incoming error"); | 5659 Dart_Handle error = Dart_Error("incoming error"); |
| 5660 Dart_Handle result; | 5660 Dart_Handle result; |
| 5661 | 5661 |
| 5662 // Load up a library. | 5662 // Load up a library. |
| 5663 Dart_Handle url = NewString("library1_url"); | 5663 Dart_Handle url = NewString("library1_url"); |
| 5664 Dart_Handle source = NewString(kLibrary1Chars); | 5664 Dart_Handle source = NewString(kLibrary1Chars); |
| 5665 Dart_Handle lib = Dart_LoadLibrary(url, source); | 5665 Dart_Handle lib = Dart_LoadLibrary(url, source); |
| 5666 EXPECT_VALID(lib); | 5666 EXPECT_VALID(lib); |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5732 } | 5732 } |
| 5733 | 5733 |
| 5734 | 5734 |
| 5735 TEST_CASE(LoadSource_LateLoad) { | 5735 TEST_CASE(LoadSource_LateLoad) { |
| 5736 const char* kLibrary1Chars = | 5736 const char* kLibrary1Chars = |
| 5737 "library library1_name;\n" | 5737 "library library1_name;\n" |
| 5738 "class OldClass {\n" | 5738 "class OldClass {\n" |
| 5739 " foo() => 'foo';\n" | 5739 " foo() => 'foo';\n" |
| 5740 "}\n"; | 5740 "}\n"; |
| 5741 const char* kSourceChars = | 5741 const char* kSourceChars = |
| 5742 "part of library1_name;\n" |
| 5742 "class NewClass extends OldClass{\n" | 5743 "class NewClass extends OldClass{\n" |
| 5743 " bar() => 'bar';\n" | 5744 " bar() => 'bar';\n" |
| 5744 "}\n"; | 5745 "}\n"; |
| 5745 Dart_Handle url = NewString("library1_url"); | 5746 Dart_Handle url = NewString("library1_url"); |
| 5746 Dart_Handle source = NewString(kLibrary1Chars); | 5747 Dart_Handle source = NewString(kLibrary1Chars); |
| 5747 Dart_Handle lib = Dart_LoadLibrary(url, source); | 5748 Dart_Handle lib = Dart_LoadLibrary(url, source); |
| 5748 EXPECT_VALID(lib); | 5749 EXPECT_VALID(lib); |
| 5749 EXPECT(Dart_IsLibrary(lib)); | 5750 EXPECT(Dart_IsLibrary(lib)); |
| 5750 | 5751 |
| 5751 // Call a dynamic function on OldClass. | 5752 // Call a dynamic function on OldClass. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 5774 result_cstr = ""; | 5775 result_cstr = ""; |
| 5775 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); | 5776 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); |
| 5776 EXPECT_STREQ("bar", result_cstr); | 5777 EXPECT_STREQ("bar", result_cstr); |
| 5777 } | 5778 } |
| 5778 | 5779 |
| 5779 | 5780 |
| 5780 TEST_CASE(LoadPatch) { | 5781 TEST_CASE(LoadPatch) { |
| 5781 const char* kLibrary1Chars = | 5782 const char* kLibrary1Chars = |
| 5782 "library library1_name;"; | 5783 "library library1_name;"; |
| 5783 const char* kSourceChars = | 5784 const char* kSourceChars = |
| 5785 "part of library1_name;\n" |
| 5784 "external int foo();"; | 5786 "external int foo();"; |
| 5785 const char* kPatchChars = | 5787 const char* kPatchChars = |
| 5786 "patch int foo() => 42;"; | 5788 "patch int foo() => 42;"; |
| 5787 | 5789 |
| 5788 // Load up a library. | 5790 // Load up a library. |
| 5789 Dart_Handle url = NewString("library1_url"); | 5791 Dart_Handle url = NewString("library1_url"); |
| 5790 Dart_Handle source = NewString(kLibrary1Chars); | 5792 Dart_Handle source = NewString(kLibrary1Chars); |
| 5791 Dart_Handle lib = Dart_LoadLibrary(url, source); | 5793 Dart_Handle lib = Dart_LoadLibrary(url, source); |
| 5792 EXPECT_VALID(lib); | 5794 EXPECT_VALID(lib); |
| 5793 EXPECT(Dart_IsLibrary(lib)); | 5795 EXPECT(Dart_IsLibrary(lib)); |
| (...skipping 1714 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7508 | 7510 |
| 7509 EXPECT(Dart_IsExternalString(str)); | 7511 EXPECT(Dart_IsExternalString(str)); |
| 7510 for (intptr_t i = 0; i < kExpectedLen; i++) { | 7512 for (intptr_t i = 0; i < kExpectedLen; i++) { |
| 7511 EXPECT_EQ(expected_str[i], ext_str[i]); | 7513 EXPECT_EQ(expected_str[i], ext_str[i]); |
| 7512 } | 7514 } |
| 7513 } | 7515 } |
| 7514 | 7516 |
| 7515 | 7517 |
| 7516 TEST_CASE(LazyLoadDeoptimizes) { | 7518 TEST_CASE(LazyLoadDeoptimizes) { |
| 7517 const char* kLoadFirst = | 7519 const char* kLoadFirst = |
| 7520 "library L;\n" |
| 7518 "start(a) {\n" | 7521 "start(a) {\n" |
| 7519 " var obj = (a == 1) ? createB() : new A();\n" | 7522 " var obj = (a == 1) ? createB() : new A();\n" |
| 7520 " for (int i = 0; i < 4000; i++) {\n" | 7523 " for (int i = 0; i < 4000; i++) {\n" |
| 7521 " var res = obj.foo();\n" | 7524 " var res = obj.foo();\n" |
| 7522 " if (a == 1) { if (res != 1) throw 'Error'; }\n" | 7525 " if (a == 1) { if (res != 1) throw 'Error'; }\n" |
| 7523 " else if (res != 2) throw 'Error'; \n" | 7526 " else if (res != 2) throw 'Error'; \n" |
| 7524 " }\n" | 7527 " }\n" |
| 7525 "}\n" | 7528 "}\n" |
| 7526 "\n" | 7529 "\n" |
| 7527 "createB() => new B();" | 7530 "createB() => new B();" |
| 7528 "\n" | 7531 "\n" |
| 7529 "class A {\n" | 7532 "class A {\n" |
| 7530 " foo() => goo();\n" | 7533 " foo() => goo();\n" |
| 7531 " goo() => 2;\n" | 7534 " goo() => 2;\n" |
| 7532 "}\n"; | 7535 "}\n"; |
| 7533 const char* kLoadSecond = | 7536 const char* kLoadSecond = |
| 7537 "part of L;" |
| 7534 "class B extends A {\n" | 7538 "class B extends A {\n" |
| 7535 " goo() => 1;\n" | 7539 " goo() => 1;\n" |
| 7536 "}\n"; | 7540 "}\n"; |
| 7537 Dart_Handle result; | 7541 Dart_Handle result; |
| 7538 // Create a test library and Load up a test script in it. | 7542 // Create a test library and Load up a test script in it. |
| 7539 Dart_Handle lib1 = TestCase::LoadTestScript(kLoadFirst, NULL); | 7543 Dart_Handle lib1 = TestCase::LoadTestScript(kLoadFirst, NULL); |
| 7540 Dart_Handle dart_args[1]; | 7544 Dart_Handle dart_args[1]; |
| 7541 dart_args[0] = Dart_NewInteger(0); | 7545 dart_args[0] = Dart_NewInteger(0); |
| 7542 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); | 7546 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); |
| 7543 EXPECT_VALID(result); | 7547 EXPECT_VALID(result); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7610 NewString("main"), | 7614 NewString("main"), |
| 7611 0, | 7615 0, |
| 7612 NULL); | 7616 NULL); |
| 7613 int64_t value = 0; | 7617 int64_t value = 0; |
| 7614 result = Dart_IntegerToInt64(result, &value); | 7618 result = Dart_IntegerToInt64(result, &value); |
| 7615 EXPECT_VALID(result); | 7619 EXPECT_VALID(result); |
| 7616 EXPECT_EQ(260, value); | 7620 EXPECT_EQ(260, value); |
| 7617 } | 7621 } |
| 7618 | 7622 |
| 7619 } // namespace dart | 7623 } // namespace dart |
| OLD | NEW |