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

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

Issue 1477573002: Remove Field::FindFieldIndex() and update service protocol (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years 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
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/service.cc » ('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/globals.h" 5 #include "platform/globals.h"
6 6
7 #include "vm/assembler.h" 7 #include "vm/assembler.h"
8 #include "vm/class_finalizer.h" 8 #include "vm/class_finalizer.h"
9 #include "vm/dart_api_impl.h" 9 #include "vm/dart_api_impl.h"
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 3751 matching lines...) Expand 10 before | Expand all | Expand 10 after
3762 3762
3763 3763
3764 static RawClass* GetClass(const Library& lib, const char* name) { 3764 static RawClass* GetClass(const Library& lib, const char* name) {
3765 const Class& cls = Class::Handle( 3765 const Class& cls = Class::Handle(
3766 lib.LookupClass(String::Handle(Symbols::New(name)))); 3766 lib.LookupClass(String::Handle(Symbols::New(name))));
3767 EXPECT(!cls.IsNull()); // No ambiguity error expected. 3767 EXPECT(!cls.IsNull()); // No ambiguity error expected.
3768 return cls.raw(); 3768 return cls.raw();
3769 } 3769 }
3770 3770
3771 3771
3772 TEST_CASE(FindFieldIndex) {
3773 const char* kScriptChars =
3774 "class A {\n"
3775 " var a;\n"
3776 " var b;\n"
3777 "}\n"
3778 "class B {\n"
3779 " var d;\n"
3780 "}\n"
3781 "test() {\n"
3782 " new A();\n"
3783 " new B();\n"
3784 "}";
3785 Dart_Handle h_lib = TestCase::LoadTestScript(kScriptChars, NULL);
3786 EXPECT_VALID(h_lib);
3787 Dart_Handle result = Dart_Invoke(h_lib, NewString("test"), 0, NULL);
3788 EXPECT_VALID(result);
3789 Library& lib = Library::Handle();
3790 lib ^= Api::UnwrapHandle(h_lib);
3791 EXPECT(!lib.IsNull());
3792 const Class& class_a = Class::Handle(GetClass(lib, "A"));
3793 const Array& class_a_fields = Array::Handle(class_a.fields());
3794 const Class& class_b = Class::Handle(GetClass(lib, "B"));
3795 const Field& field_a = Field::Handle(GetField(class_a, "a"));
3796 const Field& field_b = Field::Handle(GetField(class_a, "b"));
3797 const Field& field_d = Field::Handle(GetField(class_b, "d"));
3798 intptr_t field_a_index = class_a.FindFieldIndex(field_a);
3799 intptr_t field_b_index = class_a.FindFieldIndex(field_b);
3800 intptr_t field_d_index = class_a.FindFieldIndex(field_d);
3801 // Valid index.
3802 EXPECT_GE(field_a_index, 0);
3803 // Valid index.
3804 EXPECT_GE(field_b_index, 0);
3805 // Invalid index.
3806 EXPECT_EQ(field_d_index, -1);
3807 Field& field_a_from_index = Field::Handle();
3808 field_a_from_index ^= class_a_fields.At(field_a_index);
3809 ASSERT(!field_a_from_index.IsNull());
3810 // Same field.
3811 EXPECT_EQ(field_a.raw(), field_a_from_index.raw());
3812 Field& field_b_from_index = Field::Handle();
3813 field_b_from_index ^= class_a_fields.At(field_b_index);
3814 ASSERT(!field_b_from_index.IsNull());
3815 // Same field.
3816 EXPECT_EQ(field_b.raw(), field_b_from_index.raw());
3817 }
3818
3819
3820 TEST_CASE(FindClosureIndex) { 3772 TEST_CASE(FindClosureIndex) {
3821 // Allocate the class first. 3773 // Allocate the class first.
3822 const String& class_name = String::Handle(Symbols::New("MyClass")); 3774 const String& class_name = String::Handle(Symbols::New("MyClass"));
3823 const Script& script = Script::Handle(); 3775 const Script& script = Script::Handle();
3824 const Class& cls = Class::Handle(CreateDummyClass(class_name, script)); 3776 const Class& cls = Class::Handle(CreateDummyClass(class_name, script));
3825 const Array& functions = Array::Handle(Array::New(1)); 3777 const Array& functions = Array::Handle(Array::New(1));
3826 const Isolate* iso = Isolate::Current(); 3778 const Isolate* iso = Isolate::Current();
3827 3779
3828 Function& parent = Function::Handle(); 3780 Function& parent = Function::Handle();
3829 const String& parent_name = String::Handle(Symbols::New("foo_papa")); 3781 const String& parent_name = String::Handle(Symbols::New("foo_papa"));
(...skipping 899 matching lines...) Expand 10 before | Expand all | Expand 10 after
4729 String& test = String::Handle(); 4681 String& test = String::Handle();
4730 String& result = String::Handle(); 4682 String& result = String::Handle();
4731 for (size_t i = 0; i < ARRAY_SIZE(tests); i++) { 4683 for (size_t i = 0; i < ARRAY_SIZE(tests); i++) {
4732 test = String::New(tests[i].in); 4684 test = String::New(tests[i].in);
4733 result = String::IdentifierPrettyName(test); 4685 result = String::IdentifierPrettyName(test);
4734 EXPECT_STREQ(tests[i].out, result.ToCString()); 4686 EXPECT_STREQ(tests[i].out, result.ToCString());
4735 } 4687 }
4736 } 4688 }
4737 4689
4738 } // namespace dart 4690 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.cc ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698