| 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 2414 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3463 | 3467 | 
| 3464   if (!global_proxy_template.IsEmpty()) { | 3468   if (!global_proxy_template.IsEmpty()) { | 
| 3465     // Configure the global proxy object. | 3469     // Configure the global proxy object. | 
| 3466     Handle<ObjectTemplateInfo> global_proxy_data = | 3470     Handle<ObjectTemplateInfo> global_proxy_data = | 
| 3467         v8::Utils::OpenHandle(*global_proxy_template); | 3471         v8::Utils::OpenHandle(*global_proxy_template); | 
| 3468     if (!ConfigureApiObject(global_proxy, global_proxy_data)) return false; | 3472     if (!ConfigureApiObject(global_proxy, global_proxy_data)) return false; | 
| 3469 | 3473 | 
| 3470     // Configure the global object. | 3474     // Configure the global object. | 
| 3471     Handle<FunctionTemplateInfo> proxy_constructor( | 3475     Handle<FunctionTemplateInfo> proxy_constructor( | 
| 3472         FunctionTemplateInfo::cast(global_proxy_data->constructor())); | 3476         FunctionTemplateInfo::cast(global_proxy_data->constructor())); | 
| 3473     if (!proxy_constructor->prototype_template()->IsUndefined()) { | 3477     if (!proxy_constructor->prototype_template()->IsUndefined(isolate())) { | 
| 3474       Handle<ObjectTemplateInfo> global_object_data( | 3478       Handle<ObjectTemplateInfo> global_object_data( | 
| 3475           ObjectTemplateInfo::cast(proxy_constructor->prototype_template())); | 3479           ObjectTemplateInfo::cast(proxy_constructor->prototype_template())); | 
| 3476       if (!ConfigureApiObject(global_object, global_object_data)) return false; | 3480       if (!ConfigureApiObject(global_object, global_object_data)) return false; | 
| 3477     } | 3481     } | 
| 3478   } | 3482   } | 
| 3479 | 3483 | 
| 3480   SetObjectPrototype(global_proxy, global_object); | 3484   SetObjectPrototype(global_proxy, global_object); | 
| 3481 | 3485 | 
| 3482   native_context()->set_initial_array_prototype( | 3486   native_context()->set_initial_array_prototype( | 
| 3483       JSArray::cast(native_context()->array_function()->prototype())); | 3487       JSArray::cast(native_context()->array_function()->prototype())); | 
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3570         DCHECK(raw_key->IsName()); | 3574         DCHECK(raw_key->IsName()); | 
| 3571         // If the property is already there we skip it. | 3575         // If the property is already there we skip it. | 
| 3572         Handle<Name> key(Name::cast(raw_key)); | 3576         Handle<Name> key(Name::cast(raw_key)); | 
| 3573         LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR); | 3577         LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR); | 
| 3574         CHECK_NE(LookupIterator::ACCESS_CHECK, it.state()); | 3578         CHECK_NE(LookupIterator::ACCESS_CHECK, it.state()); | 
| 3575         if (it.IsFound()) continue; | 3579         if (it.IsFound()) continue; | 
| 3576         // Set the property. | 3580         // Set the property. | 
| 3577         DCHECK(properties->ValueAt(i)->IsPropertyCell()); | 3581         DCHECK(properties->ValueAt(i)->IsPropertyCell()); | 
| 3578         Handle<PropertyCell> cell(PropertyCell::cast(properties->ValueAt(i))); | 3582         Handle<PropertyCell> cell(PropertyCell::cast(properties->ValueAt(i))); | 
| 3579         Handle<Object> value(cell->value(), isolate()); | 3583         Handle<Object> value(cell->value(), isolate()); | 
| 3580         if (value->IsTheHole()) continue; | 3584         if (value->IsTheHole(isolate())) continue; | 
| 3581         PropertyDetails details = cell->property_details(); | 3585         PropertyDetails details = cell->property_details(); | 
| 3582         DCHECK_EQ(kData, details.kind()); | 3586         DCHECK_EQ(kData, details.kind()); | 
| 3583         JSObject::AddProperty(to, key, value, details.attributes()); | 3587         JSObject::AddProperty(to, key, value, details.attributes()); | 
| 3584       } | 3588       } | 
| 3585     } | 3589     } | 
| 3586   } else { | 3590   } else { | 
| 3587     Handle<NameDictionary> properties = | 3591     Handle<NameDictionary> properties = | 
| 3588         Handle<NameDictionary>(from->property_dictionary()); | 3592         Handle<NameDictionary>(from->property_dictionary()); | 
| 3589     int capacity = properties->Capacity(); | 3593     int capacity = properties->Capacity(); | 
| 3590     for (int i = 0; i < capacity; i++) { | 3594     for (int i = 0; i < capacity; i++) { | 
| 3591       Object* raw_key(properties->KeyAt(i)); | 3595       Object* raw_key(properties->KeyAt(i)); | 
| 3592       if (properties->IsKey(raw_key)) { | 3596       if (properties->IsKey(raw_key)) { | 
| 3593         DCHECK(raw_key->IsName()); | 3597         DCHECK(raw_key->IsName()); | 
| 3594         // If the property is already there we skip it. | 3598         // If the property is already there we skip it. | 
| 3595         Handle<Name> key(Name::cast(raw_key)); | 3599         Handle<Name> key(Name::cast(raw_key)); | 
| 3596         LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR); | 3600         LookupIterator it(to, key, LookupIterator::OWN_SKIP_INTERCEPTOR); | 
| 3597         CHECK_NE(LookupIterator::ACCESS_CHECK, it.state()); | 3601         CHECK_NE(LookupIterator::ACCESS_CHECK, it.state()); | 
| 3598         if (it.IsFound()) continue; | 3602         if (it.IsFound()) continue; | 
| 3599         // Set the property. | 3603         // Set the property. | 
| 3600         Handle<Object> value = Handle<Object>(properties->ValueAt(i), | 3604         Handle<Object> value = Handle<Object>(properties->ValueAt(i), | 
| 3601                                               isolate()); | 3605                                               isolate()); | 
| 3602         DCHECK(!value->IsCell()); | 3606         DCHECK(!value->IsCell()); | 
| 3603         DCHECK(!value->IsTheHole()); | 3607         DCHECK(!value->IsTheHole(isolate())); | 
| 3604         PropertyDetails details = properties->DetailsAt(i); | 3608         PropertyDetails details = properties->DetailsAt(i); | 
| 3605         DCHECK_EQ(kData, details.kind()); | 3609         DCHECK_EQ(kData, details.kind()); | 
| 3606         JSObject::AddProperty(to, key, value, details.attributes()); | 3610         JSObject::AddProperty(to, key, value, details.attributes()); | 
| 3607       } | 3611       } | 
| 3608     } | 3612     } | 
| 3609   } | 3613   } | 
| 3610 } | 3614 } | 
| 3611 | 3615 | 
| 3612 | 3616 | 
| 3613 void Genesis::TransferIndexedProperties(Handle<JSObject> from, | 3617 void Genesis::TransferIndexedProperties(Handle<JSObject> from, | 
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 3813 } | 3817 } | 
| 3814 | 3818 | 
| 3815 | 3819 | 
| 3816 // Called when the top-level V8 mutex is destroyed. | 3820 // Called when the top-level V8 mutex is destroyed. | 
| 3817 void Bootstrapper::FreeThreadResources() { | 3821 void Bootstrapper::FreeThreadResources() { | 
| 3818   DCHECK(!IsActive()); | 3822   DCHECK(!IsActive()); | 
| 3819 } | 3823 } | 
| 3820 | 3824 | 
| 3821 }  // namespace internal | 3825 }  // namespace internal | 
| 3822 }  // namespace v8 | 3826 }  // namespace v8 | 
| OLD | NEW | 
|---|