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 "src/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/arguments.h" | 8 #include "src/arguments.h" |
9 #include "src/ast/scopeinfo.h" | 9 #include "src/ast/scopeinfo.h" |
10 #include "src/ast/scopes.h" | 10 #include "src/ast/scopes.h" |
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 0); | 681 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 0); |
682 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 1); | 682 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 1); |
683 Handle<Context> current(isolate->context()); | 683 Handle<Context> current(isolate->context()); |
684 Handle<Context> context = | 684 Handle<Context> context = |
685 isolate->factory()->NewBlockContext(function, current, scope_info); | 685 isolate->factory()->NewBlockContext(function, current, scope_info); |
686 isolate->set_context(*context); | 686 isolate->set_context(*context); |
687 return *context; | 687 return *context; |
688 } | 688 } |
689 | 689 |
690 | 690 |
691 RUNTIME_FUNCTION(Runtime_IsJSModule) { | |
692 SealHandleScope shs(isolate); | |
693 DCHECK(args.length() == 1); | |
694 CONVERT_ARG_CHECKED(Object, obj, 0); | |
695 return isolate->heap()->ToBoolean(obj->IsJSModule()); | |
696 } | |
697 | |
698 | |
699 RUNTIME_FUNCTION(Runtime_PushModuleContext) { | |
700 SealHandleScope shs(isolate); | |
701 DCHECK(args.length() == 2); | |
702 CONVERT_SMI_ARG_CHECKED(index, 0); | |
703 | |
704 if (!args[1]->IsScopeInfo()) { | |
705 // Module already initialized. Find hosting context and retrieve context. | |
706 Context* host = Context::cast(isolate->context())->script_context(); | |
707 Context* context = Context::cast(host->get(index)); | |
708 DCHECK(context->previous() == isolate->context()); | |
709 isolate->set_context(context); | |
710 return context; | |
711 } | |
712 | |
713 CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); | |
714 | |
715 // Allocate module context. | |
716 HandleScope scope(isolate); | |
717 Factory* factory = isolate->factory(); | |
718 Handle<Context> context = factory->NewModuleContext(scope_info); | |
719 Handle<JSModule> module = factory->NewJSModule(context, scope_info); | |
720 context->set_module(*module); | |
721 Context* previous = isolate->context(); | |
722 context->set_previous(previous); | |
723 context->set_closure(previous->closure()); | |
724 context->set_native_context(previous->native_context()); | |
725 isolate->set_context(*context); | |
726 | |
727 // Find hosting scope and initialize internal variable holding module there. | |
728 previous->script_context()->set(index, *context); | |
729 | |
730 return *context; | |
731 } | |
732 | |
733 | |
734 RUNTIME_FUNCTION(Runtime_DeclareModules) { | |
735 HandleScope scope(isolate); | |
736 DCHECK(args.length() == 1); | |
737 CONVERT_ARG_HANDLE_CHECKED(FixedArray, descriptions, 0); | |
738 Context* host_context = isolate->context(); | |
739 | |
740 for (int i = 0; i < descriptions->length(); ++i) { | |
741 Handle<ModuleInfo> description(ModuleInfo::cast(descriptions->get(i))); | |
742 int host_index = description->host_index(); | |
743 Handle<Context> context(Context::cast(host_context->get(host_index))); | |
744 Handle<JSModule> module(context->module()); | |
745 | |
746 for (int j = 0; j < description->length(); ++j) { | |
747 Handle<String> name(description->name(j), isolate); | |
748 VariableMode mode = description->mode(j); | |
749 int index = description->index(j); | |
750 switch (mode) { | |
751 case VAR: | |
752 case LET: | |
753 case CONST: | |
754 case CONST_LEGACY: { | |
755 PropertyAttributes attr = | |
756 IsImmutableVariableMode(mode) ? FROZEN : SEALED; | |
757 Handle<AccessorInfo> info = | |
758 Accessors::MakeModuleExport(name, index, attr); | |
759 Handle<Object> result = | |
760 JSObject::SetAccessor(module, info).ToHandleChecked(); | |
761 DCHECK(!result->IsUndefined(isolate)); | |
762 USE(result); | |
763 break; | |
764 } | |
765 case TEMPORARY: | |
766 case DYNAMIC: | |
767 case DYNAMIC_GLOBAL: | |
768 case DYNAMIC_LOCAL: | |
769 UNREACHABLE(); | |
770 } | |
771 } | |
772 | |
773 if (JSObject::PreventExtensions(module, Object::THROW_ON_ERROR) | |
774 .IsNothing()) { | |
775 DCHECK(false); | |
776 } | |
777 } | |
778 | |
779 DCHECK(!isolate->has_pending_exception()); | |
780 return isolate->heap()->undefined_value(); | |
781 } | |
782 | |
783 | |
784 RUNTIME_FUNCTION(Runtime_DeleteLookupSlot) { | 691 RUNTIME_FUNCTION(Runtime_DeleteLookupSlot) { |
785 HandleScope scope(isolate); | 692 HandleScope scope(isolate); |
786 DCHECK_EQ(1, args.length()); | 693 DCHECK_EQ(1, args.length()); |
787 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 694 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
788 | 695 |
789 int index; | 696 int index; |
790 PropertyAttributes attributes; | 697 PropertyAttributes attributes; |
791 BindingFlags flags; | 698 BindingFlags flags; |
792 Handle<Object> holder = isolate->context()->Lookup( | 699 Handle<Object> holder = isolate->context()->Lookup( |
793 name, FOLLOW_CHAINS, &index, &attributes, &flags); | 700 name, FOLLOW_CHAINS, &index, &attributes, &flags); |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
990 RUNTIME_FUNCTION(Runtime_StoreLookupSlot_Strict) { | 897 RUNTIME_FUNCTION(Runtime_StoreLookupSlot_Strict) { |
991 HandleScope scope(isolate); | 898 HandleScope scope(isolate); |
992 DCHECK_EQ(2, args.length()); | 899 DCHECK_EQ(2, args.length()); |
993 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 900 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
994 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); | 901 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
995 RETURN_RESULT_OR_FAILURE(isolate, StoreLookupSlot(name, value, STRICT)); | 902 RETURN_RESULT_OR_FAILURE(isolate, StoreLookupSlot(name, value, STRICT)); |
996 } | 903 } |
997 | 904 |
998 } // namespace internal | 905 } // namespace internal |
999 } // namespace v8 | 906 } // namespace v8 |
OLD | NEW |