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

Side by Side Diff: src/bootstrapper.cc

Issue 7366: Split window support from V8. ... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 12 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/bootstrapper.h ('k') | src/builtins.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. 1 // Copyright 2006-2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 Handle<Context> global_context() { return global_context_; } 268 Handle<Context> global_context() { return global_context_; }
269 269
270 void CreateRoots(v8::Handle<v8::ObjectTemplate> global_template, 270 void CreateRoots(v8::Handle<v8::ObjectTemplate> global_template,
271 Handle<Object> global_object); 271 Handle<Object> global_object);
272 void InstallNativeFunctions(); 272 void InstallNativeFunctions();
273 bool InstallNatives(); 273 bool InstallNatives();
274 bool InstallExtensions(v8::ExtensionConfiguration* extensions); 274 bool InstallExtensions(v8::ExtensionConfiguration* extensions);
275 bool InstallExtension(const char* name); 275 bool InstallExtension(const char* name);
276 bool InstallExtension(v8::RegisteredExtension* current); 276 bool InstallExtension(v8::RegisteredExtension* current);
277 bool InstallSpecialObjects(); 277 bool InstallSpecialObjects();
278 bool ConfigureGlobalObject(v8::Handle<v8::ObjectTemplate> global_template); 278 bool ConfigureApiObject(Handle<JSObject> object,
279 Handle<ObjectTemplateInfo> object_template);
280 bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template);
279 281
280 // Migrates all properties from the 'from' object to the 'to' 282 // Migrates all properties from the 'from' object to the 'to'
281 // object and overrides the prototype in 'to' with the one from 283 // object and overrides the prototype in 'to' with the one from
282 // 'from'. 284 // 'from'.
283 void TransferObject(Handle<JSObject> from, Handle<JSObject> to); 285 void TransferObject(Handle<JSObject> from, Handle<JSObject> to);
284 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); 286 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to);
285 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to); 287 void TransferIndexedProperties(Handle<JSObject> from, Handle<JSObject> to);
286 288
287 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor( 289 Handle<DescriptorArray> ComputeFunctionInstanceDescriptor(
288 bool make_prototype_read_only, 290 bool make_prototype_read_only,
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
330 332
331 Handle<Context> Bootstrapper::CreateEnvironment( 333 Handle<Context> Bootstrapper::CreateEnvironment(
332 Handle<Object> global_object, 334 Handle<Object> global_object,
333 v8::Handle<v8::ObjectTemplate> global_template, 335 v8::Handle<v8::ObjectTemplate> global_template,
334 v8::ExtensionConfiguration* extensions) { 336 v8::ExtensionConfiguration* extensions) {
335 Genesis genesis(global_object, global_template, extensions); 337 Genesis genesis(global_object, global_template, extensions);
336 return genesis.result(); 338 return genesis.result();
337 } 339 }
338 340
339 341
342 static void SetObjectPrototype(Handle<JSObject> object, Handle<Object> proto) {
343 // object.__proto__ = proto;
344 Handle<Map> old_to_map = Handle<Map>(object->map());
345 Handle<Map> new_to_map = Factory::CopyMapDropTransitions(old_to_map);
346 new_to_map->set_prototype(*proto);
347 object->set_map(*new_to_map);
348 }
349
350
351 void Bootstrapper::DetachGlobal(Handle<Context> env) {
352 JSGlobalProxy::cast(env->global_proxy())->set_context(*Factory::null_value());
353 SetObjectPrototype(Handle<JSObject>(env->global_proxy()),
354 Factory::null_value());
355 env->set_global_proxy(env->global());
356 env->global()->set_global_receiver(env->global());
357 }
358
359
340 Genesis::~Genesis() { 360 Genesis::~Genesis() {
341 ASSERT(current_ == this); 361 ASSERT(current_ == this);
342 current_ = previous_; 362 current_ = previous_;
343 } 363 }
344 364
365
345 static Handle<JSFunction> InstallFunction(Handle<JSObject> target, 366 static Handle<JSFunction> InstallFunction(Handle<JSObject> target,
346 const char* name, 367 const char* name,
347 InstanceType type, 368 InstanceType type,
348 int instance_size, 369 int instance_size,
349 Handle<JSObject> prototype, 370 Handle<JSObject> prototype,
350 Builtins::Name call, 371 Builtins::Name call,
351 bool is_ecma_native) { 372 bool is_ecma_native) {
352 Handle<String> symbol = Factory::LookupAsciiSymbol(name); 373 Handle<String> symbol = Factory::LookupAsciiSymbol(name);
353 Handle<Code> call_code = Handle<Code>(Builtins::builtin(call)); 374 Handle<Code> call_code = Handle<Code>(Builtins::builtin(call));
354 Handle<JSFunction> function = 375 Handle<JSFunction> function =
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
424 void Genesis::CreateRoots(v8::Handle<v8::ObjectTemplate> global_template, 445 void Genesis::CreateRoots(v8::Handle<v8::ObjectTemplate> global_template,
425 Handle<Object> global_object) { 446 Handle<Object> global_object) {
426 HandleScope scope; 447 HandleScope scope;
427 // Allocate the global context FixedArray first and then patch the 448 // Allocate the global context FixedArray first and then patch the
428 // closure and extension object later (we need the empty function 449 // closure and extension object later (we need the empty function
429 // and the global object, but in order to create those, we need the 450 // and the global object, but in order to create those, we need the
430 // global context). 451 // global context).
431 global_context_ = 452 global_context_ =
432 Handle<Context>::cast( 453 Handle<Context>::cast(
433 GlobalHandles::Create(*Factory::NewGlobalContext())); 454 GlobalHandles::Create(*Factory::NewGlobalContext()));
434 Top::set_security_context(*global_context());
435 Top::set_context(*global_context()); 455 Top::set_context(*global_context());
436 456
437 // Allocate the message listeners object. 457 // Allocate the message listeners object.
438 v8::NeanderArray listeners; 458 v8::NeanderArray listeners;
439 global_context()->set_message_listeners(*listeners.value()); 459 global_context()->set_message_listeners(*listeners.value());
440 460
441 // Allocate the debug event listeners object. 461 // Allocate the debug event listeners object.
442 v8::NeanderArray debug_event_listeners; 462 v8::NeanderArray debug_event_listeners;
443 global_context()->set_debug_event_listeners(*debug_event_listeners.value()); 463 global_context()->set_debug_event_listeners(*debug_event_listeners.value());
444 464
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 global_context()->function_instance_map()->set_prototype(*empty_function); 519 global_context()->function_instance_map()->set_prototype(*empty_function);
500 520
501 // Allocate the function map first and then patch the prototype later 521 // Allocate the function map first and then patch the prototype later
502 Handle<Map> empty_fm = Factory::CopyMap(fm); 522 Handle<Map> empty_fm = Factory::CopyMap(fm);
503 empty_fm->set_instance_descriptors(*function_map_descriptors); 523 empty_fm->set_instance_descriptors(*function_map_descriptors);
504 empty_fm->set_prototype(global_context()->object_function()->prototype()); 524 empty_fm->set_prototype(global_context()->object_function()->prototype());
505 empty_function->set_map(*empty_fm); 525 empty_function->set_map(*empty_fm);
506 } 526 }
507 527
508 { // --- G l o b a l --- 528 { // --- G l o b a l ---
509 Handle<String> global_name = Factory::LookupAsciiSymbol("global");
510 Handle<JSFunction> global_function;
511 529
512 if (global_template.IsEmpty()) { 530 // Step 1: create a fresh inner JSGlobalObject
513 Handle<String> name = Handle<String>(Heap::empty_symbol()); 531 Handle<JSGlobalObject> object;
514 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal)); 532 {
515 global_function = Factory::NewFunction(name, JS_GLOBAL_OBJECT_TYPE, 533 Handle<JSFunction> js_global_function;
516 JSGlobalObject::kSize, code, true); 534 Handle<ObjectTemplateInfo> js_global_template;
517 // Change the constructor property of the prototype of the 535 if (!global_template.IsEmpty()) {
518 // hidden global function to refer to the Object function. 536 // Get prototype template of the global_template
519 Handle<JSObject> prototype = 537 Handle<ObjectTemplateInfo> data =
520 Handle<JSObject>( 538 v8::Utils::OpenHandle(*global_template);
521 JSObject::cast(global_function->instance_prototype())); 539 Handle<FunctionTemplateInfo> global_constructor =
522 SetProperty(prototype, Factory::constructor_symbol(), 540 Handle<FunctionTemplateInfo>(
523 Top::object_function(), NONE); 541 FunctionTemplateInfo::cast(data->constructor()));
524 } else { 542 Handle<Object> proto_template(global_constructor->prototype_template());
525 Handle<ObjectTemplateInfo> data = v8::Utils::OpenHandle(*global_template); 543 if (!proto_template->IsUndefined()) {
526 Handle<FunctionTemplateInfo> global_constructor = 544 js_global_template =
527 Handle<FunctionTemplateInfo>( 545 Handle<ObjectTemplateInfo>::cast(proto_template);
528 FunctionTemplateInfo::cast(data->constructor())); 546 }
529 global_function = Factory::CreateApiFunction(global_constructor, true); 547 }
530 }
531 548
532 SetExpectedNofProperties(global_function, 100); 549 if (js_global_template.is_null()) {
533 global_function->shared()->set_instance_class_name(*global_name); 550 Handle<String> name = Handle<String>(Heap::empty_symbol());
534 global_function->initial_map()->set_needs_access_check(); 551 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal));
552 js_global_function =
553 Factory::NewFunction(name, JS_GLOBAL_OBJECT_TYPE,
554 JSGlobalObject::kSize, code, true);
555 // Change the constructor property of the prototype of the
556 // hidden global function to refer to the Object function.
557 Handle<JSObject> prototype =
558 Handle<JSObject>(
559 JSObject::cast(js_global_function->instance_prototype()));
560 SetProperty(prototype, Factory::constructor_symbol(),
561 Top::object_function(), NONE);
562 } else {
563 Handle<FunctionTemplateInfo> js_global_constructor(
564 FunctionTemplateInfo::cast(js_global_template->constructor()));
565 js_global_function =
566 Factory::CreateApiFunction(js_global_constructor,
567 Factory::InnerGlobalObject);
568 }
535 569
536 Handle<JSGlobalObject> object; 570 js_global_function->initial_map()->set_is_hidden_prototype();
537 if (global_object.location() != NULL) { 571 SetExpectedNofProperties(js_global_function, 100);
538 ASSERT(global_object->IsJSGlobalObject()); 572 object = Handle<JSGlobalObject>::cast(
539 object = 573 Factory::NewJSObject(js_global_function, TENURED));
540 ReinitializeJSGlobalObject(
541 global_function,
542 Handle<JSGlobalObject>::cast(global_object));
543 } else {
544 object =
545 Handle<JSGlobalObject>::cast(Factory::NewJSObject(global_function,
546 TENURED));
547 } 574 }
548 575
549 // Set the global context for the global object. 576 // Set the global context for the global object.
550 object->set_global_context(*global_context()); 577 object->set_global_context(*global_context());
551 578
552 // Security setup: Set the security token of the global object to 579 // Step 2: create or re-initialize the outer global object.
553 // its global context. This makes the security check between two 580 Handle<JSGlobalProxy> global_proxy;
554 // different contexts fail by default even in case of global 581 {
555 // object reinitialization. 582 Handle<JSFunction> global_proxy_function;
556 object->set_security_token(*global_context()); 583 if (global_template.IsEmpty()) {
584 Handle<String> name = Handle<String>(Heap::empty_symbol());
585 Handle<Code> code = Handle<Code>(Builtins::builtin(Builtins::Illegal));
586 global_proxy_function =
587 Factory::NewFunction(name, JS_GLOBAL_PROXY_TYPE,
588 JSGlobalProxy::kSize, code, true);
589 } else {
590 Handle<ObjectTemplateInfo> data =
591 v8::Utils::OpenHandle(*global_template);
592 Handle<FunctionTemplateInfo> global_constructor(
593 FunctionTemplateInfo::cast(data->constructor()));
594 global_proxy_function =
595 Factory::CreateApiFunction(global_constructor,
596 Factory::OuterGlobalObject);
597 }
598
599 Handle<String> global_name = Factory::LookupAsciiSymbol("global");
600 global_proxy_function->shared()->set_instance_class_name(*global_name);
601 global_proxy_function->initial_map()->set_is_access_check_needed();
602
603 // Set global_proxy.__proto__ to js_global after ConfigureGlobalObjects
604
605 if (global_object.location() != NULL) {
606 ASSERT(global_object->IsJSGlobalProxy());
607 global_proxy =
608 ReinitializeJSGlobalProxy(
609 global_proxy_function,
610 Handle<JSGlobalProxy>::cast(global_object));
611 } else {
612 global_proxy = Handle<JSGlobalProxy>::cast(
613 Factory::NewJSObject(global_proxy_function, TENURED));
614 }
615
616 // Security setup: Set the security token of the global object to
617 // its the inner global. This makes the security check between two
618 // different contexts fail by default even in case of global
619 // object reinitialization.
620 object->set_global_receiver(*global_proxy);
621 global_proxy->set_context(*global_context());
622 }
557 623
558 { // --- G l o b a l C o n t e x t --- 624 { // --- G l o b a l C o n t e x t ---
559 // use the empty function as closure (no scope info) 625 // use the empty function as closure (no scope info)
560 global_context()->set_closure(*empty_function); 626 global_context()->set_closure(*empty_function);
561 global_context()->set_fcontext(*global_context()); 627 global_context()->set_fcontext(*global_context());
562 global_context()->set_previous(NULL); 628 global_context()->set_previous(NULL);
563 629
564 // set extension and global object 630 // set extension and global object
565 global_context()->set_extension(*object); 631 global_context()->set_extension(*object);
566 global_context()->set_global(*object); 632 global_context()->set_global(*object);
633 global_context()->set_global_proxy(*global_proxy);
634 // use inner global object as security token by default
635 global_context()->set_security_token(*object);
567 } 636 }
568 637
569 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); 638 Handle<JSObject> global = Handle<JSObject>(global_context()->global());
570 SetProperty(global, object_name, Top::object_function(), DONT_ENUM); 639 SetProperty(global, object_name, Top::object_function(), DONT_ENUM);
571 } 640 }
572 641
573 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); 642 Handle<JSObject> global = Handle<JSObject>(global_context()->global());
574 643
575 // Install global Function object 644 // Install global Function object
576 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, 645 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize,
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
828 Handle<String> name = Factory::LookupAsciiSymbol("builtins"); 897 Handle<String> name = Factory::LookupAsciiSymbol("builtins");
829 builtins_fun->shared()->set_instance_class_name(*name); 898 builtins_fun->shared()->set_instance_class_name(*name);
830 SetExpectedNofProperties(builtins_fun, 100); 899 SetExpectedNofProperties(builtins_fun, 100);
831 900
832 // Allocate the builtins object. 901 // Allocate the builtins object.
833 Handle<JSBuiltinsObject> builtins = 902 Handle<JSBuiltinsObject> builtins =
834 Handle<JSBuiltinsObject>::cast(Factory::NewJSObject(builtins_fun, 903 Handle<JSBuiltinsObject>::cast(Factory::NewJSObject(builtins_fun,
835 TENURED)); 904 TENURED));
836 builtins->set_builtins(*builtins); 905 builtins->set_builtins(*builtins);
837 builtins->set_global_context(*global_context()); 906 builtins->set_global_context(*global_context());
907 builtins->set_global_receiver(*builtins);
838 908
839 // Setup the 'global' properties of the builtins object. The 909 // Setup the 'global' properties of the builtins object. The
840 // 'global' property that refers to the global object is the only 910 // 'global' property that refers to the global object is the only
841 // way to get from code running in the builtins context to the 911 // way to get from code running in the builtins context to the
842 // global object. 912 // global object.
843 static const PropertyAttributes attributes = 913 static const PropertyAttributes attributes =
844 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); 914 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE);
845 SetProperty(builtins, Factory::LookupAsciiSymbol("global"), 915 SetProperty(builtins, Factory::LookupAsciiSymbol("global"),
846 Handle<Object>(global_context()->global()), attributes); 916 Handle<Object>(global_context()->global()), attributes);
847 917
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
925 for (int i = Natives::GetDelayCount(); 995 for (int i = Natives::GetDelayCount();
926 i < Natives::GetBuiltinsCount(); 996 i < Natives::GetBuiltinsCount();
927 i++) { 997 i++) {
928 if (!CompileBuiltin(i)) return false; 998 if (!CompileBuiltin(i)) return false;
929 } 999 }
930 1000
931 // Setup natives with lazy loading. 1001 // Setup natives with lazy loading.
932 SetupLazy(Handle<JSFunction>(global_context()->date_function()), 1002 SetupLazy(Handle<JSFunction>(global_context()->date_function()),
933 Natives::GetIndex("date"), 1003 Natives::GetIndex("date"),
934 Top::global_context(), 1004 Top::global_context(),
935 Handle<Context>(Top::context()->runtime_context()), 1005 Handle<Context>(Top::context()->runtime_context()));
936 Handle<Context>(Top::security_context()));
937 SetupLazy(Handle<JSFunction>(global_context()->regexp_function()), 1006 SetupLazy(Handle<JSFunction>(global_context()->regexp_function()),
938 Natives::GetIndex("regexp"), 1007 Natives::GetIndex("regexp"),
939 Top::global_context(), 1008 Top::global_context(),
940 Handle<Context>(Top::context()->runtime_context()), 1009 Handle<Context>(Top::context()->runtime_context()));
941 Handle<Context>(Top::security_context()));
942 1010
943 } else if (strlen(FLAG_natives_file) != 0) { 1011 } else if (strlen(FLAG_natives_file) != 0) {
944 // Otherwise install natives from natives file if file exists and 1012 // Otherwise install natives from natives file if file exists and
945 // compiles. 1013 // compiles.
946 bool exists; 1014 bool exists;
947 Vector<const char> source = ReadFile(FLAG_natives_file, &exists); 1015 Vector<const char> source = ReadFile(FLAG_natives_file, &exists);
948 Handle<String> source_string = Factory::NewStringFromAscii(source); 1016 Handle<String> source_string = Factory::NewStringFromAscii(source);
949 if (source.is_empty()) return false; 1017 if (source.is_empty()) return false;
950 bool result = CompileNative(CStrVector(FLAG_natives_file), source_string); 1018 bool result = CompileNative(CStrVector(FLAG_natives_file), source_string);
951 if (!result) return false; 1019 if (!result) return false;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
997 ASSERT(builtins->HasFastProperties()); 1065 ASSERT(builtins->HasFastProperties());
998 #ifdef DEBUG 1066 #ifdef DEBUG
999 builtins->Verify(); 1067 builtins->Verify();
1000 #endif 1068 #endif
1001 return true; 1069 return true;
1002 } 1070 }
1003 1071
1004 1072
1005 bool Genesis::InstallSpecialObjects() { 1073 bool Genesis::InstallSpecialObjects() {
1006 HandleScope scope; 1074 HandleScope scope;
1007 Handle<JSGlobalObject> global( 1075 Handle<JSGlobalObject> js_global(
1008 JSGlobalObject::cast(global_context()->global())); 1076 JSGlobalObject::cast(global_context()->global()));
1009 // Expose the natives in global if a name for it is specified. 1077 // Expose the natives in global if a name for it is specified.
1010 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { 1078 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) {
1011 Handle<String> natives_string = 1079 Handle<String> natives_string =
1012 Factory::LookupAsciiSymbol(FLAG_expose_natives_as); 1080 Factory::LookupAsciiSymbol(FLAG_expose_natives_as);
1013 SetProperty(global, natives_string, 1081 SetProperty(js_global, natives_string,
1014 Handle<JSObject>(global->builtins()), DONT_ENUM); 1082 Handle<JSObject>(js_global->builtins()), DONT_ENUM);
1015 } 1083 }
1016 1084
1017 // Expose the debug global object in global if a name for it is specified. 1085 // Expose the debug global object in global if a name for it is specified.
1018 if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { 1086 if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) {
1019 // If loading fails we just bail out without installing the 1087 // If loading fails we just bail out without installing the
1020 // debugger but without tanking the whole context. 1088 // debugger but without tanking the whole context.
1021 if (!Debug::Load()) 1089 if (!Debug::Load())
1022 return true; 1090 return true;
1023 Handle<JSGlobalObject> debug_global = 1091 // Set the security token for the debugger context to the same as
1024 Handle<JSGlobalObject>( 1092 // the shell global context to allow calling between these (otherwise
1025 JSGlobalObject::cast(Debug::debug_context()->global())); 1093 // exposing debug global object doesn't make much sense).
1094 Debug::debug_context()->set_security_token(
1095 global_context()->security_token());
1096
1026 Handle<String> debug_string = 1097 Handle<String> debug_string =
1027 Factory::LookupAsciiSymbol(FLAG_expose_debug_as); 1098 Factory::LookupAsciiSymbol(FLAG_expose_debug_as);
1028 SetProperty(global, debug_string, 1099 SetProperty(js_global, debug_string,
1029 Handle<JSObject>(debug_global), DONT_ENUM); 1100 Handle<Object>(Debug::debug_context()->global_proxy()), DONT_ENUM);
1030
1031 // Set the security token for the debugger global object to the same as
1032 // the shell global object to allow calling between these (otherwise
1033 // exposing debug global object doesn't make much sense).
1034 debug_global->set_security_token(global->security_token());
1035 } 1101 }
1036 1102
1037 return true; 1103 return true;
1038 } 1104 }
1039 1105
1040 1106
1041 bool Genesis::InstallExtensions(v8::ExtensionConfiguration* extensions) { 1107 bool Genesis::InstallExtensions(v8::ExtensionConfiguration* extensions) {
1042 // Clear coloring of extension list 1108 // Clear coloring of extension list
1043 v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); 1109 v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension();
1044 while (current != NULL) { 1110 while (current != NULL) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 if (!result) { 1181 if (!result) {
1116 Top::clear_pending_exception(); 1182 Top::clear_pending_exception();
1117 v8::Utils::ReportApiFailure( 1183 v8::Utils::ReportApiFailure(
1118 "v8::Context::New()", "Error installing extension"); 1184 "v8::Context::New()", "Error installing extension");
1119 } 1185 }
1120 current->set_state(v8::INSTALLED); 1186 current->set_state(v8::INSTALLED);
1121 return result; 1187 return result;
1122 } 1188 }
1123 1189
1124 1190
1125 bool Genesis::ConfigureGlobalObject( 1191 bool Genesis::ConfigureGlobalObjects(
1126 v8::Handle<v8::ObjectTemplate> global_template) { 1192 v8::Handle<v8::ObjectTemplate> global_proxy_template) {
1127 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); 1193 Handle<JSObject> global_proxy(
1128 if (!global_template.IsEmpty()) { 1194 JSObject::cast(global_context()->global_proxy()));
1129 Handle<ObjectTemplateInfo> data = v8::Utils::OpenHandle(*global_template); 1195 Handle<JSObject> js_global(JSObject::cast(global_context()->global()));
1130 bool pending_exception = false; 1196
1131 Handle<JSObject> obj = 1197 if (!global_proxy_template.IsEmpty()) {
1132 Execution::InstantiateObject(data, &pending_exception); 1198 // Configure the outer global object.
1133 if (pending_exception) { 1199 Handle<ObjectTemplateInfo> outer_data =
1134 ASSERT(Top::has_pending_exception()); 1200 v8::Utils::OpenHandle(*global_proxy_template);
1135 Top::clear_pending_exception(); 1201 if (!ConfigureApiObject(global_proxy, outer_data)) return false;
1136 return false; 1202
1203 // Configure the inner global object.
1204 Handle<FunctionTemplateInfo> outer_constructor(
1205 FunctionTemplateInfo::cast(outer_data->constructor()));
1206 if (!outer_constructor->prototype_template()->IsUndefined()) {
1207 Handle<ObjectTemplateInfo> inner_data(
1208 ObjectTemplateInfo::cast(outer_constructor->prototype_template()));
1209 if (!ConfigureApiObject(js_global, inner_data)) return false;
1137 } 1210 }
1138 TransferObject(obj, global);
1139 } 1211 }
1212
1213 SetObjectPrototype(global_proxy, js_global);
1214 return true;
1215 }
1216
1217
1218 bool Genesis::ConfigureApiObject(Handle<JSObject> object,
1219 Handle<ObjectTemplateInfo> object_template) {
1220 ASSERT(!object_template.is_null());
1221 ASSERT(object->IsInstanceOf(
1222 FunctionTemplateInfo::cast(object_template->constructor())));
1223
1224 bool pending_exception = false;
1225 Handle<JSObject> obj =
1226 Execution::InstantiateObject(object_template, &pending_exception);
1227 if (pending_exception) {
1228 ASSERT(Top::has_pending_exception());
1229 Top::clear_pending_exception();
1230 return false;
1231 }
1232 TransferObject(obj, object);
1140 return true; 1233 return true;
1141 } 1234 }
1142 1235
1143 1236
1144 void Genesis::TransferNamedProperties(Handle<JSObject> from, 1237 void Genesis::TransferNamedProperties(Handle<JSObject> from,
1145 Handle<JSObject> to) { 1238 Handle<JSObject> to) {
1146 if (from->HasFastProperties()) { 1239 if (from->HasFastProperties()) {
1147 Handle<DescriptorArray> descs = 1240 Handle<DescriptorArray> descs =
1148 Handle<DescriptorArray>(from->map()->instance_descriptors()); 1241 Handle<DescriptorArray>(from->map()->instance_descriptors());
1149 int offset = 0; 1242 int offset = 0;
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
1324 // Before creating the roots we must save the context and restore it 1417 // Before creating the roots we must save the context and restore it
1325 // on all function exits. 1418 // on all function exits.
1326 HandleScope scope; 1419 HandleScope scope;
1327 SaveContext context; 1420 SaveContext context;
1328 1421
1329 CreateRoots(global_template, global_object); 1422 CreateRoots(global_template, global_object);
1330 if (!InstallNatives()) return; 1423 if (!InstallNatives()) return;
1331 1424
1332 MakeFunctionInstancePrototypeWritable(); 1425 MakeFunctionInstancePrototypeWritable();
1333 BuildSpecialFunctionTable(); 1426 BuildSpecialFunctionTable();
1334 if (!ConfigureGlobalObject(global_template)) return; 1427
1428 if (!ConfigureGlobalObjects(global_template)) return;
1335 1429
1336 if (!InstallExtensions(extensions)) return; 1430 if (!InstallExtensions(extensions)) return;
1337 1431
1338 if (!InstallSpecialObjects()) return; 1432 if (!InstallSpecialObjects()) return;
1339 1433
1340 result_ = global_context_; 1434 result_ = global_context_;
1341 } 1435 }
1342 1436
1343 } } // namespace v8::internal 1437 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/bootstrapper.h ('k') | src/builtins.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698