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 "vm/object.h" | 5 #include "vm/object.h" |
6 | 6 |
7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
8 #include "platform/assert.h" | 8 #include "platform/assert.h" |
9 #include "vm/assembler.h" | 9 #include "vm/assembler.h" |
10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
(...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 const String& public_class_name, | 624 const String& public_class_name, |
625 const Library& lib) { | 625 const Library& lib) { |
626 ASSERT(public_class_name.Length() > 0); | 626 ASSERT(public_class_name.Length() > 0); |
627 ASSERT(public_class_name.CharAt(0) == '_'); | 627 ASSERT(public_class_name.CharAt(0) == '_'); |
628 String& str = String::Handle(); | 628 String& str = String::Handle(); |
629 str = lib.PrivateName(public_class_name); | 629 str = lib.PrivateName(public_class_name); |
630 cls.set_name(str); | 630 cls.set_name(str); |
631 lib.AddClass(cls); | 631 lib.AddClass(cls); |
632 } | 632 } |
633 | 633 |
634 #define INIT_LIBRARY(name, raw_script, raw_lib) \ | 634 |
635 script ^= raw_script; \ | 635 #define LOAD_LIBRARY(name, raw_name) \ |
636 Library::Init##name##Library(isolate); \ | 636 url = Symbols::Dart##name().raw(); \ |
637 lib ^= raw_lib; \ | 637 lib = Library::LookupLibrary(url); \ |
638 ASSERT(!lib.IsNull()); \ | 638 if (lib.IsNull()) { \ |
| 639 lib = Library::NewLibraryHelper(url, true); \ |
| 640 lib.Register(); \ |
| 641 } \ |
| 642 isolate->object_store()->set_##raw_name##_library(lib); \ |
| 643 |
| 644 #define INIT_LIBRARY(name, raw_name, has_patch) \ |
| 645 LOAD_LIBRARY(name, raw_name) \ |
| 646 script = Bootstrap::Load##name##Script(false); \ |
639 error = Bootstrap::Compile(lib, script); \ | 647 error = Bootstrap::Compile(lib, script); \ |
640 if (!error.IsNull()) { \ | 648 if (!error.IsNull()) { \ |
641 return error.raw(); \ | 649 return error.raw(); \ |
642 } \ | 650 } \ |
| 651 if (has_patch) { \ |
| 652 script = Bootstrap::Load##name##Script(true); \ |
| 653 error = lib.Patch(script); \ |
| 654 if (!error.IsNull()) { \ |
| 655 return error.raw(); \ |
| 656 } \ |
| 657 } \ |
643 | 658 |
644 | 659 |
645 RawError* Object::Init(Isolate* isolate) { | 660 RawError* Object::Init(Isolate* isolate) { |
646 TIMERSCOPE(time_bootstrap); | 661 TIMERSCOPE(time_bootstrap); |
647 ObjectStore* object_store = isolate->object_store(); | 662 ObjectStore* object_store = isolate->object_store(); |
648 | 663 |
649 Class& cls = Class::Handle(); | 664 Class& cls = Class::Handle(); |
650 Type& type = Type::Handle(); | 665 Type& type = Type::Handle(); |
651 Array& array = Array::Handle(); | 666 Array& array = Array::Handle(); |
| 667 String& url = String::Handle(); |
| 668 Library& lib = Library::Handle(); |
| 669 Script& script = Script::Handle(); |
| 670 Error& error = Error::Handle(); |
652 | 671 |
653 // All RawArray fields will be initialized to an empty array, therefore | 672 // All RawArray fields will be initialized to an empty array, therefore |
654 // initialize array class first. | 673 // initialize array class first. |
655 cls = Class::New<Array>(); | 674 cls = Class::New<Array>(); |
656 object_store->set_array_class(cls); | 675 object_store->set_array_class(cls); |
657 | 676 |
658 // Array and ImmutableArray are the only VM classes that are parameterized. | 677 // Array and ImmutableArray are the only VM classes that are parameterized. |
659 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we | 678 // Since they are pre-finalized, CalculateFieldOffsets() is not called, so we |
660 // need to set the offset of their type_arguments_ field, which is explicitly | 679 // need to set the offset of their type_arguments_ field, which is explicitly |
661 // declared in RawArray. | 680 // declared in RawArray. |
(...skipping 29 matching lines...) Expand all Loading... |
691 object_store->set_two_byte_string_class(cls); | 710 object_store->set_two_byte_string_class(cls); |
692 | 711 |
693 // Setup the symbol table for the symbols created in the isolate. | 712 // Setup the symbol table for the symbols created in the isolate. |
694 Symbols::SetupSymbolTable(isolate); | 713 Symbols::SetupSymbolTable(isolate); |
695 | 714 |
696 // Set up the libraries array before initializing the core library. | 715 // Set up the libraries array before initializing the core library. |
697 const GrowableObjectArray& libraries = | 716 const GrowableObjectArray& libraries = |
698 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld)); | 717 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld)); |
699 object_store->set_libraries(libraries); | 718 object_store->set_libraries(libraries); |
700 | 719 |
| 720 // Pre-register the core library. |
| 721 Library::InitCoreLibrary(isolate); |
| 722 |
701 // Basic infrastructure has been setup, initialize the class dictionary. | 723 // Basic infrastructure has been setup, initialize the class dictionary. |
702 Library::InitCoreLibrary(isolate); | |
703 Library& core_lib = Library::Handle(Library::CoreLibrary()); | 724 Library& core_lib = Library::Handle(Library::CoreLibrary()); |
704 ASSERT(!core_lib.IsNull()); | 725 ASSERT(!core_lib.IsNull()); |
705 | 726 |
706 const GrowableObjectArray& pending_classes = | 727 const GrowableObjectArray& pending_classes = |
707 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld)); | 728 GrowableObjectArray::Handle(GrowableObjectArray::New(Heap::kOld)); |
708 object_store->set_pending_classes(pending_classes); | 729 object_store->set_pending_classes(pending_classes); |
709 | 730 |
710 Context& context = Context::Handle(Context::New(0, Heap::kOld)); | 731 Context& context = Context::Handle(Context::New(0, Heap::kOld)); |
711 object_store->set_empty_context(context); | 732 object_store->set_empty_context(context); |
712 | 733 |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 RegisterClass(cls, Symbols::Stacktrace(), core_lib); | 785 RegisterClass(cls, Symbols::Stacktrace(), core_lib); |
765 pending_classes.Add(cls, Heap::kOld); | 786 pending_classes.Add(cls, Heap::kOld); |
766 // Super type set below, after Object is allocated. | 787 // Super type set below, after Object is allocated. |
767 | 788 |
768 cls = Class::New<JSRegExp>(); | 789 cls = Class::New<JSRegExp>(); |
769 object_store->set_jsregexp_class(cls); | 790 object_store->set_jsregexp_class(cls); |
770 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib); | 791 RegisterPrivateClass(cls, Symbols::JSSyntaxRegExp(), core_lib); |
771 pending_classes.Add(cls, Heap::kOld); | 792 pending_classes.Add(cls, Heap::kOld); |
772 | 793 |
773 // Initialize the base interfaces used by the core VM classes. | 794 // Initialize the base interfaces used by the core VM classes. |
774 Script& script = Script::Handle(Bootstrap::LoadCoreScript(false)); | 795 script = Bootstrap::LoadCoreScript(false); |
775 | 796 |
776 // Allocate and initialize the pre-allocated classes in the core library. | 797 // Allocate and initialize the pre-allocated classes in the core library. |
777 cls = Class::New<Instance>(kInstanceCid); | 798 cls = Class::New<Instance>(kInstanceCid); |
778 object_store->set_object_class(cls); | 799 object_store->set_object_class(cls); |
779 cls.set_name(Symbols::Object()); | 800 cls.set_name(Symbols::Object()); |
780 cls.set_script(script); | 801 cls.set_script(script); |
781 cls.set_is_prefinalized(); | 802 cls.set_is_prefinalized(); |
782 core_lib.AddClass(cls); | 803 core_lib.AddClass(cls); |
783 pending_classes.Add(cls, Heap::kOld); | 804 pending_classes.Add(cls, Heap::kOld); |
784 type = Type::NewNonParameterizedType(cls); | 805 type = Type::NewNonParameterizedType(cls); |
(...skipping 29 matching lines...) Expand all Loading... |
814 | 835 |
815 cls = Class::New<Double>(); | 836 cls = Class::New<Double>(); |
816 object_store->set_double_class(cls); | 837 object_store->set_double_class(cls); |
817 RegisterPrivateClass(cls, Symbols::_Double(), core_lib); | 838 RegisterPrivateClass(cls, Symbols::_Double(), core_lib); |
818 pending_classes.Add(cls, Heap::kOld); | 839 pending_classes.Add(cls, Heap::kOld); |
819 | 840 |
820 cls = Class::New<WeakProperty>(); | 841 cls = Class::New<WeakProperty>(); |
821 object_store->set_weak_property_class(cls); | 842 object_store->set_weak_property_class(cls); |
822 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); | 843 RegisterPrivateClass(cls, Symbols::_WeakProperty(), core_lib); |
823 | 844 |
824 Library::InitScalarlistLibrary(isolate); | 845 // Setup some default native field classes which can be extended for |
| 846 // specifying native fields in dart classes. |
| 847 Library::InitNativeWrappersLibrary(isolate); |
| 848 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null()); |
| 849 |
| 850 // Pre-register the scalarlist library so the native class implementations |
| 851 // can be hooked up before compiling it. |
| 852 LOAD_LIBRARY(Scalarlist, scalarlist); |
| 853 |
825 Library& scalarlist_lib = Library::Handle(Library::ScalarlistLibrary()); | 854 Library& scalarlist_lib = Library::Handle(Library::ScalarlistLibrary()); |
| 855 ASSERT(!scalarlist_lib.IsNull()); |
826 | 856 |
827 cls = Class::New<Int8Array>(); | 857 cls = Class::New<Int8Array>(); |
828 object_store->set_int8_array_class(cls); | 858 object_store->set_int8_array_class(cls); |
829 RegisterPrivateClass(cls, Symbols::_Int8Array(), scalarlist_lib); | 859 RegisterPrivateClass(cls, Symbols::_Int8Array(), scalarlist_lib); |
830 | 860 |
831 cls = Class::New<Uint8Array>(); | 861 cls = Class::New<Uint8Array>(); |
832 object_store->set_uint8_array_class(cls); | 862 object_store->set_uint8_array_class(cls); |
833 RegisterPrivateClass(cls, Symbols::_Uint8Array(), scalarlist_lib); | 863 RegisterPrivateClass(cls, Symbols::_Uint8Array(), scalarlist_lib); |
834 | 864 |
835 cls = Class::New<Uint8ClampedArray>(); | 865 cls = Class::New<Uint8ClampedArray>(); |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
986 object_store->set_void_type(type); | 1016 object_store->set_void_type(type); |
987 | 1017 |
988 // The class 'dynamic' is registered in the class dictionary because its name | 1018 // The class 'dynamic' is registered in the class dictionary because its name |
989 // is a built-in identifier, rather than a reserved keyword. Its name is not | 1019 // is a built-in identifier, rather than a reserved keyword. Its name is not |
990 // heap allocated, because the class resides in the VM isolate. | 1020 // heap allocated, because the class resides in the VM isolate. |
991 // The corresponding type, the "unknown type", is stored in the object store. | 1021 // The corresponding type, the "unknown type", is stored in the object store. |
992 cls = dynamic_class(); | 1022 cls = dynamic_class(); |
993 type = Type::NewNonParameterizedType(cls); | 1023 type = Type::NewNonParameterizedType(cls); |
994 object_store->set_dynamic_type(type); | 1024 object_store->set_dynamic_type(type); |
995 | 1025 |
996 // Setup some default native field classes which can be extended for | |
997 // specifying native fields in dart classes. | |
998 Library::InitNativeWrappersLibrary(isolate); | |
999 ASSERT(isolate->object_store()->native_wrappers_library() != Library::null()); | |
1000 | |
1001 // Finish the initialization by compiling the bootstrap scripts containing the | 1026 // Finish the initialization by compiling the bootstrap scripts containing the |
1002 // base interfaces and the implementation of the internal classes. | 1027 // base interfaces and the implementation of the internal classes. |
1003 Error& error = Error::Handle(); | 1028 INIT_LIBRARY(Core, core, true); |
1004 error = Bootstrap::Compile(core_lib, script); | 1029 |
1005 if (!error.IsNull()) { | 1030 INIT_LIBRARY(Async, async, true); |
1006 return error.raw(); | 1031 INIT_LIBRARY(Collection, collection, false); |
1007 } | 1032 INIT_LIBRARY(CollectionDev, collection_dev, false); |
1008 Script& patch_script = Script::Handle(Bootstrap::LoadCoreScript(true)); | 1033 INIT_LIBRARY(Crypto, crypto, false); |
1009 error = core_lib.Patch(patch_script); | 1034 INIT_LIBRARY(Isolate, isolate, true); |
1010 if (!error.IsNull()) { | 1035 INIT_LIBRARY(Json, json, false); |
1011 return error.raw(); | 1036 INIT_LIBRARY(Math, math, true); |
1012 } | 1037 INIT_LIBRARY(Mirrors, mirrors, true); |
1013 Library::InitASyncLibrary(isolate); | 1038 INIT_LIBRARY(Scalarlist, scalarlist, true); |
1014 const Script& async_script = | 1039 INIT_LIBRARY(Utf, utf, false); |
1015 Script::Handle(Bootstrap::LoadASyncScript(false)); | 1040 INIT_LIBRARY(Uri, uri, false); |
1016 const Library& async_lib = Library::Handle(Library::ASyncLibrary()); | 1041 |
1017 ASSERT(!async_lib.IsNull()); | |
1018 error = Bootstrap::Compile(async_lib, async_script); | |
1019 if (!error.IsNull()) { | |
1020 return error.raw(); | |
1021 } | |
1022 patch_script = Bootstrap::LoadASyncScript(true); | |
1023 error = async_lib.Patch(patch_script); | |
1024 if (!error.IsNull()) { | |
1025 return error.raw(); | |
1026 } | |
1027 const Script& collection_script = | |
1028 Script::Handle(Bootstrap::LoadCollectionScript(false)); | |
1029 const Library& collection_lib = | |
1030 Library::Handle(Library::CollectionLibrary()); | |
1031 ASSERT(!collection_lib.IsNull()); | |
1032 error = Bootstrap::Compile(collection_lib, collection_script); | |
1033 if (!error.IsNull()) { | |
1034 return error.raw(); | |
1035 } | |
1036 const Script& collection_dev_script = | |
1037 Script::Handle(Bootstrap::LoadCollectionDevScript(false)); | |
1038 const Library& collection_dev_lib = | |
1039 Library::Handle(Library::CollectionDevLibrary()); | |
1040 ASSERT(!collection_dev_lib.IsNull()); | |
1041 error = Bootstrap::Compile(collection_dev_lib, collection_dev_script); | |
1042 if (!error.IsNull()) { | |
1043 return error.raw(); | |
1044 } | |
1045 const Script& math_script = Script::Handle(Bootstrap::LoadMathScript(false)); | |
1046 const Library& math_lib = Library::Handle(Library::MathLibrary()); | |
1047 ASSERT(!math_lib.IsNull()); | |
1048 error = Bootstrap::Compile(math_lib, math_script); | |
1049 if (!error.IsNull()) { | |
1050 return error.raw(); | |
1051 } | |
1052 patch_script = Bootstrap::LoadMathScript(true); | |
1053 error = math_lib.Patch(patch_script); | |
1054 if (!error.IsNull()) { | |
1055 return error.raw(); | |
1056 } | |
1057 const Script& isolate_script = Script::Handle( | |
1058 Bootstrap::LoadIsolateScript(false)); | |
1059 Library::InitIsolateLibrary(isolate); | |
1060 const Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | |
1061 ASSERT(!isolate_lib.IsNull()); | |
1062 error = Bootstrap::Compile(isolate_lib, isolate_script); | |
1063 if (!error.IsNull()) { | |
1064 return error.raw(); | |
1065 } | |
1066 patch_script = Bootstrap::LoadIsolateScript(true); | |
1067 error = isolate_lib.Patch(patch_script); | |
1068 if (!error.IsNull()) { | |
1069 return error.raw(); | |
1070 } | |
1071 const Script& mirrors_script = Script::Handle( | |
1072 Bootstrap::LoadMirrorsScript(false)); | |
1073 Library::InitMirrorsLibrary(isolate); | |
1074 const Library& mirrors_lib = Library::Handle(Library::MirrorsLibrary()); | |
1075 ASSERT(!mirrors_lib.IsNull()); | |
1076 error = Bootstrap::Compile(mirrors_lib, mirrors_script); | |
1077 if (!error.IsNull()) { | |
1078 return error.raw(); | |
1079 } | |
1080 patch_script = Bootstrap::LoadMirrorsScript(true); | |
1081 error = mirrors_lib.Patch(patch_script); | |
1082 if (!error.IsNull()) { | |
1083 return error.raw(); | |
1084 } | |
1085 const Script& scalarlist_script = Script::Handle( | |
1086 Bootstrap::LoadScalarlistScript(false)); | |
1087 ASSERT(!scalarlist_lib.IsNull()); | |
1088 error = Bootstrap::Compile(scalarlist_lib, scalarlist_script); | |
1089 if (!error.IsNull()) { | |
1090 return error.raw(); | |
1091 } | |
1092 patch_script = Bootstrap::LoadScalarlistScript(true); | |
1093 error = scalarlist_lib.Patch(patch_script); | |
1094 if (!error.IsNull()) { | |
1095 return error.raw(); | |
1096 } | |
1097 Library& lib = Library::Handle(); | |
1098 INIT_LIBRARY(Crypto, | |
1099 Bootstrap::LoadCryptoScript(false), | |
1100 Library::CryptoLibrary()); | |
1101 INIT_LIBRARY(Json, | |
1102 Bootstrap::LoadJsonScript(false), | |
1103 Library::JsonLibrary()); | |
1104 INIT_LIBRARY(Utf, | |
1105 Bootstrap::LoadUtfScript(false), | |
1106 Library::UtfLibrary()); | |
1107 INIT_LIBRARY(Uri, | |
1108 Bootstrap::LoadUriScript(false), | |
1109 Library::UriLibrary()); | |
1110 Bootstrap::SetupNativeResolver(); | 1042 Bootstrap::SetupNativeResolver(); |
1111 | 1043 |
1112 // Remove the Object superclass cycle by setting the super type to null (not | 1044 // Remove the Object superclass cycle by setting the super type to null (not |
1113 // to the type of null). | 1045 // to the type of null). |
1114 cls = object_store->object_class(); | 1046 cls = object_store->object_class(); |
1115 cls.set_super_type(Type::Handle()); | 1047 cls.set_super_type(Type::Handle()); |
1116 | 1048 |
1117 ClassFinalizer::VerifyBootstrapClasses(); | 1049 ClassFinalizer::VerifyBootstrapClasses(); |
1118 MarkInvisibleFunctions(); | 1050 MarkInvisibleFunctions(); |
1119 | 1051 |
(...skipping 5213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6333 } | 6265 } |
6334 return result.raw(); | 6266 return result.raw(); |
6335 } | 6267 } |
6336 | 6268 |
6337 | 6269 |
6338 RawLibrary* Library::New(const String& url) { | 6270 RawLibrary* Library::New(const String& url) { |
6339 return NewLibraryHelper(url, false); | 6271 return NewLibraryHelper(url, false); |
6340 } | 6272 } |
6341 | 6273 |
6342 | 6274 |
6343 void Library::InitASyncLibrary(Isolate* isolate) { | |
6344 const String& url = Symbols::DartAsync(); | |
6345 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | |
6346 lib.Register(); | |
6347 isolate->object_store()->set_async_library(lib); | |
6348 } | |
6349 | |
6350 | |
6351 void Library::InitCoreLibrary(Isolate* isolate) { | 6275 void Library::InitCoreLibrary(Isolate* isolate) { |
6352 const String& core_lib_url = Symbols::DartCore(); | 6276 const String& core_lib_url = Symbols::DartCore(); |
6353 const Library& core_lib = | 6277 const Library& core_lib = |
6354 Library::Handle(Library::NewLibraryHelper(core_lib_url, false)); | 6278 Library::Handle(Library::NewLibraryHelper(core_lib_url, false)); |
6355 core_lib.Register(); | 6279 core_lib.Register(); |
6356 isolate->object_store()->set_core_library(core_lib); | 6280 isolate->object_store()->set_core_library(core_lib); |
6357 Library::InitMathLibrary(isolate); | |
6358 const Library& math_lib = Library::Handle(Library::MathLibrary()); | |
6359 const Namespace& math_ns = Namespace::Handle( | |
6360 Namespace::New(math_lib, Array::Handle(), Array::Handle())); | |
6361 Library::InitCollectionDevLibrary(isolate); | |
6362 const Library& collection_dev_lib = | |
6363 Library::Handle(Library::CollectionDevLibrary()); | |
6364 const Namespace& collection_dev_ns = Namespace::Handle( | |
6365 Namespace::New(collection_dev_lib, Array::Handle(), Array::Handle())); | |
6366 Library::InitCollectionLibrary(isolate); | |
6367 const Library& collection_lib = | |
6368 Library::Handle(Library::CollectionLibrary()); | |
6369 const Namespace& collection_ns = Namespace::Handle( | |
6370 Namespace::New(collection_lib, Array::Handle(), Array::Handle())); | |
6371 core_lib.AddImport(math_ns); | |
6372 core_lib.AddImport(collection_ns); | |
6373 core_lib.AddImport(collection_dev_ns); | |
6374 isolate->object_store()->set_root_library(Library::Handle()); | 6281 isolate->object_store()->set_root_library(Library::Handle()); |
6375 | 6282 |
6376 // Hook up predefined classes without setting their library pointers. These | 6283 // Hook up predefined classes without setting their library pointers. These |
6377 // classes are coming from the VM isolate, and are shared between multiple | 6284 // classes are coming from the VM isolate, and are shared between multiple |
6378 // isolates so setting their library pointers would be wrong. | 6285 // isolates so setting their library pointers would be wrong. |
6379 const Class& cls = Class::Handle(Object::dynamic_class()); | 6286 const Class& cls = Class::Handle(Object::dynamic_class()); |
6380 core_lib.AddObject(cls, String::Handle(cls.Name())); | 6287 core_lib.AddObject(cls, String::Handle(cls.Name())); |
6381 } | 6288 } |
6382 | 6289 |
6383 | 6290 |
6384 void Library::InitCollectionLibrary(Isolate* isolate) { | |
6385 const String& url = Symbols::DartCollection(); | |
6386 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | |
6387 lib.Register(); | |
6388 const Library& math_lib = Library::Handle(Library::MathLibrary()); | |
6389 const Namespace& math_ns = Namespace::Handle( | |
6390 Namespace::New(math_lib, Array::Handle(), Array::Handle())); | |
6391 const Library& collection_dev_lib = | |
6392 Library::Handle(Library::CollectionDevLibrary()); | |
6393 const Namespace& collection_dev_ns = Namespace::Handle( | |
6394 Namespace::New(collection_dev_lib, Array::Handle(), Array::Handle())); | |
6395 lib.AddImport(math_ns); | |
6396 lib.AddImport(collection_dev_ns); | |
6397 isolate->object_store()->set_collection_library(lib); | |
6398 } | |
6399 | |
6400 | |
6401 void Library::InitCollectionDevLibrary(Isolate* isolate) { | |
6402 const String& url = Symbols::DartCollectionDev(); | |
6403 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | |
6404 lib.Register(); | |
6405 isolate->object_store()->set_collection_dev_library(lib); | |
6406 } | |
6407 | |
6408 | |
6409 void Library::InitCryptoLibrary(Isolate* isolate) { | |
6410 const String& url = Symbols::DartCrypto(); | |
6411 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | |
6412 lib.Register(); | |
6413 const Library& math_lib = Library::Handle(Library::MathLibrary()); | |
6414 const Namespace& math_ns = Namespace::Handle( | |
6415 Namespace::New(math_lib, Array::Handle(), Array::Handle())); | |
6416 lib.AddImport(math_ns); | |
6417 isolate->object_store()->set_crypto_library(lib); | |
6418 } | |
6419 | |
6420 | |
6421 void Library::InitIsolateLibrary(Isolate* isolate) { | |
6422 const String& url = Symbols::DartIsolate(); | |
6423 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | |
6424 lib.Register(); | |
6425 const Library& async_lib = Library::Handle(Library::ASyncLibrary()); | |
6426 const Namespace& async_ns = Namespace::Handle( | |
6427 Namespace::New(async_lib, Array::Handle(), Array::Handle())); | |
6428 lib.AddImport(async_ns); | |
6429 isolate->object_store()->set_isolate_library(lib); | |
6430 } | |
6431 | |
6432 | |
6433 void Library::InitJsonLibrary(Isolate* isolate) { | |
6434 const String& url = Symbols::DartJson(); | |
6435 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | |
6436 lib.Register(); | |
6437 isolate->object_store()->set_json_library(lib); | |
6438 } | |
6439 | |
6440 | |
6441 void Library::InitMathLibrary(Isolate* isolate) { | |
6442 const String& url = Symbols::DartMath(); | |
6443 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | |
6444 lib.Register(); | |
6445 isolate->object_store()->set_math_library(lib); | |
6446 } | |
6447 | |
6448 | |
6449 void Library::InitMirrorsLibrary(Isolate* isolate) { | |
6450 const String& url = Symbols::DartMirrors(); | |
6451 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | |
6452 lib.Register(); | |
6453 const Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | |
6454 const Namespace& isolate_ns = Namespace::Handle( | |
6455 Namespace::New(isolate_lib, Array::Handle(), Array::Handle())); | |
6456 lib.AddImport(isolate_ns); | |
6457 const Library& async_lib = Library::Handle(Library::ASyncLibrary()); | |
6458 const Namespace& async_ns = Namespace::Handle( | |
6459 Namespace::New(async_lib, Array::Handle(), Array::Handle())); | |
6460 lib.AddImport(async_ns); | |
6461 const Library& wrappers_lib = | |
6462 Library::Handle(Library::NativeWrappersLibrary()); | |
6463 const Namespace& wrappers_ns = Namespace::Handle( | |
6464 Namespace::New(wrappers_lib, Array::Handle(), Array::Handle())); | |
6465 lib.AddImport(wrappers_ns); | |
6466 isolate->object_store()->set_mirrors_library(lib); | |
6467 } | |
6468 | |
6469 | |
6470 void Library::InitNativeWrappersLibrary(Isolate* isolate) { | 6291 void Library::InitNativeWrappersLibrary(Isolate* isolate) { |
6471 static const int kNumNativeWrappersClasses = 4; | 6292 static const int kNumNativeWrappersClasses = 4; |
6472 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10); | 6293 ASSERT(kNumNativeWrappersClasses > 0 && kNumNativeWrappersClasses < 10); |
6473 const String& native_flds_lib_url = Symbols::DartNativeWrappers(); | 6294 const String& native_flds_lib_url = Symbols::DartNativeWrappers(); |
6474 const Library& native_flds_lib = Library::Handle( | 6295 const Library& native_flds_lib = Library::Handle( |
6475 Library::NewLibraryHelper(native_flds_lib_url, false)); | 6296 Library::NewLibraryHelper(native_flds_lib_url, false)); |
6476 native_flds_lib.Register(); | 6297 native_flds_lib.Register(); |
6477 isolate->object_store()->set_native_wrappers_library(native_flds_lib); | 6298 isolate->object_store()->set_native_wrappers_library(native_flds_lib); |
6478 static const char* const kNativeWrappersClass = "NativeFieldWrapperClass"; | 6299 static const char* const kNativeWrappersClass = "NativeFieldWrapperClass"; |
6479 static const int kNameLength = 25; | 6300 static const int kNameLength = 25; |
6480 ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1)); | 6301 ASSERT(kNameLength == (strlen(kNativeWrappersClass) + 1 + 1)); |
6481 char name_buffer[kNameLength]; | 6302 char name_buffer[kNameLength]; |
6482 String& cls_name = String::Handle(); | 6303 String& cls_name = String::Handle(); |
6483 for (int fld_cnt = 1; fld_cnt <= kNumNativeWrappersClasses; fld_cnt++) { | 6304 for (int fld_cnt = 1; fld_cnt <= kNumNativeWrappersClasses; fld_cnt++) { |
6484 OS::SNPrint(name_buffer, | 6305 OS::SNPrint(name_buffer, |
6485 kNameLength, | 6306 kNameLength, |
6486 "%s%d", | 6307 "%s%d", |
6487 kNativeWrappersClass, | 6308 kNativeWrappersClass, |
6488 fld_cnt); | 6309 fld_cnt); |
6489 cls_name = Symbols::New(name_buffer); | 6310 cls_name = Symbols::New(name_buffer); |
6490 Class::NewNativeWrapper(native_flds_lib, cls_name, fld_cnt); | 6311 Class::NewNativeWrapper(native_flds_lib, cls_name, fld_cnt); |
6491 } | 6312 } |
6492 } | 6313 } |
6493 | 6314 |
6494 | 6315 |
6495 void Library::InitScalarlistLibrary(Isolate* isolate) { | |
6496 const String& url = Symbols::DartScalarlist(); | |
6497 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | |
6498 lib.Register(); | |
6499 const Library& collection_lib = | |
6500 Library::Handle(Library::CollectionLibrary()); | |
6501 const Namespace& collection_ns = Namespace::Handle( | |
6502 Namespace::New(collection_lib, Array::Handle(), Array::Handle())); | |
6503 lib.AddImport(collection_ns); | |
6504 isolate->object_store()->set_scalarlist_library(lib); | |
6505 } | |
6506 | |
6507 | |
6508 void Library::InitUriLibrary(Isolate* isolate) { | |
6509 const String& url = Symbols::DartUri(); | |
6510 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | |
6511 lib.Register(); | |
6512 const Library& math_lib = Library::Handle(Library::MathLibrary()); | |
6513 const Namespace& math_ns = Namespace::Handle( | |
6514 Namespace::New(math_lib, Array::Handle(), Array::Handle())); | |
6515 const Library& utf_lib = Library::Handle(Library::UtfLibrary()); | |
6516 const Namespace& utf_ns = Namespace::Handle( | |
6517 Namespace::New(utf_lib, Array::Handle(), Array::Handle())); | |
6518 lib.AddImport(math_ns); | |
6519 lib.AddImport(utf_ns); | |
6520 isolate->object_store()->set_uri_library(lib); | |
6521 } | |
6522 | |
6523 | |
6524 void Library::InitUtfLibrary(Isolate* isolate) { | |
6525 const String& url = Symbols::DartUtf(); | |
6526 const Library& lib = Library::Handle(Library::NewLibraryHelper(url, true)); | |
6527 lib.Register(); | |
6528 const Library& async_lib = Library::Handle(Library::ASyncLibrary()); | |
6529 const Namespace& async_ns = Namespace::Handle( | |
6530 Namespace::New(async_lib, Array::Handle(), Array::Handle())); | |
6531 lib.AddImport(async_ns); | |
6532 isolate->object_store()->set_utf_library(lib); | |
6533 } | |
6534 | |
6535 | |
6536 RawLibrary* Library::LookupLibrary(const String &url) { | 6316 RawLibrary* Library::LookupLibrary(const String &url) { |
6537 Isolate* isolate = Isolate::Current(); | 6317 Isolate* isolate = Isolate::Current(); |
6538 Library& lib = Library::Handle(isolate, Library::null()); | 6318 Library& lib = Library::Handle(isolate, Library::null()); |
6539 String& lib_url = String::Handle(isolate, String::null()); | 6319 String& lib_url = String::Handle(isolate, String::null()); |
6540 GrowableObjectArray& libs = GrowableObjectArray::Handle( | 6320 GrowableObjectArray& libs = GrowableObjectArray::Handle( |
6541 isolate, isolate->object_store()->libraries()); | 6321 isolate, isolate->object_store()->libraries()); |
6542 for (int i = 0; i < libs.Length(); i++) { | 6322 for (int i = 0; i < libs.Length(); i++) { |
6543 lib ^= libs.At(i); | 6323 lib ^= libs.At(i); |
6544 lib_url ^= lib.url(); | 6324 lib_url ^= lib.url(); |
6545 if (lib_url.Equals(url)) { | 6325 if (lib_url.Equals(url)) { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6619 ASSERT(Library::LookupLibrary(String::Handle(url())) == Library::null()); | 6399 ASSERT(Library::LookupLibrary(String::Handle(url())) == Library::null()); |
6620 ObjectStore* object_store = Isolate::Current()->object_store(); | 6400 ObjectStore* object_store = Isolate::Current()->object_store(); |
6621 GrowableObjectArray& libs = | 6401 GrowableObjectArray& libs = |
6622 GrowableObjectArray::Handle(object_store->libraries()); | 6402 GrowableObjectArray::Handle(object_store->libraries()); |
6623 ASSERT(!libs.IsNull()); | 6403 ASSERT(!libs.IsNull()); |
6624 set_index(libs.Length()); | 6404 set_index(libs.Length()); |
6625 libs.Add(*this); | 6405 libs.Add(*this); |
6626 } | 6406 } |
6627 | 6407 |
6628 | 6408 |
6629 RawLibrary* Library::ASyncLibrary() { | 6409 RawLibrary* Library::AsyncLibrary() { |
6630 return Isolate::Current()->object_store()->async_library(); | 6410 return Isolate::Current()->object_store()->async_library(); |
6631 } | 6411 } |
6632 | 6412 |
6633 | 6413 |
6634 RawLibrary* Library::CoreLibrary() { | 6414 RawLibrary* Library::CoreLibrary() { |
6635 return Isolate::Current()->object_store()->core_library(); | 6415 return Isolate::Current()->object_store()->core_library(); |
6636 } | 6416 } |
6637 | 6417 |
6638 | 6418 |
6639 RawLibrary* Library::CollectionLibrary() { | 6419 RawLibrary* Library::CollectionLibrary() { |
(...skipping 6375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13015 } | 12795 } |
13016 return result.raw(); | 12796 return result.raw(); |
13017 } | 12797 } |
13018 | 12798 |
13019 | 12799 |
13020 const char* WeakProperty::ToCString() const { | 12800 const char* WeakProperty::ToCString() const { |
13021 return "_WeakProperty"; | 12801 return "_WeakProperty"; |
13022 } | 12802 } |
13023 | 12803 |
13024 } // namespace dart | 12804 } // namespace dart |
OLD | NEW |