55 : data_(source), length_(length) {
56 if (bootstrapper->delete_these_non_arrays_on_tear_down_ ==
NULL) {
57 bootstrapper->delete_these_non_arrays_on_tear_down_ =
new List<char*>(2);
61 bootstrapper->delete_these_non_arrays_on_tear_down_->
62 Add(reinterpret_cast<char*>(
this));
66 Bootstrapper::Bootstrapper()
68 extensions_cache_(
Script::TYPE_EXTENSION),
69 delete_these_non_arrays_on_tear_down_(
NULL),
70 delete_these_arrays_on_tear_down_(
NULL) {
76 Isolate* isolate = Isolate::Current();
79 if (heap->natives_source_cache()->get(index)->IsUndefined()) {
88 heap->natives_source_cache()->set(index, *source_code);
90 Handle<Object> cached_source(heap->natives_source_cache()->get(index));
96 extensions_cache_.Initialize(create_heap_objects);
104 char*
memory =
new char[bytes];
105 if (memory !=
NULL) {
106 if (delete_these_arrays_on_tear_down_ ==
NULL) {
107 delete_these_arrays_on_tear_down_ =
new List<char*>(2);
109 delete_these_arrays_on_tear_down_->
Add(memory);
116 if (delete_these_non_arrays_on_tear_down_ !=
NULL) {
117 int len = delete_these_non_arrays_on_tear_down_->length();
119 for (
int i = 0; i < len; i++) {
120 delete delete_these_non_arrays_on_tear_down_->
at(i);
121 delete_these_non_arrays_on_tear_down_->
at(i) =
NULL;
123 delete delete_these_non_arrays_on_tear_down_;
124 delete_these_non_arrays_on_tear_down_ =
NULL;
127 if (delete_these_arrays_on_tear_down_ !=
NULL) {
128 int len = delete_these_arrays_on_tear_down_->length();
130 for (
int i = 0; i < len; i++) {
131 delete[] delete_these_arrays_on_tear_down_->
at(i);
132 delete_these_arrays_on_tear_down_->
at(i) =
NULL;
134 delete delete_these_arrays_on_tear_down_;
135 delete_these_arrays_on_tear_down_ =
NULL;
138 extensions_cache_.Initialize(
false);
203 void InitializeExperimentalGlobal();
206 void InstallNativeFunctions();
207 void InstallExperimentalNativeFunctions();
208 bool InstallNatives();
209 bool InstallExperimentalNatives();
210 void InstallBuiltinFunctionIds();
211 void InstallJSFunctionResultCaches();
212 void InitializeNormalizedMapCaches();
214 enum ExtensionTraversalState {
215 UNVISITED, VISITED, INSTALLED
218 class ExtensionStates {
221 ExtensionTraversalState get_state(RegisteredExtension* extension);
222 void set_state(RegisteredExtension* extension,
223 ExtensionTraversalState state);
231 static bool InstallExtensions(Handle<Context> native_context,
233 static bool InstallExtension(
const char* name,
234 ExtensionStates* extension_states);
236 ExtensionStates* extension_states);
237 static void InstallSpecialObjects(Handle<Context> native_context);
238 bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins);
239 bool ConfigureApiObject(Handle<JSObject>
object,
240 Handle<ObjectTemplateInfo> object_template);
246 void TransferObject(Handle<JSObject> from, Handle<JSObject> to);
247 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to);
248 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to);
250 enum PrototypePropertyMode {
252 ADD_READONLY_PROTOTYPE,
253 ADD_WRITEABLE_PROTOTYPE
256 Handle<Map> CreateFunctionMap(PrototypePropertyMode prototype_mode);
258 void SetFunctionInstanceDescriptor(Handle<Map> map,
259 PrototypePropertyMode prototypeMode);
260 void MakeFunctionInstancePrototypeWritable();
262 Handle<Map> CreateStrictModeFunctionMap(
263 PrototypePropertyMode prototype_mode,
264 Handle<JSFunction> empty_function);
266 void SetStrictFunctionInstanceDescriptor(Handle<Map> map,
267 PrototypePropertyMode propertyMode);
269 static bool CompileBuiltin(Isolate* isolate,
int index);
270 static bool CompileExperimentalBuiltin(Isolate* isolate,
int index);
271 static bool CompileNative(Vector<const char> name, Handle<String> source);
272 static bool CompileScriptCached(Vector<const char> name,
273 Handle<String> source,
274 SourceCodeCache* cache,
276 Handle<Context> top_context,
277 bool use_runtime_context);
279 Handle<Context> result_;
285 Handle<Map> function_instance_map_writable_prototype_;
286 Handle<Map> strict_mode_function_instance_map_writable_prototype_;
287 Handle<JSFunction> throw_type_error_function;
289 BootstrapperActive active_;
295 extensions_cache_.Iterate(v);
296 v->Synchronize(VisitorSynchronization::kExtensions);
307 Genesis genesis(isolate, global_object, global_template, extensions);
308 env = genesis.result();
309 if (!env.is_null()) {
320 Factory* factory =
object->GetIsolate()->factory();
323 new_to_map->set_prototype(*proto);
324 object->set_map(*new_to_map);
329 Factory* factory = env->GetIsolate()->factory();
331 global_proxy->set_native_context(*factory->null_value());
332 SetObjectPrototype(global_proxy, factory->null_value());
333 env->set_global_proxy(env->global_object());
334 env->global_object()->set_global_receiver(env->global_object());
340 env->global_object()->set_global_receiver(*global_proxy);
341 env->set_global_proxy(*global_proxy);
343 global_proxy->set_native_context(*env);
353 bool is_ecma_native) {
354 Isolate* isolate = target->GetIsolate();
367 if (target->IsJSBuiltinsObject()) {
375 target, symbol,
function, attributes));
376 if (is_ecma_native) {
377 function->shared()->set_instance_class_name(*symbol);
379 function->shared()->set_native(
true);
384 void Genesis::SetFunctionInstanceDescriptor(
385 Handle<Map> map, PrototypePropertyMode prototypeMode) {
386 int size = (prototypeMode == DONT_ADD_PROTOTYPE) ? 4 : 5;
387 Handle<DescriptorArray> descriptors(factory()->NewDescriptorArray(0, size));
388 DescriptorArray::WhitenessWitness witness(*descriptors);
390 Handle<Foreign> length(factory()->NewForeign(&Accessors::FunctionLength));
391 Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName));
392 Handle<Foreign> args(factory()->NewForeign(&Accessors::FunctionArguments));
393 Handle<Foreign> caller(factory()->NewForeign(&Accessors::FunctionCaller));
394 Handle<Foreign> prototype;
395 if (prototypeMode != DONT_ADD_PROTOTYPE) {
396 prototype = factory()->
NewForeign(&Accessors::FunctionPrototype);
400 map->set_instance_descriptors(*descriptors);
403 CallbacksDescriptor d(*factory()->length_symbol(), *length, attribs);
404 map->AppendDescriptor(&d, witness);
407 CallbacksDescriptor d(*factory()->name_symbol(), *name, attribs);
408 map->AppendDescriptor(&d, witness);
411 CallbacksDescriptor d(*factory()->arguments_symbol(), *args, attribs);
412 map->AppendDescriptor(&d, witness);
415 CallbacksDescriptor d(*factory()->caller_symbol(), *caller, attribs);
416 map->AppendDescriptor(&d, witness);
418 if (prototypeMode != DONT_ADD_PROTOTYPE) {
420 if (prototypeMode == ADD_WRITEABLE_PROTOTYPE) {
423 CallbacksDescriptor d(*factory()->prototype_symbol(), *prototype, attribs);
424 map->AppendDescriptor(&d, witness);
429 Handle<Map> Genesis::CreateFunctionMap(PrototypePropertyMode prototype_mode) {
431 SetFunctionInstanceDescriptor(map, prototype_mode);
432 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE);
437 Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) {
443 Handle<Map> function_instance_map =
444 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE);
445 native_context()->set_function_instance_map(*function_instance_map);
449 Handle<Map> function_without_prototype_map =
450 CreateFunctionMap(DONT_ADD_PROTOTYPE);
451 native_context()->set_function_without_prototype_map(
452 *function_without_prototype_map);
457 Handle<Map> function_map = CreateFunctionMap(ADD_READONLY_PROTOTYPE);
458 native_context()->set_function_map(*function_map);
462 function_instance_map_writable_prototype_ =
463 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE);
465 Factory* factory = isolate->factory();
466 Heap* heap = isolate->heap();
468 Handle<String> object_name = Handle<String>(heap->Object_symbol());
471 Handle<JSFunction> object_fun =
472 factory->NewFunction(object_name, factory->null_value());
473 Handle<Map> object_function_map =
475 object_fun->set_initial_map(*object_function_map);
476 object_function_map->set_constructor(*object_fun);
478 native_context()->set_object_function(*object_fun);
481 Handle<JSObject> prototype = factory->NewJSObject(
482 isolate->object_function(),
485 native_context()->set_initial_object_prototype(*prototype);
491 Handle<String> symbol = factory->LookupAsciiSymbol(
"Empty");
492 Handle<JSFunction> empty_function =
493 factory->NewFunctionWithoutPrototype(symbol,
CLASSIC_MODE);
497 Handle<Code>(isolate->builtins()->builtin(
498 Builtins::kEmptyFunction));
499 empty_function->set_code(*code);
500 empty_function->shared()->set_code(*code);
501 Handle<String> source = factory->NewStringFromAscii(
CStrVector(
"() {}"));
502 Handle<Script> script = factory->NewScript(source);
504 empty_function->shared()->set_script(*script);
505 empty_function->shared()->set_start_position(0);
506 empty_function->shared()->set_end_position(source->length());
507 empty_function->shared()->DontAdaptArguments();
510 native_context()->function_map()->set_prototype(*empty_function);
511 native_context()->function_instance_map()->set_prototype(*empty_function);
512 native_context()->function_without_prototype_map()->
513 set_prototype(*empty_function);
514 function_instance_map_writable_prototype_->set_prototype(*empty_function);
517 Handle<Map> empty_function_map = CreateFunctionMap(DONT_ADD_PROTOTYPE);
518 empty_function_map->set_prototype(
519 native_context()->object_function()->prototype());
520 empty_function->set_map(*empty_function_map);
521 return empty_function;
525 void Genesis::SetStrictFunctionInstanceDescriptor(
526 Handle<Map> map, PrototypePropertyMode prototypeMode) {
527 int size = (prototypeMode == DONT_ADD_PROTOTYPE) ? 4 : 5;
528 Handle<DescriptorArray> descriptors(factory()->NewDescriptorArray(0, size));
529 DescriptorArray::WhitenessWitness witness(*descriptors);
531 Handle<Foreign> length(factory()->NewForeign(&Accessors::FunctionLength));
532 Handle<Foreign> name(factory()->NewForeign(&Accessors::FunctionName));
533 Handle<AccessorPair> arguments(factory()->NewAccessorPair());
534 Handle<AccessorPair> caller(factory()->NewAccessorPair());
535 Handle<Foreign> prototype;
536 if (prototypeMode != DONT_ADD_PROTOTYPE) {
537 prototype = factory()->NewForeign(&Accessors::FunctionPrototype);
541 map->set_instance_descriptors(*descriptors);
544 CallbacksDescriptor d(*factory()->length_symbol(), *length, attribs);
545 map->AppendDescriptor(&d, witness);
548 CallbacksDescriptor d(*factory()->name_symbol(), *name, attribs);
549 map->AppendDescriptor(&d, witness);
552 CallbacksDescriptor d(*factory()->arguments_symbol(), *arguments, attribs);
553 map->AppendDescriptor(&d, witness);
556 CallbacksDescriptor d(*factory()->caller_symbol(), *caller, attribs);
557 map->AppendDescriptor(&d, witness);
559 if (prototypeMode != DONT_ADD_PROTOTYPE) {
561 if (prototypeMode != ADD_WRITEABLE_PROTOTYPE) {
564 CallbacksDescriptor d(*factory()->prototype_symbol(), *prototype, attribs);
565 map->AppendDescriptor(&d, witness);
571 Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() {
572 if (throw_type_error_function.is_null()) {
573 Handle<String> name = factory()->LookupAsciiSymbol(
"ThrowTypeError");
574 throw_type_error_function =
575 factory()->NewFunctionWithoutPrototype(name,
CLASSIC_MODE);
576 Handle<Code>
code(isolate()->builtins()->builtin(
577 Builtins::kStrictModePoisonPill));
578 throw_type_error_function->set_map(
579 native_context()->function_map());
580 throw_type_error_function->set_code(*code);
581 throw_type_error_function->shared()->set_code(*code);
582 throw_type_error_function->shared()->DontAdaptArguments();
586 return throw_type_error_function;
590 Handle<Map> Genesis::CreateStrictModeFunctionMap(
591 PrototypePropertyMode prototype_mode,
592 Handle<JSFunction> empty_function) {
594 SetStrictFunctionInstanceDescriptor(map, prototype_mode);
595 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE);
596 map->set_prototype(*empty_function);
601 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) {
603 Handle<Map> strict_mode_function_instance_map =
604 CreateStrictModeFunctionMap(ADD_WRITEABLE_PROTOTYPE, empty);
605 native_context()->set_strict_mode_function_instance_map(
606 *strict_mode_function_instance_map);
609 Handle<Map> strict_mode_function_without_prototype_map =
610 CreateStrictModeFunctionMap(DONT_ADD_PROTOTYPE, empty);
611 native_context()->set_strict_mode_function_without_prototype_map(
612 *strict_mode_function_without_prototype_map);
617 Handle<Map> strict_mode_function_map =
618 CreateStrictModeFunctionMap(ADD_READONLY_PROTOTYPE, empty);
619 native_context()->set_strict_mode_function_map(
620 *strict_mode_function_map);
624 strict_mode_function_instance_map_writable_prototype_ =
625 CreateStrictModeFunctionMap(ADD_WRITEABLE_PROTOTYPE, empty);
628 PoisonArgumentsAndCaller(strict_mode_function_instance_map);
629 PoisonArgumentsAndCaller(strict_mode_function_without_prototype_map);
630 PoisonArgumentsAndCaller(strict_mode_function_map);
631 PoisonArgumentsAndCaller(
632 strict_mode_function_instance_map_writable_prototype_);
636 static void SetAccessors(Handle<Map> map,
638 Handle<JSFunction> func) {
639 DescriptorArray* descs = map->instance_descriptors();
640 int number = descs->SearchWithCache(*name, *map);
642 accessors->set_getter(*func);
643 accessors->set_setter(*func);
647 void Genesis::PoisonArgumentsAndCaller(Handle<Map> map) {
648 SetAccessors(map, factory()->arguments_symbol(), GetThrowTypeErrorFunction());
649 SetAccessors(map, factory()->caller_symbol(), GetThrowTypeErrorFunction());
653 static void AddToWeakNativeContextList(Context* context) {
654 ASSERT(context->IsNativeContext());
655 Heap* heap = context->GetIsolate()->heap();
660 for (
Object* current = heap->native_contexts_list();
661 !current->IsUndefined();
663 ASSERT(current != context);
668 heap->set_native_contexts_list(context);
672 void Genesis::CreateRoots() {
678 *factory()->NewNativeContext()));
679 AddToWeakNativeContextList(*native_context_);
680 isolate()->set_context(*native_context());
685 native_context()->set_message_listeners(*listeners.
value());
690 Handle<JSGlobalProxy> Genesis::CreateNewGlobals(
692 Handle<Object> global_object,
693 Handle<GlobalObject>* inner_global_out) {
707 Handle<JSFunction> js_global_function;
708 Handle<ObjectTemplateInfo> js_global_template;
709 if (!global_template.
IsEmpty()) {
711 Handle<ObjectTemplateInfo> data =
712 v8::Utils::OpenHandle(*global_template);
713 Handle<FunctionTemplateInfo> global_constructor =
714 Handle<FunctionTemplateInfo>(
716 Handle<Object> proto_template(global_constructor->prototype_template());
717 if (!proto_template->IsUndefined()) {
723 if (js_global_template.is_null()) {
724 Handle<String> name = Handle<String>(heap()->empty_symbol());
725 Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin(
726 Builtins::kIllegal));
732 Handle<JSObject> prototype =
737 prototype, factory()->constructor_symbol(),
738 isolate()->object_function(),
NONE));
740 Handle<FunctionTemplateInfo> js_global_constructor(
743 factory()->CreateApiFunction(js_global_constructor,
744 factory()->InnerGlobalObject);
747 js_global_function->initial_map()->set_is_hidden_prototype();
748 js_global_function->initial_map()->set_dictionary_map(
true);
749 Handle<GlobalObject> inner_global =
750 factory()->NewGlobalObject(js_global_function);
751 if (inner_global_out !=
NULL) {
752 *inner_global_out = inner_global;
756 Handle<JSFunction> global_proxy_function;
757 if (global_template.
IsEmpty()) {
758 Handle<String> name = Handle<String>(heap()->empty_symbol());
759 Handle<Code> code = Handle<Code>(isolate()->builtins()->builtin(
760 Builtins::kIllegal));
761 global_proxy_function =
765 Handle<ObjectTemplateInfo> data =
766 v8::Utils::OpenHandle(*global_template);
767 Handle<FunctionTemplateInfo> global_constructor(
769 global_proxy_function =
770 factory()->CreateApiFunction(global_constructor,
771 factory()->OuterGlobalObject);
774 Handle<String> global_name = factory()->LookupAsciiSymbol(
"global");
775 global_proxy_function->shared()->set_instance_class_name(*global_name);
776 global_proxy_function->initial_map()->set_is_access_check_needed(
true);
781 if (global_object.location() !=
NULL) {
782 ASSERT(global_object->IsJSGlobalProxy());
784 global_proxy_function,
785 Handle<JSGlobalProxy>::cast(global_object));
788 factory()->NewJSObject(global_proxy_function,
TENURED));
793 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global,
794 Handle<JSGlobalProxy> global_proxy) {
796 inner_global->set_native_context(*native_context());
797 inner_global->set_global_context(*native_context());
798 inner_global->set_global_receiver(*global_proxy);
799 global_proxy->set_native_context(*native_context());
800 native_context()->set_global_proxy(*global_proxy);
804 void Genesis::HookUpInnerGlobal(Handle<GlobalObject> inner_global) {
805 Handle<GlobalObject> inner_global_from_snapshot(
807 Handle<JSBuiltinsObject> builtins_global(native_context_->builtins());
808 native_context_->set_extension(*inner_global);
809 native_context_->set_global_object(*inner_global);
810 native_context_->set_security_token(*inner_global);
814 factory()->LookupAsciiSymbol(
"global"),
819 TransferNamedProperties(inner_global_from_snapshot, inner_global);
820 TransferIndexedProperties(inner_global_from_snapshot, inner_global);
826 bool Genesis::InitializeGlobal(Handle<GlobalObject> inner_global,
827 Handle<JSFunction> empty_function) {
830 native_context()->set_closure(*empty_function);
831 native_context()->set_previous(
NULL);
833 native_context()->set_extension(*inner_global);
834 native_context()->set_global_object(*inner_global);
839 native_context()->set_security_token(*inner_global);
841 Isolate* isolate = inner_global->GetIsolate();
842 Factory* factory = isolate->factory();
843 Heap* heap = isolate->heap();
845 Handle<String> object_name = Handle<String>(heap->Object_symbol());
848 inner_global, object_name,
851 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object());
855 empty_function, Builtins::kIllegal,
true);
858 Handle<JSFunction> array_function =
860 isolate->initial_object_prototype(),
861 Builtins::kArrayCode,
true);
862 array_function->shared()->set_construct_stub(
863 isolate->builtins()->builtin(Builtins::kArrayConstructCode));
864 array_function->shared()->DontAdaptArguments();
868 array_function->shared()->set_length(1);
870 Handle<Map> initial_map(array_function->initial_map());
871 Handle<DescriptorArray> array_descriptors(
872 factory->NewDescriptorArray(0, 1));
873 DescriptorArray::WhitenessWitness witness(*array_descriptors);
875 Handle<Foreign> array_length(factory->NewForeign(&Accessors::ArrayLength));
878 initial_map->set_instance_descriptors(*array_descriptors);
881 CallbacksDescriptor d(*factory->length_symbol(), *array_length, attribs);
882 array_function->initial_map()->AppendDescriptor(&d, witness);
889 native_context()->set_array_function(*array_function);
893 Handle<JSFunction> number_fun =
895 isolate->initial_object_prototype(),
896 Builtins::kIllegal,
true);
897 native_context()->set_number_function(*number_fun);
901 Handle<JSFunction> boolean_fun =
903 isolate->initial_object_prototype(),
904 Builtins::kIllegal,
true);
905 native_context()->set_boolean_function(*boolean_fun);
909 Handle<JSFunction> string_fun =
911 isolate->initial_object_prototype(),
912 Builtins::kIllegal,
true);
913 string_fun->shared()->set_construct_stub(
914 isolate->builtins()->builtin(Builtins::kStringConstructCode));
915 native_context()->set_string_function(*string_fun);
917 Handle<Map> string_map =
918 Handle<Map>(native_context()->string_function()->initial_map());
919 Handle<DescriptorArray> string_descriptors(
920 factory->NewDescriptorArray(0, 1));
921 DescriptorArray::WhitenessWitness witness(*string_descriptors);
923 Handle<Foreign> string_length(
924 factory->NewForeign(&Accessors::StringLength));
927 string_map->set_instance_descriptors(*string_descriptors);
930 CallbacksDescriptor d(*factory->length_symbol(), *string_length, attribs);
931 string_map->AppendDescriptor(&d, witness);
937 Handle<JSFunction> date_fun =
939 isolate->initial_object_prototype(),
940 Builtins::kIllegal,
true);
942 native_context()->set_date_function(*date_fun);
948 Handle<JSFunction> regexp_fun =
950 isolate->initial_object_prototype(),
951 Builtins::kIllegal,
true);
952 native_context()->set_regexp_function(*regexp_fun);
954 ASSERT(regexp_fun->has_initial_map());
955 Handle<Map> initial_map(regexp_fun->initial_map());
957 ASSERT_EQ(0, initial_map->inobject_properties());
961 Handle<DescriptorArray> descriptors = factory->NewDescriptorArray(0, 5);
962 DescriptorArray::WhitenessWitness witness(*descriptors);
963 initial_map->set_instance_descriptors(*descriptors);
967 FieldDescriptor field(heap->source_symbol(),
970 initial_map->AppendDescriptor(&field, witness);
974 FieldDescriptor field(heap->global_symbol(),
977 initial_map->AppendDescriptor(&field, witness);
981 FieldDescriptor field(heap->ignore_case_symbol(),
984 initial_map->AppendDescriptor(&field, witness);
988 FieldDescriptor field(heap->multiline_symbol(),
991 initial_map->AppendDescriptor(&field, witness);
995 PropertyAttributes writable =
997 FieldDescriptor field(heap->last_index_symbol(),
1000 initial_map->AppendDescriptor(&field, witness);
1003 initial_map->set_inobject_properties(5);
1004 initial_map->set_pre_allocated_property_fields(5);
1005 initial_map->set_unused_property_fields(0);
1006 initial_map->set_instance_size(
1011 Handle<Map> proto_map = factory->CopyMap(initial_map);
1012 proto_map->set_prototype(native_context()->initial_object_prototype());
1013 Handle<JSObject> proto = factory->NewJSObjectFromMap(proto_map);
1015 heap->query_colon_symbol());
1017 heap->false_value());
1019 heap->false_value());
1021 heap->false_value());
1025 initial_map->set_prototype(*proto);
1026 factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto),
1028 JSRegExp::Flags(0), 0);
1032 Handle<String> name = factory->NewStringFromAscii(
CStrVector(
"JSON"));
1033 Handle<JSFunction> cons = factory->NewFunction(name,
1034 factory->the_hole_value());
1035 { MaybeObject* result = cons->SetInstancePrototype(
1036 native_context()->initial_object_prototype());
1037 if (result->IsFailure())
return false;
1039 cons->SetInstanceClassName(*name);
1040 Handle<JSObject> json_object = factory->NewJSObject(cons,
TENURED);
1041 ASSERT(json_object->IsJSObject());
1045 native_context()->set_json_object(*json_object);
1052 Handle<String> symbol = factory->LookupAsciiSymbol(
"Arguments");
1053 Handle<Code> code = Handle<Code>(
1054 isolate->builtins()->builtin(Builtins::kIllegal));
1055 Handle<JSObject> prototype =
1057 JSObject::cast(native_context()->object_function()->prototype()));
1059 Handle<JSFunction>
function =
1060 factory->NewFunctionWithPrototype(symbol,
1066 ASSERT(!function->has_initial_map());
1067 function->shared()->set_instance_class_name(*symbol);
1068 function->shared()->set_expected_nof_properties(2);
1069 Handle<JSObject> result = factory->NewJSObject(
function);
1071 native_context()->set_arguments_boilerplate(*result);
1076 result, factory->length_symbol(),
1077 factory->undefined_value(),
DONT_ENUM));
1080 result, factory->callee_symbol(),
1081 factory->undefined_value(),
DONT_ENUM));
1084 LookupResult lookup(isolate);
1085 result->LocalLookup(heap->callee_symbol(), &lookup);
1086 ASSERT(lookup.IsField());
1089 result->LocalLookup(heap->length_symbol(), &lookup);
1090 ASSERT(lookup.IsField());
1097 ASSERT(result->HasFastProperties());
1098 ASSERT(result->HasFastObjectElements());
1104 Handle<FixedArray> elements = factory->NewFixedArray(2);
1105 elements->set_map(heap->non_strict_arguments_elements_map());
1106 Handle<FixedArray> array;
1107 array = factory->NewFixedArray(0);
1108 elements->set(0, *array);
1109 array = factory->NewFixedArray(0);
1110 elements->set(1, *array);
1112 Handle<Map> old_map(native_context()->arguments_boilerplate()->map());
1113 Handle<Map> new_map = factory->CopyMap(old_map);
1114 new_map->set_pre_allocated_property_fields(2);
1115 Handle<JSObject> result = factory->NewJSObjectFromMap(new_map);
1119 result->set_elements(*elements);
1120 ASSERT(result->HasNonStrictArgumentsElements());
1121 native_context()->set_aliased_arguments_boilerplate(*result);
1125 const PropertyAttributes attributes =
1129 Handle<AccessorPair> callee = factory->NewAccessorPair();
1130 Handle<AccessorPair> caller = factory->NewAccessorPair();
1132 Handle<JSFunction> throw_function =
1133 GetThrowTypeErrorFunction();
1136 callee->set_getter(*throw_function);
1137 callee->set_setter(*throw_function);
1138 caller->set_getter(*throw_function);
1139 caller->set_setter(*throw_function);
1145 Handle<DescriptorArray> descriptors = factory->NewDescriptorArray(0, 3);
1146 DescriptorArray::WhitenessWitness witness(*descriptors);
1147 map->set_instance_descriptors(*descriptors);
1150 FieldDescriptor d(*factory->length_symbol(), 0,
DONT_ENUM);
1151 map->AppendDescriptor(&d, witness);
1154 CallbacksDescriptor d(*factory->callee_symbol(),
1157 map->AppendDescriptor(&d, witness);
1160 CallbacksDescriptor d(*factory->caller_symbol(),
1163 map->AppendDescriptor(&d, witness);
1166 map->set_function_with_prototype(
true);
1167 map->set_prototype(native_context()->object_function()->prototype());
1168 map->set_pre_allocated_property_fields(1);
1169 map->set_inobject_properties(1);
1172 map->set_constructor(
1173 native_context()->arguments_boilerplate()->map()->constructor());
1176 Handle<JSObject> result = factory->NewJSObjectFromMap(map);
1177 native_context()->set_strict_mode_arguments_boilerplate(*result);
1182 result, factory->length_symbol(),
1183 factory->undefined_value(),
DONT_ENUM));
1186 LookupResult lookup(isolate);
1187 result->LocalLookup(heap->length_symbol(), &lookup);
1188 ASSERT(lookup.IsField());
1194 ASSERT(result->HasFastProperties());
1195 ASSERT(result->HasFastObjectElements());
1201 Handle<Code> code = Handle<Code>(
1202 isolate->builtins()->builtin(Builtins::kIllegal));
1203 Handle<JSFunction> context_extension_fun =
1204 factory->NewFunction(factory->empty_symbol(),
1210 Handle<String> name = factory->LookupAsciiSymbol(
"context_extension");
1211 context_extension_fun->shared()->set_instance_class_name(*name);
1212 native_context()->set_context_extension_function(*context_extension_fun);
1219 Handle<Code>(isolate->builtins()->builtin(
1220 Builtins::kHandleApiCallAsFunction));
1221 Handle<JSFunction> delegate =
1224 native_context()->set_call_as_function_delegate(*delegate);
1225 delegate->shared()->DontAdaptArguments();
1231 Handle<Code>(isolate->builtins()->builtin(
1232 Builtins::kHandleApiCallAsConstructor));
1233 Handle<JSFunction> delegate =
1236 native_context()->set_call_as_constructor_delegate(*delegate);
1237 delegate->shared()->DontAdaptArguments();
1241 native_context()->set_out_of_memory(heap->false_value());
1244 native_context()->set_data(heap->undefined_value());
1248 Handle<ByteArray> zeroed_byte_array(
1250 native_context()->set_random_seed(*zeroed_byte_array);
1257 void Genesis::InitializeExperimentalGlobal() {
1258 Handle<JSObject> global = Handle<JSObject>(native_context()->global_object());
1262 if (FLAG_harmony_collections) {
1264 Handle<JSObject> prototype =
1265 factory()->NewJSObject(isolate()->object_function(),
TENURED);
1267 prototype, Builtins::kIllegal,
true);
1270 Handle<JSObject> prototype =
1271 factory()->NewJSObject(isolate()->object_function(),
TENURED);
1273 prototype, Builtins::kIllegal,
true);
1276 Handle<JSObject> prototype =
1277 factory()->NewJSObject(isolate()->object_function(),
TENURED);
1279 prototype, Builtins::kIllegal,
true);
1285 bool Genesis::CompileBuiltin(Isolate* isolate,
int index) {
1287 Handle<String> source_code =
1288 isolate->bootstrapper()->NativesSourceLookup(index);
1289 return CompileNative(name, source_code);
1293 bool Genesis::CompileExperimentalBuiltin(Isolate* isolate,
int index) {
1295 Factory* factory = isolate->factory();
1296 Handle<String> source_code =
1297 factory->NewStringFromAscii(
1299 return CompileNative(name, source_code);
1303 bool Genesis::CompileNative(Vector<const char> name, Handle<String> source) {
1305 Isolate* isolate = source->GetIsolate();
1306 #ifdef ENABLE_DEBUGGER_SUPPORT
1307 isolate->debugger()->set_compiling_natives(
true);
1312 StackLimitCheck
check(Isolate::Current());
1313 if (
check.HasOverflowed())
return false;
1315 bool result = CompileScriptCached(name,
1319 Handle<Context>(isolate->context()),
1321 ASSERT(isolate->has_pending_exception() != result);
1322 if (!result) isolate->clear_pending_exception();
1323 #ifdef ENABLE_DEBUGGER_SUPPORT
1324 isolate->debugger()->set_compiling_natives(
false);
1330 bool Genesis::CompileScriptCached(Vector<const char> name,
1331 Handle<String> source,
1332 SourceCodeCache* cache,
1334 Handle<Context> top_context,
1335 bool use_runtime_context) {
1336 Factory* factory = source->GetIsolate()->factory();
1338 Handle<SharedFunctionInfo> function_info;
1342 if (cache ==
NULL || !cache->Lookup(name, &function_info)) {
1343 ASSERT(source->IsAsciiRepresentation());
1344 Handle<String> script_name = factory->NewStringFromUtf8(name);
1355 if (function_info.is_null())
return false;
1356 if (cache !=
NULL) cache->Add(name, function_info);
1362 ASSERT(top_context->IsNativeContext());
1363 Handle<Context> context =
1364 Handle<Context>(use_runtime_context
1365 ? Handle<Context>(top_context->runtime_context())
1367 Handle<JSFunction> fun =
1368 factory->NewFunctionFromSharedFunctionInfo(function_info, context);
1372 Handle<Object> receiver =
1373 Handle<Object>(use_runtime_context
1374 ? top_context->builtins()
1375 : top_context->global_object());
1376 bool has_pending_exception;
1378 if (has_pending_exception)
return false;
1383 #define INSTALL_NATIVE(Type, name, var) \
1384 Handle<String> var##_name = factory()->LookupAsciiSymbol(name); \
1385 Object* var##_native = \
1386 native_context()->builtins()->GetPropertyNoExceptionThrown( \
1388 native_context()->set_##var(Type::cast(var##_native));
1391 void Genesis::InstallNativeFunctions() {
1396 INSTALL_NATIVE(JSFunction,
"ToDetailString", to_detail_string_fun);
1404 configure_instance_fun);
1405 INSTALL_NATIVE(JSFunction,
"GetStackTraceLine", get_stack_trace_line_fun);
1408 to_complete_property_descriptor);
1411 void Genesis::InstallExperimentalNativeFunctions() {
1412 if (FLAG_harmony_proxies) {
1420 #undef INSTALL_NATIVE
1423 bool Genesis::InstallNatives() {
1429 Handle<Code> code = Handle<Code>(
1430 isolate()->builtins()->builtin(Builtins::kIllegal));
1431 Handle<JSFunction> builtins_fun =
1432 factory()->NewFunction(factory()->empty_symbol(),
1436 Handle<String> name = factory()->LookupAsciiSymbol(
"builtins");
1437 builtins_fun->shared()->set_instance_class_name(*name);
1438 builtins_fun->initial_map()->set_dictionary_map(
true);
1439 builtins_fun->initial_map()->set_prototype(heap()->null_value());
1442 Handle<JSBuiltinsObject> builtins =
1444 builtins->set_builtins(*builtins);
1445 builtins->set_native_context(*native_context());
1446 builtins->set_global_context(*native_context());
1447 builtins->set_global_receiver(*builtins);
1453 static const PropertyAttributes attributes =
1455 Handle<String> global_symbol = factory()->LookupAsciiSymbol(
"global");
1456 Handle<Object> global_obj(native_context()->global_object());
1459 builtins, global_symbol, global_obj, attributes));
1463 set_builtins(*builtins);
1466 Handle<JSFunction> bridge =
1467 factory()->NewFunction(factory()->empty_symbol(),
1468 factory()->undefined_value());
1469 ASSERT(bridge->context() == *isolate()->native_context());
1472 Handle<Context> context =
1474 context->set_global_object(*builtins);
1476 native_context()->set_runtime_context(*context);
1480 Handle<JSFunction> script_fun =
1482 isolate()->initial_object_prototype(),
1483 Builtins::kIllegal,
false);
1484 Handle<JSObject> prototype =
1485 factory()->NewJSObject(isolate()->object_function(),
TENURED);
1487 native_context()->set_script_function(*script_fun);
1489 Handle<Map> script_map = Handle<Map>(script_fun->initial_map());
1491 Handle<DescriptorArray> script_descriptors(
1492 factory()->NewDescriptorArray(0, 13));
1493 DescriptorArray::WhitenessWitness witness(*script_descriptors);
1495 Handle<Foreign> script_source(
1496 factory()->NewForeign(&Accessors::ScriptSource));
1497 Handle<Foreign> script_name(factory()->NewForeign(&Accessors::ScriptName));
1498 Handle<String> id_symbol(factory()->LookupAsciiSymbol(
"id"));
1499 Handle<Foreign> script_id(factory()->NewForeign(&Accessors::ScriptId));
1500 Handle<String> line_offset_symbol(
1501 factory()->LookupAsciiSymbol(
"line_offset"));
1502 Handle<Foreign> script_line_offset(
1503 factory()->NewForeign(&Accessors::ScriptLineOffset));
1504 Handle<String> column_offset_symbol(
1505 factory()->LookupAsciiSymbol(
"column_offset"));
1506 Handle<Foreign> script_column_offset(
1507 factory()->NewForeign(&Accessors::ScriptColumnOffset));
1508 Handle<String> data_symbol(factory()->LookupAsciiSymbol(
"data"));
1509 Handle<Foreign> script_data(factory()->NewForeign(&Accessors::ScriptData));
1510 Handle<String> type_symbol(factory()->LookupAsciiSymbol(
"type"));
1511 Handle<Foreign> script_type(factory()->NewForeign(&Accessors::ScriptType));
1512 Handle<String> compilation_type_symbol(
1513 factory()->LookupAsciiSymbol(
"compilation_type"));
1514 Handle<Foreign> script_compilation_type(
1515 factory()->NewForeign(&Accessors::ScriptCompilationType));
1516 Handle<String> line_ends_symbol(factory()->LookupAsciiSymbol(
"line_ends"));
1517 Handle<Foreign> script_line_ends(
1518 factory()->NewForeign(&Accessors::ScriptLineEnds));
1519 Handle<String> context_data_symbol(
1520 factory()->LookupAsciiSymbol(
"context_data"));
1521 Handle<Foreign> script_context_data(
1522 factory()->NewForeign(&Accessors::ScriptContextData));
1523 Handle<String> eval_from_script_symbol(
1524 factory()->LookupAsciiSymbol(
"eval_from_script"));
1525 Handle<Foreign> script_eval_from_script(
1526 factory()->NewForeign(&Accessors::ScriptEvalFromScript));
1527 Handle<String> eval_from_script_position_symbol(
1528 factory()->LookupAsciiSymbol(
"eval_from_script_position"));
1529 Handle<Foreign> script_eval_from_script_position(
1530 factory()->NewForeign(&Accessors::ScriptEvalFromScriptPosition));
1531 Handle<String> eval_from_function_name_symbol(
1532 factory()->LookupAsciiSymbol(
"eval_from_function_name"));
1533 Handle<Foreign> script_eval_from_function_name(
1534 factory()->NewForeign(&Accessors::ScriptEvalFromFunctionName));
1535 PropertyAttributes attribs =
1537 script_map->set_instance_descriptors(*script_descriptors);
1540 CallbacksDescriptor d(
1541 *factory()->source_symbol(), *script_source, attribs);
1542 script_map->AppendDescriptor(&d, witness);
1546 CallbacksDescriptor d(*factory()->name_symbol(), *script_name, attribs);
1547 script_map->AppendDescriptor(&d, witness);
1551 CallbacksDescriptor d(*id_symbol, *script_id, attribs);
1552 script_map->AppendDescriptor(&d, witness);
1556 CallbacksDescriptor d(*line_offset_symbol, *script_line_offset, attribs);
1557 script_map->AppendDescriptor(&d, witness);
1561 CallbacksDescriptor d(
1562 *column_offset_symbol, *script_column_offset, attribs);
1563 script_map->AppendDescriptor(&d, witness);
1567 CallbacksDescriptor d(*data_symbol, *script_data, attribs);
1568 script_map->AppendDescriptor(&d, witness);
1572 CallbacksDescriptor d(*type_symbol, *script_type, attribs);
1573 script_map->AppendDescriptor(&d, witness);
1577 CallbacksDescriptor d(
1578 *compilation_type_symbol, *script_compilation_type, attribs);
1579 script_map->AppendDescriptor(&d, witness);
1583 CallbacksDescriptor d(*line_ends_symbol, *script_line_ends, attribs);
1584 script_map->AppendDescriptor(&d, witness);
1588 CallbacksDescriptor d(
1589 *context_data_symbol, *script_context_data, attribs);
1590 script_map->AppendDescriptor(&d, witness);
1594 CallbacksDescriptor d(
1595 *eval_from_script_symbol, *script_eval_from_script, attribs);
1596 script_map->AppendDescriptor(&d, witness);
1600 CallbacksDescriptor d(
1601 *eval_from_script_position_symbol,
1602 *script_eval_from_script_position,
1604 script_map->AppendDescriptor(&d, witness);
1608 CallbacksDescriptor d(
1609 *eval_from_function_name_symbol,
1610 *script_eval_from_function_name,
1612 script_map->AppendDescriptor(&d, witness);
1616 Handle<Script> script = factory()->NewScript(factory()->empty_string());
1618 heap()->public_set_empty_script(*script);
1624 Handle<JSFunction> opaque_reference_fun =
1627 isolate()->initial_object_prototype(),
1628 Builtins::kIllegal,
false);
1629 Handle<JSObject> prototype =
1630 factory()->NewJSObject(isolate()->object_function(),
TENURED);
1632 native_context()->set_opaque_reference_function(*opaque_reference_fun);
1641 Handle<JSFunction> array_function =
1642 InstallFunction(builtins,
1646 isolate()->initial_object_prototype(),
1647 Builtins::kInternalArrayCode,
1649 Handle<JSObject> prototype =
1650 factory()->NewJSObject(isolate()->object_function(),
TENURED);
1653 array_function->shared()->set_construct_stub(
1654 isolate()->builtins()->builtin(Builtins::kArrayConstructCode));
1655 array_function->shared()->DontAdaptArguments();
1662 MaybeObject* maybe_map = array_function->initial_map()->Copy();
1664 if (!maybe_map->To(&new_map))
return false;
1666 array_function->set_initial_map(new_map);
1669 Handle<Map> initial_map(array_function->initial_map());
1670 Handle<DescriptorArray> array_descriptors(
1671 factory()->NewDescriptorArray(0, 1));
1672 DescriptorArray::WhitenessWitness witness(*array_descriptors);
1674 Handle<Foreign> array_length(factory()->NewForeign(
1675 &Accessors::ArrayLength));
1676 PropertyAttributes attribs =
static_cast<PropertyAttributes
>(
1678 initial_map->set_instance_descriptors(*array_descriptors);
1681 CallbacksDescriptor d(
1682 *factory()->length_symbol(), *array_length, attribs);
1683 array_function->initial_map()->AppendDescriptor(&d, witness);
1686 native_context()->set_internal_array_function(*array_function);
1689 if (FLAG_disable_native_files) {
1690 PrintF(
"Warning: Running without installed natives!\n");
1698 if (!CompileBuiltin(isolate(), i))
return false;
1702 if (!InstallJSBuiltins(builtins))
return false;
1705 InstallNativeFunctions();
1709 Handle<JSFunction> string_function(native_context()->string_function());
1711 string_function->initial_map()->prototype())->HasFastProperties());
1712 native_context()->set_string_function_prototype_map(
1716 { Handle<String> key = factory()->function_class_symbol();
1717 Handle<JSFunction>
function =
1719 Handle<JSObject> proto =
1720 Handle<JSObject>(
JSObject::cast(function->instance_prototype()));
1723 Handle<JSFunction> call =
1724 InstallFunction(proto,
"call",
JS_OBJECT_TYPE, JSObject::kHeaderSize,
1725 Handle<JSObject>::null(),
1726 Builtins::kFunctionCall,
1728 Handle<JSFunction> apply =
1729 InstallFunction(proto,
"apply",
JS_OBJECT_TYPE, JSObject::kHeaderSize,
1730 Handle<JSObject>::null(),
1731 Builtins::kFunctionApply,
1737 call->shared()->DontAdaptArguments();
1738 ASSERT(call->is_compiled());
1741 apply->shared()->set_formal_parameter_count(2);
1744 call->shared()->set_length(1);
1745 apply->shared()->set_length(2);
1748 InstallBuiltinFunctionIds();
1756 Handle<JSFunction> array_constructor(native_context()->array_function());
1757 Handle<JSObject> array_prototype(
1761 Handle<Map> initial_map =
1763 initial_map->set_constructor(*array_constructor);
1766 initial_map->set_non_instance_prototype(
false);
1767 initial_map->set_prototype(*array_prototype);
1770 Handle<DescriptorArray> reresult_descriptors =
1771 factory()->NewDescriptorArray(0, 3);
1772 DescriptorArray::WhitenessWitness witness(*reresult_descriptors);
1773 initial_map->set_instance_descriptors(*reresult_descriptors);
1776 JSFunction* array_function = native_context()->array_function();
1777 Handle<DescriptorArray> array_descriptors(
1778 array_function->initial_map()->instance_descriptors());
1779 String* length = heap()->length_symbol();
1780 int old = array_descriptors->SearchWithCache(
1781 length, array_function->initial_map());
1783 CallbacksDescriptor desc(length,
1784 array_descriptors->GetValue(old),
1785 array_descriptors->GetDetails(old).attributes());
1786 initial_map->AppendDescriptor(&desc, witness);
1789 FieldDescriptor index_field(heap()->index_symbol(),
1792 initial_map->AppendDescriptor(&index_field, witness);
1796 FieldDescriptor input_field(heap()->input_symbol(),
1799 initial_map->AppendDescriptor(&input_field, witness);
1802 initial_map->set_inobject_properties(2);
1803 initial_map->set_pre_allocated_property_fields(2);
1804 initial_map->set_unused_property_fields(0);
1806 native_context()->set_regexp_result_map(*initial_map);
1817 bool Genesis::InstallExperimentalNatives() {
1821 if (FLAG_harmony_proxies &&
1823 "native proxy.js") == 0) {
1824 if (!CompileExperimentalBuiltin(isolate(), i))
return false;
1826 if (FLAG_harmony_collections &&
1828 "native collection.js") == 0) {
1829 if (!CompileExperimentalBuiltin(isolate(), i))
return false;
1833 InstallExperimentalNativeFunctions();
1839 static Handle<JSObject> ResolveBuiltinIdHolder(
1840 Handle<Context> native_context,
1841 const char* holder_expr) {
1842 Factory* factory = native_context->GetIsolate()->factory();
1843 Handle<GlobalObject> global(native_context->global_object());
1844 const char* period_pos = strchr(holder_expr,
'.');
1845 if (period_pos ==
NULL) {
1847 GetProperty(global, factory->LookupAsciiSymbol(holder_expr)));
1850 Vector<const char> property(holder_expr,
1851 static_cast<int>(period_pos - holder_expr));
1853 GetProperty(global, factory->LookupSymbol(property)));
1858 static void InstallBuiltinFunctionId(Handle<JSObject> holder,
1859 const char* function_name,
1861 Factory* factory = holder->GetIsolate()->factory();
1862 Handle<String> name = factory->LookupAsciiSymbol(function_name);
1863 Object* function_object = holder->GetProperty(*name)->ToObjectUnchecked();
1865 function->shared()->set_function_data(
Smi::FromInt(
id));
1869 void Genesis::InstallBuiltinFunctionIds() {
1871 #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \
1873 Handle<JSObject> holder = ResolveBuiltinIdHolder( \
1874 native_context(), #holder_expr); \
1875 BuiltinFunctionId id = k##name; \
1876 InstallBuiltinFunctionId(holder, #fun_name, id); \
1879 #undef INSTALL_BUILTIN_ID
1885 #define JSFUNCTION_RESULT_CACHE_LIST(F) \
1886 F(16, native_context()->regexp_function())
1889 static FixedArray* CreateCache(
int size, Handle<JSFunction> factory_function) {
1894 JSFunctionResultCache* cache =
reinterpret_cast<JSFunctionResultCache*
>(
1895 *factory->NewFixedArrayWithHoles(array_size,
TENURED));
1897 cache->MakeZeroSize();
1902 void Genesis::InstallJSFunctionResultCaches() {
1903 const int kNumberOfCaches = 0 +
1904 #define F(size, func) + 1
1909 Handle<FixedArray> caches =
FACTORY->NewFixedArray(kNumberOfCaches,
TENURED);
1913 #define F(size, func) do { \
1914 FixedArray* cache = CreateCache((size), Handle<JSFunction>(func)); \
1915 caches->set(index++, cache); \
1922 native_context()->set_jsfunction_result_caches(*caches);
1926 void Genesis::InitializeNormalizedMapCaches() {
1927 Handle<FixedArray> array(
1935 Isolate* isolate = native_context->GetIsolate();
1937 SaveContext saved_context(isolate);
1939 if (!Genesis::InstallExtensions(native_context, extensions))
return false;
1940 Genesis::InstallSpecialObjects(native_context);
1952 if (FLAG_expose_natives_as !=
NULL && strlen(FLAG_expose_natives_as) != 0) {
1962 if (Error->IsJSObject()) {
1968 stack_trace_limit,
NONE));
1971 #ifdef ENABLE_DEBUGGER_SUPPORT
1973 if (FLAG_expose_debug_as !=
NULL && strlen(FLAG_expose_debug_as) != 0) {
1974 Debug* debug = Isolate::Current()->debug();
1977 if (!debug->Load())
return;
1981 debug->debug_context()->set_security_token(
1982 native_context->security_token());
1984 Handle<String> debug_string =
1986 Handle<Object> global_proxy(debug->debug_context()->global_proxy());
1989 global, debug_string, global_proxy,
DONT_ENUM));
1994 static uint32_t Hash(RegisteredExtension* extension) {
1998 static bool MatchRegisteredExtensions(
void* key1,
void* key2) {
1999 return key1 == key2;
2002 Genesis::ExtensionStates::ExtensionStates()
2003 : map_(MatchRegisteredExtensions, 8) { }
2005 Genesis::ExtensionTraversalState Genesis::ExtensionStates::get_state(
2006 RegisteredExtension* extension) {
2007 i::HashMap::Entry* entry = map_.Lookup(extension, Hash(extension),
false);
2008 if (entry ==
NULL) {
2011 return static_cast<ExtensionTraversalState
>(
2012 reinterpret_cast<intptr_t
>(entry->value));
2015 void Genesis::ExtensionStates::set_state(RegisteredExtension* extension,
2016 ExtensionTraversalState state) {
2017 map_.Lookup(extension, Hash(extension),
true)->value =
2018 reinterpret_cast<void*
>(
static_cast<intptr_t
>(state));
2021 bool Genesis::InstallExtensions(Handle<Context> native_context,
2028 ExtensionStates extension_states;
2031 while (current !=
NULL) {
2033 InstallExtension(current, &extension_states);
2034 current = current->
next();
2037 if (FLAG_expose_gc) InstallExtension(
"v8/gc", &extension_states);
2038 if (FLAG_expose_externalize_string) {
2039 InstallExtension(
"v8/externalize", &extension_states);
2041 if (FLAG_track_gc_object_stats) {
2042 InstallExtension(
"v8/statistics", &extension_states);
2045 if (extensions ==
NULL)
return true;
2049 for (
int i = 0; i < count; i++) {
2050 if (!InstallExtension(names[i], &extension_states))
2060 bool Genesis::InstallExtension(
const char* name,
2061 ExtensionStates* extension_states) {
2064 while (current !=
NULL) {
2066 current = current->
next();
2069 if (current ==
NULL) {
2071 "v8::Context::New()",
"Cannot find required extension");
2074 return InstallExtension(current, extension_states);
2079 ExtensionStates* extension_states) {
2082 if (extension_states->get_state(current) == INSTALLED)
return true;
2085 if (extension_states->get_state(current) == VISITED) {
2087 "v8::Context::New()",
"Circular extension dependency");
2090 ASSERT(extension_states->get_state(current) == UNVISITED);
2091 extension_states->set_state(current, VISITED);
2095 if (!InstallExtension(extension->
dependencies()[i], extension_states))
2098 Isolate* isolate = Isolate::Current();
2099 Handle<String> source_code =
2100 isolate->factory()->NewExternalStringFromAscii(extension->
source());
2101 bool result = CompileScriptCached(
2104 isolate->bootstrapper()->extensions_cache(),
2106 Handle<Context>(isolate->context()),
2108 ASSERT(isolate->has_pending_exception() != result);
2116 isolate->clear_pending_exception();
2118 extension_states->set_state(current, INSTALLED);
2119 isolate->NotifyExtensionInstalled();
2124 bool Genesis::InstallJSBuiltins(Handle<JSBuiltinsObject> builtins) {
2126 Factory* factory = builtins->GetIsolate()->factory();
2130 Object* function_object = builtins->GetPropertyNoExceptionThrown(*name);
2131 Handle<JSFunction>
function
2133 builtins->set_javascript_builtin(
id, *
function);
2137 builtins->set_javascript_builtin_code(
id, function->shared()->code());
2143 bool Genesis::ConfigureGlobalObjects(
2145 Handle<JSObject> global_proxy(
2147 Handle<JSObject> inner_global(
2150 if (!global_proxy_template.
IsEmpty()) {
2152 Handle<ObjectTemplateInfo> proxy_data =
2153 v8::Utils::OpenHandle(*global_proxy_template);
2154 if (!ConfigureApiObject(global_proxy, proxy_data))
return false;
2157 Handle<FunctionTemplateInfo> proxy_constructor(
2159 if (!proxy_constructor->prototype_template()->IsUndefined()) {
2160 Handle<ObjectTemplateInfo> inner_data(
2162 if (!ConfigureApiObject(inner_global, inner_data))
return false;
2166 SetObjectPrototype(global_proxy, inner_global);
2171 bool Genesis::ConfigureApiObject(Handle<JSObject>
object,
2172 Handle<ObjectTemplateInfo> object_template) {
2173 ASSERT(!object_template.is_null());
2174 ASSERT(object->IsInstanceOf(
2177 bool pending_exception =
false;
2178 Handle<JSObject> obj =
2180 if (pending_exception) {
2181 ASSERT(isolate()->has_pending_exception());
2182 isolate()->clear_pending_exception();
2185 TransferObject(obj,
object);
2190 void Genesis::TransferNamedProperties(Handle<JSObject> from,
2191 Handle<JSObject> to) {
2192 if (from->HasFastProperties()) {
2193 Handle<DescriptorArray> descs =
2194 Handle<DescriptorArray>(from->map()->instance_descriptors());
2195 for (
int i = 0; i < descs->number_of_descriptors(); i++) {
2196 PropertyDetails details = descs->GetDetails(i);
2197 switch (details.type()) {
2200 Handle<String> key = Handle<String>(descs->GetKey(i));
2201 int index = descs->GetFieldIndex(i);
2202 Handle<Object> value = Handle<Object>(from->FastPropertyAt(index));
2205 to, key, value, details.attributes()));
2210 Handle<String> key = Handle<String>(descs->GetKey(i));
2211 Handle<JSFunction> fun =
2212 Handle<JSFunction>(descs->GetConstantFunction(i));
2215 to, key, fun, details.attributes()));
2219 LookupResult result(isolate());
2220 to->LocalLookup(descs->GetKey(i), &result);
2222 if (result.IsFound())
continue;
2224 ASSERT(!to->HasFastProperties());
2226 Handle<String> key = Handle<String>(descs->GetKey(i));
2227 Handle<Object> callbacks(descs->GetCallbacksObject(i));
2228 PropertyDetails d = PropertyDetails(details.attributes(),
2230 details.descriptor_index());
2246 Handle<StringDictionary> properties =
2247 Handle<StringDictionary>(from->property_dictionary());
2248 int capacity = properties->Capacity();
2249 for (
int i = 0; i < capacity; i++) {
2250 Object* raw_key(properties->KeyAt(i));
2251 if (properties->IsKey(raw_key)) {
2252 ASSERT(raw_key->IsString());
2254 LookupResult result(isolate());
2256 if (result.IsFound())
continue;
2258 Handle<String> key = Handle<String>(
String::cast(raw_key));
2259 Handle<Object> value = Handle<Object>(properties->ValueAt(i));
2260 if (value->IsJSGlobalPropertyCell()) {
2263 PropertyDetails details = properties->DetailsAt(i);
2266 to, key, value, details.attributes()));
2273 void Genesis::TransferIndexedProperties(Handle<JSObject> from,
2274 Handle<JSObject> to) {
2276 Handle<FixedArray> from_elements =
2278 Handle<FixedArray> to_elements =
FACTORY->CopyFixedArray(from_elements);
2279 to->set_elements(*to_elements);
2283 void Genesis::TransferObject(Handle<JSObject> from, Handle<JSObject> to) {
2285 Factory* factory = from->GetIsolate()->factory();
2287 ASSERT(!from->IsJSArray());
2288 ASSERT(!to->IsJSArray());
2290 TransferNamedProperties(from, to);
2291 TransferIndexedProperties(from, to);
2294 Handle<Map> old_to_map = Handle<Map>(to->map());
2295 Handle<Map> new_to_map = factory->CopyMap(old_to_map);
2296 new_to_map->set_prototype(from->map()->prototype());
2297 to->set_map(*new_to_map);
2301 void Genesis::MakeFunctionInstancePrototypeWritable() {
2305 ASSERT(!function_instance_map_writable_prototype_.is_null());
2306 ASSERT(!strict_mode_function_instance_map_writable_prototype_.is_null());
2309 native_context()->set_function_map(
2310 *function_instance_map_writable_prototype_);
2311 native_context()->set_strict_mode_function_map(
2312 *strict_mode_function_instance_map_writable_prototype_);
2316 Genesis::Genesis(Isolate* isolate,
2317 Handle<Object> global_object,
2327 SaveContext saved_context(isolate);
2332 StackLimitCheck
check(Isolate::Current());
2333 if (
check.HasOverflowed())
return;
2336 if (!new_context.is_null()) {
2339 AddToWeakNativeContextList(*native_context_);
2340 isolate->set_context(*native_context_);
2341 isolate->counters()->contexts_created_by_snapshot()->Increment();
2342 Handle<GlobalObject> inner_global;
2343 Handle<JSGlobalProxy> global_proxy =
2344 CreateNewGlobals(global_template,
2348 HookUpGlobalProxy(inner_global, global_proxy);
2349 HookUpInnerGlobal(inner_global);
2351 if (!ConfigureGlobalObjects(global_template))
return;
2355 Handle<JSFunction> empty_function = CreateEmptyFunction(isolate);
2356 CreateStrictModeFunctionMaps(empty_function);
2357 Handle<GlobalObject> inner_global;
2358 Handle<JSGlobalProxy> global_proxy =
2359 CreateNewGlobals(global_template, global_object, &inner_global);
2360 HookUpGlobalProxy(inner_global, global_proxy);
2361 if (!InitializeGlobal(inner_global, empty_function))
return;
2362 InstallJSFunctionResultCaches();
2363 InitializeNormalizedMapCaches();
2364 if (!InstallNatives())
return;
2366 MakeFunctionInstancePrototypeWritable();
2368 if (!ConfigureGlobalObjects(global_template))
return;
2369 isolate->counters()->contexts_created_from_scratch()->Increment();
2373 InitializeExperimentalGlobal();
2374 if (!InstallExperimentalNatives())
return;
2376 result_ = native_context_;
2384 return sizeof(NestingCounterType);
2390 *
reinterpret_cast<NestingCounterType*
>(to) = nesting_;
2392 return to +
sizeof(NestingCounterType);
2398 nesting_ = *
reinterpret_cast<NestingCounterType*
>(from);
2399 return from +
sizeof(NestingCounterType);
#define CHECK_NOT_EMPTY_HANDLE(isolate, call)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if expose natives in global object expose gc extension number of stack frames to capture disable builtin natives files print a stack trace if an assertion failure occurs use random jit cookie to mask large constants trace lazy optimization use adaptive optimizations prepare for turning on always opt minimum length for automatic enable preparsing maximum number of optimization attempts before giving up cache prototype transitions automatically set the debug break flag when debugger commands are in the queue always cause a debug break before aborting maximum length of function source code printed in a stack trace max size of the new max size of the old max size of executable memory(in Mbytes)") DEFINE_bool(gc_global
RegisteredExtension * next()
static bool Initialize(Deserializer *des)
Code * builtin(Name name)
static bool CompileLazy(Handle< JSFunction > function, ClearExceptionFlag flag)
char * ArchiveState(char *to)
Handle< String > NewExternalStringFromAscii(const ExternalAsciiString::Resource *resource)
static const int kEntries
static const int kGlobalFieldIndex
void PrintF(const char *format,...)
void Initialize(bool create_heap_objects)
char * AllocateAutoDeletedArray(int bytes)
static String * cast(Object *obj)
v8::internal::Handle< v8::internal::JSObject > value()
Handle< Context > result()
static Smi * FromInt(int value)
static ObjectTemplateInfo * cast(Object *obj)
static Vector< const char > GetRawScriptSource(int index)
static HeapObject * cast(Object *obj)
static Handle< T > cast(Handle< S > that)
static const int kSourceFieldIndex
static Vector< const char > GetScriptName(int index)
static AccessorPair * cast(Object *obj)
static const char ** GetNames(ExtensionConfiguration *that)
static int GetDebuggerCount()
static Handle< Context > NewContextFromSnapshot()
#define ASSERT(condition)
MUST_USE_RESULT MaybeObject * PreventExtensions()
char * RestoreState(char *from)
Handle< JSFunction > NewFunctionWithPrototype(Handle< String > name, InstanceType type, int instance_size, Handle< JSObject > prototype, Handle< Code > code, bool force_initial_map)
bool InstallExtensions(Handle< Context > native_context, v8::ExtensionConfiguration *extensions)
static const char * GetName(JavaScript id)
static Context * cast(Object *context)
Handle< Object > GetProperty(Handle< JSReceiver > obj, const char *name)
Handle< String > LookupAsciiSymbol(Vector< const char > str)
static const int kMultilineFieldIndex
void FreeThreadResources()
GlobalObject * global_object()
static int GetBuiltinsCount()
friend class NativesExternalStringResource
uint32_t ComputePointerHash(void *ptr)
Handle< Map > CopyMap(Handle< Map > map, int extra_inobject_props)
static const int kArgumentsObjectSizeStrict
static JSGlobalProxy * cast(Object *obj)
static const int kFactoryIndex
static const int kInputIndex
#define INSTALL_BUILTIN_ID(holder_expr, fun_name, name)
friend class BootstrapperActive
void set_context(Context *context)
const char * name() const
static int GetNameCount(ExtensionConfiguration *that)
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
static Handle< Object > SetLocalPropertyIgnoreAttributes(Handle< JSObject > object, Handle< String > key, Handle< Object > value, PropertyAttributes attributes)
static FunctionTemplateInfo * cast(Object *obj)
Handle< String > NativesSourceLookup(int index)
static int NumberOfJavaScriptBuiltins()
static const int kIgnoreCaseFieldIndex
static Handle< Object > Call(Handle< Object > callable, Handle< Object > receiver, int argc, Handle< Object > argv[], bool *pending_exception, bool convert_receiver=false)
Vector< const char > CStrVector(const char *data)
Handle< Context > CreateEnvironment(Isolate *isolate, Handle< Object > global_object, v8::Handle< v8::ObjectTemplate > global_template, v8::ExtensionConfiguration *extensions)
void Iterate(ObjectVisitor *v)
Isolate * isolate() const
Handle< JSFunction > NewFunctionWithoutPrototype(Handle< String > name, LanguageMode language_mode)
#define INSTALL_NATIVE(Type, name, var)
static Handle< SharedFunctionInfo > Compile(Handle< String > source, Handle< Object > script_name, int line_offset, int column_offset, Handle< Context > context, v8::Extension *extension, ScriptDataImpl *pre_data, Handle< Object > script_data, NativesFlag is_natives_code)
#define JSFUNCTION_RESULT_CACHE_LIST(F)
static const int kArgumentsLengthIndex
void DetachGlobal(Handle< Context > env)
const String::ExternalAsciiStringResource * source() const
static JSGlobalPropertyCell * cast(Object *obj)
static RegisteredExtension * first_extension()
static const int kEntriesIndex
static void PrintError(const char *format,...)
Handle< JSGlobalProxy > ReinitializeJSGlobalProxy(Handle< JSFunction > constructor, Handle< JSGlobalProxy > global)
static Handle< String > null()
TemplateHashMapImpl< FreeStoreAllocationPolicy > HashMap
Handle< Foreign > NewForeign(Address addr, PretenureFlag pretenure=NOT_TENURED)
#define ASSERT_EQ(v1, v2)
static const int kIndexIndex
const int kRandomStateSize
static Handle< JSObject > InstantiateObject(Handle< ObjectTemplateInfo > data, bool *exc)
static const int kArgumentsCalleeIndex
static FixedArray * cast(Object *obj)
static const int kHeaderSize
Object * SetNormalizedProperty(LookupResult *result, Object *value)
static bool ReportApiFailure(const char *location, const char *message)
void Add(const T &element, AllocationPolicy allocator=AllocationPolicy())
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra emit comments in code disassembly enable use of SSE3 instructions if available enable use of CMOV instruction if available enable use of SAHF instruction if enable use of VFP3 instructions if available this implies enabling ARMv7 and VFP2 enable use of VFP2 instructions if available enable use of SDIV and UDIV instructions if enable loading bit constant by means of movw movt instruction enable unaligned accesses for enable use of MIPS FPU instructions if NULL
static VisitorId GetVisitorId(int instance_type, int instance_size)
Handle< Object > ForceSetProperty(Handle< JSObject > object, Handle< Object > key, Handle< Object > value, PropertyAttributes attributes)
activate correct semantics for inheriting readonliness enable harmony semantics for typeof enable harmony enable harmony proxies enable all harmony harmony_scoping harmony_proxies harmony_scoping tracks arrays with only smi values automatically unbox arrays of doubles use crankshaft use hydrogen range analysis use hydrogen global value numbering use function inlining maximum number of AST nodes considered for a single inlining loop invariant code motion print statistics for hydrogen trace generated IR for specified phases trace register allocator trace range analysis trace representation types environment for every instruction put a break point before deoptimizing polymorphic inlining perform array bounds checks elimination use dead code elimination trace on stack replacement optimize closures cache optimized code for closures functions with arguments object loop weight for representation inference allow uint32 values on optimize frames if they are used only in safe operations track parallel recompilation enable all profiler experiments number of stack frames inspected by the profiler call recompile stub directly when self optimizing trigger profiler ticks based on counting instead of timing weight back edges by jump distance for interrupt triggering percentage of ICs that must have type info to allow optimization watch_ic_patching retry_self_opt interrupt_at_exit extra verbose compilation tracing generate extra code(assertions) for debugging") DEFINE_bool(code_comments
static NormalizedMapCache * cast(Object *obj)
void ReattachGlobal(Handle< Context > env, Handle< JSGlobalProxy > global_proxy)
Handle< Object > SetPrototype(Handle< JSFunction > function, Handle< Object > prototype)
static const int kLastIndexFieldIndex
static GlobalObject * cast(Object *obj)
#define FUNCTIONS_WITH_ID_LIST(V)
NativesExternalStringResource(Bootstrapper *bootstrapper, const char *source, size_t length)
Handle< Map > NewMap(InstanceType type, int instance_size, ElementsKind elements_kind=TERMINAL_FAST_ELEMENTS_KIND)
Factory * factory() const
const char ** dependencies()
static const int kNotFound
void check(i::Vector< const char > string)
static int ArchiveSpacePerThread()
static JSObject * cast(Object *obj)
static JSGlobalObject * cast(Object *obj)
static JSFunction * cast(Object *obj)