OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "factory.h" | 5 #include "factory.h" |
6 | 6 |
7 #include "isolate-inl.h" | 7 #include "isolate-inl.h" |
8 | 8 |
9 namespace v8 { | 9 namespace v8 { |
10 namespace internal { | 10 namespace internal { |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 array->set_map_no_write_barrier(*native_context_map()); | 584 array->set_map_no_write_barrier(*native_context_map()); |
585 Handle<Context> context = Handle<Context>::cast(array); | 585 Handle<Context> context = Handle<Context>::cast(array); |
586 context->set_js_array_maps(*undefined_value()); | 586 context->set_js_array_maps(*undefined_value()); |
587 ASSERT(context->IsNativeContext()); | 587 ASSERT(context->IsNativeContext()); |
588 return context; | 588 return context; |
589 } | 589 } |
590 | 590 |
591 | 591 |
592 Handle<Context> Factory::NewGlobalContext(Handle<JSFunction> function, | 592 Handle<Context> Factory::NewGlobalContext(Handle<JSFunction> function, |
593 Handle<ScopeInfo> scope_info) { | 593 Handle<ScopeInfo> scope_info) { |
594 CALL_HEAP_FUNCTION( | 594 Handle<FixedArray> array = |
595 isolate(), | 595 NewFixedArray(scope_info->ContextLength(), TENURED); |
596 isolate()->heap()->AllocateGlobalContext(*function, *scope_info), | 596 array->set_map_no_write_barrier(*global_context_map()); |
597 Context); | 597 Handle<Context> context = Handle<Context>::cast(array); |
| 598 context->set_closure(*function); |
| 599 context->set_previous(function->context()); |
| 600 context->set_extension(*scope_info); |
| 601 context->set_global_object(function->context()->global_object()); |
| 602 ASSERT(context->IsGlobalContext()); |
| 603 return context; |
598 } | 604 } |
599 | 605 |
600 | 606 |
601 Handle<Context> Factory::NewModuleContext(Handle<ScopeInfo> scope_info) { | 607 Handle<Context> Factory::NewModuleContext(Handle<ScopeInfo> scope_info) { |
602 Handle<FixedArray> array = | 608 Handle<FixedArray> array = |
603 NewFixedArray(scope_info->ContextLength(), TENURED); | 609 NewFixedArray(scope_info->ContextLength(), TENURED); |
604 array->set_map_no_write_barrier(*module_context_map()); | 610 array->set_map_no_write_barrier(*module_context_map()); |
605 // Instance link will be set later. | 611 // Instance link will be set later. |
606 Handle<Context> context = Handle<Context>::cast(array); | 612 Handle<Context> context = Handle<Context>::cast(array); |
607 context->set_extension(Smi::FromInt(0)); | 613 context->set_extension(Smi::FromInt(0)); |
608 return context; | 614 return context; |
609 } | 615 } |
610 | 616 |
611 | 617 |
612 Handle<Context> Factory::NewFunctionContext(int length, | 618 Handle<Context> Factory::NewFunctionContext(int length, |
613 Handle<JSFunction> function) { | 619 Handle<JSFunction> function) { |
614 CALL_HEAP_FUNCTION( | 620 ASSERT(length >= Context::MIN_CONTEXT_SLOTS); |
615 isolate(), | 621 Handle<FixedArray> array = NewFixedArray(length); |
616 isolate()->heap()->AllocateFunctionContext(length, *function), | 622 array->set_map_no_write_barrier(*function_context_map()); |
617 Context); | 623 Handle<Context> context = Handle<Context>::cast(array); |
| 624 context->set_closure(*function); |
| 625 context->set_previous(function->context()); |
| 626 context->set_extension(Smi::FromInt(0)); |
| 627 context->set_global_object(function->context()->global_object()); |
| 628 return context; |
618 } | 629 } |
619 | 630 |
620 | 631 |
621 Handle<Context> Factory::NewCatchContext(Handle<JSFunction> function, | 632 Handle<Context> Factory::NewCatchContext(Handle<JSFunction> function, |
622 Handle<Context> previous, | 633 Handle<Context> previous, |
623 Handle<String> name, | 634 Handle<String> name, |
624 Handle<Object> thrown_object) { | 635 Handle<Object> thrown_object) { |
625 CALL_HEAP_FUNCTION( | 636 STATIC_ASSERT(Context::MIN_CONTEXT_SLOTS == Context::THROWN_OBJECT_INDEX); |
626 isolate(), | 637 Handle<FixedArray> array = NewFixedArray(Context::MIN_CONTEXT_SLOTS + 1); |
627 isolate()->heap()->AllocateCatchContext(*function, | 638 array->set_map_no_write_barrier(*catch_context_map()); |
628 *previous, | 639 Handle<Context> context = Handle<Context>::cast(array); |
629 *name, | 640 context->set_closure(*function); |
630 *thrown_object), | 641 context->set_previous(*previous); |
631 Context); | 642 context->set_extension(*name); |
| 643 context->set_global_object(previous->global_object()); |
| 644 context->set(Context::THROWN_OBJECT_INDEX, *thrown_object); |
| 645 return context; |
632 } | 646 } |
633 | 647 |
634 | 648 |
635 Handle<Context> Factory::NewWithContext(Handle<JSFunction> function, | 649 Handle<Context> Factory::NewWithContext(Handle<JSFunction> function, |
636 Handle<Context> previous, | 650 Handle<Context> previous, |
637 Handle<JSObject> extension) { | 651 Handle<JSReceiver> extension) { |
638 CALL_HEAP_FUNCTION( | 652 Handle<FixedArray> array = NewFixedArray(Context::MIN_CONTEXT_SLOTS); |
639 isolate(), | 653 array->set_map_no_write_barrier(*with_context_map()); |
640 isolate()->heap()->AllocateWithContext(*function, *previous, *extension), | 654 Handle<Context> context = Handle<Context>::cast(array); |
641 Context); | 655 context->set_closure(*function); |
| 656 context->set_previous(*previous); |
| 657 context->set_extension(*extension); |
| 658 context->set_global_object(previous->global_object()); |
| 659 return context; |
642 } | 660 } |
643 | 661 |
644 | 662 |
645 Handle<Context> Factory::NewBlockContext(Handle<JSFunction> function, | 663 Handle<Context> Factory::NewBlockContext(Handle<JSFunction> function, |
646 Handle<Context> previous, | 664 Handle<Context> previous, |
647 Handle<ScopeInfo> scope_info) { | 665 Handle<ScopeInfo> scope_info) { |
648 CALL_HEAP_FUNCTION( | 666 Handle<FixedArray> array = |
649 isolate(), | 667 NewFixedArrayWithHoles(scope_info->ContextLength()); |
650 isolate()->heap()->AllocateBlockContext(*function, | 668 array->set_map_no_write_barrier(*block_context_map()); |
651 *previous, | 669 Handle<Context> context = Handle<Context>::cast(array); |
652 *scope_info), | 670 context->set_closure(*function); |
653 Context); | 671 context->set_previous(*previous); |
| 672 context->set_extension(*scope_info); |
| 673 context->set_global_object(previous->global_object()); |
| 674 return context; |
654 } | 675 } |
655 | 676 |
656 | 677 |
657 Handle<Struct> Factory::NewStruct(InstanceType type) { | 678 Handle<Struct> Factory::NewStruct(InstanceType type) { |
658 CALL_HEAP_FUNCTION( | 679 CALL_HEAP_FUNCTION( |
659 isolate(), | 680 isolate(), |
660 isolate()->heap()->AllocateStruct(type), | 681 isolate()->heap()->AllocateStruct(type), |
661 Struct); | 682 Struct); |
662 } | 683 } |
663 | 684 |
(...skipping 1323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1987 if (name->Equals(h->infinity_string())) return infinity_value(); | 2008 if (name->Equals(h->infinity_string())) return infinity_value(); |
1988 return Handle<Object>::null(); | 2009 return Handle<Object>::null(); |
1989 } | 2010 } |
1990 | 2011 |
1991 | 2012 |
1992 Handle<Object> Factory::ToBoolean(bool value) { | 2013 Handle<Object> Factory::ToBoolean(bool value) { |
1993 return value ? true_value() : false_value(); | 2014 return value ? true_value() : false_value(); |
1994 } | 2015 } |
1995 | 2016 |
1996 } } // namespace v8::internal | 2017 } } // namespace v8::internal |
OLD | NEW |