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 "platform/assert.h" | 5 #include "platform/assert.h" |
6 #include "vm/assembler.h" | 6 #include "vm/assembler.h" |
7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
9 #include "vm/dart_api_impl.h" | |
9 #include "vm/isolate.h" | 10 #include "vm/isolate.h" |
10 #include "vm/object.h" | 11 #include "vm/object.h" |
11 #include "vm/object_store.h" | 12 #include "vm/object_store.h" |
12 #include "vm/simulator.h" | 13 #include "vm/simulator.h" |
13 #include "vm/symbols.h" | 14 #include "vm/symbols.h" |
14 #include "vm/unit_test.h" | 15 #include "vm/unit_test.h" |
15 | 16 |
16 namespace dart { | 17 namespace dart { |
17 | 18 |
18 static RawClass* CreateDummyClass(const String& class_name, | 19 static RawClass* CreateDummyClass(const String& class_name, |
(...skipping 3145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3164 | 3165 |
3165 | 3166 |
3166 static RawFunction* GetFunction(const Class& cls, const char* name) { | 3167 static RawFunction* GetFunction(const Class& cls, const char* name) { |
3167 const Function& result = Function::Handle(cls.LookupDynamicFunction( | 3168 const Function& result = Function::Handle(cls.LookupDynamicFunction( |
3168 String::Handle(String::New(name)))); | 3169 String::Handle(String::New(name)))); |
3169 ASSERT(!result.IsNull()); | 3170 ASSERT(!result.IsNull()); |
3170 return result.raw(); | 3171 return result.raw(); |
3171 } | 3172 } |
3172 | 3173 |
3173 | 3174 |
3175 static RawField* GetField(const Class& cls, const char* name) { | |
3176 const Field& field = | |
3177 Field::Handle(cls.LookupField(String::Handle(String::New(name)))); | |
3178 ASSERT(!field.IsNull()); | |
3179 return field.raw(); | |
3180 } | |
3181 | |
3182 | |
3183 static RawClass* GetClass(const Library& lib, const char* name) { | |
3184 const Class& cls = | |
3185 Class::Handle(lib.LookupClass(String::Handle(Symbols::New(name)))); | |
3186 ASSERT(!cls.IsNull()); | |
3187 return cls.raw(); | |
3188 } | |
3189 | |
3190 | |
3191 static void PrintMetadata(const char* name, const Object& data) { | |
3192 if (data.IsError()) { | |
3193 OS::Print("Error in metadata evaluation for %s: '%s'\n", | |
3194 name, | |
3195 Error::Cast(data).ToErrorCString()); | |
3196 } | |
3197 ASSERT(data.IsArray()); | |
3198 const Array& metadata = Array::Cast(data); | |
3199 OS::Print("Metadata for %s has %"Pd" values:\n", name, metadata.Length()); | |
3200 Object& elem = Object::Handle(); | |
3201 for (int i = 0; i < metadata.Length(); i++) { | |
3202 elem = metadata.At(i); | |
3203 OS::Print(" %d: %s\n", i, elem.ToCString()); | |
3204 } | |
3205 } | |
3206 | |
3207 | |
3208 TEST_CASE(Metadata) { | |
3209 const char* kScriptChars = | |
3210 "@metafoo \n" | |
3211 "class Meta { \n" | |
3212 " final m; \n" | |
3213 " const Meta(this.m); \n" | |
3214 "} \n" | |
3215 " \n" | |
3216 "const metafoo = 'metafoo'; \n" | |
3217 "const metabar = 'meta' 'bar'; \n" | |
3218 " \n" | |
3219 "@metafoo \n" | |
3220 "@Meta(0) String gVar; \n" | |
3221 " \n" | |
3222 "@metafoo \n" | |
3223 "get tlGetter => gVar; \n" | |
3224 " \n" | |
3225 "@metabar \n" | |
3226 "class A { \n" | |
3227 " @metafoo \n" | |
3228 " @metabar \n" | |
3229 " @Meta('baz') \n" | |
3230 " var aField; \n" | |
3231 " \n" | |
3232 " @metabar @Meta('baa') \n" | |
3233 " int aFunc(a,b) => a + b; \n" | |
3234 "} \n" | |
3235 " \n" | |
3236 "@Meta('main') \n" | |
3237 "void main() { \n" | |
3238 " return new A(); \n" | |
3239 "} \n"; | |
3240 | |
3241 Dart_Handle h_lib = TestCase::LoadTestScript(kScriptChars, NULL); | |
3242 EXPECT_VALID(h_lib); | |
3243 Dart_Handle result = Dart_Invoke(h_lib, NewString("main"), 0, NULL); | |
3244 EXPECT_VALID(result); | |
3245 Library& lib = Library::Handle(); | |
3246 lib ^= Api::UnwrapHandle(h_lib); | |
3247 ASSERT(!lib.IsNull()); | |
3248 const Class& class_a = Class::Handle(GetClass(lib, "A")); | |
3249 Object& res = Object::Handle(lib.GetMetadata(class_a)); | |
3250 PrintMetadata("A", res); | |
siva
2013/06/12 00:16:52
Instead of PrintMetadata why not convert this to
E
| |
3251 | |
3252 const Class& class_meta = Class::Handle(GetClass(lib, "Meta")); | |
3253 res = lib.GetMetadata(class_meta); | |
3254 PrintMetadata("Meta", res); | |
3255 | |
3256 Field& field = Field::Handle(GetField(class_a, "aField")); | |
3257 res = lib.GetMetadata(field); | |
3258 PrintMetadata("A.aField", res); | |
3259 | |
3260 Function& func = Function::Handle(GetFunction(class_a, "aFunc")); | |
3261 res = lib.GetMetadata(func); | |
3262 PrintMetadata("A.aFunc", res); | |
3263 | |
3264 func = lib.LookupLocalFunction(String::Handle(Symbols::New("main"))); | |
3265 ASSERT(!func.IsNull()); | |
3266 res = lib.GetMetadata(func); | |
3267 PrintMetadata("main", res); | |
3268 | |
3269 func = lib.LookupLocalFunction(String::Handle(Symbols::New("get:tlGetter"))); | |
3270 ASSERT(!func.IsNull()); | |
3271 res = lib.GetMetadata(func); | |
3272 PrintMetadata("tlGetter", res); | |
3273 | |
3274 field = lib.LookupLocalField(String::Handle(Symbols::New("gVar"))); | |
3275 ASSERT(!field.IsNull()); | |
3276 res = lib.GetMetadata(field); | |
3277 PrintMetadata("gVar", res); | |
3278 } | |
3279 | |
3280 | |
3174 TEST_CASE(FunctionSourceFingerprint) { | 3281 TEST_CASE(FunctionSourceFingerprint) { |
3175 const char* kScriptChars = | 3282 const char* kScriptChars = |
3176 "class A {\n" | 3283 "class A {\n" |
3177 " void test1(int a) {\n" | 3284 " void test1(int a) {\n" |
3178 " return a > 1 ? a + 1 : a;\n" | 3285 " return a > 1 ? a + 1 : a;\n" |
3179 " }\n" | 3286 " }\n" |
3180 " void test2(int a) {\n" | 3287 " void test2(int a) {\n" |
3181 " return a > 1 ? a + 1 : a;\n" | 3288 " return a > 1 ? a + 1 : a;\n" |
3182 " }\n" | 3289 " }\n" |
3183 " void test3(a) {\n" | 3290 " void test3(a) {\n" |
(...skipping 30 matching lines...) Expand all Loading... | |
3214 const Function& test7 = Function::Handle(GetFunction(class_a, "test7")); | 3321 const Function& test7 = Function::Handle(GetFunction(class_a, "test7")); |
3215 EXPECT_EQ(test1.SourceFingerprint(), test2.SourceFingerprint()); | 3322 EXPECT_EQ(test1.SourceFingerprint(), test2.SourceFingerprint()); |
3216 EXPECT_NE(test1.SourceFingerprint(), test3.SourceFingerprint()); | 3323 EXPECT_NE(test1.SourceFingerprint(), test3.SourceFingerprint()); |
3217 EXPECT_NE(test3.SourceFingerprint(), test4.SourceFingerprint()); | 3324 EXPECT_NE(test3.SourceFingerprint(), test4.SourceFingerprint()); |
3218 EXPECT_NE(test4.SourceFingerprint(), test5.SourceFingerprint()); | 3325 EXPECT_NE(test4.SourceFingerprint(), test5.SourceFingerprint()); |
3219 EXPECT_NE(test5.SourceFingerprint(), test6.SourceFingerprint()); | 3326 EXPECT_NE(test5.SourceFingerprint(), test6.SourceFingerprint()); |
3220 EXPECT_EQ(test6.SourceFingerprint(), test7.SourceFingerprint()); | 3327 EXPECT_EQ(test6.SourceFingerprint(), test7.SourceFingerprint()); |
3221 } | 3328 } |
3222 | 3329 |
3223 } // namespace dart | 3330 } // namespace dart |
OLD | NEW |