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

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

Issue 16780008: Reified metadata in the VM (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/object.cc ('k') | runtime/vm/parser.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 "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 2744 matching lines...) Expand 10 before | Expand all | Expand 10 after
2763 "}\n"; 2764 "}\n";
2764 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL); 2765 Dart_Handle lib = TestCase::LoadTestScript(kScriptChars, NULL);
2765 EXPECT_VALID(lib); 2766 EXPECT_VALID(lib);
2766 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL); 2767 Dart_Handle result = Dart_Invoke(lib, NewString("main"), 0, NULL);
2767 EXPECT_ERROR( 2768 EXPECT_ERROR(
2768 result, 2769 result,
2769 "Unhandled exception:\n" 2770 "Unhandled exception:\n"
2770 "MyException\n" 2771 "MyException\n"
2771 "#0 baz (dart:test-lib:2:3)\n" 2772 "#0 baz (dart:test-lib:2:3)\n"
2772 "#1 _OtherClass._OtherClass._named (dart:test-lib:7:8)\n" 2773 "#1 _OtherClass._OtherClass._named (dart:test-lib:7:8)\n"
2773 "#2 globalVar= (dart:test-lib:12:3)\n" 2774 "#2 globalVar= (dart:test-lib:12:7)\n"
2774 "#3 _bar (dart:test-lib:16:3)\n" 2775 "#3 _bar (dart:test-lib:16:3)\n"
2775 "#4 MyClass.field (dart:test-lib:25:9)\n" 2776 "#4 MyClass.field (dart:test-lib:25:9)\n"
2776 "#5 MyClass.foo.fooHelper (dart:test-lib:30:7)\n" 2777 "#5 MyClass.foo.fooHelper (dart:test-lib:30:7)\n"
2777 "#6 MyClass.foo (dart:test-lib:32:14)\n" 2778 "#6 MyClass.foo (dart:test-lib:32:14)\n"
2778 "#7 MyClass.MyClass.<anonymous closure> (dart:test-lib:21:15)\n" 2779 "#7 MyClass.MyClass.<anonymous closure> (dart:test-lib:21:15)\n"
2779 "#8 MyClass.MyClass (dart:test-lib:21:18)\n" 2780 "#8 MyClass.MyClass (dart:test-lib:21:18)\n"
2780 "#9 main.<anonymous closure> (dart:test-lib:37:10)\n" 2781 "#9 main.<anonymous closure> (dart:test-lib:37:14)\n"
2781 "#10 main (dart:test-lib:37:24)"); 2782 "#10 main (dart:test-lib:37:24)");
2782 } 2783 }
2783 2784
2784 2785
2785 TEST_CASE(WeakProperty_PreserveCrossGen) { 2786 TEST_CASE(WeakProperty_PreserveCrossGen) {
2786 Isolate* isolate = Isolate::Current(); 2787 Isolate* isolate = Isolate::Current();
2787 WeakProperty& weak = WeakProperty::Handle(); 2788 WeakProperty& weak = WeakProperty::Handle();
2788 { 2789 {
2789 // Weak property and value in new. Key in old. 2790 // Weak property and value in new. Key in old.
2790 HANDLESCOPE(isolate); 2791 HANDLESCOPE(isolate);
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
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);
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
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
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/parser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698