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 3599 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3610 | 3610 |
3611 const int kNumArgs = 1; | 3611 const int kNumArgs = 1; |
3612 Dart_Handle args[kNumArgs]; | 3612 Dart_Handle args[kNumArgs]; |
3613 args[0] = Dart_NewInteger(1); | 3613 args[0] = Dart_NewInteger(1); |
3614 Dart_Handle list_obj = Dart_New(list_class, Dart_Null(), kNumArgs, args); | 3614 Dart_Handle list_obj = Dart_New(list_class, Dart_Null(), kNumArgs, args); |
3615 EXPECT_VALID(list_obj); | 3615 EXPECT_VALID(list_obj); |
3616 EXPECT(Dart_IsList(list_obj)); | 3616 EXPECT(Dart_IsList(list_obj)); |
3617 } | 3617 } |
3618 | 3618 |
3619 | 3619 |
| 3620 static Dart_Handle PrivateLibName(Dart_Handle lib, const char* str) { |
| 3621 EXPECT(Dart_IsLibrary(lib)); |
| 3622 Isolate* isolate = Isolate::Current(); |
| 3623 const Library& library_obj = Api::UnwrapLibraryHandle(isolate, lib); |
| 3624 const String& name = String::Handle(String::New(str)); |
| 3625 return Api::NewHandle(isolate, library_obj.PrivateName(name)); |
| 3626 } |
| 3627 |
| 3628 |
3620 TEST_CASE(Invoke) { | 3629 TEST_CASE(Invoke) { |
3621 const char* kScriptChars = | 3630 const char* kScriptChars = |
3622 "class BaseMethods {\n" | 3631 "class BaseMethods {\n" |
3623 " inheritedMethod(arg) => 'inherited $arg';\n" | 3632 " inheritedMethod(arg) => 'inherited $arg';\n" |
3624 " static nonInheritedMethod(arg) => 'noninherited $arg';\n" | 3633 " static nonInheritedMethod(arg) => 'noninherited $arg';\n" |
3625 "}\n" | 3634 "}\n" |
3626 "\n" | 3635 "\n" |
3627 "class Methods extends BaseMethods {\n" | 3636 "class Methods extends BaseMethods {\n" |
3628 " instanceMethod(arg) => 'instance $arg';\n" | 3637 " instanceMethod(arg) => 'instance $arg';\n" |
3629 " _instanceMethod(arg) => 'hidden instance $arg';\n" | 3638 " _instanceMethod(arg) => 'hidden instance $arg';\n" |
(...skipping 29 matching lines...) Expand all Loading... |
3659 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); | 3668 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); |
3660 result = Dart_Invoke(instance, name, 1, args); | 3669 result = Dart_Invoke(instance, name, 1, args); |
3661 EXPECT_VALID(result); | 3670 EXPECT_VALID(result); |
3662 result = Dart_StringToCString(result, &str); | 3671 result = Dart_StringToCString(result, &str); |
3663 EXPECT_STREQ("instance !!!", str); | 3672 EXPECT_STREQ("instance !!!", str); |
3664 | 3673 |
3665 // Instance method, wrong arg count. | 3674 // Instance method, wrong arg count. |
3666 EXPECT_ERROR(Dart_Invoke(instance, name, 2, bad_args), | 3675 EXPECT_ERROR(Dart_Invoke(instance, name, 2, bad_args), |
3667 "did not find instance method 'Methods.instanceMethod'"); | 3676 "did not find instance method 'Methods.instanceMethod'"); |
3668 | 3677 |
3669 // Hidden instance method. | 3678 name = PrivateLibName(lib, "_instanceMethod"); |
3670 name = NewString("_instanceMethod"); | |
3671 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); | 3679 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); |
3672 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); | 3680 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); |
3673 result = Dart_Invoke(instance, name, 1, args); | 3681 result = Dart_Invoke(instance, name, 1, args); |
3674 EXPECT_VALID(result); | 3682 EXPECT_VALID(result); |
3675 result = Dart_StringToCString(result, &str); | 3683 result = Dart_StringToCString(result, &str); |
3676 EXPECT_STREQ("hidden instance !!!", str); | 3684 EXPECT_STREQ("hidden instance !!!", str); |
3677 | 3685 |
3678 // Inherited method. | 3686 // Inherited method. |
3679 name = NewString("inheritedMethod"); | 3687 name = NewString("inheritedMethod"); |
3680 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); | 3688 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); |
(...skipping 10 matching lines...) Expand all Loading... |
3691 result = Dart_Invoke(cls, name, 1, args); | 3699 result = Dart_Invoke(cls, name, 1, args); |
3692 EXPECT_VALID(result); | 3700 EXPECT_VALID(result); |
3693 result = Dart_StringToCString(result, &str); | 3701 result = Dart_StringToCString(result, &str); |
3694 EXPECT_STREQ("static !!!", str); | 3702 EXPECT_STREQ("static !!!", str); |
3695 | 3703 |
3696 // Static method, wrong arg count. | 3704 // Static method, wrong arg count. |
3697 EXPECT_ERROR(Dart_Invoke(cls, name, 2, bad_args), | 3705 EXPECT_ERROR(Dart_Invoke(cls, name, 2, bad_args), |
3698 "did not find static method 'Methods.staticMethod'"); | 3706 "did not find static method 'Methods.staticMethod'"); |
3699 | 3707 |
3700 // Hidden static method. | 3708 // Hidden static method. |
3701 name = NewString("_staticMethod"); | 3709 name = PrivateLibName(lib, "_staticMethod"); |
3702 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); | 3710 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); |
3703 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); | 3711 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); |
3704 result = Dart_Invoke(cls, name, 1, args); | 3712 result = Dart_Invoke(cls, name, 1, args); |
3705 EXPECT_VALID(result); | 3713 EXPECT_VALID(result); |
3706 result = Dart_StringToCString(result, &str); | 3714 result = Dart_StringToCString(result, &str); |
3707 EXPECT_STREQ("hidden static !!!", str); | 3715 EXPECT_STREQ("hidden static !!!", str); |
3708 | 3716 |
3709 // Static non-inherited method. Not found at any level. | 3717 // Static non-inherited method. Not found at any level. |
3710 name = NewString("non_inheritedMethod"); | 3718 name = NewString("non_inheritedMethod"); |
3711 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); | 3719 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); |
3712 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); | 3720 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); |
3713 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); | 3721 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); |
3714 | 3722 |
3715 // Top-Level method. | 3723 // Top-Level method. |
3716 name = NewString("topMethod"); | 3724 name = NewString("topMethod"); |
3717 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); | 3725 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); |
3718 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); | 3726 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); |
3719 result = Dart_Invoke(lib, name, 1, args); | 3727 result = Dart_Invoke(lib, name, 1, args); |
3720 EXPECT_VALID(result); | 3728 EXPECT_VALID(result); |
3721 result = Dart_StringToCString(result, &str); | 3729 result = Dart_StringToCString(result, &str); |
3722 EXPECT_STREQ("top !!!", str); | 3730 EXPECT_STREQ("top !!!", str); |
3723 | 3731 |
3724 // Top-level method, wrong arg count. | 3732 // Top-level method, wrong arg count. |
3725 EXPECT_ERROR(Dart_Invoke(lib, name, 2, bad_args), | 3733 EXPECT_ERROR(Dart_Invoke(lib, name, 2, bad_args), |
3726 "Dart_Invoke: wrong argument count for function 'topMethod': " | 3734 "Dart_Invoke: wrong argument count for function 'topMethod': " |
3727 "2 passed, 1 expected."); | 3735 "2 passed, 1 expected."); |
3728 | 3736 |
3729 // Hidden top-level method. | 3737 // Hidden top-level method. |
3730 name = NewString("_topMethod"); | 3738 name = PrivateLibName(lib, "_topMethod"); |
3731 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); | 3739 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); |
3732 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); | 3740 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); |
3733 result = Dart_Invoke(lib, name, 1, args); | 3741 result = Dart_Invoke(lib, name, 1, args); |
3734 EXPECT_VALID(result); | 3742 EXPECT_VALID(result); |
3735 result = Dart_StringToCString(result, &str); | 3743 result = Dart_StringToCString(result, &str); |
3736 EXPECT_STREQ("hidden top !!!", str); | 3744 EXPECT_STREQ("hidden top !!!", str); |
3737 } | 3745 } |
3738 | 3746 |
3739 | 3747 |
3740 TEST_CASE(Invoke_FunnyArgs) { | 3748 TEST_CASE(Invoke_FunnyArgs) { |
(...skipping 3698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
7439 Dart_LoadSource(TestCase::lib(), url, source); | 7447 Dart_LoadSource(TestCase::lib(), url, source); |
7440 | 7448 |
7441 dart_args[0] = Dart_NewInteger(1); | 7449 dart_args[0] = Dart_NewInteger(1); |
7442 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); | 7450 result = Dart_Invoke(lib1, NewString("start"), 1, dart_args); |
7443 EXPECT_VALID(result); | 7451 EXPECT_VALID(result); |
7444 } | 7452 } |
7445 | 7453 |
7446 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 7454 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
7447 | 7455 |
7448 } // namespace dart | 7456 } // namespace dart |
OLD | NEW |