| 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 3694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3705 // We can invoke both private and non-private local functions. | 3705 // We can invoke both private and non-private local functions. |
| 3706 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("local"), 0, NULL)); | 3706 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("local"), 0, NULL)); |
| 3707 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("_local"), 0, NULL)); | 3707 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("_local"), 0, NULL)); |
| 3708 | 3708 |
| 3709 // We can only invoke non-private imported functions. | 3709 // We can only invoke non-private imported functions. |
| 3710 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("imported"), 0, NULL)); | 3710 EXPECT_VALID(Dart_Invoke(lib1, Dart_NewString("imported"), 0, NULL)); |
| 3711 EXPECT_ERROR(Dart_Invoke(lib1, Dart_NewString("_imported"), 0, NULL), | 3711 EXPECT_ERROR(Dart_Invoke(lib1, Dart_NewString("_imported"), 0, NULL), |
| 3712 "did not find top-level function '_imported'"); | 3712 "did not find top-level function '_imported'"); |
| 3713 } | 3713 } |
| 3714 | 3714 |
| 3715 TEST_CASE(ClosureFunction) { |
| 3716 const char* kScriptChars = |
| 3717 "Function getClosure() {\n" |
| 3718 " return (x, y, [z]) => x + y + z;\n" |
| 3719 "}\n"; |
| 3720 Dart_Handle result; |
| 3721 DARTSCOPE_NOCHECKS(Isolate::Current()); |
| 3722 |
| 3723 // Create a test library and Load up a test script in it. |
| 3724 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); |
| 3725 |
| 3726 // Invoke a function which returns a closure. |
| 3727 Dart_Handle retobj = Dart_Invoke(lib, Dart_NewString("getClosure"), 0, NULL); |
| 3728 EXPECT_VALID(retobj); |
| 3729 |
| 3730 EXPECT(Dart_IsClosure(retobj)); |
| 3731 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); |
| 3732 |
| 3733 // Retrieve the closure's function |
| 3734 result = Dart_ClosureFunction(retobj); |
| 3735 EXPECT_VALID(result); |
| 3736 EXPECT(Dart_IsFunction(result)); |
| 3737 int64_t fixed_param_count = -1; |
| 3738 int64_t opt_param_count = -1; |
| 3739 result = Dart_FunctionParameterCounts(result, |
| 3740 &fixed_param_count, |
| 3741 &opt_param_count); |
| 3742 EXPECT_VALID(result); |
| 3743 EXPECT_EQ(2, fixed_param_count); |
| 3744 EXPECT_EQ(1, opt_param_count); |
| 3745 |
| 3746 // Try to retrieve function from a non-closure object |
| 3747 result = Dart_ClosureFunction(Dart_NewInteger(1)); |
| 3748 EXPECT(Dart_IsError(result)); |
| 3749 } |
| 3715 | 3750 |
| 3716 TEST_CASE(InvokeClosure) { | 3751 TEST_CASE(InvokeClosure) { |
| 3717 const char* kScriptChars = | 3752 const char* kScriptChars = |
| 3718 "class InvokeClosure {\n" | 3753 "class InvokeClosure {\n" |
| 3719 " InvokeClosure(int i, int j) : fld1 = i, fld2 = j {}\n" | 3754 " InvokeClosure(int i, int j) : fld1 = i, fld2 = j {}\n" |
| 3720 " Function method1(int i) {\n" | 3755 " Function method1(int i) {\n" |
| 3721 " f(int j) => j + i + fld1 + fld2 + fld4; \n" | 3756 " f(int j) => j + i + fld1 + fld2 + fld4; \n" |
| 3722 " return f;\n" | 3757 " return f;\n" |
| 3723 " }\n" | 3758 " }\n" |
| 3724 " static Function method2(int i) {\n" | 3759 " static Function method2(int i) {\n" |
| (...skipping 2459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6184 EXPECT_VALID(result); | 6219 EXPECT_VALID(result); |
| 6185 EXPECT(Dart_IsInteger(result)); | 6220 EXPECT(Dart_IsInteger(result)); |
| 6186 int64_t value = 0; | 6221 int64_t value = 0; |
| 6187 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); | 6222 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); |
| 6188 EXPECT_EQ(0, value); | 6223 EXPECT_EQ(0, value); |
| 6189 } | 6224 } |
| 6190 | 6225 |
| 6191 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). | 6226 #endif // defined(TARGET_ARCH_IA32) || defined(TARGET_ARCH_X64). |
| 6192 | 6227 |
| 6193 } // namespace dart | 6228 } // namespace dart |
| OLD | NEW |