| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 149 | 149 |
| 150 Handle<Context> result() { return result_; } | 150 Handle<Context> result() { return result_; } |
| 151 | 151 |
| 152 Genesis* previous() { return previous_; } | 152 Genesis* previous() { return previous_; } |
| 153 | 153 |
| 154 Isolate* isolate() const { return isolate_; } | 154 Isolate* isolate() const { return isolate_; } |
| 155 Factory* factory() const { return isolate_->factory(); } | 155 Factory* factory() const { return isolate_->factory(); } |
| 156 Heap* heap() const { return isolate_->heap(); } | 156 Heap* heap() const { return isolate_->heap(); } |
| 157 | 157 |
| 158 private: | 158 private: |
| 159 Handle<Context> global_context_; | 159 Handle<Context> native_context_; |
| 160 Isolate* isolate_; | 160 Isolate* isolate_; |
| 161 | 161 |
| 162 // There may be more than one active genesis object: When GC is | 162 // There may be more than one active genesis object: When GC is |
| 163 // triggered during environment creation there may be weak handle | 163 // triggered during environment creation there may be weak handle |
| 164 // processing callbacks which may create new environments. | 164 // processing callbacks which may create new environments. |
| 165 Genesis* previous_; | 165 Genesis* previous_; |
| 166 | 166 |
| 167 Handle<Context> global_context() { return global_context_; } | 167 Handle<Context> native_context() { return native_context_; } |
| 168 | 168 |
| 169 // Creates some basic objects. Used for creating a context from scratch. | 169 // Creates some basic objects. Used for creating a context from scratch. |
| 170 void CreateRoots(); | 170 void CreateRoots(); |
| 171 // Creates the empty function. Used for creating a context from scratch. | 171 // Creates the empty function. Used for creating a context from scratch. |
| 172 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate); | 172 Handle<JSFunction> CreateEmptyFunction(Isolate* isolate); |
| 173 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3 | 173 // Creates the ThrowTypeError function. ECMA 5th Ed. 13.2.3 |
| 174 Handle<JSFunction> GetThrowTypeErrorFunction(); | 174 Handle<JSFunction> GetThrowTypeErrorFunction(); |
| 175 | 175 |
| 176 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty); | 176 void CreateStrictModeFunctionMaps(Handle<JSFunction> empty); |
| 177 | 177 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 221 ExtensionTraversalState get_state(RegisteredExtension* extension); | 221 ExtensionTraversalState get_state(RegisteredExtension* extension); |
| 222 void set_state(RegisteredExtension* extension, | 222 void set_state(RegisteredExtension* extension, |
| 223 ExtensionTraversalState state); | 223 ExtensionTraversalState state); |
| 224 private: | 224 private: |
| 225 HashMap map_; | 225 HashMap map_; |
| 226 DISALLOW_COPY_AND_ASSIGN(ExtensionStates); | 226 DISALLOW_COPY_AND_ASSIGN(ExtensionStates); |
| 227 }; | 227 }; |
| 228 | 228 |
| 229 // Used both for deserialized and from-scratch contexts to add the extensions | 229 // Used both for deserialized and from-scratch contexts to add the extensions |
| 230 // provided. | 230 // provided. |
| 231 static bool InstallExtensions(Handle<Context> global_context, | 231 static bool InstallExtensions(Handle<Context> native_context, |
| 232 v8::ExtensionConfiguration* extensions); | 232 v8::ExtensionConfiguration* extensions); |
| 233 static bool InstallExtension(const char* name, | 233 static bool InstallExtension(const char* name, |
| 234 ExtensionStates* extension_states); | 234 ExtensionStates* extension_states); |
| 235 static bool InstallExtension(v8::RegisteredExtension* current, | 235 static bool InstallExtension(v8::RegisteredExtension* current, |
| 236 ExtensionStates* extension_states); | 236 ExtensionStates* extension_states); |
| 237 static void InstallSpecialObjects(Handle<Context> global_context); | 237 static void InstallSpecialObjects(Handle<Context> native_context); |
| 238 bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins); | 238 bool InstallJSBuiltins(Handle<JSBuiltinsObject> builtins); |
| 239 bool ConfigureApiObject(Handle<JSObject> object, | 239 bool ConfigureApiObject(Handle<JSObject> object, |
| 240 Handle<ObjectTemplateInfo> object_template); | 240 Handle<ObjectTemplateInfo> object_template); |
| 241 bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template); | 241 bool ConfigureGlobalObjects(v8::Handle<v8::ObjectTemplate> global_template); |
| 242 | 242 |
| 243 // Migrates all properties from the 'from' object to the 'to' | 243 // Migrates all properties from the 'from' object to the 'to' |
| 244 // object and overrides the prototype in 'to' with the one from | 244 // object and overrides the prototype in 'to' with the one from |
| 245 // 'from'. | 245 // 'from'. |
| 246 void TransferObject(Handle<JSObject> from, Handle<JSObject> to); | 246 void TransferObject(Handle<JSObject> from, Handle<JSObject> to); |
| 247 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); | 247 void TransferNamedProperties(Handle<JSObject> from, Handle<JSObject> to); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 | 437 |
| 438 | 438 |
| 439 Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { | 439 Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { |
| 440 // Allocate the map for function instances. Maps are allocated first and their | 440 // Allocate the map for function instances. Maps are allocated first and their |
| 441 // prototypes patched later, once empty function is created. | 441 // prototypes patched later, once empty function is created. |
| 442 | 442 |
| 443 // Please note that the prototype property for function instances must be | 443 // Please note that the prototype property for function instances must be |
| 444 // writable. | 444 // writable. |
| 445 Handle<Map> function_instance_map = | 445 Handle<Map> function_instance_map = |
| 446 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); | 446 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); |
| 447 global_context()->set_function_instance_map(*function_instance_map); | 447 native_context()->set_function_instance_map(*function_instance_map); |
| 448 | 448 |
| 449 // Functions with this map will not have a 'prototype' property, and | 449 // Functions with this map will not have a 'prototype' property, and |
| 450 // can not be used as constructors. | 450 // can not be used as constructors. |
| 451 Handle<Map> function_without_prototype_map = | 451 Handle<Map> function_without_prototype_map = |
| 452 CreateFunctionMap(DONT_ADD_PROTOTYPE); | 452 CreateFunctionMap(DONT_ADD_PROTOTYPE); |
| 453 global_context()->set_function_without_prototype_map( | 453 native_context()->set_function_without_prototype_map( |
| 454 *function_without_prototype_map); | 454 *function_without_prototype_map); |
| 455 | 455 |
| 456 // Allocate the function map. This map is temporary, used only for processing | 456 // Allocate the function map. This map is temporary, used only for processing |
| 457 // of builtins. | 457 // of builtins. |
| 458 // Later the map is replaced with writable prototype map, allocated below. | 458 // Later the map is replaced with writable prototype map, allocated below. |
| 459 Handle<Map> function_map = CreateFunctionMap(ADD_READONLY_PROTOTYPE); | 459 Handle<Map> function_map = CreateFunctionMap(ADD_READONLY_PROTOTYPE); |
| 460 global_context()->set_function_map(*function_map); | 460 native_context()->set_function_map(*function_map); |
| 461 | 461 |
| 462 // The final map for functions. Writeable prototype. | 462 // The final map for functions. Writeable prototype. |
| 463 // This map is installed in MakeFunctionInstancePrototypeWritable. | 463 // This map is installed in MakeFunctionInstancePrototypeWritable. |
| 464 function_instance_map_writable_prototype_ = | 464 function_instance_map_writable_prototype_ = |
| 465 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); | 465 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); |
| 466 | 466 |
| 467 Factory* factory = isolate->factory(); | 467 Factory* factory = isolate->factory(); |
| 468 Heap* heap = isolate->heap(); | 468 Heap* heap = isolate->heap(); |
| 469 | 469 |
| 470 Handle<String> object_name = Handle<String>(heap->Object_symbol()); | 470 Handle<String> object_name = Handle<String>(heap->Object_symbol()); |
| 471 | 471 |
| 472 { // --- O b j e c t --- | 472 { // --- O b j e c t --- |
| 473 Handle<JSFunction> object_fun = | 473 Handle<JSFunction> object_fun = |
| 474 factory->NewFunction(object_name, factory->null_value()); | 474 factory->NewFunction(object_name, factory->null_value()); |
| 475 Handle<Map> object_function_map = | 475 Handle<Map> object_function_map = |
| 476 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); | 476 factory->NewMap(JS_OBJECT_TYPE, JSObject::kHeaderSize); |
| 477 object_fun->set_initial_map(*object_function_map); | 477 object_fun->set_initial_map(*object_function_map); |
| 478 object_function_map->set_constructor(*object_fun); | 478 object_function_map->set_constructor(*object_fun); |
| 479 | 479 |
| 480 global_context()->set_object_function(*object_fun); | 480 native_context()->set_object_function(*object_fun); |
| 481 | 481 |
| 482 // Allocate a new prototype for the object function. | 482 // Allocate a new prototype for the object function. |
| 483 Handle<JSObject> prototype = factory->NewJSObject( | 483 Handle<JSObject> prototype = factory->NewJSObject( |
| 484 isolate->object_function(), | 484 isolate->object_function(), |
| 485 TENURED); | 485 TENURED); |
| 486 | 486 |
| 487 global_context()->set_initial_object_prototype(*prototype); | 487 native_context()->set_initial_object_prototype(*prototype); |
| 488 SetPrototype(object_fun, prototype); | 488 SetPrototype(object_fun, prototype); |
| 489 } | 489 } |
| 490 | 490 |
| 491 // Allocate the empty function as the prototype for function ECMAScript | 491 // Allocate the empty function as the prototype for function ECMAScript |
| 492 // 262 15.3.4. | 492 // 262 15.3.4. |
| 493 Handle<String> symbol = factory->LookupAsciiSymbol("Empty"); | 493 Handle<String> symbol = factory->LookupAsciiSymbol("Empty"); |
| 494 Handle<JSFunction> empty_function = | 494 Handle<JSFunction> empty_function = |
| 495 factory->NewFunctionWithoutPrototype(symbol, CLASSIC_MODE); | 495 factory->NewFunctionWithoutPrototype(symbol, CLASSIC_MODE); |
| 496 | 496 |
| 497 // --- E m p t y --- | 497 // --- E m p t y --- |
| 498 Handle<Code> code = | 498 Handle<Code> code = |
| 499 Handle<Code>(isolate->builtins()->builtin( | 499 Handle<Code>(isolate->builtins()->builtin( |
| 500 Builtins::kEmptyFunction)); | 500 Builtins::kEmptyFunction)); |
| 501 empty_function->set_code(*code); | 501 empty_function->set_code(*code); |
| 502 empty_function->shared()->set_code(*code); | 502 empty_function->shared()->set_code(*code); |
| 503 Handle<String> source = factory->NewStringFromAscii(CStrVector("() {}")); | 503 Handle<String> source = factory->NewStringFromAscii(CStrVector("() {}")); |
| 504 Handle<Script> script = factory->NewScript(source); | 504 Handle<Script> script = factory->NewScript(source); |
| 505 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 505 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| 506 empty_function->shared()->set_script(*script); | 506 empty_function->shared()->set_script(*script); |
| 507 empty_function->shared()->set_start_position(0); | 507 empty_function->shared()->set_start_position(0); |
| 508 empty_function->shared()->set_end_position(source->length()); | 508 empty_function->shared()->set_end_position(source->length()); |
| 509 empty_function->shared()->DontAdaptArguments(); | 509 empty_function->shared()->DontAdaptArguments(); |
| 510 | 510 |
| 511 // Set prototypes for the function maps. | 511 // Set prototypes for the function maps. |
| 512 global_context()->function_map()->set_prototype(*empty_function); | 512 native_context()->function_map()->set_prototype(*empty_function); |
| 513 global_context()->function_instance_map()->set_prototype(*empty_function); | 513 native_context()->function_instance_map()->set_prototype(*empty_function); |
| 514 global_context()->function_without_prototype_map()-> | 514 native_context()->function_without_prototype_map()-> |
| 515 set_prototype(*empty_function); | 515 set_prototype(*empty_function); |
| 516 function_instance_map_writable_prototype_->set_prototype(*empty_function); | 516 function_instance_map_writable_prototype_->set_prototype(*empty_function); |
| 517 | 517 |
| 518 // Allocate the function map first and then patch the prototype later | 518 // Allocate the function map first and then patch the prototype later |
| 519 Handle<Map> empty_function_map = CreateFunctionMap(DONT_ADD_PROTOTYPE); | 519 Handle<Map> empty_function_map = CreateFunctionMap(DONT_ADD_PROTOTYPE); |
| 520 empty_function_map->set_prototype( | 520 empty_function_map->set_prototype( |
| 521 global_context()->object_function()->prototype()); | 521 native_context()->object_function()->prototype()); |
| 522 empty_function->set_map(*empty_function_map); | 522 empty_function->set_map(*empty_function_map); |
| 523 return empty_function; | 523 return empty_function; |
| 524 } | 524 } |
| 525 | 525 |
| 526 | 526 |
| 527 void Genesis::SetStrictFunctionInstanceDescriptor( | 527 void Genesis::SetStrictFunctionInstanceDescriptor( |
| 528 Handle<Map> map, PrototypePropertyMode prototypeMode) { | 528 Handle<Map> map, PrototypePropertyMode prototypeMode) { |
| 529 int size = (prototypeMode == DONT_ADD_PROTOTYPE) ? 4 : 5; | 529 int size = (prototypeMode == DONT_ADD_PROTOTYPE) ? 4 : 5; |
| 530 Handle<DescriptorArray> descriptors(factory()->NewDescriptorArray(size)); | 530 Handle<DescriptorArray> descriptors(factory()->NewDescriptorArray(size)); |
| 531 DescriptorArray::WhitenessWitness witness(*descriptors); | 531 DescriptorArray::WhitenessWitness witness(*descriptors); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 | 571 |
| 572 // ECMAScript 5th Edition, 13.2.3 | 572 // ECMAScript 5th Edition, 13.2.3 |
| 573 Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() { | 573 Handle<JSFunction> Genesis::GetThrowTypeErrorFunction() { |
| 574 if (throw_type_error_function.is_null()) { | 574 if (throw_type_error_function.is_null()) { |
| 575 Handle<String> name = factory()->LookupAsciiSymbol("ThrowTypeError"); | 575 Handle<String> name = factory()->LookupAsciiSymbol("ThrowTypeError"); |
| 576 throw_type_error_function = | 576 throw_type_error_function = |
| 577 factory()->NewFunctionWithoutPrototype(name, CLASSIC_MODE); | 577 factory()->NewFunctionWithoutPrototype(name, CLASSIC_MODE); |
| 578 Handle<Code> code(isolate()->builtins()->builtin( | 578 Handle<Code> code(isolate()->builtins()->builtin( |
| 579 Builtins::kStrictModePoisonPill)); | 579 Builtins::kStrictModePoisonPill)); |
| 580 throw_type_error_function->set_map( | 580 throw_type_error_function->set_map( |
| 581 global_context()->function_map()); | 581 native_context()->function_map()); |
| 582 throw_type_error_function->set_code(*code); | 582 throw_type_error_function->set_code(*code); |
| 583 throw_type_error_function->shared()->set_code(*code); | 583 throw_type_error_function->shared()->set_code(*code); |
| 584 throw_type_error_function->shared()->DontAdaptArguments(); | 584 throw_type_error_function->shared()->DontAdaptArguments(); |
| 585 | 585 |
| 586 JSObject::PreventExtensions(throw_type_error_function); | 586 JSObject::PreventExtensions(throw_type_error_function); |
| 587 } | 587 } |
| 588 return throw_type_error_function; | 588 return throw_type_error_function; |
| 589 } | 589 } |
| 590 | 590 |
| 591 | 591 |
| 592 Handle<Map> Genesis::CreateStrictModeFunctionMap( | 592 Handle<Map> Genesis::CreateStrictModeFunctionMap( |
| 593 PrototypePropertyMode prototype_mode, | 593 PrototypePropertyMode prototype_mode, |
| 594 Handle<JSFunction> empty_function) { | 594 Handle<JSFunction> empty_function) { |
| 595 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); | 595 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
| 596 SetStrictFunctionInstanceDescriptor(map, prototype_mode); | 596 SetStrictFunctionInstanceDescriptor(map, prototype_mode); |
| 597 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); | 597 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); |
| 598 map->set_prototype(*empty_function); | 598 map->set_prototype(*empty_function); |
| 599 return map; | 599 return map; |
| 600 } | 600 } |
| 601 | 601 |
| 602 | 602 |
| 603 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { | 603 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { |
| 604 // Allocate map for the strict mode function instances. | 604 // Allocate map for the strict mode function instances. |
| 605 Handle<Map> strict_mode_function_instance_map = | 605 Handle<Map> strict_mode_function_instance_map = |
| 606 CreateStrictModeFunctionMap(ADD_WRITEABLE_PROTOTYPE, empty); | 606 CreateStrictModeFunctionMap(ADD_WRITEABLE_PROTOTYPE, empty); |
| 607 global_context()->set_strict_mode_function_instance_map( | 607 native_context()->set_strict_mode_function_instance_map( |
| 608 *strict_mode_function_instance_map); | 608 *strict_mode_function_instance_map); |
| 609 | 609 |
| 610 // Allocate map for the prototype-less strict mode instances. | 610 // Allocate map for the prototype-less strict mode instances. |
| 611 Handle<Map> strict_mode_function_without_prototype_map = | 611 Handle<Map> strict_mode_function_without_prototype_map = |
| 612 CreateStrictModeFunctionMap(DONT_ADD_PROTOTYPE, empty); | 612 CreateStrictModeFunctionMap(DONT_ADD_PROTOTYPE, empty); |
| 613 global_context()->set_strict_mode_function_without_prototype_map( | 613 native_context()->set_strict_mode_function_without_prototype_map( |
| 614 *strict_mode_function_without_prototype_map); | 614 *strict_mode_function_without_prototype_map); |
| 615 | 615 |
| 616 // Allocate map for the strict mode functions. This map is temporary, used | 616 // Allocate map for the strict mode functions. This map is temporary, used |
| 617 // only for processing of builtins. | 617 // only for processing of builtins. |
| 618 // Later the map is replaced with writable prototype map, allocated below. | 618 // Later the map is replaced with writable prototype map, allocated below. |
| 619 Handle<Map> strict_mode_function_map = | 619 Handle<Map> strict_mode_function_map = |
| 620 CreateStrictModeFunctionMap(ADD_READONLY_PROTOTYPE, empty); | 620 CreateStrictModeFunctionMap(ADD_READONLY_PROTOTYPE, empty); |
| 621 global_context()->set_strict_mode_function_map( | 621 native_context()->set_strict_mode_function_map( |
| 622 *strict_mode_function_map); | 622 *strict_mode_function_map); |
| 623 | 623 |
| 624 // The final map for the strict mode functions. Writeable prototype. | 624 // The final map for the strict mode functions. Writeable prototype. |
| 625 // This map is installed in MakeFunctionInstancePrototypeWritable. | 625 // This map is installed in MakeFunctionInstancePrototypeWritable. |
| 626 strict_mode_function_instance_map_writable_prototype_ = | 626 strict_mode_function_instance_map_writable_prototype_ = |
| 627 CreateStrictModeFunctionMap(ADD_WRITEABLE_PROTOTYPE, empty); | 627 CreateStrictModeFunctionMap(ADD_WRITEABLE_PROTOTYPE, empty); |
| 628 | 628 |
| 629 // Complete the callbacks. | 629 // Complete the callbacks. |
| 630 PoisonArgumentsAndCaller(strict_mode_function_instance_map); | 630 PoisonArgumentsAndCaller(strict_mode_function_instance_map); |
| 631 PoisonArgumentsAndCaller(strict_mode_function_without_prototype_map); | 631 PoisonArgumentsAndCaller(strict_mode_function_without_prototype_map); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 645 accessors->set_setter(*func); | 645 accessors->set_setter(*func); |
| 646 } | 646 } |
| 647 | 647 |
| 648 | 648 |
| 649 void Genesis::PoisonArgumentsAndCaller(Handle<Map> map) { | 649 void Genesis::PoisonArgumentsAndCaller(Handle<Map> map) { |
| 650 SetAccessors(map, factory()->arguments_symbol(), GetThrowTypeErrorFunction()); | 650 SetAccessors(map, factory()->arguments_symbol(), GetThrowTypeErrorFunction()); |
| 651 SetAccessors(map, factory()->caller_symbol(), GetThrowTypeErrorFunction()); | 651 SetAccessors(map, factory()->caller_symbol(), GetThrowTypeErrorFunction()); |
| 652 } | 652 } |
| 653 | 653 |
| 654 | 654 |
| 655 static void AddToWeakGlobalContextList(Context* context) { | 655 static void AddToWeakNativeContextList(Context* context) { |
| 656 ASSERT(context->IsGlobalContext()); | 656 ASSERT(context->IsNativeContext()); |
| 657 Heap* heap = context->GetIsolate()->heap(); | 657 Heap* heap = context->GetIsolate()->heap(); |
| 658 #ifdef DEBUG | 658 #ifdef DEBUG |
| 659 { // NOLINT | 659 { // NOLINT |
| 660 ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined()); | 660 ASSERT(context->get(Context::NEXT_CONTEXT_LINK)->IsUndefined()); |
| 661 // Check that context is not in the list yet. | 661 // Check that context is not in the list yet. |
| 662 for (Object* current = heap->global_contexts_list(); | 662 for (Object* current = heap->native_contexts_list(); |
| 663 !current->IsUndefined(); | 663 !current->IsUndefined(); |
| 664 current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) { | 664 current = Context::cast(current)->get(Context::NEXT_CONTEXT_LINK)) { |
| 665 ASSERT(current != context); | 665 ASSERT(current != context); |
| 666 } | 666 } |
| 667 } | 667 } |
| 668 #endif | 668 #endif |
| 669 context->set(Context::NEXT_CONTEXT_LINK, heap->global_contexts_list()); | 669 context->set(Context::NEXT_CONTEXT_LINK, heap->native_contexts_list()); |
| 670 heap->set_global_contexts_list(context); | 670 heap->set_native_contexts_list(context); |
| 671 } | 671 } |
| 672 | 672 |
| 673 | 673 |
| 674 void Genesis::CreateRoots() { | 674 void Genesis::CreateRoots() { |
| 675 // Allocate the global context FixedArray first and then patch the | 675 // Allocate the native context FixedArray first and then patch the |
| 676 // closure and extension object later (we need the empty function | 676 // closure and extension object later (we need the empty function |
| 677 // and the global object, but in order to create those, we need the | 677 // and the global object, but in order to create those, we need the |
| 678 // global context). | 678 // native context). |
| 679 global_context_ = Handle<Context>::cast(isolate()->global_handles()->Create( | 679 native_context_ = Handle<Context>::cast(isolate()->global_handles()->Create( |
| 680 *factory()->NewGlobalContext())); | 680 *factory()->NewNativeContext())); |
| 681 AddToWeakGlobalContextList(*global_context_); | 681 AddToWeakNativeContextList(*native_context_); |
| 682 isolate()->set_context(*global_context()); | 682 isolate()->set_context(*native_context()); |
| 683 | 683 |
| 684 // Allocate the message listeners object. | 684 // Allocate the message listeners object. |
| 685 { | 685 { |
| 686 v8::NeanderArray listeners; | 686 v8::NeanderArray listeners; |
| 687 global_context()->set_message_listeners(*listeners.value()); | 687 native_context()->set_message_listeners(*listeners.value()); |
| 688 } | 688 } |
| 689 } | 689 } |
| 690 | 690 |
| 691 | 691 |
| 692 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( | 692 Handle<JSGlobalProxy> Genesis::CreateNewGlobals( |
| 693 v8::Handle<v8::ObjectTemplate> global_template, | 693 v8::Handle<v8::ObjectTemplate> global_template, |
| 694 Handle<Object> global_object, | 694 Handle<Object> global_object, |
| 695 Handle<GlobalObject>* inner_global_out) { | 695 Handle<GlobalObject>* inner_global_out) { |
| 696 // The argument global_template aka data is an ObjectTemplateInfo. | 696 // The argument global_template aka data is an ObjectTemplateInfo. |
| 697 // It has a constructor pointer that points at global_constructor which is a | 697 // It has a constructor pointer that points at global_constructor which is a |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 Handle<JSGlobalProxy>::cast(global_object)); | 787 Handle<JSGlobalProxy>::cast(global_object)); |
| 788 } else { | 788 } else { |
| 789 return Handle<JSGlobalProxy>::cast( | 789 return Handle<JSGlobalProxy>::cast( |
| 790 factory()->NewJSObject(global_proxy_function, TENURED)); | 790 factory()->NewJSObject(global_proxy_function, TENURED)); |
| 791 } | 791 } |
| 792 } | 792 } |
| 793 | 793 |
| 794 | 794 |
| 795 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global, | 795 void Genesis::HookUpGlobalProxy(Handle<GlobalObject> inner_global, |
| 796 Handle<JSGlobalProxy> global_proxy) { | 796 Handle<JSGlobalProxy> global_proxy) { |
| 797 // Set the global context for the global object. | 797 // Set the native context for the global object. |
| 798 inner_global->set_global_context(*global_context()); | 798 inner_global->set_native_context(*native_context()); |
| 799 inner_global->set_global_receiver(*global_proxy); | 799 inner_global->set_global_receiver(*global_proxy); |
| 800 global_proxy->set_context(*global_context()); | 800 global_proxy->set_context(*native_context()); |
| 801 global_context()->set_global_proxy(*global_proxy); | 801 native_context()->set_global_proxy(*global_proxy); |
| 802 } | 802 } |
| 803 | 803 |
| 804 | 804 |
| 805 void Genesis::HookUpInnerGlobal(Handle<GlobalObject> inner_global) { | 805 void Genesis::HookUpInnerGlobal(Handle<GlobalObject> inner_global) { |
| 806 Handle<GlobalObject> inner_global_from_snapshot( | 806 Handle<GlobalObject> inner_global_from_snapshot( |
| 807 GlobalObject::cast(global_context_->extension())); | 807 GlobalObject::cast(native_context_->extension())); |
| 808 Handle<JSBuiltinsObject> builtins_global(global_context_->builtins()); | 808 Handle<JSBuiltinsObject> builtins_global(native_context_->builtins()); |
| 809 global_context_->set_extension(*inner_global); | 809 native_context_->set_extension(*inner_global); |
| 810 global_context_->set_global(*inner_global); | 810 native_context_->set_global(*inner_global); |
| 811 global_context_->set_security_token(*inner_global); | 811 native_context_->set_security_token(*inner_global); |
| 812 static const PropertyAttributes attributes = | 812 static const PropertyAttributes attributes = |
| 813 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); | 813 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
| 814 ForceSetProperty(builtins_global, | 814 ForceSetProperty(builtins_global, |
| 815 factory()->LookupAsciiSymbol("global"), | 815 factory()->LookupAsciiSymbol("global"), |
| 816 inner_global, | 816 inner_global, |
| 817 attributes); | 817 attributes); |
| 818 // Set up the reference from the global object to the builtins object. | 818 // Set up the reference from the global object to the builtins object. |
| 819 JSGlobalObject::cast(*inner_global)->set_builtins(*builtins_global); | 819 JSGlobalObject::cast(*inner_global)->set_builtins(*builtins_global); |
| 820 TransferNamedProperties(inner_global_from_snapshot, inner_global); | 820 TransferNamedProperties(inner_global_from_snapshot, inner_global); |
| 821 TransferIndexedProperties(inner_global_from_snapshot, inner_global); | 821 TransferIndexedProperties(inner_global_from_snapshot, inner_global); |
| 822 } | 822 } |
| 823 | 823 |
| 824 | 824 |
| 825 // This is only called if we are not using snapshots. The equivalent | 825 // This is only called if we are not using snapshots. The equivalent |
| 826 // work in the snapshot case is done in HookUpInnerGlobal. | 826 // work in the snapshot case is done in HookUpInnerGlobal. |
| 827 bool Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, | 827 bool Genesis::InitializeGlobal(Handle<GlobalObject> inner_global, |
| 828 Handle<JSFunction> empty_function) { | 828 Handle<JSFunction> empty_function) { |
| 829 // --- G l o b a l C o n t e x t --- | 829 // --- G l o b a l C o n t e x t --- |
| 830 // Use the empty function as closure (no scope info). | 830 // Use the empty function as closure (no scope info). |
| 831 global_context()->set_closure(*empty_function); | 831 native_context()->set_closure(*empty_function); |
| 832 global_context()->set_previous(NULL); | 832 native_context()->set_previous(NULL); |
| 833 // Set extension and global object. | 833 // Set extension and global object. |
| 834 global_context()->set_extension(*inner_global); | 834 native_context()->set_extension(*inner_global); |
| 835 global_context()->set_global(*inner_global); | 835 native_context()->set_global(*inner_global); |
| 836 // Security setup: Set the security token of the global object to | 836 // Security setup: Set the security token of the global object to |
| 837 // its the inner global. This makes the security check between two | 837 // its the inner global. This makes the security check between two |
| 838 // different contexts fail by default even in case of global | 838 // different contexts fail by default even in case of global |
| 839 // object reinitialization. | 839 // object reinitialization. |
| 840 global_context()->set_security_token(*inner_global); | 840 native_context()->set_security_token(*inner_global); |
| 841 | 841 |
| 842 Isolate* isolate = inner_global->GetIsolate(); | 842 Isolate* isolate = inner_global->GetIsolate(); |
| 843 Factory* factory = isolate->factory(); | 843 Factory* factory = isolate->factory(); |
| 844 Heap* heap = isolate->heap(); | 844 Heap* heap = isolate->heap(); |
| 845 | 845 |
| 846 Handle<String> object_name = Handle<String>(heap->Object_symbol()); | 846 Handle<String> object_name = Handle<String>(heap->Object_symbol()); |
| 847 CHECK_NOT_EMPTY_HANDLE(isolate, | 847 CHECK_NOT_EMPTY_HANDLE(isolate, |
| 848 JSObject::SetLocalPropertyIgnoreAttributes( | 848 JSObject::SetLocalPropertyIgnoreAttributes( |
| 849 inner_global, object_name, | 849 inner_global, object_name, |
| 850 isolate->object_function(), DONT_ENUM)); | 850 isolate->object_function(), DONT_ENUM)); |
| 851 | 851 |
| 852 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); | 852 Handle<JSObject> global = Handle<JSObject>(native_context()->global()); |
| 853 | 853 |
| 854 // Install global Function object | 854 // Install global Function object |
| 855 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, | 855 InstallFunction(global, "Function", JS_FUNCTION_TYPE, JSFunction::kSize, |
| 856 empty_function, Builtins::kIllegal, true); // ECMA native. | 856 empty_function, Builtins::kIllegal, true); // ECMA native. |
| 857 | 857 |
| 858 { // --- A r r a y --- | 858 { // --- A r r a y --- |
| 859 Handle<JSFunction> array_function = | 859 Handle<JSFunction> array_function = |
| 860 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, | 860 InstallFunction(global, "Array", JS_ARRAY_TYPE, JSArray::kSize, |
| 861 isolate->initial_object_prototype(), | 861 isolate->initial_object_prototype(), |
| 862 Builtins::kArrayCode, true); | 862 Builtins::kArrayCode, true); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 879 | 879 |
| 880 { // Add length. | 880 { // Add length. |
| 881 CallbacksDescriptor d(*factory->length_symbol(), *array_length, attribs); | 881 CallbacksDescriptor d(*factory->length_symbol(), *array_length, attribs); |
| 882 array_function->initial_map()->AppendDescriptor(&d, witness); | 882 array_function->initial_map()->AppendDescriptor(&d, witness); |
| 883 } | 883 } |
| 884 | 884 |
| 885 // array_function is used internally. JS code creating array object should | 885 // array_function is used internally. JS code creating array object should |
| 886 // search for the 'Array' property on the global object and use that one | 886 // search for the 'Array' property on the global object and use that one |
| 887 // as the constructor. 'Array' property on a global object can be | 887 // as the constructor. 'Array' property on a global object can be |
| 888 // overwritten by JS code. | 888 // overwritten by JS code. |
| 889 global_context()->set_array_function(*array_function); | 889 native_context()->set_array_function(*array_function); |
| 890 } | 890 } |
| 891 | 891 |
| 892 { // --- N u m b e r --- | 892 { // --- N u m b e r --- |
| 893 Handle<JSFunction> number_fun = | 893 Handle<JSFunction> number_fun = |
| 894 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, | 894 InstallFunction(global, "Number", JS_VALUE_TYPE, JSValue::kSize, |
| 895 isolate->initial_object_prototype(), | 895 isolate->initial_object_prototype(), |
| 896 Builtins::kIllegal, true); | 896 Builtins::kIllegal, true); |
| 897 global_context()->set_number_function(*number_fun); | 897 native_context()->set_number_function(*number_fun); |
| 898 } | 898 } |
| 899 | 899 |
| 900 { // --- B o o l e a n --- | 900 { // --- B o o l e a n --- |
| 901 Handle<JSFunction> boolean_fun = | 901 Handle<JSFunction> boolean_fun = |
| 902 InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, | 902 InstallFunction(global, "Boolean", JS_VALUE_TYPE, JSValue::kSize, |
| 903 isolate->initial_object_prototype(), | 903 isolate->initial_object_prototype(), |
| 904 Builtins::kIllegal, true); | 904 Builtins::kIllegal, true); |
| 905 global_context()->set_boolean_function(*boolean_fun); | 905 native_context()->set_boolean_function(*boolean_fun); |
| 906 } | 906 } |
| 907 | 907 |
| 908 { // --- S t r i n g --- | 908 { // --- S t r i n g --- |
| 909 Handle<JSFunction> string_fun = | 909 Handle<JSFunction> string_fun = |
| 910 InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize, | 910 InstallFunction(global, "String", JS_VALUE_TYPE, JSValue::kSize, |
| 911 isolate->initial_object_prototype(), | 911 isolate->initial_object_prototype(), |
| 912 Builtins::kIllegal, true); | 912 Builtins::kIllegal, true); |
| 913 string_fun->shared()->set_construct_stub( | 913 string_fun->shared()->set_construct_stub( |
| 914 isolate->builtins()->builtin(Builtins::kStringConstructCode)); | 914 isolate->builtins()->builtin(Builtins::kStringConstructCode)); |
| 915 global_context()->set_string_function(*string_fun); | 915 native_context()->set_string_function(*string_fun); |
| 916 | 916 |
| 917 Handle<Map> string_map = | 917 Handle<Map> string_map = |
| 918 Handle<Map>(global_context()->string_function()->initial_map()); | 918 Handle<Map>(native_context()->string_function()->initial_map()); |
| 919 Handle<DescriptorArray> string_descriptors(factory->NewDescriptorArray(1)); | 919 Handle<DescriptorArray> string_descriptors(factory->NewDescriptorArray(1)); |
| 920 DescriptorArray::WhitenessWitness witness(*string_descriptors); | 920 DescriptorArray::WhitenessWitness witness(*string_descriptors); |
| 921 | 921 |
| 922 Handle<Foreign> string_length( | 922 Handle<Foreign> string_length( |
| 923 factory->NewForeign(&Accessors::StringLength)); | 923 factory->NewForeign(&Accessors::StringLength)); |
| 924 PropertyAttributes attribs = static_cast<PropertyAttributes>( | 924 PropertyAttributes attribs = static_cast<PropertyAttributes>( |
| 925 DONT_ENUM | DONT_DELETE | READ_ONLY); | 925 DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 926 Map::SetDescriptors(string_map, string_descriptors); | 926 Map::SetDescriptors(string_map, string_descriptors); |
| 927 | 927 |
| 928 { // Add length. | 928 { // Add length. |
| 929 CallbacksDescriptor d(*factory->length_symbol(), *string_length, attribs); | 929 CallbacksDescriptor d(*factory->length_symbol(), *string_length, attribs); |
| 930 string_map->AppendDescriptor(&d, witness); | 930 string_map->AppendDescriptor(&d, witness); |
| 931 } | 931 } |
| 932 } | 932 } |
| 933 | 933 |
| 934 { // --- D a t e --- | 934 { // --- D a t e --- |
| 935 // Builtin functions for Date.prototype. | 935 // Builtin functions for Date.prototype. |
| 936 Handle<JSFunction> date_fun = | 936 Handle<JSFunction> date_fun = |
| 937 InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize, | 937 InstallFunction(global, "Date", JS_DATE_TYPE, JSDate::kSize, |
| 938 isolate->initial_object_prototype(), | 938 isolate->initial_object_prototype(), |
| 939 Builtins::kIllegal, true); | 939 Builtins::kIllegal, true); |
| 940 | 940 |
| 941 global_context()->set_date_function(*date_fun); | 941 native_context()->set_date_function(*date_fun); |
| 942 } | 942 } |
| 943 | 943 |
| 944 | 944 |
| 945 { // -- R e g E x p | 945 { // -- R e g E x p |
| 946 // Builtin functions for RegExp.prototype. | 946 // Builtin functions for RegExp.prototype. |
| 947 Handle<JSFunction> regexp_fun = | 947 Handle<JSFunction> regexp_fun = |
| 948 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, | 948 InstallFunction(global, "RegExp", JS_REGEXP_TYPE, JSRegExp::kSize, |
| 949 isolate->initial_object_prototype(), | 949 isolate->initial_object_prototype(), |
| 950 Builtins::kIllegal, true); | 950 Builtins::kIllegal, true); |
| 951 global_context()->set_regexp_function(*regexp_fun); | 951 native_context()->set_regexp_function(*regexp_fun); |
| 952 | 952 |
| 953 ASSERT(regexp_fun->has_initial_map()); | 953 ASSERT(regexp_fun->has_initial_map()); |
| 954 Handle<Map> initial_map(regexp_fun->initial_map()); | 954 Handle<Map> initial_map(regexp_fun->initial_map()); |
| 955 | 955 |
| 956 ASSERT_EQ(0, initial_map->inobject_properties()); | 956 ASSERT_EQ(0, initial_map->inobject_properties()); |
| 957 | 957 |
| 958 PropertyAttributes final = | 958 PropertyAttributes final = |
| 959 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 959 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 960 Handle<DescriptorArray> descriptors = factory->NewDescriptorArray(5); | 960 Handle<DescriptorArray> descriptors = factory->NewDescriptorArray(5); |
| 961 DescriptorArray::WhitenessWitness witness(*descriptors); | 961 DescriptorArray::WhitenessWitness witness(*descriptors); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 | 1001 |
| 1002 initial_map->set_inobject_properties(5); | 1002 initial_map->set_inobject_properties(5); |
| 1003 initial_map->set_pre_allocated_property_fields(5); | 1003 initial_map->set_pre_allocated_property_fields(5); |
| 1004 initial_map->set_unused_property_fields(0); | 1004 initial_map->set_unused_property_fields(0); |
| 1005 initial_map->set_instance_size( | 1005 initial_map->set_instance_size( |
| 1006 initial_map->instance_size() + 5 * kPointerSize); | 1006 initial_map->instance_size() + 5 * kPointerSize); |
| 1007 initial_map->set_visitor_id(StaticVisitorBase::GetVisitorId(*initial_map)); | 1007 initial_map->set_visitor_id(StaticVisitorBase::GetVisitorId(*initial_map)); |
| 1008 | 1008 |
| 1009 // RegExp prototype object is itself a RegExp. | 1009 // RegExp prototype object is itself a RegExp. |
| 1010 Handle<Map> proto_map = factory->CopyMap(initial_map); | 1010 Handle<Map> proto_map = factory->CopyMap(initial_map); |
| 1011 proto_map->set_prototype(global_context()->initial_object_prototype()); | 1011 proto_map->set_prototype(native_context()->initial_object_prototype()); |
| 1012 Handle<JSObject> proto = factory->NewJSObjectFromMap(proto_map); | 1012 Handle<JSObject> proto = factory->NewJSObjectFromMap(proto_map); |
| 1013 proto->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex, | 1013 proto->InObjectPropertyAtPut(JSRegExp::kSourceFieldIndex, |
| 1014 heap->query_colon_symbol()); | 1014 heap->query_colon_symbol()); |
| 1015 proto->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex, | 1015 proto->InObjectPropertyAtPut(JSRegExp::kGlobalFieldIndex, |
| 1016 heap->false_value()); | 1016 heap->false_value()); |
| 1017 proto->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex, | 1017 proto->InObjectPropertyAtPut(JSRegExp::kIgnoreCaseFieldIndex, |
| 1018 heap->false_value()); | 1018 heap->false_value()); |
| 1019 proto->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex, | 1019 proto->InObjectPropertyAtPut(JSRegExp::kMultilineFieldIndex, |
| 1020 heap->false_value()); | 1020 heap->false_value()); |
| 1021 proto->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, | 1021 proto->InObjectPropertyAtPut(JSRegExp::kLastIndexFieldIndex, |
| 1022 Smi::FromInt(0), | 1022 Smi::FromInt(0), |
| 1023 SKIP_WRITE_BARRIER); // It's a Smi. | 1023 SKIP_WRITE_BARRIER); // It's a Smi. |
| 1024 initial_map->set_prototype(*proto); | 1024 initial_map->set_prototype(*proto); |
| 1025 factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto), | 1025 factory->SetRegExpIrregexpData(Handle<JSRegExp>::cast(proto), |
| 1026 JSRegExp::IRREGEXP, factory->empty_string(), | 1026 JSRegExp::IRREGEXP, factory->empty_string(), |
| 1027 JSRegExp::Flags(0), 0); | 1027 JSRegExp::Flags(0), 0); |
| 1028 } | 1028 } |
| 1029 | 1029 |
| 1030 { // -- J S O N | 1030 { // -- J S O N |
| 1031 Handle<String> name = factory->NewStringFromAscii(CStrVector("JSON")); | 1031 Handle<String> name = factory->NewStringFromAscii(CStrVector("JSON")); |
| 1032 Handle<JSFunction> cons = factory->NewFunction(name, | 1032 Handle<JSFunction> cons = factory->NewFunction(name, |
| 1033 factory->the_hole_value()); | 1033 factory->the_hole_value()); |
| 1034 { MaybeObject* result = cons->SetInstancePrototype( | 1034 { MaybeObject* result = cons->SetInstancePrototype( |
| 1035 global_context()->initial_object_prototype()); | 1035 native_context()->initial_object_prototype()); |
| 1036 if (result->IsFailure()) return false; | 1036 if (result->IsFailure()) return false; |
| 1037 } | 1037 } |
| 1038 cons->SetInstanceClassName(*name); | 1038 cons->SetInstanceClassName(*name); |
| 1039 Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED); | 1039 Handle<JSObject> json_object = factory->NewJSObject(cons, TENURED); |
| 1040 ASSERT(json_object->IsJSObject()); | 1040 ASSERT(json_object->IsJSObject()); |
| 1041 CHECK_NOT_EMPTY_HANDLE(isolate, | 1041 CHECK_NOT_EMPTY_HANDLE(isolate, |
| 1042 JSObject::SetLocalPropertyIgnoreAttributes( | 1042 JSObject::SetLocalPropertyIgnoreAttributes( |
| 1043 global, name, json_object, DONT_ENUM)); | 1043 global, name, json_object, DONT_ENUM)); |
| 1044 global_context()->set_json_object(*json_object); | 1044 native_context()->set_json_object(*json_object); |
| 1045 } | 1045 } |
| 1046 | 1046 |
| 1047 { // --- arguments_boilerplate_ | 1047 { // --- arguments_boilerplate_ |
| 1048 // Make sure we can recognize argument objects at runtime. | 1048 // Make sure we can recognize argument objects at runtime. |
| 1049 // This is done by introducing an anonymous function with | 1049 // This is done by introducing an anonymous function with |
| 1050 // class_name equals 'Arguments'. | 1050 // class_name equals 'Arguments'. |
| 1051 Handle<String> symbol = factory->LookupAsciiSymbol("Arguments"); | 1051 Handle<String> symbol = factory->LookupAsciiSymbol("Arguments"); |
| 1052 Handle<Code> code = Handle<Code>( | 1052 Handle<Code> code = Handle<Code>( |
| 1053 isolate->builtins()->builtin(Builtins::kIllegal)); | 1053 isolate->builtins()->builtin(Builtins::kIllegal)); |
| 1054 Handle<JSObject> prototype = | 1054 Handle<JSObject> prototype = |
| 1055 Handle<JSObject>( | 1055 Handle<JSObject>( |
| 1056 JSObject::cast(global_context()->object_function()->prototype())); | 1056 JSObject::cast(native_context()->object_function()->prototype())); |
| 1057 | 1057 |
| 1058 Handle<JSFunction> function = | 1058 Handle<JSFunction> function = |
| 1059 factory->NewFunctionWithPrototype(symbol, | 1059 factory->NewFunctionWithPrototype(symbol, |
| 1060 JS_OBJECT_TYPE, | 1060 JS_OBJECT_TYPE, |
| 1061 JSObject::kHeaderSize, | 1061 JSObject::kHeaderSize, |
| 1062 prototype, | 1062 prototype, |
| 1063 code, | 1063 code, |
| 1064 false); | 1064 false); |
| 1065 ASSERT(!function->has_initial_map()); | 1065 ASSERT(!function->has_initial_map()); |
| 1066 function->shared()->set_instance_class_name(*symbol); | 1066 function->shared()->set_instance_class_name(*symbol); |
| 1067 function->shared()->set_expected_nof_properties(2); | 1067 function->shared()->set_expected_nof_properties(2); |
| 1068 Handle<JSObject> result = factory->NewJSObject(function); | 1068 Handle<JSObject> result = factory->NewJSObject(function); |
| 1069 | 1069 |
| 1070 global_context()->set_arguments_boilerplate(*result); | 1070 native_context()->set_arguments_boilerplate(*result); |
| 1071 // Note: length must be added as the first property and | 1071 // Note: length must be added as the first property and |
| 1072 // callee must be added as the second property. | 1072 // callee must be added as the second property. |
| 1073 CHECK_NOT_EMPTY_HANDLE(isolate, | 1073 CHECK_NOT_EMPTY_HANDLE(isolate, |
| 1074 JSObject::SetLocalPropertyIgnoreAttributes( | 1074 JSObject::SetLocalPropertyIgnoreAttributes( |
| 1075 result, factory->length_symbol(), | 1075 result, factory->length_symbol(), |
| 1076 factory->undefined_value(), DONT_ENUM)); | 1076 factory->undefined_value(), DONT_ENUM)); |
| 1077 CHECK_NOT_EMPTY_HANDLE(isolate, | 1077 CHECK_NOT_EMPTY_HANDLE(isolate, |
| 1078 JSObject::SetLocalPropertyIgnoreAttributes( | 1078 JSObject::SetLocalPropertyIgnoreAttributes( |
| 1079 result, factory->callee_symbol(), | 1079 result, factory->callee_symbol(), |
| 1080 factory->undefined_value(), DONT_ENUM)); | 1080 factory->undefined_value(), DONT_ENUM)); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 1101 { // --- aliased_arguments_boilerplate_ | 1101 { // --- aliased_arguments_boilerplate_ |
| 1102 // Set up a well-formed parameter map to make assertions happy. | 1102 // Set up a well-formed parameter map to make assertions happy. |
| 1103 Handle<FixedArray> elements = factory->NewFixedArray(2); | 1103 Handle<FixedArray> elements = factory->NewFixedArray(2); |
| 1104 elements->set_map(heap->non_strict_arguments_elements_map()); | 1104 elements->set_map(heap->non_strict_arguments_elements_map()); |
| 1105 Handle<FixedArray> array; | 1105 Handle<FixedArray> array; |
| 1106 array = factory->NewFixedArray(0); | 1106 array = factory->NewFixedArray(0); |
| 1107 elements->set(0, *array); | 1107 elements->set(0, *array); |
| 1108 array = factory->NewFixedArray(0); | 1108 array = factory->NewFixedArray(0); |
| 1109 elements->set(1, *array); | 1109 elements->set(1, *array); |
| 1110 | 1110 |
| 1111 Handle<Map> old_map(global_context()->arguments_boilerplate()->map()); | 1111 Handle<Map> old_map(native_context()->arguments_boilerplate()->map()); |
| 1112 Handle<Map> new_map = factory->CopyMap(old_map); | 1112 Handle<Map> new_map = factory->CopyMap(old_map); |
| 1113 new_map->set_pre_allocated_property_fields(2); | 1113 new_map->set_pre_allocated_property_fields(2); |
| 1114 Handle<JSObject> result = factory->NewJSObjectFromMap(new_map); | 1114 Handle<JSObject> result = factory->NewJSObjectFromMap(new_map); |
| 1115 // Set elements kind after allocating the object because | 1115 // Set elements kind after allocating the object because |
| 1116 // NewJSObjectFromMap assumes a fast elements map. | 1116 // NewJSObjectFromMap assumes a fast elements map. |
| 1117 new_map->set_elements_kind(NON_STRICT_ARGUMENTS_ELEMENTS); | 1117 new_map->set_elements_kind(NON_STRICT_ARGUMENTS_ELEMENTS); |
| 1118 result->set_elements(*elements); | 1118 result->set_elements(*elements); |
| 1119 ASSERT(result->HasNonStrictArgumentsElements()); | 1119 ASSERT(result->HasNonStrictArgumentsElements()); |
| 1120 global_context()->set_aliased_arguments_boilerplate(*result); | 1120 native_context()->set_aliased_arguments_boilerplate(*result); |
| 1121 } | 1121 } |
| 1122 | 1122 |
| 1123 { // --- strict mode arguments boilerplate | 1123 { // --- strict mode arguments boilerplate |
| 1124 const PropertyAttributes attributes = | 1124 const PropertyAttributes attributes = |
| 1125 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); | 1125 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 1126 | 1126 |
| 1127 // Create the ThrowTypeError functions. | 1127 // Create the ThrowTypeError functions. |
| 1128 Handle<AccessorPair> callee = factory->NewAccessorPair(); | 1128 Handle<AccessorPair> callee = factory->NewAccessorPair(); |
| 1129 Handle<AccessorPair> caller = factory->NewAccessorPair(); | 1129 Handle<AccessorPair> caller = factory->NewAccessorPair(); |
| 1130 | 1130 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1156 map->AppendDescriptor(&d, witness); | 1156 map->AppendDescriptor(&d, witness); |
| 1157 } | 1157 } |
| 1158 { // caller | 1158 { // caller |
| 1159 CallbacksDescriptor d(*factory->caller_symbol(), | 1159 CallbacksDescriptor d(*factory->caller_symbol(), |
| 1160 *caller, | 1160 *caller, |
| 1161 attributes); | 1161 attributes); |
| 1162 map->AppendDescriptor(&d, witness); | 1162 map->AppendDescriptor(&d, witness); |
| 1163 } | 1163 } |
| 1164 | 1164 |
| 1165 map->set_function_with_prototype(true); | 1165 map->set_function_with_prototype(true); |
| 1166 map->set_prototype(global_context()->object_function()->prototype()); | 1166 map->set_prototype(native_context()->object_function()->prototype()); |
| 1167 map->set_pre_allocated_property_fields(1); | 1167 map->set_pre_allocated_property_fields(1); |
| 1168 map->set_inobject_properties(1); | 1168 map->set_inobject_properties(1); |
| 1169 | 1169 |
| 1170 // Copy constructor from the non-strict arguments boilerplate. | 1170 // Copy constructor from the non-strict arguments boilerplate. |
| 1171 map->set_constructor( | 1171 map->set_constructor( |
| 1172 global_context()->arguments_boilerplate()->map()->constructor()); | 1172 native_context()->arguments_boilerplate()->map()->constructor()); |
| 1173 | 1173 |
| 1174 // Allocate the arguments boilerplate object. | 1174 // Allocate the arguments boilerplate object. |
| 1175 Handle<JSObject> result = factory->NewJSObjectFromMap(map); | 1175 Handle<JSObject> result = factory->NewJSObjectFromMap(map); |
| 1176 global_context()->set_strict_mode_arguments_boilerplate(*result); | 1176 native_context()->set_strict_mode_arguments_boilerplate(*result); |
| 1177 | 1177 |
| 1178 // Add length property only for strict mode boilerplate. | 1178 // Add length property only for strict mode boilerplate. |
| 1179 CHECK_NOT_EMPTY_HANDLE(isolate, | 1179 CHECK_NOT_EMPTY_HANDLE(isolate, |
| 1180 JSObject::SetLocalPropertyIgnoreAttributes( | 1180 JSObject::SetLocalPropertyIgnoreAttributes( |
| 1181 result, factory->length_symbol(), | 1181 result, factory->length_symbol(), |
| 1182 factory->undefined_value(), DONT_ENUM)); | 1182 factory->undefined_value(), DONT_ENUM)); |
| 1183 | 1183 |
| 1184 #ifdef DEBUG | 1184 #ifdef DEBUG |
| 1185 LookupResult lookup(isolate); | 1185 LookupResult lookup(isolate); |
| 1186 result->LocalLookup(heap->length_symbol(), &lookup); | 1186 result->LocalLookup(heap->length_symbol(), &lookup); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1201 isolate->builtins()->builtin(Builtins::kIllegal)); | 1201 isolate->builtins()->builtin(Builtins::kIllegal)); |
| 1202 Handle<JSFunction> context_extension_fun = | 1202 Handle<JSFunction> context_extension_fun = |
| 1203 factory->NewFunction(factory->empty_symbol(), | 1203 factory->NewFunction(factory->empty_symbol(), |
| 1204 JS_CONTEXT_EXTENSION_OBJECT_TYPE, | 1204 JS_CONTEXT_EXTENSION_OBJECT_TYPE, |
| 1205 JSObject::kHeaderSize, | 1205 JSObject::kHeaderSize, |
| 1206 code, | 1206 code, |
| 1207 true); | 1207 true); |
| 1208 | 1208 |
| 1209 Handle<String> name = factory->LookupAsciiSymbol("context_extension"); | 1209 Handle<String> name = factory->LookupAsciiSymbol("context_extension"); |
| 1210 context_extension_fun->shared()->set_instance_class_name(*name); | 1210 context_extension_fun->shared()->set_instance_class_name(*name); |
| 1211 global_context()->set_context_extension_function(*context_extension_fun); | 1211 native_context()->set_context_extension_function(*context_extension_fun); |
| 1212 } | 1212 } |
| 1213 | 1213 |
| 1214 | 1214 |
| 1215 { | 1215 { |
| 1216 // Set up the call-as-function delegate. | 1216 // Set up the call-as-function delegate. |
| 1217 Handle<Code> code = | 1217 Handle<Code> code = |
| 1218 Handle<Code>(isolate->builtins()->builtin( | 1218 Handle<Code>(isolate->builtins()->builtin( |
| 1219 Builtins::kHandleApiCallAsFunction)); | 1219 Builtins::kHandleApiCallAsFunction)); |
| 1220 Handle<JSFunction> delegate = | 1220 Handle<JSFunction> delegate = |
| 1221 factory->NewFunction(factory->empty_symbol(), JS_OBJECT_TYPE, | 1221 factory->NewFunction(factory->empty_symbol(), JS_OBJECT_TYPE, |
| 1222 JSObject::kHeaderSize, code, true); | 1222 JSObject::kHeaderSize, code, true); |
| 1223 global_context()->set_call_as_function_delegate(*delegate); | 1223 native_context()->set_call_as_function_delegate(*delegate); |
| 1224 delegate->shared()->DontAdaptArguments(); | 1224 delegate->shared()->DontAdaptArguments(); |
| 1225 } | 1225 } |
| 1226 | 1226 |
| 1227 { | 1227 { |
| 1228 // Set up the call-as-constructor delegate. | 1228 // Set up the call-as-constructor delegate. |
| 1229 Handle<Code> code = | 1229 Handle<Code> code = |
| 1230 Handle<Code>(isolate->builtins()->builtin( | 1230 Handle<Code>(isolate->builtins()->builtin( |
| 1231 Builtins::kHandleApiCallAsConstructor)); | 1231 Builtins::kHandleApiCallAsConstructor)); |
| 1232 Handle<JSFunction> delegate = | 1232 Handle<JSFunction> delegate = |
| 1233 factory->NewFunction(factory->empty_symbol(), JS_OBJECT_TYPE, | 1233 factory->NewFunction(factory->empty_symbol(), JS_OBJECT_TYPE, |
| 1234 JSObject::kHeaderSize, code, true); | 1234 JSObject::kHeaderSize, code, true); |
| 1235 global_context()->set_call_as_constructor_delegate(*delegate); | 1235 native_context()->set_call_as_constructor_delegate(*delegate); |
| 1236 delegate->shared()->DontAdaptArguments(); | 1236 delegate->shared()->DontAdaptArguments(); |
| 1237 } | 1237 } |
| 1238 | 1238 |
| 1239 // Initialize the out of memory slot. | 1239 // Initialize the out of memory slot. |
| 1240 global_context()->set_out_of_memory(heap->false_value()); | 1240 native_context()->set_out_of_memory(heap->false_value()); |
| 1241 | 1241 |
| 1242 // Initialize the data slot. | 1242 // Initialize the data slot. |
| 1243 global_context()->set_data(heap->undefined_value()); | 1243 native_context()->set_data(heap->undefined_value()); |
| 1244 | 1244 |
| 1245 { | 1245 { |
| 1246 // Initialize the random seed slot. | 1246 // Initialize the random seed slot. |
| 1247 Handle<ByteArray> zeroed_byte_array( | 1247 Handle<ByteArray> zeroed_byte_array( |
| 1248 factory->NewByteArray(kRandomStateSize)); | 1248 factory->NewByteArray(kRandomStateSize)); |
| 1249 global_context()->set_random_seed(*zeroed_byte_array); | 1249 native_context()->set_random_seed(*zeroed_byte_array); |
| 1250 memset(zeroed_byte_array->GetDataStartAddress(), 0, kRandomStateSize); | 1250 memset(zeroed_byte_array->GetDataStartAddress(), 0, kRandomStateSize); |
| 1251 } | 1251 } |
| 1252 return true; | 1252 return true; |
| 1253 } | 1253 } |
| 1254 | 1254 |
| 1255 | 1255 |
| 1256 void Genesis::InitializeExperimentalGlobal() { | 1256 void Genesis::InitializeExperimentalGlobal() { |
| 1257 Handle<JSObject> global = Handle<JSObject>(global_context()->global()); | 1257 Handle<JSObject> global = Handle<JSObject>(native_context()->global()); |
| 1258 | 1258 |
| 1259 // TODO(mstarzinger): Move this into Genesis::InitializeGlobal once we no | 1259 // TODO(mstarzinger): Move this into Genesis::InitializeGlobal once we no |
| 1260 // longer need to live behind a flag, so functions get added to the snapshot. | 1260 // longer need to live behind a flag, so functions get added to the snapshot. |
| 1261 if (FLAG_harmony_collections) { | 1261 if (FLAG_harmony_collections) { |
| 1262 { // -- S e t | 1262 { // -- S e t |
| 1263 Handle<JSObject> prototype = | 1263 Handle<JSObject> prototype = |
| 1264 factory()->NewJSObject(isolate()->object_function(), TENURED); | 1264 factory()->NewJSObject(isolate()->object_function(), TENURED); |
| 1265 InstallFunction(global, "Set", JS_SET_TYPE, JSSet::kSize, | 1265 InstallFunction(global, "Set", JS_SET_TYPE, JSSet::kSize, |
| 1266 prototype, Builtins::kIllegal, true); | 1266 prototype, Builtins::kIllegal, true); |
| 1267 } | 1267 } |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1350 NULL, | 1350 NULL, |
| 1351 Handle<String>::null(), | 1351 Handle<String>::null(), |
| 1352 use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE); | 1352 use_runtime_context ? NATIVES_CODE : NOT_NATIVES_CODE); |
| 1353 if (function_info.is_null()) return false; | 1353 if (function_info.is_null()) return false; |
| 1354 if (cache != NULL) cache->Add(name, function_info); | 1354 if (cache != NULL) cache->Add(name, function_info); |
| 1355 } | 1355 } |
| 1356 | 1356 |
| 1357 // Set up the function context. Conceptually, we should clone the | 1357 // Set up the function context. Conceptually, we should clone the |
| 1358 // function before overwriting the context but since we're in a | 1358 // function before overwriting the context but since we're in a |
| 1359 // single-threaded environment it is not strictly necessary. | 1359 // single-threaded environment it is not strictly necessary. |
| 1360 ASSERT(top_context->IsGlobalContext()); | 1360 ASSERT(top_context->IsNativeContext()); |
| 1361 Handle<Context> context = | 1361 Handle<Context> context = |
| 1362 Handle<Context>(use_runtime_context | 1362 Handle<Context>(use_runtime_context |
| 1363 ? Handle<Context>(top_context->runtime_context()) | 1363 ? Handle<Context>(top_context->runtime_context()) |
| 1364 : top_context); | 1364 : top_context); |
| 1365 Handle<JSFunction> fun = | 1365 Handle<JSFunction> fun = |
| 1366 factory->NewFunctionFromSharedFunctionInfo(function_info, context); | 1366 factory->NewFunctionFromSharedFunctionInfo(function_info, context); |
| 1367 | 1367 |
| 1368 // Call function using either the runtime object or the global | 1368 // Call function using either the runtime object or the global |
| 1369 // object as the receiver. Provide no parameters. | 1369 // object as the receiver. Provide no parameters. |
| 1370 Handle<Object> receiver = | 1370 Handle<Object> receiver = |
| 1371 Handle<Object>(use_runtime_context | 1371 Handle<Object>(use_runtime_context |
| 1372 ? top_context->builtins() | 1372 ? top_context->builtins() |
| 1373 : top_context->global()); | 1373 : top_context->global()); |
| 1374 bool has_pending_exception; | 1374 bool has_pending_exception; |
| 1375 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); | 1375 Execution::Call(fun, receiver, 0, NULL, &has_pending_exception); |
| 1376 if (has_pending_exception) return false; | 1376 if (has_pending_exception) return false; |
| 1377 return true; | 1377 return true; |
| 1378 } | 1378 } |
| 1379 | 1379 |
| 1380 | 1380 |
| 1381 #define INSTALL_NATIVE(Type, name, var) \ | 1381 #define INSTALL_NATIVE(Type, name, var) \ |
| 1382 Handle<String> var##_name = factory()->LookupAsciiSymbol(name); \ | 1382 Handle<String> var##_name = factory()->LookupAsciiSymbol(name); \ |
| 1383 Object* var##_native = \ | 1383 Object* var##_native = \ |
| 1384 global_context()->builtins()->GetPropertyNoExceptionThrown( \ | 1384 native_context()->builtins()->GetPropertyNoExceptionThrown( \ |
| 1385 *var##_name); \ | 1385 *var##_name); \ |
| 1386 global_context()->set_##var(Type::cast(var##_native)); | 1386 native_context()->set_##var(Type::cast(var##_native)); |
| 1387 | 1387 |
| 1388 | 1388 |
| 1389 void Genesis::InstallNativeFunctions() { | 1389 void Genesis::InstallNativeFunctions() { |
| 1390 HandleScope scope; | 1390 HandleScope scope; |
| 1391 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun); | 1391 INSTALL_NATIVE(JSFunction, "CreateDate", create_date_fun); |
| 1392 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun); | 1392 INSTALL_NATIVE(JSFunction, "ToNumber", to_number_fun); |
| 1393 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun); | 1393 INSTALL_NATIVE(JSFunction, "ToString", to_string_fun); |
| 1394 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun); | 1394 INSTALL_NATIVE(JSFunction, "ToDetailString", to_detail_string_fun); |
| 1395 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun); | 1395 INSTALL_NATIVE(JSFunction, "ToObject", to_object_fun); |
| 1396 INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun); | 1396 INSTALL_NATIVE(JSFunction, "ToInteger", to_integer_fun); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1416 } | 1416 } |
| 1417 | 1417 |
| 1418 #undef INSTALL_NATIVE | 1418 #undef INSTALL_NATIVE |
| 1419 | 1419 |
| 1420 | 1420 |
| 1421 bool Genesis::InstallNatives() { | 1421 bool Genesis::InstallNatives() { |
| 1422 HandleScope scope; | 1422 HandleScope scope; |
| 1423 | 1423 |
| 1424 // Create a function for the builtins object. Allocate space for the | 1424 // Create a function for the builtins object. Allocate space for the |
| 1425 // JavaScript builtins, a reference to the builtins object | 1425 // JavaScript builtins, a reference to the builtins object |
| 1426 // (itself) and a reference to the global_context directly in the object. | 1426 // (itself) and a reference to the native_context directly in the object. |
| 1427 Handle<Code> code = Handle<Code>( | 1427 Handle<Code> code = Handle<Code>( |
| 1428 isolate()->builtins()->builtin(Builtins::kIllegal)); | 1428 isolate()->builtins()->builtin(Builtins::kIllegal)); |
| 1429 Handle<JSFunction> builtins_fun = | 1429 Handle<JSFunction> builtins_fun = |
| 1430 factory()->NewFunction(factory()->empty_symbol(), | 1430 factory()->NewFunction(factory()->empty_symbol(), |
| 1431 JS_BUILTINS_OBJECT_TYPE, | 1431 JS_BUILTINS_OBJECT_TYPE, |
| 1432 JSBuiltinsObject::kSize, code, true); | 1432 JSBuiltinsObject::kSize, code, true); |
| 1433 | 1433 |
| 1434 Handle<String> name = factory()->LookupAsciiSymbol("builtins"); | 1434 Handle<String> name = factory()->LookupAsciiSymbol("builtins"); |
| 1435 builtins_fun->shared()->set_instance_class_name(*name); | 1435 builtins_fun->shared()->set_instance_class_name(*name); |
| 1436 builtins_fun->initial_map()->set_dictionary_map(true); | 1436 builtins_fun->initial_map()->set_dictionary_map(true); |
| 1437 builtins_fun->initial_map()->set_prototype(heap()->null_value()); | 1437 builtins_fun->initial_map()->set_prototype(heap()->null_value()); |
| 1438 | 1438 |
| 1439 // Allocate the builtins object. | 1439 // Allocate the builtins object. |
| 1440 Handle<JSBuiltinsObject> builtins = | 1440 Handle<JSBuiltinsObject> builtins = |
| 1441 Handle<JSBuiltinsObject>::cast(factory()->NewGlobalObject(builtins_fun)); | 1441 Handle<JSBuiltinsObject>::cast(factory()->NewGlobalObject(builtins_fun)); |
| 1442 builtins->set_builtins(*builtins); | 1442 builtins->set_builtins(*builtins); |
| 1443 builtins->set_global_context(*global_context()); | 1443 builtins->set_native_context(*native_context()); |
| 1444 builtins->set_global_receiver(*builtins); | 1444 builtins->set_global_receiver(*builtins); |
| 1445 | 1445 |
| 1446 // Set up the 'global' properties of the builtins object. The | 1446 // Set up the 'global' properties of the builtins object. The |
| 1447 // 'global' property that refers to the global object is the only | 1447 // 'global' property that refers to the global object is the only |
| 1448 // way to get from code running in the builtins context to the | 1448 // way to get from code running in the builtins context to the |
| 1449 // global object. | 1449 // global object. |
| 1450 static const PropertyAttributes attributes = | 1450 static const PropertyAttributes attributes = |
| 1451 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); | 1451 static_cast<PropertyAttributes>(READ_ONLY | DONT_DELETE); |
| 1452 Handle<String> global_symbol = factory()->LookupAsciiSymbol("global"); | 1452 Handle<String> global_symbol = factory()->LookupAsciiSymbol("global"); |
| 1453 Handle<Object> global_obj(global_context()->global()); | 1453 Handle<Object> global_obj(native_context()->global()); |
| 1454 CHECK_NOT_EMPTY_HANDLE(isolate(), | 1454 CHECK_NOT_EMPTY_HANDLE(isolate(), |
| 1455 JSObject::SetLocalPropertyIgnoreAttributes( | 1455 JSObject::SetLocalPropertyIgnoreAttributes( |
| 1456 builtins, global_symbol, global_obj, attributes)); | 1456 builtins, global_symbol, global_obj, attributes)); |
| 1457 | 1457 |
| 1458 // Set up the reference from the global object to the builtins object. | 1458 // Set up the reference from the global object to the builtins object. |
| 1459 JSGlobalObject::cast(global_context()->global())->set_builtins(*builtins); | 1459 JSGlobalObject::cast(native_context()->global())->set_builtins(*builtins); |
| 1460 | 1460 |
| 1461 // Create a bridge function that has context in the global context. | 1461 // Create a bridge function that has context in the native context. |
| 1462 Handle<JSFunction> bridge = | 1462 Handle<JSFunction> bridge = |
| 1463 factory()->NewFunction(factory()->empty_symbol(), | 1463 factory()->NewFunction(factory()->empty_symbol(), |
| 1464 factory()->undefined_value()); | 1464 factory()->undefined_value()); |
| 1465 ASSERT(bridge->context() == *isolate()->global_context()); | 1465 ASSERT(bridge->context() == *isolate()->native_context()); |
| 1466 | 1466 |
| 1467 // Allocate the builtins context. | 1467 // Allocate the builtins context. |
| 1468 Handle<Context> context = | 1468 Handle<Context> context = |
| 1469 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); | 1469 factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, bridge); |
| 1470 context->set_global(*builtins); // override builtins global object | 1470 context->set_global(*builtins); // override builtins global object |
| 1471 | 1471 |
| 1472 global_context()->set_runtime_context(*context); | 1472 native_context()->set_runtime_context(*context); |
| 1473 | 1473 |
| 1474 { // -- S c r i p t | 1474 { // -- S c r i p t |
| 1475 // Builtin functions for Script. | 1475 // Builtin functions for Script. |
| 1476 Handle<JSFunction> script_fun = | 1476 Handle<JSFunction> script_fun = |
| 1477 InstallFunction(builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, | 1477 InstallFunction(builtins, "Script", JS_VALUE_TYPE, JSValue::kSize, |
| 1478 isolate()->initial_object_prototype(), | 1478 isolate()->initial_object_prototype(), |
| 1479 Builtins::kIllegal, false); | 1479 Builtins::kIllegal, false); |
| 1480 Handle<JSObject> prototype = | 1480 Handle<JSObject> prototype = |
| 1481 factory()->NewJSObject(isolate()->object_function(), TENURED); | 1481 factory()->NewJSObject(isolate()->object_function(), TENURED); |
| 1482 SetPrototype(script_fun, prototype); | 1482 SetPrototype(script_fun, prototype); |
| 1483 global_context()->set_script_function(*script_fun); | 1483 native_context()->set_script_function(*script_fun); |
| 1484 | 1484 |
| 1485 Handle<Map> script_map = Handle<Map>(script_fun->initial_map()); | 1485 Handle<Map> script_map = Handle<Map>(script_fun->initial_map()); |
| 1486 | 1486 |
| 1487 Handle<DescriptorArray> script_descriptors( | 1487 Handle<DescriptorArray> script_descriptors( |
| 1488 factory()->NewDescriptorArray(13)); | 1488 factory()->NewDescriptorArray(13)); |
| 1489 DescriptorArray::WhitenessWitness witness(*script_descriptors); | 1489 DescriptorArray::WhitenessWitness witness(*script_descriptors); |
| 1490 | 1490 |
| 1491 Handle<Foreign> script_source( | 1491 Handle<Foreign> script_source( |
| 1492 factory()->NewForeign(&Accessors::ScriptSource)); | 1492 factory()->NewForeign(&Accessors::ScriptSource)); |
| 1493 Handle<Foreign> script_name(factory()->NewForeign(&Accessors::ScriptName)); | 1493 Handle<Foreign> script_name(factory()->NewForeign(&Accessors::ScriptName)); |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1618 // that keeps its field isolated from JavaScript code. It may store | 1618 // that keeps its field isolated from JavaScript code. It may store |
| 1619 // objects, that JavaScript code may not access. | 1619 // objects, that JavaScript code may not access. |
| 1620 Handle<JSFunction> opaque_reference_fun = | 1620 Handle<JSFunction> opaque_reference_fun = |
| 1621 InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE, | 1621 InstallFunction(builtins, "OpaqueReference", JS_VALUE_TYPE, |
| 1622 JSValue::kSize, | 1622 JSValue::kSize, |
| 1623 isolate()->initial_object_prototype(), | 1623 isolate()->initial_object_prototype(), |
| 1624 Builtins::kIllegal, false); | 1624 Builtins::kIllegal, false); |
| 1625 Handle<JSObject> prototype = | 1625 Handle<JSObject> prototype = |
| 1626 factory()->NewJSObject(isolate()->object_function(), TENURED); | 1626 factory()->NewJSObject(isolate()->object_function(), TENURED); |
| 1627 SetPrototype(opaque_reference_fun, prototype); | 1627 SetPrototype(opaque_reference_fun, prototype); |
| 1628 global_context()->set_opaque_reference_function(*opaque_reference_fun); | 1628 native_context()->set_opaque_reference_function(*opaque_reference_fun); |
| 1629 } | 1629 } |
| 1630 | 1630 |
| 1631 { // --- I n t e r n a l A r r a y --- | 1631 { // --- I n t e r n a l A r r a y --- |
| 1632 // An array constructor on the builtins object that works like | 1632 // An array constructor on the builtins object that works like |
| 1633 // the public Array constructor, except that its prototype | 1633 // the public Array constructor, except that its prototype |
| 1634 // doesn't inherit from Object.prototype. | 1634 // doesn't inherit from Object.prototype. |
| 1635 // To be used only for internal work by builtins. Instances | 1635 // To be used only for internal work by builtins. Instances |
| 1636 // must not be leaked to user code. | 1636 // must not be leaked to user code. |
| 1637 Handle<JSFunction> array_function = | 1637 Handle<JSFunction> array_function = |
| 1638 InstallFunction(builtins, | 1638 InstallFunction(builtins, |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1671 PropertyAttributes attribs = static_cast<PropertyAttributes>( | 1671 PropertyAttributes attribs = static_cast<PropertyAttributes>( |
| 1672 DONT_ENUM | DONT_DELETE); | 1672 DONT_ENUM | DONT_DELETE); |
| 1673 Map::SetDescriptors(initial_map, array_descriptors); | 1673 Map::SetDescriptors(initial_map, array_descriptors); |
| 1674 | 1674 |
| 1675 { // Add length. | 1675 { // Add length. |
| 1676 CallbacksDescriptor d( | 1676 CallbacksDescriptor d( |
| 1677 *factory()->length_symbol(), *array_length, attribs); | 1677 *factory()->length_symbol(), *array_length, attribs); |
| 1678 array_function->initial_map()->AppendDescriptor(&d, witness); | 1678 array_function->initial_map()->AppendDescriptor(&d, witness); |
| 1679 } | 1679 } |
| 1680 | 1680 |
| 1681 global_context()->set_internal_array_function(*array_function); | 1681 native_context()->set_internal_array_function(*array_function); |
| 1682 } | 1682 } |
| 1683 | 1683 |
| 1684 if (FLAG_disable_native_files) { | 1684 if (FLAG_disable_native_files) { |
| 1685 PrintF("Warning: Running without installed natives!\n"); | 1685 PrintF("Warning: Running without installed natives!\n"); |
| 1686 return true; | 1686 return true; |
| 1687 } | 1687 } |
| 1688 | 1688 |
| 1689 // Install natives. | 1689 // Install natives. |
| 1690 for (int i = Natives::GetDebuggerCount(); | 1690 for (int i = Natives::GetDebuggerCount(); |
| 1691 i < Natives::GetBuiltinsCount(); | 1691 i < Natives::GetBuiltinsCount(); |
| 1692 i++) { | 1692 i++) { |
| 1693 if (!CompileBuiltin(isolate(), i)) return false; | 1693 if (!CompileBuiltin(isolate(), i)) return false; |
| 1694 // TODO(ager): We really only need to install the JS builtin | 1694 // TODO(ager): We really only need to install the JS builtin |
| 1695 // functions on the builtins object after compiling and running | 1695 // functions on the builtins object after compiling and running |
| 1696 // runtime.js. | 1696 // runtime.js. |
| 1697 if (!InstallJSBuiltins(builtins)) return false; | 1697 if (!InstallJSBuiltins(builtins)) return false; |
| 1698 } | 1698 } |
| 1699 | 1699 |
| 1700 InstallNativeFunctions(); | 1700 InstallNativeFunctions(); |
| 1701 | 1701 |
| 1702 // Store the map for the string prototype after the natives has been compiled | 1702 // Store the map for the string prototype after the natives has been compiled |
| 1703 // and the String function has been set up. | 1703 // and the String function has been set up. |
| 1704 Handle<JSFunction> string_function(global_context()->string_function()); | 1704 Handle<JSFunction> string_function(native_context()->string_function()); |
| 1705 ASSERT(JSObject::cast( | 1705 ASSERT(JSObject::cast( |
| 1706 string_function->initial_map()->prototype())->HasFastProperties()); | 1706 string_function->initial_map()->prototype())->HasFastProperties()); |
| 1707 global_context()->set_string_function_prototype_map( | 1707 native_context()->set_string_function_prototype_map( |
| 1708 HeapObject::cast(string_function->initial_map()->prototype())->map()); | 1708 HeapObject::cast(string_function->initial_map()->prototype())->map()); |
| 1709 | 1709 |
| 1710 // Install Function.prototype.call and apply. | 1710 // Install Function.prototype.call and apply. |
| 1711 { Handle<String> key = factory()->function_class_symbol(); | 1711 { Handle<String> key = factory()->function_class_symbol(); |
| 1712 Handle<JSFunction> function = | 1712 Handle<JSFunction> function = |
| 1713 Handle<JSFunction>::cast(GetProperty(isolate()->global(), key)); | 1713 Handle<JSFunction>::cast(GetProperty(isolate()->global(), key)); |
| 1714 Handle<JSObject> proto = | 1714 Handle<JSObject> proto = |
| 1715 Handle<JSObject>(JSObject::cast(function->instance_prototype())); | 1715 Handle<JSObject>(JSObject::cast(function->instance_prototype())); |
| 1716 | 1716 |
| 1717 // Install the call and the apply functions. | 1717 // Install the call and the apply functions. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1741 } | 1741 } |
| 1742 | 1742 |
| 1743 InstallBuiltinFunctionIds(); | 1743 InstallBuiltinFunctionIds(); |
| 1744 | 1744 |
| 1745 // Create a constructor for RegExp results (a variant of Array that | 1745 // Create a constructor for RegExp results (a variant of Array that |
| 1746 // predefines the two properties index and match). | 1746 // predefines the two properties index and match). |
| 1747 { | 1747 { |
| 1748 // RegExpResult initial map. | 1748 // RegExpResult initial map. |
| 1749 | 1749 |
| 1750 // Find global.Array.prototype to inherit from. | 1750 // Find global.Array.prototype to inherit from. |
| 1751 Handle<JSFunction> array_constructor(global_context()->array_function()); | 1751 Handle<JSFunction> array_constructor(native_context()->array_function()); |
| 1752 Handle<JSObject> array_prototype( | 1752 Handle<JSObject> array_prototype( |
| 1753 JSObject::cast(array_constructor->instance_prototype())); | 1753 JSObject::cast(array_constructor->instance_prototype())); |
| 1754 | 1754 |
| 1755 // Add initial map. | 1755 // Add initial map. |
| 1756 Handle<Map> initial_map = | 1756 Handle<Map> initial_map = |
| 1757 factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize); | 1757 factory()->NewMap(JS_ARRAY_TYPE, JSRegExpResult::kSize); |
| 1758 initial_map->set_constructor(*array_constructor); | 1758 initial_map->set_constructor(*array_constructor); |
| 1759 | 1759 |
| 1760 // Set prototype on map. | 1760 // Set prototype on map. |
| 1761 initial_map->set_non_instance_prototype(false); | 1761 initial_map->set_non_instance_prototype(false); |
| 1762 initial_map->set_prototype(*array_prototype); | 1762 initial_map->set_prototype(*array_prototype); |
| 1763 | 1763 |
| 1764 // Update map with length accessor from Array and add "index" and "input". | 1764 // Update map with length accessor from Array and add "index" and "input". |
| 1765 Handle<DescriptorArray> reresult_descriptors = | 1765 Handle<DescriptorArray> reresult_descriptors = |
| 1766 factory()->NewDescriptorArray(3); | 1766 factory()->NewDescriptorArray(3); |
| 1767 DescriptorArray::WhitenessWitness witness(*reresult_descriptors); | 1767 DescriptorArray::WhitenessWitness witness(*reresult_descriptors); |
| 1768 Map::SetDescriptors(initial_map, reresult_descriptors); | 1768 Map::SetDescriptors(initial_map, reresult_descriptors); |
| 1769 | 1769 |
| 1770 { | 1770 { |
| 1771 JSFunction* array_function = global_context()->array_function(); | 1771 JSFunction* array_function = native_context()->array_function(); |
| 1772 Handle<DescriptorArray> array_descriptors( | 1772 Handle<DescriptorArray> array_descriptors( |
| 1773 array_function->initial_map()->instance_descriptors()); | 1773 array_function->initial_map()->instance_descriptors()); |
| 1774 String* length = heap()->length_symbol(); | 1774 String* length = heap()->length_symbol(); |
| 1775 int old = array_descriptors->SearchWithCache(length); | 1775 int old = array_descriptors->SearchWithCache(length); |
| 1776 ASSERT(old != DescriptorArray::kNotFound); | 1776 ASSERT(old != DescriptorArray::kNotFound); |
| 1777 CallbacksDescriptor desc(length, | 1777 CallbacksDescriptor desc(length, |
| 1778 array_descriptors->GetValue(old), | 1778 array_descriptors->GetValue(old), |
| 1779 array_descriptors->GetDetails(old).attributes()); | 1779 array_descriptors->GetDetails(old).attributes()); |
| 1780 initial_map->AppendDescriptor(&desc, witness); | 1780 initial_map->AppendDescriptor(&desc, witness); |
| 1781 } | 1781 } |
| 1782 { | 1782 { |
| 1783 FieldDescriptor index_field(heap()->index_symbol(), | 1783 FieldDescriptor index_field(heap()->index_symbol(), |
| 1784 JSRegExpResult::kIndexIndex, | 1784 JSRegExpResult::kIndexIndex, |
| 1785 NONE); | 1785 NONE); |
| 1786 initial_map->AppendDescriptor(&index_field, witness); | 1786 initial_map->AppendDescriptor(&index_field, witness); |
| 1787 } | 1787 } |
| 1788 | 1788 |
| 1789 { | 1789 { |
| 1790 FieldDescriptor input_field(heap()->input_symbol(), | 1790 FieldDescriptor input_field(heap()->input_symbol(), |
| 1791 JSRegExpResult::kInputIndex, | 1791 JSRegExpResult::kInputIndex, |
| 1792 NONE); | 1792 NONE); |
| 1793 initial_map->AppendDescriptor(&input_field, witness); | 1793 initial_map->AppendDescriptor(&input_field, witness); |
| 1794 } | 1794 } |
| 1795 | 1795 |
| 1796 initial_map->set_inobject_properties(2); | 1796 initial_map->set_inobject_properties(2); |
| 1797 initial_map->set_pre_allocated_property_fields(2); | 1797 initial_map->set_pre_allocated_property_fields(2); |
| 1798 initial_map->set_unused_property_fields(0); | 1798 initial_map->set_unused_property_fields(0); |
| 1799 | 1799 |
| 1800 global_context()->set_regexp_result_map(*initial_map); | 1800 native_context()->set_regexp_result_map(*initial_map); |
| 1801 } | 1801 } |
| 1802 | 1802 |
| 1803 #ifdef DEBUG | 1803 #ifdef DEBUG |
| 1804 builtins->Verify(); | 1804 builtins->Verify(); |
| 1805 #endif | 1805 #endif |
| 1806 | 1806 |
| 1807 return true; | 1807 return true; |
| 1808 } | 1808 } |
| 1809 | 1809 |
| 1810 | 1810 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1824 } | 1824 } |
| 1825 } | 1825 } |
| 1826 | 1826 |
| 1827 InstallExperimentalNativeFunctions(); | 1827 InstallExperimentalNativeFunctions(); |
| 1828 | 1828 |
| 1829 return true; | 1829 return true; |
| 1830 } | 1830 } |
| 1831 | 1831 |
| 1832 | 1832 |
| 1833 static Handle<JSObject> ResolveBuiltinIdHolder( | 1833 static Handle<JSObject> ResolveBuiltinIdHolder( |
| 1834 Handle<Context> global_context, | 1834 Handle<Context> native_context, |
| 1835 const char* holder_expr) { | 1835 const char* holder_expr) { |
| 1836 Factory* factory = global_context->GetIsolate()->factory(); | 1836 Factory* factory = native_context->GetIsolate()->factory(); |
| 1837 Handle<GlobalObject> global(global_context->global()); | 1837 Handle<GlobalObject> global(native_context->global()); |
| 1838 const char* period_pos = strchr(holder_expr, '.'); | 1838 const char* period_pos = strchr(holder_expr, '.'); |
| 1839 if (period_pos == NULL) { | 1839 if (period_pos == NULL) { |
| 1840 return Handle<JSObject>::cast( | 1840 return Handle<JSObject>::cast( |
| 1841 GetProperty(global, factory->LookupAsciiSymbol(holder_expr))); | 1841 GetProperty(global, factory->LookupAsciiSymbol(holder_expr))); |
| 1842 } | 1842 } |
| 1843 ASSERT_EQ(".prototype", period_pos); | 1843 ASSERT_EQ(".prototype", period_pos); |
| 1844 Vector<const char> property(holder_expr, | 1844 Vector<const char> property(holder_expr, |
| 1845 static_cast<int>(period_pos - holder_expr)); | 1845 static_cast<int>(period_pos - holder_expr)); |
| 1846 Handle<JSFunction> function = Handle<JSFunction>::cast( | 1846 Handle<JSFunction> function = Handle<JSFunction>::cast( |
| 1847 GetProperty(global, factory->LookupSymbol(property))); | 1847 GetProperty(global, factory->LookupSymbol(property))); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1858 Handle<JSFunction> function(JSFunction::cast(function_object)); | 1858 Handle<JSFunction> function(JSFunction::cast(function_object)); |
| 1859 function->shared()->set_function_data(Smi::FromInt(id)); | 1859 function->shared()->set_function_data(Smi::FromInt(id)); |
| 1860 } | 1860 } |
| 1861 | 1861 |
| 1862 | 1862 |
| 1863 void Genesis::InstallBuiltinFunctionIds() { | 1863 void Genesis::InstallBuiltinFunctionIds() { |
| 1864 HandleScope scope; | 1864 HandleScope scope; |
| 1865 #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \ | 1865 #define INSTALL_BUILTIN_ID(holder_expr, fun_name, name) \ |
| 1866 { \ | 1866 { \ |
| 1867 Handle<JSObject> holder = ResolveBuiltinIdHolder( \ | 1867 Handle<JSObject> holder = ResolveBuiltinIdHolder( \ |
| 1868 global_context(), #holder_expr); \ | 1868 native_context(), #holder_expr); \ |
| 1869 BuiltinFunctionId id = k##name; \ | 1869 BuiltinFunctionId id = k##name; \ |
| 1870 InstallBuiltinFunctionId(holder, #fun_name, id); \ | 1870 InstallBuiltinFunctionId(holder, #fun_name, id); \ |
| 1871 } | 1871 } |
| 1872 FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID) | 1872 FUNCTIONS_WITH_ID_LIST(INSTALL_BUILTIN_ID) |
| 1873 #undef INSTALL_BUILTIN_ID | 1873 #undef INSTALL_BUILTIN_ID |
| 1874 } | 1874 } |
| 1875 | 1875 |
| 1876 | 1876 |
| 1877 // Do not forget to update macros.py with named constant | 1877 // Do not forget to update macros.py with named constant |
| 1878 // of cache id. | 1878 // of cache id. |
| 1879 #define JSFUNCTION_RESULT_CACHE_LIST(F) \ | 1879 #define JSFUNCTION_RESULT_CACHE_LIST(F) \ |
| 1880 F(16, global_context()->regexp_function()) | 1880 F(16, native_context()->regexp_function()) |
| 1881 | 1881 |
| 1882 | 1882 |
| 1883 static FixedArray* CreateCache(int size, Handle<JSFunction> factory_function) { | 1883 static FixedArray* CreateCache(int size, Handle<JSFunction> factory_function) { |
| 1884 Factory* factory = factory_function->GetIsolate()->factory(); | 1884 Factory* factory = factory_function->GetIsolate()->factory(); |
| 1885 // Caches are supposed to live for a long time, allocate in old space. | 1885 // Caches are supposed to live for a long time, allocate in old space. |
| 1886 int array_size = JSFunctionResultCache::kEntriesIndex + 2 * size; | 1886 int array_size = JSFunctionResultCache::kEntriesIndex + 2 * size; |
| 1887 // Cannot use cast as object is not fully initialized yet. | 1887 // Cannot use cast as object is not fully initialized yet. |
| 1888 JSFunctionResultCache* cache = reinterpret_cast<JSFunctionResultCache*>( | 1888 JSFunctionResultCache* cache = reinterpret_cast<JSFunctionResultCache*>( |
| 1889 *factory->NewFixedArrayWithHoles(array_size, TENURED)); | 1889 *factory->NewFixedArrayWithHoles(array_size, TENURED)); |
| 1890 cache->set(JSFunctionResultCache::kFactoryIndex, *factory_function); | 1890 cache->set(JSFunctionResultCache::kFactoryIndex, *factory_function); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1906 | 1906 |
| 1907 #define F(size, func) do { \ | 1907 #define F(size, func) do { \ |
| 1908 FixedArray* cache = CreateCache((size), Handle<JSFunction>(func)); \ | 1908 FixedArray* cache = CreateCache((size), Handle<JSFunction>(func)); \ |
| 1909 caches->set(index++, cache); \ | 1909 caches->set(index++, cache); \ |
| 1910 } while (false) | 1910 } while (false) |
| 1911 | 1911 |
| 1912 JSFUNCTION_RESULT_CACHE_LIST(F); | 1912 JSFUNCTION_RESULT_CACHE_LIST(F); |
| 1913 | 1913 |
| 1914 #undef F | 1914 #undef F |
| 1915 | 1915 |
| 1916 global_context()->set_jsfunction_result_caches(*caches); | 1916 native_context()->set_jsfunction_result_caches(*caches); |
| 1917 } | 1917 } |
| 1918 | 1918 |
| 1919 | 1919 |
| 1920 void Genesis::InitializeNormalizedMapCaches() { | 1920 void Genesis::InitializeNormalizedMapCaches() { |
| 1921 Handle<FixedArray> array( | 1921 Handle<FixedArray> array( |
| 1922 FACTORY->NewFixedArray(NormalizedMapCache::kEntries, TENURED)); | 1922 FACTORY->NewFixedArray(NormalizedMapCache::kEntries, TENURED)); |
| 1923 global_context()->set_normalized_map_cache(NormalizedMapCache::cast(*array)); | 1923 native_context()->set_normalized_map_cache(NormalizedMapCache::cast(*array)); |
| 1924 } | 1924 } |
| 1925 | 1925 |
| 1926 | 1926 |
| 1927 bool Bootstrapper::InstallExtensions(Handle<Context> global_context, | 1927 bool Bootstrapper::InstallExtensions(Handle<Context> native_context, |
| 1928 v8::ExtensionConfiguration* extensions) { | 1928 v8::ExtensionConfiguration* extensions) { |
| 1929 Isolate* isolate = global_context->GetIsolate(); | 1929 Isolate* isolate = native_context->GetIsolate(); |
| 1930 BootstrapperActive active; | 1930 BootstrapperActive active; |
| 1931 SaveContext saved_context(isolate); | 1931 SaveContext saved_context(isolate); |
| 1932 isolate->set_context(*global_context); | 1932 isolate->set_context(*native_context); |
| 1933 if (!Genesis::InstallExtensions(global_context, extensions)) return false; | 1933 if (!Genesis::InstallExtensions(native_context, extensions)) return false; |
| 1934 Genesis::InstallSpecialObjects(global_context); | 1934 Genesis::InstallSpecialObjects(native_context); |
| 1935 return true; | 1935 return true; |
| 1936 } | 1936 } |
| 1937 | 1937 |
| 1938 | 1938 |
| 1939 void Genesis::InstallSpecialObjects(Handle<Context> global_context) { | 1939 void Genesis::InstallSpecialObjects(Handle<Context> native_context) { |
| 1940 Isolate* isolate = global_context->GetIsolate(); | 1940 Isolate* isolate = native_context->GetIsolate(); |
| 1941 Factory* factory = isolate->factory(); | 1941 Factory* factory = isolate->factory(); |
| 1942 HandleScope scope; | 1942 HandleScope scope; |
| 1943 Handle<JSGlobalObject> global(JSGlobalObject::cast(global_context->global())); | 1943 Handle<JSGlobalObject> global(JSGlobalObject::cast(native_context->global())); |
| 1944 // Expose the natives in global if a name for it is specified. | 1944 // Expose the natives in global if a name for it is specified. |
| 1945 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { | 1945 if (FLAG_expose_natives_as != NULL && strlen(FLAG_expose_natives_as) != 0) { |
| 1946 Handle<String> natives = factory->LookupAsciiSymbol(FLAG_expose_natives_as); | 1946 Handle<String> natives = factory->LookupAsciiSymbol(FLAG_expose_natives_as); |
| 1947 CHECK_NOT_EMPTY_HANDLE(isolate, | 1947 CHECK_NOT_EMPTY_HANDLE(isolate, |
| 1948 JSObject::SetLocalPropertyIgnoreAttributes( | 1948 JSObject::SetLocalPropertyIgnoreAttributes( |
| 1949 global, natives, | 1949 global, natives, |
| 1950 Handle<JSObject>(global->builtins()), | 1950 Handle<JSObject>(global->builtins()), |
| 1951 DONT_ENUM)); | 1951 DONT_ENUM)); |
| 1952 } | 1952 } |
| 1953 | 1953 |
| 1954 Handle<Object> Error = GetProperty(global, "Error"); | 1954 Handle<Object> Error = GetProperty(global, "Error"); |
| 1955 if (Error->IsJSObject()) { | 1955 if (Error->IsJSObject()) { |
| 1956 Handle<String> name = factory->LookupAsciiSymbol("stackTraceLimit"); | 1956 Handle<String> name = factory->LookupAsciiSymbol("stackTraceLimit"); |
| 1957 Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit)); | 1957 Handle<Smi> stack_trace_limit(Smi::FromInt(FLAG_stack_trace_limit)); |
| 1958 CHECK_NOT_EMPTY_HANDLE(isolate, | 1958 CHECK_NOT_EMPTY_HANDLE(isolate, |
| 1959 JSObject::SetLocalPropertyIgnoreAttributes( | 1959 JSObject::SetLocalPropertyIgnoreAttributes( |
| 1960 Handle<JSObject>::cast(Error), name, | 1960 Handle<JSObject>::cast(Error), name, |
| 1961 stack_trace_limit, NONE)); | 1961 stack_trace_limit, NONE)); |
| 1962 } | 1962 } |
| 1963 | 1963 |
| 1964 #ifdef ENABLE_DEBUGGER_SUPPORT | 1964 #ifdef ENABLE_DEBUGGER_SUPPORT |
| 1965 // Expose the debug global object in global if a name for it is specified. | 1965 // Expose the debug global object in global if a name for it is specified. |
| 1966 if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { | 1966 if (FLAG_expose_debug_as != NULL && strlen(FLAG_expose_debug_as) != 0) { |
| 1967 Debug* debug = Isolate::Current()->debug(); | 1967 Debug* debug = Isolate::Current()->debug(); |
| 1968 // If loading fails we just bail out without installing the | 1968 // If loading fails we just bail out without installing the |
| 1969 // debugger but without tanking the whole context. | 1969 // debugger but without tanking the whole context. |
| 1970 if (!debug->Load()) return; | 1970 if (!debug->Load()) return; |
| 1971 // Set the security token for the debugger context to the same as | 1971 // Set the security token for the debugger context to the same as |
| 1972 // the shell global context to allow calling between these (otherwise | 1972 // the shell native context to allow calling between these (otherwise |
| 1973 // exposing debug global object doesn't make much sense). | 1973 // exposing debug global object doesn't make much sense). |
| 1974 debug->debug_context()->set_security_token( | 1974 debug->debug_context()->set_security_token( |
| 1975 global_context->security_token()); | 1975 native_context->security_token()); |
| 1976 | 1976 |
| 1977 Handle<String> debug_string = | 1977 Handle<String> debug_string = |
| 1978 factory->LookupAsciiSymbol(FLAG_expose_debug_as); | 1978 factory->LookupAsciiSymbol(FLAG_expose_debug_as); |
| 1979 Handle<Object> global_proxy(debug->debug_context()->global_proxy()); | 1979 Handle<Object> global_proxy(debug->debug_context()->global_proxy()); |
| 1980 CHECK_NOT_EMPTY_HANDLE(isolate, | 1980 CHECK_NOT_EMPTY_HANDLE(isolate, |
| 1981 JSObject::SetLocalPropertyIgnoreAttributes( | 1981 JSObject::SetLocalPropertyIgnoreAttributes( |
| 1982 global, debug_string, global_proxy, DONT_ENUM)); | 1982 global, debug_string, global_proxy, DONT_ENUM)); |
| 1983 } | 1983 } |
| 1984 #endif | 1984 #endif |
| 1985 } | 1985 } |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2004 return static_cast<ExtensionTraversalState>( | 2004 return static_cast<ExtensionTraversalState>( |
| 2005 reinterpret_cast<intptr_t>(entry->value)); | 2005 reinterpret_cast<intptr_t>(entry->value)); |
| 2006 } | 2006 } |
| 2007 | 2007 |
| 2008 void Genesis::ExtensionStates::set_state(RegisteredExtension* extension, | 2008 void Genesis::ExtensionStates::set_state(RegisteredExtension* extension, |
| 2009 ExtensionTraversalState state) { | 2009 ExtensionTraversalState state) { |
| 2010 map_.Lookup(extension, Hash(extension), true)->value = | 2010 map_.Lookup(extension, Hash(extension), true)->value = |
| 2011 reinterpret_cast<void*>(static_cast<intptr_t>(state)); | 2011 reinterpret_cast<void*>(static_cast<intptr_t>(state)); |
| 2012 } | 2012 } |
| 2013 | 2013 |
| 2014 bool Genesis::InstallExtensions(Handle<Context> global_context, | 2014 bool Genesis::InstallExtensions(Handle<Context> native_context, |
| 2015 v8::ExtensionConfiguration* extensions) { | 2015 v8::ExtensionConfiguration* extensions) { |
| 2016 // TODO(isolates): Extensions on multiple isolates may take a little more | 2016 // TODO(isolates): Extensions on multiple isolates may take a little more |
| 2017 // effort. (The external API reads 'ignore'-- does that mean | 2017 // effort. (The external API reads 'ignore'-- does that mean |
| 2018 // we can break the interface?) | 2018 // we can break the interface?) |
| 2019 | 2019 |
| 2020 | 2020 |
| 2021 ExtensionStates extension_states; // All extensions have state UNVISITED. | 2021 ExtensionStates extension_states; // All extensions have state UNVISITED. |
| 2022 // Install auto extensions. | 2022 // Install auto extensions. |
| 2023 v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); | 2023 v8::RegisteredExtension* current = v8::RegisteredExtension::first_extension(); |
| 2024 while (current != NULL) { | 2024 while (current != NULL) { |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2129 } | 2129 } |
| 2130 builtins->set_javascript_builtin_code(id, function->shared()->code()); | 2130 builtins->set_javascript_builtin_code(id, function->shared()->code()); |
| 2131 } | 2131 } |
| 2132 return true; | 2132 return true; |
| 2133 } | 2133 } |
| 2134 | 2134 |
| 2135 | 2135 |
| 2136 bool Genesis::ConfigureGlobalObjects( | 2136 bool Genesis::ConfigureGlobalObjects( |
| 2137 v8::Handle<v8::ObjectTemplate> global_proxy_template) { | 2137 v8::Handle<v8::ObjectTemplate> global_proxy_template) { |
| 2138 Handle<JSObject> global_proxy( | 2138 Handle<JSObject> global_proxy( |
| 2139 JSObject::cast(global_context()->global_proxy())); | 2139 JSObject::cast(native_context()->global_proxy())); |
| 2140 Handle<JSObject> inner_global(JSObject::cast(global_context()->global())); | 2140 Handle<JSObject> inner_global(JSObject::cast(native_context()->global())); |
| 2141 | 2141 |
| 2142 if (!global_proxy_template.IsEmpty()) { | 2142 if (!global_proxy_template.IsEmpty()) { |
| 2143 // Configure the global proxy object. | 2143 // Configure the global proxy object. |
| 2144 Handle<ObjectTemplateInfo> proxy_data = | 2144 Handle<ObjectTemplateInfo> proxy_data = |
| 2145 v8::Utils::OpenHandle(*global_proxy_template); | 2145 v8::Utils::OpenHandle(*global_proxy_template); |
| 2146 if (!ConfigureApiObject(global_proxy, proxy_data)) return false; | 2146 if (!ConfigureApiObject(global_proxy, proxy_data)) return false; |
| 2147 | 2147 |
| 2148 // Configure the inner global object. | 2148 // Configure the inner global object. |
| 2149 Handle<FunctionTemplateInfo> proxy_constructor( | 2149 Handle<FunctionTemplateInfo> proxy_constructor( |
| 2150 FunctionTemplateInfo::cast(proxy_data->constructor())); | 2150 FunctionTemplateInfo::cast(proxy_data->constructor())); |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2290 | 2290 |
| 2291 | 2291 |
| 2292 void Genesis::MakeFunctionInstancePrototypeWritable() { | 2292 void Genesis::MakeFunctionInstancePrototypeWritable() { |
| 2293 // The maps with writable prototype are created in CreateEmptyFunction | 2293 // The maps with writable prototype are created in CreateEmptyFunction |
| 2294 // and CreateStrictModeFunctionMaps respectively. Initially the maps are | 2294 // and CreateStrictModeFunctionMaps respectively. Initially the maps are |
| 2295 // created with read-only prototype for JS builtins processing. | 2295 // created with read-only prototype for JS builtins processing. |
| 2296 ASSERT(!function_instance_map_writable_prototype_.is_null()); | 2296 ASSERT(!function_instance_map_writable_prototype_.is_null()); |
| 2297 ASSERT(!strict_mode_function_instance_map_writable_prototype_.is_null()); | 2297 ASSERT(!strict_mode_function_instance_map_writable_prototype_.is_null()); |
| 2298 | 2298 |
| 2299 // Replace function instance maps to make prototype writable. | 2299 // Replace function instance maps to make prototype writable. |
| 2300 global_context()->set_function_map( | 2300 native_context()->set_function_map( |
| 2301 *function_instance_map_writable_prototype_); | 2301 *function_instance_map_writable_prototype_); |
| 2302 global_context()->set_strict_mode_function_map( | 2302 native_context()->set_strict_mode_function_map( |
| 2303 *strict_mode_function_instance_map_writable_prototype_); | 2303 *strict_mode_function_instance_map_writable_prototype_); |
| 2304 } | 2304 } |
| 2305 | 2305 |
| 2306 | 2306 |
| 2307 Genesis::Genesis(Isolate* isolate, | 2307 Genesis::Genesis(Isolate* isolate, |
| 2308 Handle<Object> global_object, | 2308 Handle<Object> global_object, |
| 2309 v8::Handle<v8::ObjectTemplate> global_template, | 2309 v8::Handle<v8::ObjectTemplate> global_template, |
| 2310 v8::ExtensionConfiguration* extensions) : isolate_(isolate) { | 2310 v8::ExtensionConfiguration* extensions) : isolate_(isolate) { |
| 2311 result_ = Handle<Context>::null(); | 2311 result_ = Handle<Context>::null(); |
| 2312 // If V8 isn't running and cannot be initialized, just return. | 2312 // If V8 isn't running and cannot be initialized, just return. |
| 2313 if (!V8::IsRunning() && !V8::Initialize(NULL)) return; | 2313 if (!V8::IsRunning() && !V8::Initialize(NULL)) return; |
| 2314 | 2314 |
| 2315 // Before creating the roots we must save the context and restore it | 2315 // Before creating the roots we must save the context and restore it |
| 2316 // on all function exits. | 2316 // on all function exits. |
| 2317 HandleScope scope; | 2317 HandleScope scope; |
| 2318 SaveContext saved_context(isolate); | 2318 SaveContext saved_context(isolate); |
| 2319 | 2319 |
| 2320 // During genesis, the boilerplate for stack overflow won't work until the | 2320 // During genesis, the boilerplate for stack overflow won't work until the |
| 2321 // environment has been at least partially initialized. Add a stack check | 2321 // environment has been at least partially initialized. Add a stack check |
| 2322 // before entering JS code to catch overflow early. | 2322 // before entering JS code to catch overflow early. |
| 2323 StackLimitCheck check(Isolate::Current()); | 2323 StackLimitCheck check(Isolate::Current()); |
| 2324 if (check.HasOverflowed()) return; | 2324 if (check.HasOverflowed()) return; |
| 2325 | 2325 |
| 2326 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); | 2326 Handle<Context> new_context = Snapshot::NewContextFromSnapshot(); |
| 2327 if (!new_context.is_null()) { | 2327 if (!new_context.is_null()) { |
| 2328 global_context_ = | 2328 native_context_ = |
| 2329 Handle<Context>::cast(isolate->global_handles()->Create(*new_context)); | 2329 Handle<Context>::cast(isolate->global_handles()->Create(*new_context)); |
| 2330 AddToWeakGlobalContextList(*global_context_); | 2330 AddToWeakNativeContextList(*native_context_); |
| 2331 isolate->set_context(*global_context_); | 2331 isolate->set_context(*native_context_); |
| 2332 isolate->counters()->contexts_created_by_snapshot()->Increment(); | 2332 isolate->counters()->contexts_created_by_snapshot()->Increment(); |
| 2333 Handle<GlobalObject> inner_global; | 2333 Handle<GlobalObject> inner_global; |
| 2334 Handle<JSGlobalProxy> global_proxy = | 2334 Handle<JSGlobalProxy> global_proxy = |
| 2335 CreateNewGlobals(global_template, | 2335 CreateNewGlobals(global_template, |
| 2336 global_object, | 2336 global_object, |
| 2337 &inner_global); | 2337 &inner_global); |
| 2338 | 2338 |
| 2339 HookUpGlobalProxy(inner_global, global_proxy); | 2339 HookUpGlobalProxy(inner_global, global_proxy); |
| 2340 HookUpInnerGlobal(inner_global); | 2340 HookUpInnerGlobal(inner_global); |
| 2341 | 2341 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2357 MakeFunctionInstancePrototypeWritable(); | 2357 MakeFunctionInstancePrototypeWritable(); |
| 2358 | 2358 |
| 2359 if (!ConfigureGlobalObjects(global_template)) return; | 2359 if (!ConfigureGlobalObjects(global_template)) return; |
| 2360 isolate->counters()->contexts_created_from_scratch()->Increment(); | 2360 isolate->counters()->contexts_created_from_scratch()->Increment(); |
| 2361 } | 2361 } |
| 2362 | 2362 |
| 2363 // Initialize experimental globals and install experimental natives. | 2363 // Initialize experimental globals and install experimental natives. |
| 2364 InitializeExperimentalGlobal(); | 2364 InitializeExperimentalGlobal(); |
| 2365 if (!InstallExperimentalNatives()) return; | 2365 if (!InstallExperimentalNatives()) return; |
| 2366 | 2366 |
| 2367 result_ = global_context_; | 2367 result_ = native_context_; |
| 2368 } | 2368 } |
| 2369 | 2369 |
| 2370 | 2370 |
| 2371 // Support for thread preemption. | 2371 // Support for thread preemption. |
| 2372 | 2372 |
| 2373 // Reserve space for statics needing saving and restoring. | 2373 // Reserve space for statics needing saving and restoring. |
| 2374 int Bootstrapper::ArchiveSpacePerThread() { | 2374 int Bootstrapper::ArchiveSpacePerThread() { |
| 2375 return sizeof(NestingCounterType); | 2375 return sizeof(NestingCounterType); |
| 2376 } | 2376 } |
| 2377 | 2377 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2390 return from + sizeof(NestingCounterType); | 2390 return from + sizeof(NestingCounterType); |
| 2391 } | 2391 } |
| 2392 | 2392 |
| 2393 | 2393 |
| 2394 // Called when the top-level V8 mutex is destroyed. | 2394 // Called when the top-level V8 mutex is destroyed. |
| 2395 void Bootstrapper::FreeThreadResources() { | 2395 void Bootstrapper::FreeThreadResources() { |
| 2396 ASSERT(!IsActive()); | 2396 ASSERT(!IsActive()); |
| 2397 } | 2397 } |
| 2398 | 2398 |
| 2399 } } // namespace v8::internal | 2399 } } // namespace v8::internal |
| OLD | NEW |