OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/bootstrapper.h" | 5 #include "src/bootstrapper.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/code-stubs.h" | 9 #include "src/code-stubs.h" |
10 #include "src/extensions/externalize-string-extension.h" | 10 #include "src/extensions/externalize-string-extension.h" |
(...skipping 13 matching lines...) Expand all Loading... |
24 | 24 |
25 Bootstrapper::Bootstrapper(Isolate* isolate) | 25 Bootstrapper::Bootstrapper(Isolate* isolate) |
26 : isolate_(isolate), | 26 : isolate_(isolate), |
27 nesting_(0), | 27 nesting_(0), |
28 extensions_cache_(Script::TYPE_EXTENSION) {} | 28 extensions_cache_(Script::TYPE_EXTENSION) {} |
29 | 29 |
30 template <class Source> | 30 template <class Source> |
31 Handle<String> Bootstrapper::SourceLookup(int index) { | 31 Handle<String> Bootstrapper::SourceLookup(int index) { |
32 DCHECK(0 <= index && index < Source::GetBuiltinsCount()); | 32 DCHECK(0 <= index && index < Source::GetBuiltinsCount()); |
33 Heap* heap = isolate_->heap(); | 33 Heap* heap = isolate_->heap(); |
34 if (Source::GetSourceCache(heap)->get(index)->IsUndefined()) { | 34 if (Source::GetSourceCache(heap)->get(index)->IsUndefined(isolate_)) { |
35 // We can use external strings for the natives. | 35 // We can use external strings for the natives. |
36 Vector<const char> source = Source::GetScriptSource(index); | 36 Vector<const char> source = Source::GetScriptSource(index); |
37 NativesExternalStringResource* resource = | 37 NativesExternalStringResource* resource = |
38 new NativesExternalStringResource(source.start(), source.length()); | 38 new NativesExternalStringResource(source.start(), source.length()); |
39 Handle<ExternalOneByteString> source_code = | 39 Handle<ExternalOneByteString> source_code = |
40 isolate_->factory()->NewNativeSourceString(resource); | 40 isolate_->factory()->NewNativeSourceString(resource); |
41 // Mark this external string with a special map. | 41 // Mark this external string with a special map. |
42 DCHECK(source_code->is_short()); | 42 DCHECK(source_code->is_short()); |
43 Source::GetSourceCache(heap)->set(index, *source_code); | 43 Source::GetSourceCache(heap)->set(index, *source_code); |
44 } | 44 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 delete trigger_failure_extension_; | 102 delete trigger_failure_extension_; |
103 trigger_failure_extension_ = NULL; | 103 trigger_failure_extension_ = NULL; |
104 delete ignition_statistics_extension_; | 104 delete ignition_statistics_extension_; |
105 ignition_statistics_extension_ = NULL; | 105 ignition_statistics_extension_ = NULL; |
106 } | 106 } |
107 | 107 |
108 | 108 |
109 void DeleteNativeSources(Object* maybe_array) { | 109 void DeleteNativeSources(Object* maybe_array) { |
110 if (maybe_array->IsFixedArray()) { | 110 if (maybe_array->IsFixedArray()) { |
111 FixedArray* array = FixedArray::cast(maybe_array); | 111 FixedArray* array = FixedArray::cast(maybe_array); |
| 112 Isolate* isolate = array->GetIsolate(); |
112 for (int i = 0; i < array->length(); i++) { | 113 for (int i = 0; i < array->length(); i++) { |
113 Object* natives_source = array->get(i); | 114 Object* natives_source = array->get(i); |
114 if (!natives_source->IsUndefined()) { | 115 if (!natives_source->IsUndefined(isolate)) { |
115 const NativesExternalStringResource* resource = | 116 const NativesExternalStringResource* resource = |
116 reinterpret_cast<const NativesExternalStringResource*>( | 117 reinterpret_cast<const NativesExternalStringResource*>( |
117 ExternalOneByteString::cast(natives_source)->resource()); | 118 ExternalOneByteString::cast(natives_source)->resource()); |
118 delete resource; | 119 delete resource; |
119 } | 120 } |
120 } | 121 } |
121 } | 122 } |
122 } | 123 } |
123 | 124 |
124 | 125 |
(...skipping 752 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 accessors->set_setter(*thrower); | 878 accessors->set_setter(*thrower); |
878 | 879 |
879 Handle<Map> map(empty->map()); | 880 Handle<Map> map(empty->map()); |
880 ReplaceAccessors(map, factory()->arguments_string(), rw_attribs, accessors); | 881 ReplaceAccessors(map, factory()->arguments_string(), rw_attribs, accessors); |
881 ReplaceAccessors(map, factory()->caller_string(), rw_attribs, accessors); | 882 ReplaceAccessors(map, factory()->caller_string(), rw_attribs, accessors); |
882 } | 883 } |
883 | 884 |
884 | 885 |
885 static void AddToWeakNativeContextList(Context* context) { | 886 static void AddToWeakNativeContextList(Context* context) { |
886 DCHECK(context->IsNativeContext()); | 887 DCHECK(context->IsNativeContext()); |
887 Heap* heap = context->GetIsolate()->heap(); | 888 Isolate* isolate = context->GetIsolate(); |
| 889 Heap* heap = isolate->heap(); |
888 #ifdef DEBUG | 890 #ifdef DEBUG |
889 { // NOLINT | 891 { // NOLINT |
890 DCHECK(context->next_context_link()->IsUndefined()); | 892 DCHECK(context->next_context_link()->IsUndefined(isolate)); |
891 // Check that context is not in the list yet. | 893 // Check that context is not in the list yet. |
892 for (Object* current = heap->native_contexts_list(); | 894 for (Object* current = heap->native_contexts_list(); |
893 !current->IsUndefined(); | 895 !current->IsUndefined(isolate); |
894 current = Context::cast(current)->next_context_link()) { | 896 current = Context::cast(current)->next_context_link()) { |
895 DCHECK(current != context); | 897 DCHECK(current != context); |
896 } | 898 } |
897 } | 899 } |
898 #endif | 900 #endif |
899 context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list(), | 901 context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list(), |
900 UPDATE_WEAK_WRITE_BARRIER); | 902 UPDATE_WEAK_WRITE_BARRIER); |
901 heap->set_native_contexts_list(context); | 903 heap->set_native_contexts_list(context); |
902 } | 904 } |
903 | 905 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
958 Handle<ObjectTemplateInfo> js_global_object_template; | 960 Handle<ObjectTemplateInfo> js_global_object_template; |
959 if (!global_proxy_template.IsEmpty()) { | 961 if (!global_proxy_template.IsEmpty()) { |
960 // Get prototype template of the global_proxy_template. | 962 // Get prototype template of the global_proxy_template. |
961 Handle<ObjectTemplateInfo> data = | 963 Handle<ObjectTemplateInfo> data = |
962 v8::Utils::OpenHandle(*global_proxy_template); | 964 v8::Utils::OpenHandle(*global_proxy_template); |
963 Handle<FunctionTemplateInfo> global_constructor = | 965 Handle<FunctionTemplateInfo> global_constructor = |
964 Handle<FunctionTemplateInfo>( | 966 Handle<FunctionTemplateInfo>( |
965 FunctionTemplateInfo::cast(data->constructor())); | 967 FunctionTemplateInfo::cast(data->constructor())); |
966 Handle<Object> proto_template(global_constructor->prototype_template(), | 968 Handle<Object> proto_template(global_constructor->prototype_template(), |
967 isolate()); | 969 isolate()); |
968 if (!proto_template->IsUndefined()) { | 970 if (!proto_template->IsUndefined(isolate())) { |
969 js_global_object_template = | 971 js_global_object_template = |
970 Handle<ObjectTemplateInfo>::cast(proto_template); | 972 Handle<ObjectTemplateInfo>::cast(proto_template); |
971 } | 973 } |
972 } | 974 } |
973 | 975 |
974 if (js_global_object_template.is_null()) { | 976 if (js_global_object_template.is_null()) { |
975 Handle<String> name = Handle<String>(heap()->empty_string()); | 977 Handle<String> name = Handle<String>(heap()->empty_string()); |
976 Handle<Code> code = isolate()->builtins()->Illegal(); | 978 Handle<Code> code = isolate()->builtins()->Illegal(); |
977 Handle<JSObject> prototype = | 979 Handle<JSObject> prototype = |
978 factory()->NewFunctionPrototype(isolate()->object_function()); | 980 factory()->NewFunctionPrototype(isolate()->object_function()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1028 | 1030 |
1029 | 1031 |
1030 void Genesis::HookUpGlobalProxy(Handle<JSGlobalObject> global_object, | 1032 void Genesis::HookUpGlobalProxy(Handle<JSGlobalObject> global_object, |
1031 Handle<JSGlobalProxy> global_proxy) { | 1033 Handle<JSGlobalProxy> global_proxy) { |
1032 // Set the native context for the global object. | 1034 // Set the native context for the global object. |
1033 global_object->set_native_context(*native_context()); | 1035 global_object->set_native_context(*native_context()); |
1034 global_object->set_global_proxy(*global_proxy); | 1036 global_object->set_global_proxy(*global_proxy); |
1035 global_proxy->set_native_context(*native_context()); | 1037 global_proxy->set_native_context(*native_context()); |
1036 // If we deserialized the context, the global proxy is already | 1038 // If we deserialized the context, the global proxy is already |
1037 // correctly set up. Otherwise it's undefined. | 1039 // correctly set up. Otherwise it's undefined. |
1038 DCHECK(native_context()->get(Context::GLOBAL_PROXY_INDEX)->IsUndefined() || | 1040 DCHECK(native_context() |
| 1041 ->get(Context::GLOBAL_PROXY_INDEX) |
| 1042 ->IsUndefined(isolate()) || |
1039 native_context()->global_proxy() == *global_proxy); | 1043 native_context()->global_proxy() == *global_proxy); |
1040 native_context()->set_global_proxy(*global_proxy); | 1044 native_context()->set_global_proxy(*global_proxy); |
1041 } | 1045 } |
1042 | 1046 |
1043 | 1047 |
1044 void Genesis::HookUpGlobalObject(Handle<JSGlobalObject> global_object) { | 1048 void Genesis::HookUpGlobalObject(Handle<JSGlobalObject> global_object) { |
1045 Handle<JSGlobalObject> global_object_from_snapshot( | 1049 Handle<JSGlobalObject> global_object_from_snapshot( |
1046 JSGlobalObject::cast(native_context()->extension())); | 1050 JSGlobalObject::cast(native_context()->extension())); |
1047 native_context()->set_extension(*global_object); | 1051 native_context()->set_extension(*global_object); |
1048 native_context()->set_security_token(*global_object); | 1052 native_context()->set_security_token(*global_object); |
(...skipping 2411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3460 | 3464 |
3461 if (!global_proxy_template.IsEmpty()) { | 3465 if (!global_proxy_template.IsEmpty()) { |
3462 // Configure the global proxy object. | 3466 // Configure the global proxy object. |
3463 Handle<ObjectTemplateInfo> global_proxy_data = | 3467 Handle<ObjectTemplateInfo> global_proxy_data = |
3464 v8::Utils::OpenHandle(*global_proxy_template); | 3468 v8::Utils::OpenHandle(*global_proxy_template); |
3465 if (!ConfigureApiObject(global_proxy, global_proxy_data)) return false; | 3469 if (!ConfigureApiObject(global_proxy, global_proxy_data)) return false; |
3466 | 3470 |
3467 // Configure the global object. | 3471 // Configure the global object. |
3468 Handle<FunctionTemplateInfo> proxy_constructor( | 3472 Handle<FunctionTemplateInfo> proxy_constructor( |
3469 FunctionTemplateInfo::cast(global_proxy_data->constructor())); | 3473 FunctionTemplateInfo::cast(global_proxy_data->constructor())); |
3470 if (!proxy_constructor->prototype_template()->IsUndefined()) { | 3474 if (!proxy_constructor->prototype_template()->IsUndefined(isolate())) { |
3471 Handle<ObjectTemplateInfo> global_object_data( | 3475 Handle<ObjectTemplateInfo> global_object_data( |
3472 ObjectTemplateInfo::cast(proxy_constructor->prototype_template())); | 3476 ObjectTemplateInfo::cast(proxy_constructor->prototype_template())); |
3473 if (!ConfigureApiObject(global_object, global_object_data)) return false; | 3477 if (!ConfigureApiObject(global_object, global_object_data)) return false; |
3474 } | 3478 } |
3475 } | 3479 } |
3476 | 3480 |
3477 SetObjectPrototype(global_proxy, global_object); | 3481 SetObjectPrototype(global_proxy, global_object); |
3478 | 3482 |
3479 native_context()->set_initial_array_prototype( | 3483 native_context()->set_initial_array_prototype( |
3480 JSArray::cast(native_context()->array_function()->prototype())); | 3484 JSArray::cast(native_context()->array_function()->prototype())); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3567 DCHECK(raw_key->IsName()); | 3571 DCHECK(raw_key->IsName()); |
3568 // If the property is already there we skip it. | 3572 // If the property is already there we skip it. |
3569 Handle<Name> key(Name::cast(raw_key)); | 3573 Handle<Name> key(Name::cast(raw_key)); |
3570 LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR); | 3574 LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR); |
3571 CHECK_NE(LookupIterator::ACCESS_CHECK, it.state()); | 3575 CHECK_NE(LookupIterator::ACCESS_CHECK, it.state()); |
3572 if (it.IsFound()) continue; | 3576 if (it.IsFound()) continue; |
3573 // Set the property. | 3577 // Set the property. |
3574 DCHECK(properties->ValueAt(i)->IsPropertyCell()); | 3578 DCHECK(properties->ValueAt(i)->IsPropertyCell()); |
3575 Handle<PropertyCell> cell(PropertyCell::cast(properties->ValueAt(i))); | 3579 Handle<PropertyCell> cell(PropertyCell::cast(properties->ValueAt(i))); |
3576 Handle<Object> value(cell->value(), isolate()); | 3580 Handle<Object> value(cell->value(), isolate()); |
3577 if (value->IsTheHole()) continue; | 3581 if (value->IsTheHole(isolate())) continue; |
3578 PropertyDetails details = cell->property_details(); | 3582 PropertyDetails details = cell->property_details(); |
3579 DCHECK_EQ(kData, details.kind()); | 3583 DCHECK_EQ(kData, details.kind()); |
3580 JSObject::AddProperty(to, key, value, details.attributes()); | 3584 JSObject::AddProperty(to, key, value, details.attributes()); |
3581 } | 3585 } |
3582 } | 3586 } |
3583 } else { | 3587 } else { |
3584 Handle<NameDictionary> properties = | 3588 Handle<NameDictionary> properties = |
3585 Handle<NameDictionary>(from->property_dictionary()); | 3589 Handle<NameDictionary>(from->property_dictionary()); |
3586 int capacity = properties->Capacity(); | 3590 int capacity = properties->Capacity(); |
3587 for (int i = 0; i < capacity; i++) { | 3591 for (int i = 0; i < capacity; i++) { |
3588 Object* raw_key(properties->KeyAt(i)); | 3592 Object* raw_key(properties->KeyAt(i)); |
3589 if (properties->IsKey(raw_key)) { | 3593 if (properties->IsKey(raw_key)) { |
3590 DCHECK(raw_key->IsName()); | 3594 DCHECK(raw_key->IsName()); |
3591 // If the property is already there we skip it. | 3595 // If the property is already there we skip it. |
3592 Handle<Name> key(Name::cast(raw_key)); | 3596 Handle<Name> key(Name::cast(raw_key)); |
3593 LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR); | 3597 LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR); |
3594 CHECK_NE(LookupIterator::ACCESS_CHECK, it.state()); | 3598 CHECK_NE(LookupIterator::ACCESS_CHECK, it.state()); |
3595 if (it.IsFound()) continue; | 3599 if (it.IsFound()) continue; |
3596 // Set the property. | 3600 // Set the property. |
3597 Handle<Object> value = Handle<Object>(properties->ValueAt(i), | 3601 Handle<Object> value = Handle<Object>(properties->ValueAt(i), |
3598 isolate()); | 3602 isolate()); |
3599 DCHECK(!value->IsCell()); | 3603 DCHECK(!value->IsCell()); |
3600 DCHECK(!value->IsTheHole()); | 3604 DCHECK(!value->IsTheHole(isolate())); |
3601 PropertyDetails details = properties->DetailsAt(i); | 3605 PropertyDetails details = properties->DetailsAt(i); |
3602 DCHECK_EQ(kData, details.kind()); | 3606 DCHECK_EQ(kData, details.kind()); |
3603 JSObject::AddProperty(to, key, value, details.attributes()); | 3607 JSObject::AddProperty(to, key, value, details.attributes()); |
3604 } | 3608 } |
3605 } | 3609 } |
3606 } | 3610 } |
3607 } | 3611 } |
3608 | 3612 |
3609 | 3613 |
3610 void Genesis::TransferIndexedProperties(Handle<JSObject> from, | 3614 void Genesis::TransferIndexedProperties(Handle<JSObject> from, |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3810 } | 3814 } |
3811 | 3815 |
3812 | 3816 |
3813 // Called when the top-level V8 mutex is destroyed. | 3817 // Called when the top-level V8 mutex is destroyed. |
3814 void Bootstrapper::FreeThreadResources() { | 3818 void Bootstrapper::FreeThreadResources() { |
3815 DCHECK(!IsActive()); | 3819 DCHECK(!IsActive()); |
3816 } | 3820 } |
3817 | 3821 |
3818 } // namespace internal | 3822 } // namespace internal |
3819 } // namespace v8 | 3823 } // namespace v8 |
OLD | NEW |