| 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 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 Handle<String> source, | 274 Handle<String> source, |
| 275 SourceCodeCache* cache, | 275 SourceCodeCache* cache, |
| 276 v8::Extension* extension, | 276 v8::Extension* extension, |
| 277 Handle<Context> top_context, | 277 Handle<Context> top_context, |
| 278 bool use_runtime_context); | 278 bool use_runtime_context); |
| 279 | 279 |
| 280 Isolate* isolate_; | 280 Isolate* isolate_; |
| 281 Handle<Context> result_; | 281 Handle<Context> result_; |
| 282 Handle<Context> native_context_; | 282 Handle<Context> native_context_; |
| 283 | 283 |
| 284 // Function instance maps. Function literal maps are created initially with | 284 // Function maps. Function maps are created initially with a read only |
| 285 // a read only prototype for the processing of JS builtins. Later the function | 285 // prototype for the processing of JS builtins. Later the function maps are |
| 286 // instance maps are replaced in order to make prototype writable. | 286 // replaced in order to make prototype writable. These are the final, writable |
| 287 // These are the final, writable prototype, maps. | 287 // prototype, maps. |
| 288 Handle<Map> function_instance_map_writable_prototype_; | 288 Handle<Map> function_map_writable_prototype_; |
| 289 Handle<Map> strict_mode_function_instance_map_writable_prototype_; | 289 Handle<Map> strict_mode_function_map_writable_prototype_; |
| 290 Handle<JSFunction> throw_type_error_function; | 290 Handle<JSFunction> throw_type_error_function; |
| 291 | 291 |
| 292 BootstrapperActive active_; | 292 BootstrapperActive active_; |
| 293 friend class Bootstrapper; | 293 friend class Bootstrapper; |
| 294 }; | 294 }; |
| 295 | 295 |
| 296 | 296 |
| 297 void Bootstrapper::Iterate(ObjectVisitor* v) { | 297 void Bootstrapper::Iterate(ObjectVisitor* v) { |
| 298 extensions_cache_.Iterate(v); | 298 extensions_cache_.Iterate(v); |
| 299 v->Synchronize(VisitorSynchronization::kExtensions); | 299 v->Synchronize(VisitorSynchronization::kExtensions); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 SetFunctionInstanceDescriptor(map, prototype_mode); | 430 SetFunctionInstanceDescriptor(map, prototype_mode); |
| 431 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); | 431 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); |
| 432 return map; | 432 return map; |
| 433 } | 433 } |
| 434 | 434 |
| 435 | 435 |
| 436 Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { | 436 Handle<JSFunction> Genesis::CreateEmptyFunction(Isolate* isolate) { |
| 437 // Allocate the map for function instances. Maps are allocated first and their | 437 // Allocate the map for function instances. Maps are allocated first and their |
| 438 // prototypes patched later, once empty function is created. | 438 // prototypes patched later, once empty function is created. |
| 439 | 439 |
| 440 // Please note that the prototype property for function instances must be | |
| 441 // writable. | |
| 442 Handle<Map> function_instance_map = | |
| 443 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); | |
| 444 native_context()->set_function_instance_map(*function_instance_map); | |
| 445 | |
| 446 // Functions with this map will not have a 'prototype' property, and | 440 // Functions with this map will not have a 'prototype' property, and |
| 447 // can not be used as constructors. | 441 // can not be used as constructors. |
| 448 Handle<Map> function_without_prototype_map = | 442 Handle<Map> function_without_prototype_map = |
| 449 CreateFunctionMap(DONT_ADD_PROTOTYPE); | 443 CreateFunctionMap(DONT_ADD_PROTOTYPE); |
| 450 native_context()->set_function_without_prototype_map( | 444 native_context()->set_function_without_prototype_map( |
| 451 *function_without_prototype_map); | 445 *function_without_prototype_map); |
| 452 | 446 |
| 453 // Allocate the function map. This map is temporary, used only for processing | 447 // Allocate the function map. This map is temporary, used only for processing |
| 454 // of builtins. | 448 // of builtins. |
| 455 // Later the map is replaced with writable prototype map, allocated below. | 449 // Later the map is replaced with writable prototype map, allocated below. |
| 456 Handle<Map> function_map = CreateFunctionMap(ADD_READONLY_PROTOTYPE); | 450 Handle<Map> function_map = CreateFunctionMap(ADD_READONLY_PROTOTYPE); |
| 457 native_context()->set_function_map(*function_map); | 451 native_context()->set_function_map(*function_map); |
| 458 | 452 |
| 459 // The final map for functions. Writeable prototype. | 453 // The final map for functions. Writeable prototype. |
| 460 // This map is installed in MakeFunctionInstancePrototypeWritable. | 454 // This map is installed in MakeFunctionInstancePrototypeWritable. |
| 461 function_instance_map_writable_prototype_ = | 455 function_map_writable_prototype_ = CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); |
| 462 CreateFunctionMap(ADD_WRITEABLE_PROTOTYPE); | |
| 463 | 456 |
| 464 Factory* factory = isolate->factory(); | 457 Factory* factory = isolate->factory(); |
| 465 Heap* heap = isolate->heap(); | 458 Heap* heap = isolate->heap(); |
| 466 | 459 |
| 467 Handle<String> object_name = Handle<String>(heap->Object_string()); | 460 Handle<String> object_name = Handle<String>(heap->Object_string()); |
| 468 | 461 |
| 469 { // --- O b j e c t --- | 462 { // --- O b j e c t --- |
| 470 Handle<JSFunction> object_fun = | 463 Handle<JSFunction> object_fun = |
| 471 factory->NewFunction(object_name, factory->null_value()); | 464 factory->NewFunction(object_name, factory->null_value()); |
| 472 Handle<Map> object_function_map = | 465 Handle<Map> object_function_map = |
| (...skipping 29 matching lines...) Expand all Loading... |
| 502 factory->NewStringFromOneByte(STATIC_ASCII_VECTOR("() {}")); | 495 factory->NewStringFromOneByte(STATIC_ASCII_VECTOR("() {}")); |
| 503 Handle<Script> script = factory->NewScript(source); | 496 Handle<Script> script = factory->NewScript(source); |
| 504 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); | 497 script->set_type(Smi::FromInt(Script::TYPE_NATIVE)); |
| 505 empty_function->shared()->set_script(*script); | 498 empty_function->shared()->set_script(*script); |
| 506 empty_function->shared()->set_start_position(0); | 499 empty_function->shared()->set_start_position(0); |
| 507 empty_function->shared()->set_end_position(source->length()); | 500 empty_function->shared()->set_end_position(source->length()); |
| 508 empty_function->shared()->DontAdaptArguments(); | 501 empty_function->shared()->DontAdaptArguments(); |
| 509 | 502 |
| 510 // Set prototypes for the function maps. | 503 // Set prototypes for the function maps. |
| 511 native_context()->function_map()->set_prototype(*empty_function); | 504 native_context()->function_map()->set_prototype(*empty_function); |
| 512 native_context()->function_instance_map()->set_prototype(*empty_function); | |
| 513 native_context()->function_without_prototype_map()-> | 505 native_context()->function_without_prototype_map()-> |
| 514 set_prototype(*empty_function); | 506 set_prototype(*empty_function); |
| 515 function_instance_map_writable_prototype_->set_prototype(*empty_function); | 507 function_map_writable_prototype_->set_prototype(*empty_function); |
| 516 | 508 |
| 517 // Allocate the function map first and then patch the prototype later | 509 // Allocate the function map first and then patch the prototype later |
| 518 Handle<Map> empty_function_map = CreateFunctionMap(DONT_ADD_PROTOTYPE); | 510 Handle<Map> empty_function_map = CreateFunctionMap(DONT_ADD_PROTOTYPE); |
| 519 empty_function_map->set_prototype( | 511 empty_function_map->set_prototype( |
| 520 native_context()->object_function()->prototype()); | 512 native_context()->object_function()->prototype()); |
| 521 empty_function->set_map(*empty_function_map); | 513 empty_function->set_map(*empty_function_map); |
| 522 return empty_function; | 514 return empty_function; |
| 523 } | 515 } |
| 524 | 516 |
| 525 | 517 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 594 Handle<JSFunction> empty_function) { | 586 Handle<JSFunction> empty_function) { |
| 595 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); | 587 Handle<Map> map = factory()->NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
| 596 SetStrictFunctionInstanceDescriptor(map, prototype_mode); | 588 SetStrictFunctionInstanceDescriptor(map, prototype_mode); |
| 597 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); | 589 map->set_function_with_prototype(prototype_mode != DONT_ADD_PROTOTYPE); |
| 598 map->set_prototype(*empty_function); | 590 map->set_prototype(*empty_function); |
| 599 return map; | 591 return map; |
| 600 } | 592 } |
| 601 | 593 |
| 602 | 594 |
| 603 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { | 595 void Genesis::CreateStrictModeFunctionMaps(Handle<JSFunction> empty) { |
| 604 // Allocate map for the strict mode function instances. | |
| 605 Handle<Map> strict_mode_function_instance_map = | |
| 606 CreateStrictModeFunctionMap(ADD_WRITEABLE_PROTOTYPE, empty); | |
| 607 native_context()->set_strict_mode_function_instance_map( | |
| 608 *strict_mode_function_instance_map); | |
| 609 | |
| 610 // Allocate map for the prototype-less strict mode instances. | 596 // Allocate map for the prototype-less strict mode instances. |
| 611 Handle<Map> strict_mode_function_without_prototype_map = | 597 Handle<Map> strict_mode_function_without_prototype_map = |
| 612 CreateStrictModeFunctionMap(DONT_ADD_PROTOTYPE, empty); | 598 CreateStrictModeFunctionMap(DONT_ADD_PROTOTYPE, empty); |
| 613 native_context()->set_strict_mode_function_without_prototype_map( | 599 native_context()->set_strict_mode_function_without_prototype_map( |
| 614 *strict_mode_function_without_prototype_map); | 600 *strict_mode_function_without_prototype_map); |
| 615 | 601 |
| 616 // Allocate map for the strict mode functions. This map is temporary, used | 602 // Allocate map for the strict mode functions. This map is temporary, used |
| 617 // only for processing of builtins. | 603 // only for processing of builtins. |
| 618 // Later the map is replaced with writable prototype map, allocated below. | 604 // Later the map is replaced with writable prototype map, allocated below. |
| 619 Handle<Map> strict_mode_function_map = | 605 Handle<Map> strict_mode_function_map = |
| 620 CreateStrictModeFunctionMap(ADD_READONLY_PROTOTYPE, empty); | 606 CreateStrictModeFunctionMap(ADD_READONLY_PROTOTYPE, empty); |
| 621 native_context()->set_strict_mode_function_map( | 607 native_context()->set_strict_mode_function_map( |
| 622 *strict_mode_function_map); | 608 *strict_mode_function_map); |
| 623 | 609 |
| 624 // The final map for the strict mode functions. Writeable prototype. | 610 // The final map for the strict mode functions. Writeable prototype. |
| 625 // This map is installed in MakeFunctionInstancePrototypeWritable. | 611 // This map is installed in MakeFunctionInstancePrototypeWritable. |
| 626 strict_mode_function_instance_map_writable_prototype_ = | 612 strict_mode_function_map_writable_prototype_ = |
| 627 CreateStrictModeFunctionMap(ADD_WRITEABLE_PROTOTYPE, empty); | 613 CreateStrictModeFunctionMap(ADD_WRITEABLE_PROTOTYPE, empty); |
| 628 | 614 |
| 629 // Complete the callbacks. | 615 // Complete the callbacks. |
| 630 PoisonArgumentsAndCaller(strict_mode_function_instance_map); | |
| 631 PoisonArgumentsAndCaller(strict_mode_function_without_prototype_map); | 616 PoisonArgumentsAndCaller(strict_mode_function_without_prototype_map); |
| 632 PoisonArgumentsAndCaller(strict_mode_function_map); | 617 PoisonArgumentsAndCaller(strict_mode_function_map); |
| 633 PoisonArgumentsAndCaller( | 618 PoisonArgumentsAndCaller(strict_mode_function_map_writable_prototype_); |
| 634 strict_mode_function_instance_map_writable_prototype_); | |
| 635 } | 619 } |
| 636 | 620 |
| 637 | 621 |
| 638 static void SetAccessors(Handle<Map> map, | 622 static void SetAccessors(Handle<Map> map, |
| 639 Handle<String> name, | 623 Handle<String> name, |
| 640 Handle<JSFunction> func) { | 624 Handle<JSFunction> func) { |
| 641 DescriptorArray* descs = map->instance_descriptors(); | 625 DescriptorArray* descs = map->instance_descriptors(); |
| 642 int number = descs->SearchWithCache(*name, *map); | 626 int number = descs->SearchWithCache(*name, *map); |
| 643 AccessorPair* accessors = AccessorPair::cast(descs->GetValue(number)); | 627 AccessorPair* accessors = AccessorPair::cast(descs->GetValue(number)); |
| 644 accessors->set_getter(*func); | 628 accessors->set_getter(*func); |
| (...skipping 1870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2515 Handle<Map> new_to_map = factory->CopyMap(old_to_map); | 2499 Handle<Map> new_to_map = factory->CopyMap(old_to_map); |
| 2516 new_to_map->set_prototype(from->map()->prototype()); | 2500 new_to_map->set_prototype(from->map()->prototype()); |
| 2517 to->set_map(*new_to_map); | 2501 to->set_map(*new_to_map); |
| 2518 } | 2502 } |
| 2519 | 2503 |
| 2520 | 2504 |
| 2521 void Genesis::MakeFunctionInstancePrototypeWritable() { | 2505 void Genesis::MakeFunctionInstancePrototypeWritable() { |
| 2522 // The maps with writable prototype are created in CreateEmptyFunction | 2506 // The maps with writable prototype are created in CreateEmptyFunction |
| 2523 // and CreateStrictModeFunctionMaps respectively. Initially the maps are | 2507 // and CreateStrictModeFunctionMaps respectively. Initially the maps are |
| 2524 // created with read-only prototype for JS builtins processing. | 2508 // created with read-only prototype for JS builtins processing. |
| 2525 ASSERT(!function_instance_map_writable_prototype_.is_null()); | 2509 ASSERT(!function_map_writable_prototype_.is_null()); |
| 2526 ASSERT(!strict_mode_function_instance_map_writable_prototype_.is_null()); | 2510 ASSERT(!strict_mode_function_map_writable_prototype_.is_null()); |
| 2527 | 2511 |
| 2528 // Replace function instance maps to make prototype writable. | 2512 // Replace function instance maps to make prototype writable. |
| 2529 native_context()->set_function_map( | 2513 native_context()->set_function_map(*function_map_writable_prototype_); |
| 2530 *function_instance_map_writable_prototype_); | |
| 2531 native_context()->set_strict_mode_function_map( | 2514 native_context()->set_strict_mode_function_map( |
| 2532 *strict_mode_function_instance_map_writable_prototype_); | 2515 *strict_mode_function_map_writable_prototype_); |
| 2533 } | 2516 } |
| 2534 | 2517 |
| 2535 | 2518 |
| 2536 Genesis::Genesis(Isolate* isolate, | 2519 Genesis::Genesis(Isolate* isolate, |
| 2537 Handle<Object> global_object, | 2520 Handle<Object> global_object, |
| 2538 v8::Handle<v8::ObjectTemplate> global_template, | 2521 v8::Handle<v8::ObjectTemplate> global_template, |
| 2539 v8::ExtensionConfiguration* extensions) | 2522 v8::ExtensionConfiguration* extensions) |
| 2540 : isolate_(isolate), | 2523 : isolate_(isolate), |
| 2541 active_(isolate->bootstrapper()) { | 2524 active_(isolate->bootstrapper()) { |
| 2542 result_ = Handle<Context>::null(); | 2525 result_ = Handle<Context>::null(); |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2618 return from + sizeof(NestingCounterType); | 2601 return from + sizeof(NestingCounterType); |
| 2619 } | 2602 } |
| 2620 | 2603 |
| 2621 | 2604 |
| 2622 // Called when the top-level V8 mutex is destroyed. | 2605 // Called when the top-level V8 mutex is destroyed. |
| 2623 void Bootstrapper::FreeThreadResources() { | 2606 void Bootstrapper::FreeThreadResources() { |
| 2624 ASSERT(!IsActive()); | 2607 ASSERT(!IsActive()); |
| 2625 } | 2608 } |
| 2626 | 2609 |
| 2627 } } // namespace v8::internal | 2610 } } // namespace v8::internal |
| OLD | NEW |