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