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

Side by Side Diff: runtime/vm/dart_api_impl_test.cc

Issue 891053004: Make Dart_Invoke work for private static functions (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 10 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 | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/resolver.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "bin/builtin.h" 5 #include "bin/builtin.h"
6 #include "include/dart_api.h" 6 #include "include/dart_api.h"
7 #include "include/dart_debugger_api.h" 7 #include "include/dart_debugger_api.h"
8 #include "include/dart_mirrors_api.h" 8 #include "include/dart_mirrors_api.h"
9 #include "include/dart_native_api.h" 9 #include "include/dart_native_api.h"
10 #include "platform/assert.h" 10 #include "platform/assert.h"
(...skipping 5094 matching lines...) Expand 10 before | Expand all | Expand 10 after
5105 result = Dart_Invoke(type, name, 1, args); 5105 result = Dart_Invoke(type, name, 1, args);
5106 EXPECT_VALID(result); 5106 EXPECT_VALID(result);
5107 result = Dart_StringToCString(result, &str); 5107 result = Dart_StringToCString(result, &str);
5108 EXPECT_STREQ("static !!!", str); 5108 EXPECT_STREQ("static !!!", str);
5109 5109
5110 // Static method, wrong arg count. 5110 // Static method, wrong arg count.
5111 EXPECT_ERROR(Dart_Invoke(type, name, 2, bad_args), 5111 EXPECT_ERROR(Dart_Invoke(type, name, 2, bad_args),
5112 "did not find static method 'Methods.staticMethod'"); 5112 "did not find static method 'Methods.staticMethod'");
5113 5113
5114 // Hidden static method. 5114 // Hidden static method.
5115 name = PrivateLibName(lib, "_staticMethod"); 5115 name = NewString("_staticMethod");
5116 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); 5116 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args)));
5117 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); 5117 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args)));
5118 result = Dart_Invoke(type, name, 1, args); 5118 result = Dart_Invoke(type, name, 1, args);
5119 EXPECT_VALID(result); 5119 EXPECT_VALID(result);
5120 result = Dart_StringToCString(result, &str); 5120 result = Dart_StringToCString(result, &str);
5121 EXPECT_STREQ("hidden static !!!", str); 5121 EXPECT_STREQ("hidden static !!!", str);
5122 5122
5123 // Static non-inherited method. Not found at any level. 5123 // Static non-inherited method. Not found at any level.
5124 name = NewString("non_inheritedMethod"); 5124 name = NewString("non_inheritedMethod");
5125 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); 5125 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args)));
5126 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); 5126 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args)));
5127 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args))); 5127 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args)));
5128 5128
5129 // Top-Level method. 5129 // Top-Level method.
5130 name = NewString("topMethod"); 5130 name = NewString("topMethod");
5131 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args))); 5131 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args)));
5132 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); 5132 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args)));
5133 result = Dart_Invoke(lib, name, 1, args); 5133 result = Dart_Invoke(lib, name, 1, args);
5134 EXPECT_VALID(result); 5134 EXPECT_VALID(result);
5135 result = Dart_StringToCString(result, &str); 5135 result = Dart_StringToCString(result, &str);
5136 EXPECT_STREQ("top !!!", str); 5136 EXPECT_STREQ("top !!!", str);
5137 5137
5138 // Top-level method, wrong arg count. 5138 // Top-level method, wrong arg count.
5139 EXPECT_ERROR(Dart_Invoke(lib, name, 2, bad_args), 5139 EXPECT_ERROR(Dart_Invoke(lib, name, 2, bad_args),
5140 "Dart_Invoke: wrong argument count for function 'topMethod': " 5140 "Dart_Invoke: wrong argument count for function 'topMethod': "
5141 "2 passed, 1 expected."); 5141 "2 passed, 1 expected.");
5142 5142
5143 // Hidden top-level method. 5143 // Hidden top-level method.
5144 name = PrivateLibName(lib, "_topMethod"); 5144 name = NewString("_topMethod");
5145 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args))); 5145 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args)));
5146 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); 5146 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args)));
5147 result = Dart_Invoke(lib, name, 1, args); 5147 result = Dart_Invoke(lib, name, 1, args);
5148 EXPECT_VALID(result); 5148 EXPECT_VALID(result);
5149 result = Dart_StringToCString(result, &str); 5149 result = Dart_StringToCString(result, &str);
5150 EXPECT_STREQ("hidden top !!!", str); 5150 EXPECT_STREQ("hidden top !!!", str);
5151 } 5151 }
5152 5152
5153 5153
5154 TEST_CASE(Invoke_PrivateStatic) {
5155 const char* kScriptChars =
5156 "class Methods {\n"
5157 " static _staticMethod(arg) => 'hidden static $arg';\n"
5158 "}\n"
5159 "\n";
5160
5161 // Shared setup.
5162 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
5163 Dart_Handle type = Dart_GetType(lib, NewString("Methods"), 0, NULL);
5164 Dart_Handle result;
5165 EXPECT_VALID(type);
5166 Dart_Handle name = NewString("_staticMethod");
5167 EXPECT_VALID(name);
5168
5169 Dart_Handle args[1];
5170 args[0] = NewString("!!!");
5171 result = Dart_Invoke(type, name, 1, args);
5172 EXPECT_VALID(result);
5173
5174 const char* str = NULL;
5175 result = Dart_StringToCString(result, &str);
5176 EXPECT_STREQ("hidden static !!!", str);
5177 }
5178
5179
5154 TEST_CASE(Invoke_FunnyArgs) { 5180 TEST_CASE(Invoke_FunnyArgs) {
5155 const char* kScriptChars = 5181 const char* kScriptChars =
5156 "test(arg) => 'hello $arg';\n"; 5182 "test(arg) => 'hello $arg';\n";
5157 5183
5158 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 5184 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
5159 Dart_Handle func_name = NewString("test"); 5185 Dart_Handle func_name = NewString("test");
5160 Dart_Handle args[1]; 5186 Dart_Handle args[1];
5161 const char* str; 5187 const char* str;
5162 5188
5163 // Make sure that valid args yield valid results. 5189 // Make sure that valid args yield valid results.
(...skipping 3652 matching lines...) Expand 10 before | Expand all | Expand 10 after
8816 result = Dart_Invoke(lib, 8842 result = Dart_Invoke(lib,
8817 NewString("testView16"), 8843 NewString("testView16"),
8818 1, 8844 1,
8819 dart_args); 8845 dart_args);
8820 EXPECT_VALID(result); 8846 EXPECT_VALID(result);
8821 EXPECT(Dart_IsString(result)); 8847 EXPECT(Dart_IsString(result));
8822 } 8848 }
8823 } 8849 }
8824 8850
8825 } // namespace dart 8851 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/resolver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698