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

Side by Side Diff: vm/object.cc

Issue 9616044: Adds new apis Dart_GetField/Dart_SetField. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 9 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 | « vm/object.h ('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 "vm/object.h" 5 #include "vm/object.h"
6 6
7 #include "platform/assert.h" 7 #include "platform/assert.h"
8 #include "vm/assembler.h" 8 #include "vm/assembler.h"
9 #include "vm/bigint_operations.h" 9 #include "vm/bigint_operations.h"
10 #include "vm/bootstrap.h" 10 #include "vm/bootstrap.h"
(...skipping 552 matching lines...) Expand 10 before | Expand all | Expand 10 after
563 object_store->set_object_class(cls); 563 object_store->set_object_class(cls);
564 cls.set_name(String::Handle(String::NewSymbol("Object"))); 564 cls.set_name(String::Handle(String::NewSymbol("Object")));
565 cls.set_script(script); 565 cls.set_script(script);
566 core_lib.AddClass(cls); 566 core_lib.AddClass(cls);
567 pending_classes.Add(&Class::ZoneHandle(cls.raw())); 567 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
568 type = Type::NewNonParameterizedType(cls); 568 type = Type::NewNonParameterizedType(cls);
569 object_store->set_object_type(type); 569 object_store->set_object_type(type);
570 570
571 cls = Class::New<InternalByteArray>(); 571 cls = Class::New<InternalByteArray>();
572 object_store->set_internal_byte_array_class(cls); 572 object_store->set_internal_byte_array_class(cls);
573 cls.set_name(String::Handle(core_lib.PrivateName("_InternalByteArray"))); 573 String& public_class_name = String::Handle();
574 public_class_name = String::New("_InternalByteArray");
575 cls.set_name(String::Handle(core_lib.PrivateName(public_class_name)));
574 cls.set_script(script); 576 cls.set_script(script);
575 core_lib.AddClass(cls); 577 core_lib.AddClass(cls);
576 578
577 cls = Class::New<ExternalByteArray>(); 579 cls = Class::New<ExternalByteArray>();
578 object_store->set_external_byte_array_class(cls); 580 object_store->set_external_byte_array_class(cls);
579 cls.set_name(String::Handle(core_lib.PrivateName("_ExternalByteArray"))); 581 public_class_name = String::New("_ExternalByteArray");
582 cls.set_name(String::Handle(core_lib.PrivateName(public_class_name)));
580 cls.set_script(script); 583 cls.set_script(script);
581 core_lib.AddClass(cls); 584 core_lib.AddClass(cls);
582 585
583 // Set the super type of class Stacktrace to Object type so that the 586 // Set the super type of class Stacktrace to Object type so that the
584 // 'toString' method is implemented. 587 // 'toString' method is implemented.
585 cls = object_store->stacktrace_class(); 588 cls = object_store->stacktrace_class();
586 cls.set_super_type(type); 589 cls.set_super_type(type);
587 590
588 cls = CreateAndRegisterInterface("Function", script, core_lib); 591 cls = CreateAndRegisterInterface("Function", script, core_lib);
589 pending_classes.Add(&Class::ZoneHandle(cls.raw())); 592 pending_classes.Add(&Class::ZoneHandle(cls.raw()));
(...skipping 3947 matching lines...) Expand 10 before | Expand all | Expand 10 after
4537 if (entry_name.Equals(name)) { 4540 if (entry_name.Equals(name)) {
4538 return entry.raw(); 4541 return entry.raw();
4539 } 4542 }
4540 index = (index + 1) % dict_size; 4543 index = (index + 1) % dict_size;
4541 entry = dict.At(index); 4544 entry = dict.At(index);
4542 } 4545 }
4543 return Class::null(); 4546 return Class::null();
4544 } 4547 }
4545 4548
4546 4549
4550 static bool ShouldBePrivate(const String& name) {
4551 return
4552 (name.Length() >= 1 &&
4553 name.CharAt(0) == '_') ||
4554 (name.Length() >= 5 &&
4555 (name.CharAt(4) == '_' &&
4556 (name.CharAt(0) == 'g' || name.CharAt(0) == 's') &&
4557 name.CharAt(1) == 'e' &&
4558 name.CharAt(2) == 't' &&
4559 name.CharAt(3) == ':'));
4560 }
4561
4562
4563 RawField* Library::LookupLocalField(const String& name) const {
4564 Isolate* isolate = Isolate::Current();
4565 Field& field = Field::Handle(isolate, Field::null());
4566 Object& obj = Object::Handle(isolate, Object::null());
4567 obj = LookupLocalObject(name);
4568 if (obj.IsNull() && ShouldBePrivate(name)) {
4569 String& private_name = String::Handle(isolate, PrivateName(name));
4570 obj = LookupLocalObject(private_name);
4571 }
4572 if (!obj.IsNull()) {
4573 if (obj.IsField()) {
4574 field ^= obj.raw();
4575 return field.raw();
4576 }
4577 }
4578
4579 // No field found.
4580 return Field::null();
4581 }
4582
4583
4584 RawFunction* Library::LookupLocalFunction(const String& name) const {
4585 Isolate* isolate = Isolate::Current();
4586 Function& function = Function::Handle(isolate, Function::null());
4587 Object& obj = Object::Handle(isolate, Object::null());
4588 obj = LookupLocalObject(name);
4589 if (obj.IsNull() && ShouldBePrivate(name)) {
4590 String& private_name = String::Handle(isolate, PrivateName(name));
4591 obj = LookupLocalObject(private_name);
4592 }
4593 if (!obj.IsNull()) {
4594 if (obj.IsFunction()) {
4595 function ^= obj.raw();
4596 return function.raw();
4597 }
4598 }
4599
4600 // No function found.
4601 return Function::null();
4602 }
4603
4604
4547 RawObject* Library::LookupObjectFiltered(const String& name, 4605 RawObject* Library::LookupObjectFiltered(const String& name,
4548 const Library& filter_lib) const { 4606 const Library& filter_lib) const {
4549 // First check if name is found in the local scope of the library. 4607 // First check if name is found in the local scope of the library.
4550 Object& obj = Object::Handle(LookupLocalObject(name)); 4608 Object& obj = Object::Handle(LookupLocalObject(name));
4551 if (!obj.IsNull()) { 4609 if (!obj.IsNull()) {
4552 return obj.raw(); 4610 return obj.raw();
4553 } 4611 }
4554 // Now check if name is found in the top level scope of any imported libs. 4612 // Now check if name is found in the top level scope of any imported libs.
4555 const Array& imports = Array::Handle(this->imports()); 4613 const Array& imports = Array::Handle(this->imports());
4556 Library& import_lib = Library::Handle(); 4614 Library& import_lib = Library::Handle();
(...skipping 395 matching lines...) Expand 10 before | Expand all | Expand 10 after
4952 lib_key = lib_url.Hash(); 5010 lib_key = lib_url.Hash();
4953 if (lib_key == key) { 5011 if (lib_key == key) {
4954 return true; 5012 return true;
4955 } 5013 }
4956 lib = lib.next_registered(); 5014 lib = lib.next_registered();
4957 } 5015 }
4958 return false; 5016 return false;
4959 } 5017 }
4960 5018
4961 5019
4962 RawString* Library::PrivateName(const char* name) { 5020 RawString* Library::PrivateName(const String& name) const {
4963 ASSERT(name[0] == '_'); 5021 ASSERT(ShouldBePrivate(name));
4964 ASSERT(strchr(name, '@') == NULL); 5022 // ASSERT(strchr(name, '@') == NULL);
4965 String& str = String::Handle(); 5023 String& str = String::Handle();
4966 str = String::New(name); 5024 str ^= name.raw();
4967 str = String::Concat(str, String::Handle(this->private_key())); 5025 str = String::Concat(str, String::Handle(this->private_key()));
4968 str = String::NewSymbol(str); 5026 str = String::NewSymbol(str);
4969 return str.raw(); 5027 return str.raw();
4970 } 5028 }
4971 5029
4972 5030
4973 void Library::Register() const { 5031 void Library::Register() const {
4974 ASSERT(Library::LookupLibrary(String::Handle(url())) == Library::null()); 5032 ASSERT(Library::LookupLibrary(String::Handle(url())) == Library::null());
4975 raw_ptr()->next_registered_ = 5033 raw_ptr()->next_registered_ =
4976 Isolate::Current()->object_store()->registered_libraries(); 5034 Isolate::Current()->object_store()->registered_libraries();
(...skipping 3627 matching lines...) Expand 10 before | Expand all | Expand 10 after
8604 result.set_num_args_tested(num_args_tested); 8662 result.set_num_args_tested(num_args_tested);
8605 // Number of array elements in one test entry (num_args_tested + 1) 8663 // Number of array elements in one test entry (num_args_tested + 1)
8606 intptr_t len = result.TestEntryLength(); 8664 intptr_t len = result.TestEntryLength();
8607 // IC data array must be null terminated (sentinel entry). 8665 // IC data array must be null terminated (sentinel entry).
8608 Array& ic_data = Array::Handle(Array::New(len, Heap::kOld)); 8666 Array& ic_data = Array::Handle(Array::New(len, Heap::kOld));
8609 result.set_ic_data(ic_data); 8667 result.set_ic_data(ic_data);
8610 return result.raw(); 8668 return result.raw();
8611 } 8669 }
8612 8670
8613 } // namespace dart 8671 } // namespace dart
OLDNEW
« no previous file with comments | « vm/object.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698