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

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

Issue 17390008: Fix for issue 11262. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 6 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') | no next file » | 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_mirrors_api.h" 7 #include "include/dart_mirrors_api.h"
8 #include "include/dart_native_api.h" 8 #include "include/dart_native_api.h"
9 #include "platform/assert.h" 9 #include "platform/assert.h"
10 #include "platform/json.h" 10 #include "platform/json.h"
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 235
236 TEST_CASE(InstanceValues) { 236 TEST_CASE(InstanceValues) {
237 EXPECT(Dart_IsInstance(NewString("test"))); 237 EXPECT(Dart_IsInstance(NewString("test")));
238 EXPECT(Dart_IsInstance(Dart_True())); 238 EXPECT(Dart_IsInstance(Dart_True()));
239 239
240 // By convention, our Is*() functions exclude null. 240 // By convention, our Is*() functions exclude null.
241 EXPECT(!Dart_IsInstance(Dart_Null())); 241 EXPECT(!Dart_IsInstance(Dart_Null()));
242 } 242 }
243 243
244 244
245 TEST_CASE(InstanceGetType) {
246 Isolate* isolate = Isolate::Current();
247 // Get the handle from a valid instance handle.
248 Dart_Handle type = Dart_InstanceGetType(Dart_Null());
249 EXPECT_VALID(type);
250 EXPECT(Dart_IsType(type));
251 const Type& null_type_obj = Api::UnwrapTypeHandle(isolate, type);
252 EXPECT(null_type_obj.raw() == Type::NullType());
253
254 Dart_Handle instance = Dart_True();
255 type = Dart_InstanceGetType(instance);
256 EXPECT_VALID(type);
257 EXPECT(Dart_IsType(type));
258 const Type& bool_type_obj = Api::UnwrapTypeHandle(isolate, type);
259 EXPECT(bool_type_obj.raw() == Type::BoolType());
260
261 // Errors propagate.
262 Dart_Handle error = Dart_NewApiError("MyError");
263 Dart_Handle error_type = Dart_InstanceGetType(error);
264 EXPECT_ERROR(error_type, "MyError");
265
266 // Get the handle from a non-instance handle
267 Dart_Handle obj = Api::NewHandle(isolate,
268 isolate->object_store()->type_class());
269 Dart_Handle type_type = Dart_InstanceGetType(obj);
270 EXPECT_ERROR(type_type,
271 "Dart_InstanceGetType expects argument 'instance' to be of "
272 "type Instance.");
273 }
274
275
245 TEST_CASE(InstanceGetClass) { 276 TEST_CASE(InstanceGetClass) {
246 // Get the handle from a valid instance handle. 277 // Get the handle from a valid instance handle.
247 Dart_Handle instance = Dart_True(); 278 Dart_Handle instance = Dart_True();
248 Dart_Handle cls = Dart_InstanceGetClass(instance); 279 Dart_Handle cls = Dart_InstanceGetClass(instance);
249 EXPECT_VALID(cls); 280 EXPECT_VALID(cls);
250 EXPECT(Dart_IsClass(cls)); 281 EXPECT(Dart_IsClass(cls));
251 Dart_Handle cls_name = Dart_ClassName(cls); 282 Dart_Handle cls_name = Dart_ClassName(cls);
252 EXPECT_VALID(cls_name); 283 EXPECT_VALID(cls_name);
253 const char* cls_name_cstr = ""; 284 const char* cls_name_cstr = "";
254 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr)); 285 EXPECT_VALID(Dart_StringToCString(cls_name, &cls_name_cstr));
(...skipping 2449 matching lines...) Expand 10 before | Expand all | Expand 10 after
2704 EXPECT_VALID( 2735 EXPECT_VALID(
2705 Dart_FunctionParameterCounts(sig_func, &fixed_params, &opt_params)); 2736 Dart_FunctionParameterCounts(sig_func, &fixed_params, &opt_params));
2706 EXPECT_EQ(1, fixed_params); 2737 EXPECT_EQ(1, fixed_params);
2707 EXPECT_EQ(0, opt_params); 2738 EXPECT_EQ(0, opt_params);
2708 2739
2709 // Pass the wrong class kind to Dart_ClassGetFunctionTypeSignature 2740 // Pass the wrong class kind to Dart_ClassGetFunctionTypeSignature
2710 EXPECT_ERROR(Dart_ClassGetFunctionTypeSignature(normal_cls), 2741 EXPECT_ERROR(Dart_ClassGetFunctionTypeSignature(normal_cls),
2711 "class 'SomeClass' is not a function-type class."); 2742 "class 'SomeClass' is not a function-type class.");
2712 } 2743 }
2713 2744
2714 #define CHECK_ABSTRACT_CLASS(handle, name) \ 2745 #define CHECK_CLASS(handle, name) \
2715 { \ 2746 { \
2716 Dart_Handle tmp = (handle); \ 2747 Dart_Handle tmp = (handle); \
2717 EXPECT_VALID(tmp); \ 2748 EXPECT_VALID(tmp); \
2718 EXPECT(Dart_IsAbstractClass(tmp)); \ 2749 EXPECT(Dart_IsClass(tmp)); \
2719 Dart_Handle intf_name = Dart_ClassName(tmp); \ 2750 Dart_Handle intf_name = Dart_ClassName(tmp); \
2720 EXPECT_VALID(intf_name); \ 2751 EXPECT_VALID(intf_name); \
2721 const char* intf_name_cstr = ""; \ 2752 const char* intf_name_cstr = ""; \
2722 EXPECT_VALID(Dart_StringToCString(intf_name, &intf_name_cstr)); \ 2753 EXPECT_VALID(Dart_StringToCString(intf_name, &intf_name_cstr)); \
2723 EXPECT_STREQ((name), intf_name_cstr); \ 2754 EXPECT_STREQ((name), intf_name_cstr); \
2724 } 2755 }
2725 2756
2726 2757
2727 TEST_CASE(ClassGetInterfaces) { 2758 TEST_CASE(ClassGetInterfaces) {
2728 const char* kScriptChars = 2759 const char* kScriptChars =
(...skipping 22 matching lines...) Expand all
2751 intptr_t len = -1; 2782 intptr_t len = -1;
2752 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls0, &len)); 2783 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls0, &len));
2753 EXPECT_EQ(0, len); 2784 EXPECT_EQ(0, len);
2754 2785
2755 EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls0, 0), 2786 EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls0, 0),
2756 "Dart_ClassGetInterfaceAt: argument 'index' out of bounds"); 2787 "Dart_ClassGetInterfaceAt: argument 'index' out of bounds");
2757 2788
2758 len = -1; 2789 len = -1;
2759 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls1, &len)); 2790 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls1, &len));
2760 EXPECT_EQ(1, len); 2791 EXPECT_EQ(1, len);
2761 CHECK_ABSTRACT_CLASS(Dart_ClassGetInterfaceAt(cls1, 0), "MyInterface1"); 2792 CHECK_CLASS(Dart_ClassGetInterfaceAt(cls1, 0), "MyInterface1");
2762 2793
2763 EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls1, -1), 2794 EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls1, -1),
2764 "Dart_ClassGetInterfaceAt: argument 'index' out of bounds"); 2795 "Dart_ClassGetInterfaceAt: argument 'index' out of bounds");
2765 EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls1, 1), 2796 EXPECT_ERROR(Dart_ClassGetInterfaceAt(cls1, 1),
2766 "Dart_ClassGetInterfaceAt: argument 'index' out of bounds"); 2797 "Dart_ClassGetInterfaceAt: argument 'index' out of bounds");
2767 2798
2768 len = -1; 2799 len = -1;
2769 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls2, &len)); 2800 EXPECT_VALID(Dart_ClassGetInterfaceCount(cls2, &len));
2770 EXPECT_EQ(2, len); 2801 EXPECT_EQ(2, len);
2771 2802
2772 // TODO(turnidge): The test relies on the ordering here. Sort this. 2803 // TODO(turnidge): The test relies on the ordering here. Sort this.
2773 CHECK_ABSTRACT_CLASS(Dart_ClassGetInterfaceAt(cls2, 0), "MyInterface0"); 2804 CHECK_CLASS(Dart_ClassGetInterfaceAt(cls2, 0), "MyInterface0");
2774 CHECK_ABSTRACT_CLASS(Dart_ClassGetInterfaceAt(cls2, 1), "MyInterface1"); 2805 CHECK_CLASS(Dart_ClassGetInterfaceAt(cls2, 1), "MyInterface1");
2775 2806
2776 len = -1; 2807 len = -1;
2777 EXPECT_VALID(Dart_ClassGetInterfaceCount(intf0, &len)); 2808 EXPECT_VALID(Dart_ClassGetInterfaceCount(intf0, &len));
2778 EXPECT_EQ(0, len); 2809 EXPECT_EQ(0, len);
2779 2810
2780 len = -1; 2811 len = -1;
2781 EXPECT_VALID(Dart_ClassGetInterfaceCount(intf1, &len)); 2812 EXPECT_VALID(Dart_ClassGetInterfaceCount(intf1, &len));
2782 EXPECT_EQ(1, len); 2813 EXPECT_EQ(1, len);
2783 CHECK_ABSTRACT_CLASS(Dart_ClassGetInterfaceAt(intf1, 0), "MyInterface0"); 2814 CHECK_CLASS(Dart_ClassGetInterfaceAt(intf1, 0), "MyInterface0");
2784 2815
2785 // Error cases. 2816 // Error cases.
2786 EXPECT_ERROR(Dart_ClassGetInterfaceCount(Dart_True(), &len), 2817 EXPECT_ERROR(Dart_ClassGetInterfaceCount(Dart_True(), &len),
2787 "Dart_ClassGetInterfaceCount expects argument 'clazz' to be of " 2818 "Dart_ClassGetInterfaceCount expects argument 'clazz' to be of "
2788 "type Class."); 2819 "type Class.");
2789 EXPECT_ERROR(Dart_ClassGetInterfaceCount(Dart_NewApiError("MyError"), &len), 2820 EXPECT_ERROR(Dart_ClassGetInterfaceCount(Dart_NewApiError("MyError"), &len),
2790 "MyError"); 2821 "MyError");
2791 } 2822 }
2792 2823
2793 2824
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
3118 "void set _imported_getset_fld(var value) { _gs_fld2 = value; }\n" 3149 "void set _imported_getset_fld(var value) { _gs_fld2 = value; }\n"
3119 "var _gs_fld1;\n" 3150 "var _gs_fld1;\n"
3120 "var _gs_fld2;\n" 3151 "var _gs_fld2;\n"
3121 "void test2() {\n" 3152 "void test2() {\n"
3122 " imported_getset_fld = 'imported getset';\n" 3153 " imported_getset_fld = 'imported getset';\n"
3123 " _imported_getset_fld = 'hidden imported getset';\n" 3154 " _imported_getset_fld = 'hidden imported getset';\n"
3124 "}\n"; 3155 "}\n";
3125 3156
3126 // Shared setup. 3157 // Shared setup.
3127 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 3158 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
3128 Dart_Handle cls = Dart_GetClass(lib, NewString("Fields")); 3159 Dart_Handle type = Dart_GetType(lib, NewString("Fields"), 0, NULL);
3129 EXPECT_VALID(cls); 3160 EXPECT_VALID(type);
3130 Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL); 3161 Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL);
3131 EXPECT_VALID(instance); 3162 EXPECT_VALID(instance);
3132 Dart_Handle name; 3163 Dart_Handle name;
3133 3164
3134 // Load imported lib. 3165 // Load imported lib.
3135 Dart_Handle url = NewString("library_url"); 3166 Dart_Handle url = NewString("library_url");
3136 Dart_Handle source = NewString(kImportedScriptChars); 3167 Dart_Handle source = NewString(kImportedScriptChars);
3137 Dart_Handle imported_lib = Dart_LoadLibrary(url, source); 3168 Dart_Handle imported_lib = Dart_LoadLibrary(url, source);
3138 Dart_Handle prefix = NewString(""); 3169 Dart_Handle prefix = NewString("");
3139 EXPECT_VALID(imported_lib); 3170 EXPECT_VALID(imported_lib);
3140 Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib, prefix); 3171 Dart_Handle result = Dart_LibraryImportLibrary(lib, imported_lib, prefix);
3141 EXPECT_VALID(result); 3172 EXPECT_VALID(result);
3142 result = Dart_Invoke(imported_lib, NewString("test2"), 0, NULL); 3173 result = Dart_Invoke(imported_lib, NewString("test2"), 0, NULL);
3143 EXPECT_VALID(result); 3174 EXPECT_VALID(result);
3144 3175
3145 // Instance field. 3176 // Instance field.
3146 name = NewString("instance_fld"); 3177 name = NewString("instance_fld");
3147 TestFieldNotFound(lib, name); 3178 TestFieldNotFound(lib, name);
3148 TestFieldNotFound(cls, name); 3179 TestFieldNotFound(type, name);
3149 TestFieldOk(instance, name, false, "instance"); 3180 TestFieldOk(instance, name, false, "instance");
3150 3181
3151 // Hidden instance field. 3182 // Hidden instance field.
3152 name = NewString("_instance_fld"); 3183 name = NewString("_instance_fld");
3153 TestFieldNotFound(lib, name); 3184 TestFieldNotFound(lib, name);
3154 TestFieldNotFound(cls, name); 3185 TestFieldNotFound(type, name);
3155 TestFieldOk(instance, name, false, "hidden instance"); 3186 TestFieldOk(instance, name, false, "hidden instance");
3156 3187
3157 // Final instance field. 3188 // Final instance field.
3158 name = NewString("final_instance_fld"); 3189 name = NewString("final_instance_fld");
3159 TestFieldNotFound(lib, name); 3190 TestFieldNotFound(lib, name);
3160 TestFieldNotFound(cls, name); 3191 TestFieldNotFound(type, name);
3161 TestFieldOk(instance, name, true, "final instance"); 3192 TestFieldOk(instance, name, true, "final instance");
3162 3193
3163 // Hidden final instance field. 3194 // Hidden final instance field.
3164 name = NewString("_final_instance_fld"); 3195 name = NewString("_final_instance_fld");
3165 TestFieldNotFound(lib, name); 3196 TestFieldNotFound(lib, name);
3166 TestFieldNotFound(cls, name); 3197 TestFieldNotFound(type, name);
3167 TestFieldOk(instance, name, true, "hidden final instance"); 3198 TestFieldOk(instance, name, true, "hidden final instance");
3168 3199
3169 // Inherited field. 3200 // Inherited field.
3170 name = NewString("inherited_fld"); 3201 name = NewString("inherited_fld");
3171 TestFieldNotFound(lib, name); 3202 TestFieldNotFound(lib, name);
3172 TestFieldNotFound(cls, name); 3203 TestFieldNotFound(type, name);
3173 TestFieldOk(instance, name, false, "inherited"); 3204 TestFieldOk(instance, name, false, "inherited");
3174 3205
3175 // Instance get/set field. 3206 // Instance get/set field.
3176 name = NewString("instance_getset_fld"); 3207 name = NewString("instance_getset_fld");
3177 TestFieldNotFound(lib, name); 3208 TestFieldNotFound(lib, name);
3178 TestFieldNotFound(cls, name); 3209 TestFieldNotFound(type, name);
3179 TestFieldOk(instance, name, false, "instance getset"); 3210 TestFieldOk(instance, name, false, "instance getset");
3180 3211
3181 // Hidden instance get/set field. 3212 // Hidden instance get/set field.
3182 name = NewString("_instance_getset_fld"); 3213 name = NewString("_instance_getset_fld");
3183 TestFieldNotFound(lib, name); 3214 TestFieldNotFound(lib, name);
3184 TestFieldNotFound(cls, name); 3215 TestFieldNotFound(type, name);
3185 TestFieldOk(instance, name, false, "hidden instance getset"); 3216 TestFieldOk(instance, name, false, "hidden instance getset");
3186 3217
3187 // Static field. 3218 // Static field.
3188 name = NewString("static_fld"); 3219 name = NewString("static_fld");
3189 TestFieldNotFound(lib, name); 3220 TestFieldNotFound(lib, name);
3190 TestFieldNotFound(instance, name); 3221 TestFieldNotFound(instance, name);
3191 TestFieldOk(cls, name, false, "static"); 3222 TestFieldOk(type, name, false, "static");
3192 3223
3193 // Hidden static field. 3224 // Hidden static field.
3194 name = NewString("_static_fld"); 3225 name = NewString("_static_fld");
3195 TestFieldNotFound(lib, name); 3226 TestFieldNotFound(lib, name);
3196 TestFieldNotFound(instance, name); 3227 TestFieldNotFound(instance, name);
3197 TestFieldOk(cls, name, false, "hidden static"); 3228 TestFieldOk(type, name, false, "hidden static");
3198 3229
3199 // Static final field. 3230 // Static final field.
3200 name = NewString("const_static_fld"); 3231 name = NewString("const_static_fld");
3201 TestFieldNotFound(lib, name); 3232 TestFieldNotFound(lib, name);
3202 TestFieldNotFound(instance, name); 3233 TestFieldNotFound(instance, name);
3203 TestFieldOk(cls, name, true, "const static"); 3234 TestFieldOk(type, name, true, "const static");
3204 3235
3205 // Hidden static const field. 3236 // Hidden static const field.
3206 name = NewString("_const_static_fld"); 3237 name = NewString("_const_static_fld");
3207 TestFieldNotFound(lib, name); 3238 TestFieldNotFound(lib, name);
3208 TestFieldNotFound(instance, name); 3239 TestFieldNotFound(instance, name);
3209 TestFieldOk(cls, name, true, "hidden const static"); 3240 TestFieldOk(type, name, true, "hidden const static");
3210 3241
3211 // Static non-inherited field. Not found at any level. 3242 // Static non-inherited field. Not found at any level.
3212 name = NewString("non_inherited_fld"); 3243 name = NewString("non_inherited_fld");
3213 TestFieldNotFound(lib, name); 3244 TestFieldNotFound(lib, name);
3214 TestFieldNotFound(instance, name); 3245 TestFieldNotFound(instance, name);
3215 TestFieldNotFound(cls, name); 3246 TestFieldNotFound(type, name);
3216 3247
3217 // Static get/set field. 3248 // Static get/set field.
3218 name = NewString("static_getset_fld"); 3249 name = NewString("static_getset_fld");
3219 TestFieldNotFound(lib, name); 3250 TestFieldNotFound(lib, name);
3220 TestFieldNotFound(instance, name); 3251 TestFieldNotFound(instance, name);
3221 TestFieldOk(cls, name, false, "static getset"); 3252 TestFieldOk(type, name, false, "static getset");
3222 3253
3223 // Hidden static get/set field. 3254 // Hidden static get/set field.
3224 name = NewString("_static_getset_fld"); 3255 name = NewString("_static_getset_fld");
3225 TestFieldNotFound(lib, name); 3256 TestFieldNotFound(lib, name);
3226 TestFieldNotFound(instance, name); 3257 TestFieldNotFound(instance, name);
3227 TestFieldOk(cls, name, false, "hidden static getset"); 3258 TestFieldOk(type, name, false, "hidden static getset");
3228 3259
3229 // Top-Level field. 3260 // Top-Level field.
3230 name = NewString("top_fld"); 3261 name = NewString("top_fld");
3231 TestFieldNotFound(cls, name); 3262 TestFieldNotFound(type, name);
3232 TestFieldNotFound(instance, name); 3263 TestFieldNotFound(instance, name);
3233 TestFieldOk(lib, name, false, "top"); 3264 TestFieldOk(lib, name, false, "top");
3234 3265
3235 // Hidden top-level field. 3266 // Hidden top-level field.
3236 name = NewString("_top_fld"); 3267 name = NewString("_top_fld");
3237 TestFieldNotFound(cls, name); 3268 TestFieldNotFound(type, name);
3238 TestFieldNotFound(instance, name); 3269 TestFieldNotFound(instance, name);
3239 TestFieldOk(lib, name, false, "hidden top"); 3270 TestFieldOk(lib, name, false, "hidden top");
3240 3271
3241 // Top-Level final field. 3272 // Top-Level final field.
3242 name = NewString("const_top_fld"); 3273 name = NewString("const_top_fld");
3243 TestFieldNotFound(cls, name); 3274 TestFieldNotFound(type, name);
3244 TestFieldNotFound(instance, name); 3275 TestFieldNotFound(instance, name);
3245 TestFieldOk(lib, name, true, "const top"); 3276 TestFieldOk(lib, name, true, "const top");
3246 3277
3247 // Hidden top-level final field. 3278 // Hidden top-level final field.
3248 name = NewString("_const_top_fld"); 3279 name = NewString("_const_top_fld");
3249 TestFieldNotFound(cls, name); 3280 TestFieldNotFound(type, name);
3250 TestFieldNotFound(instance, name); 3281 TestFieldNotFound(instance, name);
3251 TestFieldOk(lib, name, true, "hidden const top"); 3282 TestFieldOk(lib, name, true, "hidden const top");
3252 3283
3253 // Top-Level get/set field. 3284 // Top-Level get/set field.
3254 name = NewString("top_getset_fld"); 3285 name = NewString("top_getset_fld");
3255 TestFieldNotFound(cls, name); 3286 TestFieldNotFound(type, name);
3256 TestFieldNotFound(instance, name); 3287 TestFieldNotFound(instance, name);
3257 TestFieldOk(lib, name, false, "top getset"); 3288 TestFieldOk(lib, name, false, "top getset");
3258 3289
3259 // Hidden top-level get/set field. 3290 // Hidden top-level get/set field.
3260 name = NewString("_top_getset_fld"); 3291 name = NewString("_top_getset_fld");
3261 TestFieldNotFound(cls, name); 3292 TestFieldNotFound(type, name);
3262 TestFieldNotFound(instance, name); 3293 TestFieldNotFound(instance, name);
3263 TestFieldOk(lib, name, false, "hidden top getset"); 3294 TestFieldOk(lib, name, false, "hidden top getset");
3264 3295
3265 // Imported top-Level field. 3296 // Imported top-Level field.
3266 name = NewString("imported_fld"); 3297 name = NewString("imported_fld");
3267 TestFieldNotFound(cls, name); 3298 TestFieldNotFound(type, name);
3268 TestFieldNotFound(instance, name); 3299 TestFieldNotFound(instance, name);
3269 TestFieldOk(lib, name, false, "imported"); 3300 TestFieldOk(lib, name, false, "imported");
3270 3301
3271 // Hidden imported top-level field. Not found at any level. 3302 // Hidden imported top-level field. Not found at any level.
3272 name = NewString("_imported_fld"); 3303 name = NewString("_imported_fld");
3273 TestFieldNotFound(cls, name); 3304 TestFieldNotFound(type, name);
3274 TestFieldNotFound(instance, name); 3305 TestFieldNotFound(instance, name);
3275 TestFieldNotFound(lib, name); 3306 TestFieldNotFound(lib, name);
3276 3307
3277 // Imported top-Level get/set field. 3308 // Imported top-Level get/set field.
3278 name = NewString("imported_getset_fld"); 3309 name = NewString("imported_getset_fld");
3279 TestFieldNotFound(cls, name); 3310 TestFieldNotFound(type, name);
3280 TestFieldNotFound(instance, name); 3311 TestFieldNotFound(instance, name);
3281 TestFieldOk(lib, name, false, "imported getset"); 3312 TestFieldOk(lib, name, false, "imported getset");
3282 3313
3283 // Hidden imported top-level get/set field. Not found at any level. 3314 // Hidden imported top-level get/set field. Not found at any level.
3284 name = NewString("_imported_getset_fld"); 3315 name = NewString("_imported_getset_fld");
3285 TestFieldNotFound(cls, name); 3316 TestFieldNotFound(type, name);
3286 TestFieldNotFound(instance, name); 3317 TestFieldNotFound(instance, name);
3287 TestFieldNotFound(lib, name); 3318 TestFieldNotFound(lib, name);
3288 } 3319 }
3289 3320
3290 3321
3291 TEST_CASE(SetField_FunnyValue) { 3322 TEST_CASE(SetField_FunnyValue) {
3292 const char* kScriptChars = 3323 const char* kScriptChars =
3293 "var top;\n"; 3324 "var top;\n";
3294 3325
3295 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 3326 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
3783 const char* kScriptChars = 3814 const char* kScriptChars =
3784 "class TestClass {\n" 3815 "class TestClass {\n"
3785 " static const int fld1 = 7;\n" 3816 " static const int fld1 = 7;\n"
3786 " static int fld2 = 11;\n" 3817 " static int fld2 = 11;\n"
3787 " static void testMain() {\n" 3818 " static void testMain() {\n"
3788 " }\n" 3819 " }\n"
3789 "}\n"; 3820 "}\n";
3790 Dart_Handle result; 3821 Dart_Handle result;
3791 // Create a test library and Load up a test script in it. 3822 // Create a test library and Load up a test script in it.
3792 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 3823 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
3793 Dart_Handle cls = Dart_GetClass(lib, NewString("TestClass")); 3824 Dart_Handle type = Dart_GetType(lib, NewString("TestClass"), 0, NULL);
3794 EXPECT_VALID(cls); 3825 EXPECT_VALID(type);
3795 3826
3796 // Invoke a function which returns an object. 3827 // Invoke a function which returns an object.
3797 result = Dart_Invoke(cls, NewString("testMain"), 0, NULL); 3828 result = Dart_Invoke(type, NewString("testMain"), 0, NULL);
3798 EXPECT_VALID(result); 3829 EXPECT_VALID(result);
3799 3830
3800 // For uninitialized fields, the getter is returned 3831 // For uninitialized fields, the getter is returned
3801 result = Dart_GetField(cls, NewString("fld1")); 3832 result = Dart_GetField(type, NewString("fld1"));
3802 EXPECT_VALID(result); 3833 EXPECT_VALID(result);
3803 int64_t value = 0; 3834 int64_t value = 0;
3804 result = Dart_IntegerToInt64(result, &value); 3835 result = Dart_IntegerToInt64(result, &value);
3805 EXPECT_EQ(7, value); 3836 EXPECT_EQ(7, value);
3806 3837
3807 result = Dart_GetField(cls, NewString("fld2")); 3838 result = Dart_GetField(type, NewString("fld2"));
3808 EXPECT_VALID(result); 3839 EXPECT_VALID(result);
3809 result = Dart_IntegerToInt64(result, &value); 3840 result = Dart_IntegerToInt64(result, &value);
3810 EXPECT_EQ(11, value); 3841 EXPECT_EQ(11, value);
3811 3842
3812 // Overwrite fld2 3843 // Overwrite fld2
3813 result = Dart_SetField(cls, 3844 result = Dart_SetField(type,
3814 NewString("fld2"), 3845 NewString("fld2"),
3815 Dart_NewInteger(13)); 3846 Dart_NewInteger(13));
3816 EXPECT_VALID(result); 3847 EXPECT_VALID(result);
3817 3848
3818 // We now get the new value for fld2, not the initializer 3849 // We now get the new value for fld2, not the initializer
3819 result = Dart_GetField(cls, NewString("fld2")); 3850 result = Dart_GetField(type, NewString("fld2"));
3820 EXPECT_VALID(result); 3851 EXPECT_VALID(result);
3821 result = Dart_IntegerToInt64(result, &value); 3852 result = Dart_IntegerToInt64(result, &value);
3822 EXPECT_EQ(13, value); 3853 EXPECT_EQ(13, value);
3823 } 3854 }
3824 3855
3825 3856
3826 TEST_CASE(GetField_CheckIsolate) { 3857 TEST_CASE(GetField_CheckIsolate) {
3827 const char* kScriptChars = 3858 const char* kScriptChars =
3828 "class TestClass {\n" 3859 "class TestClass {\n"
3829 " static int fld2 = 11;\n" 3860 " static int fld2 = 11;\n"
3830 " static void testMain() {\n" 3861 " static void testMain() {\n"
3831 " }\n" 3862 " }\n"
3832 "}\n"; 3863 "}\n";
3833 Dart_Handle result; 3864 Dart_Handle result;
3834 int64_t value = 0; 3865 int64_t value = 0;
3835 3866
3836 // Create a test library and Load up a test script in it. 3867 // Create a test library and Load up a test script in it.
3837 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 3868 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
3838 Dart_Handle cls = Dart_GetClass(lib, NewString("TestClass")); 3869 Dart_Handle type = Dart_GetType(lib, NewString("TestClass"), 0, NULL);
3839 EXPECT_VALID(cls); 3870 EXPECT_VALID(type);
3840 3871
3841 result = Dart_GetField(cls, NewString("fld2")); 3872 result = Dart_GetField(type, NewString("fld2"));
3842 EXPECT_VALID(result); 3873 EXPECT_VALID(result);
3843 result = Dart_IntegerToInt64(result, &value); 3874 result = Dart_IntegerToInt64(result, &value);
3844 EXPECT_EQ(11, value); 3875 EXPECT_EQ(11, value);
3845 } 3876 }
3846 3877
3847 3878
3848 TEST_CASE(SetField_CheckIsolate) { 3879 TEST_CASE(SetField_CheckIsolate) {
3849 const char* kScriptChars = 3880 const char* kScriptChars =
3850 "class TestClass {\n" 3881 "class TestClass {\n"
3851 " static int fld2 = 11;\n" 3882 " static int fld2 = 11;\n"
3852 " static void testMain() {\n" 3883 " static void testMain() {\n"
3853 " }\n" 3884 " }\n"
3854 "}\n"; 3885 "}\n";
3855 Dart_Handle result; 3886 Dart_Handle result;
3856 int64_t value = 0; 3887 int64_t value = 0;
3857 3888
3858 // Create a test library and Load up a test script in it. 3889 // Create a test library and Load up a test script in it.
3859 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 3890 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
3860 Dart_Handle cls = Dart_GetClass(lib, NewString("TestClass")); 3891 Dart_Handle type = Dart_GetType(lib, NewString("TestClass"), 0, NULL);
3861 EXPECT_VALID(cls); 3892 EXPECT_VALID(type);
3862 3893
3863 result = Dart_SetField(cls, NewString("fld2"), Dart_NewInteger(13)); 3894 result = Dart_SetField(type, NewString("fld2"), Dart_NewInteger(13));
3864 EXPECT_VALID(result); 3895 EXPECT_VALID(result);
3865 3896
3866 result = Dart_GetField(cls, NewString("fld2")); 3897 result = Dart_GetField(type, NewString("fld2"));
3867 EXPECT_VALID(result); 3898 EXPECT_VALID(result);
3868 result = Dart_IntegerToInt64(result, &value); 3899 result = Dart_IntegerToInt64(result, &value);
3869 EXPECT_EQ(13, value); 3900 EXPECT_EQ(13, value);
3870 } 3901 }
3871 3902
3872 3903
3873 TEST_CASE(New) { 3904 TEST_CASE(New) {
3874 const char* kScriptChars = 3905 const char* kScriptChars =
3875 "class MyClass {\n" 3906 "class MyClass {\n"
3876 " MyClass() : foo = 7 {}\n" 3907 " MyClass() : foo = 7 {}\n"
(...skipping 15 matching lines...) Expand all
3892 " factory MyExtraHop.hop(value) = MyClass.named;\n" 3923 " factory MyExtraHop.hop(value) = MyClass.named;\n"
3893 "}\n" 3924 "}\n"
3894 "\n" 3925 "\n"
3895 "abstract class MyInterface {\n" 3926 "abstract class MyInterface {\n"
3896 " factory MyInterface.named(value) = MyExtraHop.hop;\n" 3927 " factory MyInterface.named(value) = MyExtraHop.hop;\n"
3897 " factory MyInterface.multiply(value) = MyClass.multiply;\n" 3928 " factory MyInterface.multiply(value) = MyClass.multiply;\n"
3898 " MyInterface.notfound(value);\n" 3929 " MyInterface.notfound(value);\n"
3899 "}\n"; 3930 "}\n";
3900 3931
3901 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 3932 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
3902 Dart_Handle cls = Dart_GetClass(lib, NewString("MyClass")); 3933 Dart_Handle type = Dart_GetType(lib, NewString("MyClass"), 0, NULL);
3903 EXPECT_VALID(cls); 3934 EXPECT_VALID(type);
3904 Dart_Handle intf = Dart_GetClass(lib, NewString("MyInterface")); 3935 Dart_Handle intf = Dart_GetType(lib, NewString("MyInterface"), 0, NULL);
3905 EXPECT_VALID(intf); 3936 EXPECT_VALID(intf);
3906 Dart_Handle args[1]; 3937 Dart_Handle args[1];
3907 args[0] = Dart_NewInteger(11); 3938 args[0] = Dart_NewInteger(11);
3908 Dart_Handle bad_args[1]; 3939 Dart_Handle bad_args[1];
3909 bad_args[0] = Dart_Error("myerror"); 3940 bad_args[0] = Dart_Error("myerror");
3910 3941
3911 // Invoke the unnamed constructor. 3942 // Invoke the unnamed constructor.
3912 Dart_Handle result = Dart_New(cls, Dart_Null(), 0, NULL); 3943 Dart_Handle result = Dart_New(type, Dart_Null(), 0, NULL);
3913 EXPECT_VALID(result); 3944 EXPECT_VALID(result);
3914 bool instanceof = false; 3945 bool instanceof = false;
3915 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); 3946 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
3916 EXPECT(instanceof); 3947 EXPECT(instanceof);
3917 int64_t int_value = 0; 3948 int64_t int_value = 0;
3918 Dart_Handle foo = Dart_GetField(result, NewString("foo")); 3949 Dart_Handle foo = Dart_GetField(result, NewString("foo"));
3919 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); 3950 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3920 EXPECT_EQ(7, int_value); 3951 EXPECT_EQ(7, int_value);
3921 3952
3922 // Invoke the unnamed constructor with an empty string. 3953 // Invoke the unnamed constructor with an empty string.
3923 result = Dart_New(cls, NewString(""), 0, NULL); 3954 result = Dart_New(type, NewString(""), 0, NULL);
3924 EXPECT_VALID(result); 3955 EXPECT_VALID(result);
3925 instanceof = false; 3956 instanceof = false;
3926 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); 3957 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
3927 EXPECT(instanceof); 3958 EXPECT(instanceof);
3928 int_value = 0; 3959 int_value = 0;
3929 foo = Dart_GetField(result, NewString("foo")); 3960 foo = Dart_GetField(result, NewString("foo"));
3930 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); 3961 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3931 EXPECT_EQ(7, int_value); 3962 EXPECT_EQ(7, int_value);
3932 3963
3933 // Invoke a named constructor. 3964 // Invoke a named constructor.
3934 result = Dart_New(cls, NewString("named"), 1, args); 3965 result = Dart_New(type, NewString("named"), 1, args);
3935 EXPECT_VALID(result); 3966 EXPECT_VALID(result);
3936 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); 3967 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
3937 EXPECT(instanceof); 3968 EXPECT(instanceof);
3938 int_value = 0; 3969 int_value = 0;
3939 foo = Dart_GetField(result, NewString("foo")); 3970 foo = Dart_GetField(result, NewString("foo"));
3940 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); 3971 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3941 EXPECT_EQ(11, int_value); 3972 EXPECT_EQ(11, int_value);
3942 3973
3943 // Invoke a hidden named constructor. 3974 // Invoke a hidden named constructor.
3944 result = Dart_New(cls, NewString("_hidden"), 1, args); 3975 result = Dart_New(type, NewString("_hidden"), 1, args);
3945 EXPECT_VALID(result); 3976 EXPECT_VALID(result);
3946 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); 3977 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
3947 EXPECT(instanceof); 3978 EXPECT(instanceof);
3948 int_value = 0; 3979 int_value = 0;
3949 foo = Dart_GetField(result, NewString("foo")); 3980 foo = Dart_GetField(result, NewString("foo"));
3950 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); 3981 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3951 EXPECT_EQ(-11, int_value); 3982 EXPECT_EQ(-11, int_value);
3952 3983
3953 // Invoke a factory constructor. 3984 // Invoke a factory constructor.
3954 result = Dart_New(cls, NewString("multiply"), 1, args); 3985 result = Dart_New(type, NewString("multiply"), 1, args);
3955 EXPECT_VALID(result); 3986 EXPECT_VALID(result);
3956 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); 3987 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
3957 EXPECT(instanceof); 3988 EXPECT(instanceof);
3958 int_value = 0; 3989 int_value = 0;
3959 foo = Dart_GetField(result, NewString("foo")); 3990 foo = Dart_GetField(result, NewString("foo"));
3960 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); 3991 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
3961 EXPECT_EQ(1100, int_value); 3992 EXPECT_EQ(1100, int_value);
3962 3993
3963 // Invoke a factory constructor which returns null. 3994 // Invoke a factory constructor which returns null.
3964 result = Dart_New(cls, NewString("nullo"), 0, NULL); 3995 result = Dart_New(type, NewString("nullo"), 0, NULL);
3965 EXPECT_VALID(result); 3996 EXPECT_VALID(result);
3966 EXPECT(Dart_IsNull(result)); 3997 EXPECT(Dart_IsNull(result));
3967 3998
3968 // Pass an error class object. Error is passed through. 3999 // Pass an error class object. Error is passed through.
3969 result = Dart_New(Dart_Error("myerror"), NewString("named"), 1, args); 4000 result = Dart_New(Dart_Error("myerror"), NewString("named"), 1, args);
3970 EXPECT_ERROR(result, "myerror"); 4001 EXPECT_ERROR(result, "myerror");
3971 4002
3972 // Pass a bad class object. 4003 // Pass a bad class object.
3973 result = Dart_New(Dart_Null(), NewString("named"), 1, args); 4004 result = Dart_New(Dart_Null(), NewString("named"), 1, args);
3974 EXPECT_ERROR(result, "Dart_New expects argument 'clazz' to be non-null."); 4005 EXPECT_ERROR(result, "Dart_New expects argument 'type' to be non-null.");
3975 4006
3976 // Pass a negative arg count. 4007 // Pass a negative arg count.
3977 result = Dart_New(cls, NewString("named"), -1, args); 4008 result = Dart_New(type, NewString("named"), -1, args);
3978 EXPECT_ERROR( 4009 EXPECT_ERROR(
3979 result, 4010 result,
3980 "Dart_New expects argument 'number_of_arguments' to be non-negative."); 4011 "Dart_New expects argument 'number_of_arguments' to be non-negative.");
3981 4012
3982 // Pass the wrong arg count. 4013 // Pass the wrong arg count.
3983 result = Dart_New(cls, NewString("named"), 0, NULL); 4014 result = Dart_New(type, NewString("named"), 0, NULL);
3984 EXPECT_ERROR( 4015 EXPECT_ERROR(
3985 result, 4016 result,
3986 "Dart_New: wrong argument count for constructor 'MyClass.named': " 4017 "Dart_New: wrong argument count for constructor 'MyClass.named': "
3987 "0 passed, 1 expected."); 4018 "0 passed, 1 expected.");
3988 4019
3989 // Pass a bad argument. Error is passed through. 4020 // Pass a bad argument. Error is passed through.
3990 result = Dart_New(cls, NewString("named"), 1, bad_args); 4021 result = Dart_New(type, NewString("named"), 1, bad_args);
3991 EXPECT_ERROR(result, "myerror"); 4022 EXPECT_ERROR(result, "myerror");
3992 4023
3993 // Pass a bad constructor name. 4024 // Pass a bad constructor name.
3994 result = Dart_New(cls, Dart_NewInteger(55), 1, args); 4025 result = Dart_New(type, Dart_NewInteger(55), 1, args);
3995 EXPECT_ERROR( 4026 EXPECT_ERROR(
3996 result, 4027 result,
3997 "Dart_New expects argument 'constructor_name' to be of type String."); 4028 "Dart_New expects argument 'constructor_name' to be of type String.");
3998 4029
3999 // Invoke a missing constructor. 4030 // Invoke a missing constructor.
4000 result = Dart_New(cls, NewString("missing"), 1, args); 4031 result = Dart_New(type, NewString("missing"), 1, args);
4001 EXPECT_ERROR(result, 4032 EXPECT_ERROR(result,
4002 "Dart_New: could not find constructor 'MyClass.missing'."); 4033 "Dart_New: could not find constructor 'MyClass.missing'.");
4003 4034
4004 // Invoke a constructor which throws an exception. 4035 // Invoke a constructor which throws an exception.
4005 result = Dart_New(cls, NewString("exception"), 1, args); 4036 result = Dart_New(type, NewString("exception"), 1, args);
4006 EXPECT_ERROR(result, "ConstructorDeath"); 4037 EXPECT_ERROR(result, "ConstructorDeath");
4007 4038
4008 // Invoke two-hop redirecting factory constructor. 4039 // Invoke two-hop redirecting factory constructor.
4009 result = Dart_New(intf, NewString("named"), 1, args); 4040 result = Dart_New(intf, NewString("named"), 1, args);
4010 EXPECT_VALID(result); 4041 EXPECT_VALID(result);
4011 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); 4042 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
4012 EXPECT(instanceof); 4043 EXPECT(instanceof);
4013 int_value = 0; 4044 int_value = 0;
4014 foo = Dart_GetField(result, NewString("foo")); 4045 foo = Dart_GetField(result, NewString("foo"));
4015 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); 4046 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
4016 EXPECT_EQ(11, int_value); 4047 EXPECT_EQ(11, int_value);
4017 4048
4018 // Invoke one-hop redirecting factory constructor. 4049 // Invoke one-hop redirecting factory constructor.
4019 result = Dart_New(intf, NewString("multiply"), 1, args); 4050 result = Dart_New(intf, NewString("multiply"), 1, args);
4020 EXPECT_VALID(result); 4051 EXPECT_VALID(result);
4021 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); 4052 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
4022 EXPECT(instanceof); 4053 EXPECT(instanceof);
4023 int_value = 0; 4054 int_value = 0;
4024 foo = Dart_GetField(result, NewString("foo")); 4055 foo = Dart_GetField(result, NewString("foo"));
4025 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value)); 4056 EXPECT_VALID(Dart_IntegerToInt64(foo, &int_value));
4026 EXPECT_EQ(1100, int_value); 4057 EXPECT_EQ(1100, int_value);
4027 4058
4028 // Invoke a constructor that is missing in the interface. 4059 // Invoke a constructor that is missing in the interface.
4029 result = Dart_New(intf, Dart_Null(), 0, NULL); 4060 result = Dart_New(intf, Dart_Null(), 0, NULL);
4030 EXPECT_ERROR(result, 4061 EXPECT_ERROR(result,
4031 "Dart_New: could not find constructor 'MyInterface.'."); 4062 "Dart_New: could not find constructor 'MyInterface.'.");
4032 4063
4033 // Invoke abstract constructor that is present in the interface. 4064 // Invoke abstract constructor that is present in the interface.
4034 result = Dart_New(intf, NewString("notfound"), 1, args); 4065 result = Dart_New(intf, NewString("notfound"), 1, args);
4035 EXPECT_VALID(result); 4066 EXPECT_VALID(result);
4036 EXPECT_VALID(Dart_ObjectIsType(result, cls, &instanceof)); 4067 EXPECT_VALID(Dart_ObjectIsType(result, type, &instanceof));
4037 EXPECT(!instanceof); 4068 EXPECT(!instanceof);
4038 } 4069 }
4039 4070
4040 4071
4041 TEST_CASE(New_Issue2971) { 4072 TEST_CASE(New_Issue2971) {
4042 // Issue 2971: We were unable to use Dart_New to construct an 4073 // Issue 2971: We were unable to use Dart_New to construct an
4043 // instance of List, due to problems implementing interface 4074 // instance of List, due to problems implementing interface
4044 // factories. 4075 // factories.
4045 Dart_Handle core_lib = Dart_LookupLibrary(NewString("dart:core")); 4076 Dart_Handle core_lib = Dart_LookupLibrary(NewString("dart:core"));
4046 EXPECT_VALID(core_lib); 4077 EXPECT_VALID(core_lib);
4047 Dart_Handle list_class = Dart_GetClass(core_lib, NewString("List")); 4078 Dart_Handle list_type = Dart_GetType(core_lib, NewString("List"), 0, NULL);
4048 EXPECT_VALID(list_class); 4079 EXPECT_VALID(list_type);
4049 4080
4050 const int kNumArgs = 1; 4081 const int kNumArgs = 1;
4051 Dart_Handle args[kNumArgs]; 4082 Dart_Handle args[kNumArgs];
4052 args[0] = Dart_NewInteger(1); 4083 args[0] = Dart_NewInteger(1);
4053 Dart_Handle list_obj = Dart_New(list_class, Dart_Null(), kNumArgs, args); 4084 Dart_Handle list_obj = Dart_New(list_type, Dart_Null(), kNumArgs, args);
4054 EXPECT_VALID(list_obj); 4085 EXPECT_VALID(list_obj);
4055 EXPECT(Dart_IsList(list_obj)); 4086 EXPECT(Dart_IsList(list_obj));
4056 } 4087 }
4057 4088
4058 4089
4059 static Dart_Handle PrivateLibName(Dart_Handle lib, const char* str) { 4090 static Dart_Handle PrivateLibName(Dart_Handle lib, const char* str) {
4060 EXPECT(Dart_IsLibrary(lib)); 4091 EXPECT(Dart_IsLibrary(lib));
4061 Isolate* isolate = Isolate::Current(); 4092 Isolate* isolate = Isolate::Current();
4062 const Library& library_obj = Api::UnwrapLibraryHandle(isolate, lib); 4093 const Library& library_obj = Api::UnwrapLibraryHandle(isolate, lib);
4063 const String& name = String::Handle(String::New(str)); 4094 const String& name = String::Handle(String::New(str));
(...skipping 17 matching lines...) Expand all
4081 "\n" 4112 "\n"
4082 "topMethod(arg) => 'top $arg';\n" 4113 "topMethod(arg) => 'top $arg';\n"
4083 "_topMethod(arg) => 'hidden top $arg';\n" 4114 "_topMethod(arg) => 'hidden top $arg';\n"
4084 "\n" 4115 "\n"
4085 "Methods test() {\n" 4116 "Methods test() {\n"
4086 " return new Methods();\n" 4117 " return new Methods();\n"
4087 "}\n"; 4118 "}\n";
4088 4119
4089 // Shared setup. 4120 // Shared setup.
4090 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 4121 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
4091 Dart_Handle cls = Dart_GetClass(lib, NewString("Methods")); 4122 Dart_Handle type = Dart_GetType(lib, NewString("Methods"), 0, NULL);
4092 EXPECT_VALID(cls); 4123 EXPECT_VALID(type);
4093 Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL); 4124 Dart_Handle instance = Dart_Invoke(lib, NewString("test"), 0, NULL);
4094 EXPECT_VALID(instance); 4125 EXPECT_VALID(instance);
4095 Dart_Handle args[1]; 4126 Dart_Handle args[1];
4096 args[0] = NewString("!!!"); 4127 args[0] = NewString("!!!");
4097 Dart_Handle bad_args[2]; 4128 Dart_Handle bad_args[2];
4098 bad_args[0] = NewString("bad1"); 4129 bad_args[0] = NewString("bad1");
4099 bad_args[1] = NewString("bad2"); 4130 bad_args[1] = NewString("bad2");
4100 Dart_Handle result; 4131 Dart_Handle result;
4101 Dart_Handle name; 4132 Dart_Handle name;
4102 const char* str; 4133 const char* str;
4103 4134
4104 // Instance method. 4135 // Instance method.
4105 name = NewString("instanceMethod"); 4136 name = NewString("instanceMethod");
4106 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); 4137 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args)));
4107 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); 4138 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args)));
4108 result = Dart_Invoke(instance, name, 1, args); 4139 result = Dart_Invoke(instance, name, 1, args);
4109 EXPECT_VALID(result); 4140 EXPECT_VALID(result);
4110 result = Dart_StringToCString(result, &str); 4141 result = Dart_StringToCString(result, &str);
4111 EXPECT_STREQ("instance !!!", str); 4142 EXPECT_STREQ("instance !!!", str);
4112 4143
4113 // Instance method, wrong arg count. 4144 // Instance method, wrong arg count.
4114 EXPECT_ERROR(Dart_Invoke(instance, name, 2, bad_args), 4145 EXPECT_ERROR(Dart_Invoke(instance, name, 2, bad_args),
4115 "Class 'Methods' has no instance method 'instanceMethod'" 4146 "Class 'Methods' has no instance method 'instanceMethod'"
4116 " with matching arguments"); 4147 " with matching arguments");
4117 4148
4118 name = PrivateLibName(lib, "_instanceMethod"); 4149 name = PrivateLibName(lib, "_instanceMethod");
4119 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); 4150 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args)));
4120 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); 4151 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args)));
4121 result = Dart_Invoke(instance, name, 1, args); 4152 result = Dart_Invoke(instance, name, 1, args);
4122 EXPECT_VALID(result); 4153 EXPECT_VALID(result);
4123 result = Dart_StringToCString(result, &str); 4154 result = Dart_StringToCString(result, &str);
4124 EXPECT_STREQ("hidden instance !!!", str); 4155 EXPECT_STREQ("hidden instance !!!", str);
4125 4156
4126 // Inherited method. 4157 // Inherited method.
4127 name = NewString("inheritedMethod"); 4158 name = NewString("inheritedMethod");
4128 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); 4159 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args)));
4129 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); 4160 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args)));
4130 result = Dart_Invoke(instance, name, 1, args); 4161 result = Dart_Invoke(instance, name, 1, args);
4131 EXPECT_VALID(result); 4162 EXPECT_VALID(result);
4132 result = Dart_StringToCString(result, &str); 4163 result = Dart_StringToCString(result, &str);
4133 EXPECT_STREQ("inherited !!!", str); 4164 EXPECT_STREQ("inherited !!!", str);
4134 4165
4135 // Static method. 4166 // Static method.
4136 name = NewString("staticMethod"); 4167 name = NewString("staticMethod");
4137 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); 4168 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args)));
4138 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); 4169 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args)));
4139 result = Dart_Invoke(cls, name, 1, args); 4170 result = Dart_Invoke(type, name, 1, args);
4140 EXPECT_VALID(result); 4171 EXPECT_VALID(result);
4141 result = Dart_StringToCString(result, &str); 4172 result = Dart_StringToCString(result, &str);
4142 EXPECT_STREQ("static !!!", str); 4173 EXPECT_STREQ("static !!!", str);
4143 4174
4144 // Static method, wrong arg count. 4175 // Static method, wrong arg count.
4145 EXPECT_ERROR(Dart_Invoke(cls, name, 2, bad_args), 4176 EXPECT_ERROR(Dart_Invoke(type, name, 2, bad_args),
4146 "did not find static method 'Methods.staticMethod'"); 4177 "did not find static method 'Methods.staticMethod'");
4147 4178
4148 // Hidden static method. 4179 // Hidden static method.
4149 name = PrivateLibName(lib, "_staticMethod"); 4180 name = PrivateLibName(lib, "_staticMethod");
4150 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); 4181 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args)));
4151 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); 4182 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args)));
4152 result = Dart_Invoke(cls, name, 1, args); 4183 result = Dart_Invoke(type, name, 1, args);
4153 EXPECT_VALID(result); 4184 EXPECT_VALID(result);
4154 result = Dart_StringToCString(result, &str); 4185 result = Dart_StringToCString(result, &str);
4155 EXPECT_STREQ("hidden static !!!", str); 4186 EXPECT_STREQ("hidden static !!!", str);
4156 4187
4157 // Static non-inherited method. Not found at any level. 4188 // Static non-inherited method. Not found at any level.
4158 name = NewString("non_inheritedMethod"); 4189 name = NewString("non_inheritedMethod");
4159 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args))); 4190 EXPECT(Dart_IsError(Dart_Invoke(lib, name, 1, args)));
4160 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); 4191 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args)));
4161 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); 4192 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args)));
4162 4193
4163 // Top-Level method. 4194 // Top-Level method.
4164 name = NewString("topMethod"); 4195 name = NewString("topMethod");
4165 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); 4196 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args)));
4166 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); 4197 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args)));
4167 result = Dart_Invoke(lib, name, 1, args); 4198 result = Dart_Invoke(lib, name, 1, args);
4168 EXPECT_VALID(result); 4199 EXPECT_VALID(result);
4169 result = Dart_StringToCString(result, &str); 4200 result = Dart_StringToCString(result, &str);
4170 EXPECT_STREQ("top !!!", str); 4201 EXPECT_STREQ("top !!!", str);
4171 4202
4172 // Top-level method, wrong arg count. 4203 // Top-level method, wrong arg count.
4173 EXPECT_ERROR(Dart_Invoke(lib, name, 2, bad_args), 4204 EXPECT_ERROR(Dart_Invoke(lib, name, 2, bad_args),
4174 "Dart_Invoke: wrong argument count for function 'topMethod': " 4205 "Dart_Invoke: wrong argument count for function 'topMethod': "
4175 "2 passed, 1 expected."); 4206 "2 passed, 1 expected.");
4176 4207
4177 // Hidden top-level method. 4208 // Hidden top-level method.
4178 name = PrivateLibName(lib, "_topMethod"); 4209 name = PrivateLibName(lib, "_topMethod");
4179 EXPECT(Dart_IsError(Dart_Invoke(cls, name, 1, args))); 4210 EXPECT(Dart_IsError(Dart_Invoke(type, name, 1, args)));
4180 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args))); 4211 EXPECT(Dart_IsError(Dart_Invoke(instance, name, 1, args)));
4181 result = Dart_Invoke(lib, name, 1, args); 4212 result = Dart_Invoke(lib, name, 1, args);
4182 EXPECT_VALID(result); 4213 EXPECT_VALID(result);
4183 result = Dart_StringToCString(result, &str); 4214 result = Dart_StringToCString(result, &str);
4184 EXPECT_STREQ("hidden top !!!", str); 4215 EXPECT_STREQ("hidden top !!!", str);
4185 } 4216 }
4186 4217
4187 4218
4188 TEST_CASE(Invoke_FunnyArgs) { 4219 TEST_CASE(Invoke_FunnyArgs) {
4189 const char* kScriptChars = 4220 const char* kScriptChars =
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
4286 " TestClass.fld1 += 1;\n" 4317 " TestClass.fld1 += 1;\n"
4287 " }\n" 4318 " }\n"
4288 " static TestClass testMain() {\n" 4319 " static TestClass testMain() {\n"
4289 " return new TestClass();\n" 4320 " return new TestClass();\n"
4290 " }\n" 4321 " }\n"
4291 "}\n"; 4322 "}\n";
4292 Dart_Handle result; 4323 Dart_Handle result;
4293 Dart_Handle instance; 4324 Dart_Handle instance;
4294 // Create a test library and Load up a test script in it. 4325 // Create a test library and Load up a test script in it.
4295 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 4326 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
4296 Dart_Handle cls = Dart_GetClass(lib, NewString("TestClass")); 4327 Dart_Handle type = Dart_GetType(lib, NewString("TestClass"), 0, NULL);
4297 EXPECT_VALID(cls); 4328 EXPECT_VALID(type);
4298 4329
4299 // Invoke a function which returns an object. 4330 // Invoke a function which returns an object.
4300 instance = Dart_Invoke(cls, NewString("testMain"), 0, NULL); 4331 instance = Dart_Invoke(type, NewString("testMain"), 0, NULL);
4301 EXPECT_VALID(instance); 4332 EXPECT_VALID(instance);
4302 4333
4303 // Try to get a field that does not exist, should call noSuchMethod. 4334 // Try to get a field that does not exist, should call noSuchMethod.
4304 result = Dart_GetField(instance, NewString("fld")); 4335 result = Dart_GetField(instance, NewString("fld"));
4305 EXPECT_VALID(result); 4336 EXPECT_VALID(result);
4306 4337
4307 // Try to set a field that does not exist, should call noSuchMethod. 4338 // Try to set a field that does not exist, should call noSuchMethod.
4308 result = Dart_SetField(instance, NewString("setfld"), Dart_NewInteger(13)); 4339 result = Dart_SetField(instance, NewString("setfld"), Dart_NewInteger(13));
4309 EXPECT_VALID(result); 4340 EXPECT_VALID(result);
4310 4341
4311 // Try to invoke a method that does not exist, should call noSuchMethod. 4342 // Try to invoke a method that does not exist, should call noSuchMethod.
4312 result = Dart_Invoke(instance, NewString("method"), 0, NULL); 4343 result = Dart_Invoke(instance, NewString("method"), 0, NULL);
4313 EXPECT_VALID(result); 4344 EXPECT_VALID(result);
4314 4345
4315 result = Dart_GetField(cls, NewString("fld1")); 4346 result = Dart_GetField(type, NewString("fld1"));
4316 EXPECT_VALID(result); 4347 EXPECT_VALID(result);
4317 int64_t value = 0; 4348 int64_t value = 0;
4318 result = Dart_IntegerToInt64(result, &value); 4349 result = Dart_IntegerToInt64(result, &value);
4319 EXPECT_EQ(3, value); 4350 EXPECT_EQ(3, value);
4320 } 4351 }
4321 4352
4322 4353
4323 TEST_CASE(Invoke_CrossLibrary) { 4354 TEST_CASE(Invoke_CrossLibrary) {
4324 const char* kLibrary1Chars = 4355 const char* kLibrary1Chars =
4325 "library library1_name;\n" 4356 "library library1_name;\n"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
4388 " return Foo.getStaticClosureWithArgs();\n" 4419 " return Foo.getStaticClosureWithArgs();\n"
4389 "}\n"; 4420 "}\n";
4390 Dart_Handle result; 4421 Dart_Handle result;
4391 Dart_Handle owner; 4422 Dart_Handle owner;
4392 Dart_Handle defining_function; 4423 Dart_Handle defining_function;
4393 DARTSCOPE(Isolate::Current()); 4424 DARTSCOPE(Isolate::Current());
4394 4425
4395 // Create a test library and Load up a test script in it. 4426 // Create a test library and Load up a test script in it.
4396 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 4427 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
4397 EXPECT_VALID(lib); 4428 EXPECT_VALID(lib);
4398 Dart_Handle cls = Dart_GetClass(lib, NewString("Foo")); 4429 Dart_Handle type = Dart_GetType(lib, NewString("Foo"), 0, NULL);
4399 EXPECT_VALID(cls); 4430 EXPECT_VALID(type);
4400 4431
4401 // Invoke a function which returns a closure. 4432 // Invoke a function which returns a closure.
4402 Dart_Handle retobj = Dart_Invoke(lib, NewString("getClosure"), 0, NULL); 4433 Dart_Handle retobj = Dart_Invoke(lib, NewString("getClosure"), 0, NULL);
4403 EXPECT_VALID(retobj); 4434 EXPECT_VALID(retobj);
4404 4435
4405 EXPECT(Dart_IsClosure(retobj)); 4436 EXPECT(Dart_IsClosure(retobj));
4406 EXPECT(!Dart_IsClosure(Dart_NewInteger(101))); 4437 EXPECT(!Dart_IsClosure(Dart_NewInteger(101)));
4407 4438
4408 // Retrieve the closure's function 4439 // Retrieve the closure's function
4409 result = Dart_ClosureFunction(retobj); 4440 result = Dart_ClosureFunction(retobj);
(...skipping 20 matching lines...) Expand all
4430 retobj = Dart_Invoke(lib, NewString("getInstanceClosure"), 0, NULL); 4461 retobj = Dart_Invoke(lib, NewString("getInstanceClosure"), 0, NULL);
4431 EXPECT_VALID(retobj); 4462 EXPECT_VALID(retobj);
4432 EXPECT(Dart_IsClosure(retobj)); 4463 EXPECT(Dart_IsClosure(retobj));
4433 4464
4434 // Retrieve the closure's function 4465 // Retrieve the closure's function
4435 result = Dart_ClosureFunction(retobj); 4466 result = Dart_ClosureFunction(retobj);
4436 EXPECT_VALID(result); 4467 EXPECT_VALID(result);
4437 EXPECT(Dart_IsFunction(result)); 4468 EXPECT(Dart_IsFunction(result));
4438 owner = Dart_FunctionOwner(result); 4469 owner = Dart_FunctionOwner(result);
4439 EXPECT_VALID(owner); 4470 EXPECT_VALID(owner);
4471 Isolate* isolate = Isolate::Current();
4472 Dart_Handle cls = Api::NewHandle(
4473 isolate, Api::UnwrapTypeHandle(isolate, type).type_class());
4440 defining_function = Dart_LookupFunction(cls, 4474 defining_function = Dart_LookupFunction(cls,
4441 NewString("getInstanceClosure")); 4475 NewString("getInstanceClosure"));
4442 EXPECT(Dart_IdentityEquals(owner, defining_function)); 4476 EXPECT(Dart_IdentityEquals(owner, defining_function));
4443 // -999: We want to distinguish between a non-answer and a wrong answer, and 4477 // -999: We want to distinguish between a non-answer and a wrong answer, and
4444 // -1 has been a previous wrong answer 4478 // -1 has been a previous wrong answer
4445 fixed_param_count = -999; 4479 fixed_param_count = -999;
4446 opt_param_count = -999; 4480 opt_param_count = -999;
4447 result = Dart_FunctionParameterCounts(result, 4481 result = Dart_FunctionParameterCounts(result,
4448 &fixed_param_count, 4482 &fixed_param_count,
4449 &opt_param_count); 4483 &opt_param_count);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
4674 EXPECT_VALID(result); 4708 EXPECT_VALID(result);
4675 EXPECT(Dart_IsInteger(result)); 4709 EXPECT(Dart_IsInteger(result));
4676 4710
4677 int64_t value = 0; 4711 int64_t value = 0;
4678 result = Dart_IntegerToInt64(result, &value); 4712 result = Dart_IntegerToInt64(result, &value);
4679 EXPECT_VALID(result); 4713 EXPECT_VALID(result);
4680 EXPECT_EQ(3, value); 4714 EXPECT_EQ(3, value);
4681 } 4715 }
4682 4716
4683 4717
4684 TEST_CASE(GetClass) { 4718 TEST_CASE(GetType) {
4685 const char* kScriptChars = 4719 const char* kScriptChars =
4686 "class Class {\n" 4720 "class Class {\n"
4687 " static var name = 'Class';\n" 4721 " static var name = 'Class';\n"
4688 "}\n" 4722 "}\n"
4689 "\n" 4723 "\n"
4690 "class _Class {\n" 4724 "class _Class {\n"
4691 " static var name = '_Class';\n" 4725 " static var name = '_Class';\n"
4692 "}\n"; 4726 "}\n";
4693 4727
4694 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 4728 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
4695 4729
4696 // Lookup a class. 4730 // Lookup a class.
4697 Dart_Handle cls = Dart_GetClass(lib, NewString("Class")); 4731 Dart_Handle type = Dart_GetType(lib, NewString("Class"), 0, NULL);
4698 EXPECT_VALID(cls); 4732 EXPECT_VALID(type);
4699 Dart_Handle name = Dart_GetField(cls, NewString("name")); 4733 Dart_Handle name = Dart_GetField(type, NewString("name"));
4700 EXPECT_VALID(name); 4734 EXPECT_VALID(name);
4701 const char* name_cstr = ""; 4735 const char* name_cstr = "";
4702 EXPECT_VALID(Dart_StringToCString(name, &name_cstr)); 4736 EXPECT_VALID(Dart_StringToCString(name, &name_cstr));
4703 EXPECT_STREQ("Class", name_cstr); 4737 EXPECT_STREQ("Class", name_cstr);
4704 4738
4705 // Lookup a private class. 4739 // Lookup a private class.
4706 cls = Dart_GetClass(lib, NewString("_Class")); 4740 type = Dart_GetType(lib, NewString("_Class"), 0, NULL);
4707 EXPECT_VALID(cls); 4741 EXPECT_VALID(type);
4708 name = Dart_GetField(cls, NewString("name")); 4742 name = Dart_GetField(type, NewString("name"));
4709 EXPECT_VALID(name); 4743 EXPECT_VALID(name);
4710 name_cstr = ""; 4744 name_cstr = "";
4711 EXPECT_VALID(Dart_StringToCString(name, &name_cstr)); 4745 EXPECT_VALID(Dart_StringToCString(name, &name_cstr));
4712 EXPECT_STREQ("_Class", name_cstr); 4746 EXPECT_STREQ("_Class", name_cstr);
4713 4747
4714 // Lookup a class that does not exist. 4748 // Lookup a class that does not exist.
4715 cls = Dart_GetClass(lib, NewString("DoesNotExist")); 4749 type = Dart_GetType(lib, NewString("DoesNotExist"), 0, NULL);
4716 EXPECT(Dart_IsError(cls)); 4750 EXPECT(Dart_IsError(type));
4717 EXPECT_STREQ("Class 'DoesNotExist' not found in library 'dart:test-lib'.", 4751 EXPECT_STREQ("Type 'DoesNotExist' not found in library 'dart:test-lib'.",
4718 Dart_GetError(cls)); 4752 Dart_GetError(type));
4719 4753
4720 // Lookup a class from an error library. The error propagates. 4754 // Lookup a class from an error library. The error propagates.
4721 cls = Dart_GetClass(Api::NewError("myerror"), NewString("Class")); 4755 type = Dart_GetType(Api::NewError("myerror"), NewString("Class"), 0, NULL);
4722 EXPECT(Dart_IsError(cls)); 4756 EXPECT(Dart_IsError(type));
4723 EXPECT_STREQ("myerror", Dart_GetError(cls)); 4757 EXPECT_STREQ("myerror", Dart_GetError(type));
4724 4758
4725 // Lookup a class using an error class name. The error propagates. 4759 // Lookup a type using an error class name. The error propagates.
4726 cls = Dart_GetClass(lib, Api::NewError("myerror")); 4760 type = Dart_GetType(lib, Api::NewError("myerror"), 0, NULL);
4727 EXPECT(Dart_IsError(cls)); 4761 EXPECT(Dart_IsError(type));
4728 EXPECT_STREQ("myerror", Dart_GetError(cls)); 4762 EXPECT_STREQ("myerror", Dart_GetError(type));
4729 } 4763 }
4730 4764
4731 4765
4732 static void BuildFunctionDescription(TextBuffer* buffer, Dart_Handle func) { 4766 static void BuildFunctionDescription(TextBuffer* buffer, Dart_Handle func) {
4733 buffer->Clear(); 4767 buffer->Clear();
4734 if (Dart_IsNull(func)) { 4768 if (Dart_IsNull(func)) {
4735 WARN("Function not found"); 4769 WARN("Function not found");
4736 return; 4770 return;
4737 } 4771 }
4738 Dart_Handle name = Dart_FunctionName(func); 4772 Dart_Handle name = Dart_FunctionName(func);
(...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after
5416 " InstanceOfTest() {}\n" 5450 " InstanceOfTest() {}\n"
5417 " static InstanceOfTest testMain() {\n" 5451 " static InstanceOfTest testMain() {\n"
5418 " return new InstanceOfTest();\n" 5452 " return new InstanceOfTest();\n"
5419 " }\n" 5453 " }\n"
5420 "}\n"; 5454 "}\n";
5421 Dart_Handle result; 5455 Dart_Handle result;
5422 // Create a test library and Load up a test script in it. 5456 // Create a test library and Load up a test script in it.
5423 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 5457 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
5424 5458
5425 // Fetch InstanceOfTest class. 5459 // Fetch InstanceOfTest class.
5426 Dart_Handle cls = Dart_GetClass(lib, NewString("InstanceOfTest")); 5460 Dart_Handle type = Dart_GetType(lib, NewString("InstanceOfTest"), 0, NULL);
5427 EXPECT_VALID(cls); 5461 EXPECT_VALID(type);
5428 5462
5429 // Invoke a function which returns an object of type InstanceOf.. 5463 // Invoke a function which returns an object of type InstanceOf..
5430 Dart_Handle instanceOfTestObj = 5464 Dart_Handle instanceOfTestObj =
5431 Dart_Invoke(cls, NewString("testMain"), 0, NULL); 5465 Dart_Invoke(type, NewString("testMain"), 0, NULL);
5432 EXPECT_VALID(instanceOfTestObj); 5466 EXPECT_VALID(instanceOfTestObj);
5433 5467
5434 // Now check instanceOfTestObj reported as an instance of 5468 // Now check instanceOfTestObj reported as an instance of
5435 // InstanceOfTest class. 5469 // InstanceOfTest class.
5436 bool is_instance = false; 5470 bool is_instance = false;
5437 result = Dart_ObjectIsType(instanceOfTestObj, cls, &is_instance); 5471 result = Dart_ObjectIsType(instanceOfTestObj, type, &is_instance);
5438 EXPECT_VALID(result); 5472 EXPECT_VALID(result);
5439 EXPECT(is_instance); 5473 EXPECT(is_instance);
5440 5474
5441 // Fetch OtherClass and check if instanceOfTestObj is instance of it. 5475 // Fetch OtherClass and check if instanceOfTestObj is instance of it.
5442 Dart_Handle otherClass = Dart_GetClass(lib, NewString("OtherClass")); 5476 Dart_Handle otherType = Dart_GetType(lib, NewString("OtherClass"), 0, NULL);
5443 EXPECT_VALID(otherClass); 5477 EXPECT_VALID(otherType);
5444 5478
5445 result = Dart_ObjectIsType(instanceOfTestObj, otherClass, &is_instance); 5479 result = Dart_ObjectIsType(instanceOfTestObj, otherType, &is_instance);
5446 EXPECT_VALID(result); 5480 EXPECT_VALID(result);
5447 EXPECT(!is_instance); 5481 EXPECT(!is_instance);
5448 5482
5449 // Check that primitives are not instances of InstanceOfTest class. 5483 // Check that primitives are not instances of InstanceOfTest class.
5450 result = Dart_ObjectIsType(NewString("a string"), otherClass, 5484 result = Dart_ObjectIsType(NewString("a string"), otherType,
5451 &is_instance); 5485 &is_instance);
5452 EXPECT_VALID(result); 5486 EXPECT_VALID(result);
5453 EXPECT(!is_instance); 5487 EXPECT(!is_instance);
5454 5488
5455 result = Dart_ObjectIsType(Dart_NewInteger(42), otherClass, &is_instance); 5489 result = Dart_ObjectIsType(Dart_NewInteger(42), otherType, &is_instance);
5456 EXPECT_VALID(result); 5490 EXPECT_VALID(result);
5457 EXPECT(!is_instance); 5491 EXPECT(!is_instance);
5458 5492
5459 result = Dart_ObjectIsType(Dart_NewBoolean(true), otherClass, &is_instance); 5493 result = Dart_ObjectIsType(Dart_NewBoolean(true), otherType, &is_instance);
5460 EXPECT_VALID(result); 5494 EXPECT_VALID(result);
5461 EXPECT(!is_instance); 5495 EXPECT(!is_instance);
5462 5496
5463 // Check that null is not an instance of InstanceOfTest class. 5497 // Check that null is not an instance of InstanceOfTest class.
5464 Dart_Handle null = Dart_Invoke(otherClass, 5498 Dart_Handle null = Dart_Invoke(otherType,
5465 NewString("returnNull"), 5499 NewString("returnNull"),
5466 0, 5500 0,
5467 NULL); 5501 NULL);
5468 EXPECT_VALID(null); 5502 EXPECT_VALID(null);
5469 5503
5470 result = Dart_ObjectIsType(null, otherClass, &is_instance); 5504 result = Dart_ObjectIsType(null, otherType, &is_instance);
5471 EXPECT_VALID(result); 5505 EXPECT_VALID(result);
5472 EXPECT(!is_instance); 5506 EXPECT(!is_instance);
5473 5507
5474 // Check that error is returned if null is passed as a class argument. 5508 // Check that error is returned if null is passed as a class argument.
5475 result = Dart_ObjectIsType(null, null, &is_instance); 5509 result = Dart_ObjectIsType(null, null, &is_instance);
5476 EXPECT(Dart_IsError(result)); 5510 EXPECT(Dart_IsError(result));
5477 } 5511 }
5478 5512
5479 5513
5480 static Dart_Handle library_handler(Dart_LibraryTag tag, 5514 static Dart_Handle library_handler(Dart_LibraryTag tag,
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
6163 "class NewClass extends OldClass{\n" 6197 "class NewClass extends OldClass{\n"
6164 " bar() => 'bar';\n" 6198 " bar() => 'bar';\n"
6165 "}\n"; 6199 "}\n";
6166 Dart_Handle url = NewString("library1_url"); 6200 Dart_Handle url = NewString("library1_url");
6167 Dart_Handle source = NewString(kLibrary1Chars); 6201 Dart_Handle source = NewString(kLibrary1Chars);
6168 Dart_Handle lib = Dart_LoadLibrary(url, source); 6202 Dart_Handle lib = Dart_LoadLibrary(url, source);
6169 EXPECT_VALID(lib); 6203 EXPECT_VALID(lib);
6170 EXPECT(Dart_IsLibrary(lib)); 6204 EXPECT(Dart_IsLibrary(lib));
6171 6205
6172 // Call a dynamic function on OldClass. 6206 // Call a dynamic function on OldClass.
6173 Dart_Handle cls = Dart_GetClass(lib, NewString("OldClass")); 6207 Dart_Handle type = Dart_GetType(lib, NewString("OldClass"), 0, NULL);
6174 EXPECT_VALID(cls); 6208 EXPECT_VALID(type);
6175 Dart_Handle recv = Dart_New(cls, Dart_Null(), 0, NULL); 6209 Dart_Handle recv = Dart_New(type, Dart_Null(), 0, NULL);
6176 Dart_Handle result = Dart_Invoke(recv, NewString("foo"), 0, NULL); 6210 Dart_Handle result = Dart_Invoke(recv, NewString("foo"), 0, NULL);
6177 EXPECT_VALID(result); 6211 EXPECT_VALID(result);
6178 EXPECT(Dart_IsString(result)); 6212 EXPECT(Dart_IsString(result));
6179 const char* result_cstr = ""; 6213 const char* result_cstr = "";
6180 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); 6214 EXPECT_VALID(Dart_StringToCString(result, &result_cstr));
6181 EXPECT_STREQ("foo", result_cstr); 6215 EXPECT_STREQ("foo", result_cstr);
6182 6216
6183 // Load a source file late. 6217 // Load a source file late.
6184 url = NewString("source_url"); 6218 url = NewString("source_url");
6185 source = NewString(kSourceChars); 6219 source = NewString(kSourceChars);
6186 EXPECT_VALID(Dart_LoadSource(lib, url, source)); 6220 EXPECT_VALID(Dart_LoadSource(lib, url, source));
6187 6221
6188 // Call a dynamic function on NewClass in the updated library. 6222 // Call a dynamic function on NewClass in the updated library.
6189 cls = Dart_GetClass(lib, NewString("NewClass")); 6223 type = Dart_GetType(lib, NewString("NewClass"), 0, NULL);
6190 EXPECT_VALID(cls); 6224 EXPECT_VALID(type);
6191 recv = Dart_New(cls, Dart_Null(), 0, NULL); 6225 recv = Dart_New(type, Dart_Null(), 0, NULL);
6192 result = Dart_Invoke(recv, NewString("bar"), 0, NULL); 6226 result = Dart_Invoke(recv, NewString("bar"), 0, NULL);
6193 EXPECT_VALID(result); 6227 EXPECT_VALID(result);
6194 EXPECT(Dart_IsString(result)); 6228 EXPECT(Dart_IsString(result));
6195 result_cstr = ""; 6229 result_cstr = "";
6196 EXPECT_VALID(Dart_StringToCString(result, &result_cstr)); 6230 EXPECT_VALID(Dart_StringToCString(result, &result_cstr));
6197 EXPECT_STREQ("bar", result_cstr); 6231 EXPECT_STREQ("bar", result_cstr);
6198 } 6232 }
6199 6233
6200 6234
6201 TEST_CASE(LoadPatch) { 6235 TEST_CASE(LoadPatch) {
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
6428 Dart_Handle result; 6462 Dart_Handle result;
6429 6463
6430 // Load a test script. 6464 // Load a test script.
6431 Dart_Handle url = NewString(TestCase::url()); 6465 Dart_Handle url = NewString(TestCase::url());
6432 Dart_Handle source = NewString(kScriptChars); 6466 Dart_Handle source = NewString(kScriptChars);
6433 result = Dart_SetLibraryTagHandler(library_handler); 6467 result = Dart_SetLibraryTagHandler(library_handler);
6434 EXPECT_VALID(result); 6468 EXPECT_VALID(result);
6435 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0); 6469 Dart_Handle lib = Dart_LoadScript(url, source, 0, 0);
6436 EXPECT_VALID(lib); 6470 EXPECT_VALID(lib);
6437 EXPECT(Dart_IsLibrary(lib)); 6471 EXPECT(Dart_IsLibrary(lib));
6438 Dart_Handle cls = Dart_GetClass(lib, NewString("Test")); 6472 Dart_Handle type = Dart_GetType(lib, NewString("Test"), 0, NULL);
6439 EXPECT_VALID(cls); 6473 EXPECT_VALID(type);
6440 6474
6441 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1); 6475 result = Dart_SetNativeResolver(Dart_Null(), &MyNativeResolver1);
6442 EXPECT(Dart_IsError(result)); 6476 EXPECT(Dart_IsError(result));
6443 EXPECT_STREQ( 6477 EXPECT_STREQ(
6444 "Dart_SetNativeResolver expects argument 'library' to be non-null.", 6478 "Dart_SetNativeResolver expects argument 'library' to be non-null.",
6445 Dart_GetError(result)); 6479 Dart_GetError(result));
6446 6480
6447 result = Dart_SetNativeResolver(Dart_True(), &MyNativeResolver1); 6481 result = Dart_SetNativeResolver(Dart_True(), &MyNativeResolver1);
6448 EXPECT(Dart_IsError(result)); 6482 EXPECT(Dart_IsError(result));
6449 EXPECT_STREQ("Dart_SetNativeResolver expects argument 'library' to be of " 6483 EXPECT_STREQ("Dart_SetNativeResolver expects argument 'library' to be of "
6450 "type Library.", 6484 "type Library.",
6451 Dart_GetError(result)); 6485 Dart_GetError(result));
6452 6486
6453 result = Dart_SetNativeResolver(error, &MyNativeResolver1); 6487 result = Dart_SetNativeResolver(error, &MyNativeResolver1);
6454 EXPECT(Dart_IsError(result)); 6488 EXPECT(Dart_IsError(result));
6455 EXPECT_STREQ("incoming error", Dart_GetError(result)); 6489 EXPECT_STREQ("incoming error", Dart_GetError(result));
6456 6490
6457 result = Dart_SetNativeResolver(lib, &MyNativeResolver1); 6491 result = Dart_SetNativeResolver(lib, &MyNativeResolver1);
6458 EXPECT_VALID(result); 6492 EXPECT_VALID(result);
6459 6493
6460 // Call a function and make sure native resolution works. 6494 // Call a function and make sure native resolution works.
6461 result = Dart_Invoke(cls, NewString("foo"), 0, NULL); 6495 result = Dart_Invoke(type, NewString("foo"), 0, NULL);
6462 EXPECT_VALID(result); 6496 EXPECT_VALID(result);
6463 EXPECT(Dart_IsInteger(result)); 6497 EXPECT(Dart_IsInteger(result));
6464 int64_t value = 0; 6498 int64_t value = 0;
6465 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); 6499 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
6466 EXPECT_EQ(654321, value); 6500 EXPECT_EQ(654321, value);
6467 6501
6468 // A second call succeeds. 6502 // A second call succeeds.
6469 result = Dart_SetNativeResolver(lib, &MyNativeResolver2); 6503 result = Dart_SetNativeResolver(lib, &MyNativeResolver2);
6470 EXPECT_VALID(result); 6504 EXPECT_VALID(result);
6471 6505
6472 // 'foo' has already been resolved so gets the old value. 6506 // 'foo' has already been resolved so gets the old value.
6473 result = Dart_Invoke(cls, NewString("foo"), 0, NULL); 6507 result = Dart_Invoke(type, NewString("foo"), 0, NULL);
6474 EXPECT_VALID(result); 6508 EXPECT_VALID(result);
6475 EXPECT(Dart_IsInteger(result)); 6509 EXPECT(Dart_IsInteger(result));
6476 value = 0; 6510 value = 0;
6477 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); 6511 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
6478 EXPECT_EQ(654321, value); 6512 EXPECT_EQ(654321, value);
6479 6513
6480 // 'bar' has not yet been resolved so gets the new value. 6514 // 'bar' has not yet been resolved so gets the new value.
6481 result = Dart_Invoke(cls, NewString("bar"), 0, NULL); 6515 result = Dart_Invoke(type, NewString("bar"), 0, NULL);
6482 EXPECT_VALID(result); 6516 EXPECT_VALID(result);
6483 EXPECT(Dart_IsInteger(result)); 6517 EXPECT(Dart_IsInteger(result));
6484 value = 0; 6518 value = 0;
6485 EXPECT_VALID(Dart_IntegerToInt64(result, &value)); 6519 EXPECT_VALID(Dart_IntegerToInt64(result, &value));
6486 EXPECT_EQ(123456, value); 6520 EXPECT_EQ(123456, value);
6487 6521
6488 // A NULL resolver is okay, but resolution will fail. 6522 // A NULL resolver is okay, but resolution will fail.
6489 result = Dart_SetNativeResolver(lib, NULL); 6523 result = Dart_SetNativeResolver(lib, NULL);
6490 EXPECT_VALID(result); 6524 EXPECT_VALID(result);
6491 6525
6492 EXPECT_ERROR(Dart_Invoke(cls, NewString("baz"), 0, NULL), 6526 EXPECT_ERROR(Dart_Invoke(type, NewString("baz"), 0, NULL),
6493 "native function 'SomeNativeFunction3' cannot be found"); 6527 "native function 'SomeNativeFunction3' cannot be found");
6494 } 6528 }
6495 6529
6496 6530
6497 // Test that an imported name does not clash with the same name defined 6531 // Test that an imported name does not clash with the same name defined
6498 // in the importing library. 6532 // in the importing library.
6499 TEST_CASE(ImportLibrary2) { 6533 TEST_CASE(ImportLibrary2) {
6500 const char* kScriptChars = 6534 const char* kScriptChars =
6501 "import 'library1_dart';\n" 6535 "import 'library1_dart';\n"
6502 "var foo;\n" 6536 "var foo;\n"
(...skipping 1596 matching lines...) Expand 10 before | Expand all | Expand 10 after
8099 NewString("main"), 8133 NewString("main"),
8100 0, 8134 0,
8101 NULL); 8135 NULL);
8102 int64_t value = 0; 8136 int64_t value = 0;
8103 result = Dart_IntegerToInt64(result, &value); 8137 result = Dart_IntegerToInt64(result, &value);
8104 EXPECT_VALID(result); 8138 EXPECT_VALID(result);
8105 EXPECT_EQ(8, value); 8139 EXPECT_EQ(8, value);
8106 } 8140 }
8107 8141
8108 } // namespace dart 8142 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698