| 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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 | 102 |
| 103 // Traverse the name/value pairs and set the properties. | 103 // Traverse the name/value pairs and set the properties. |
| 104 int length = pairs->length(); | 104 int length = pairs->length(); |
| 105 FOR_WITH_HANDLE_SCOPE(isolate, int, i = 0, i, i < length, i += 2, { | 105 FOR_WITH_HANDLE_SCOPE(isolate, int, i = 0, i, i < length, i += 2, { |
| 106 Handle<String> name(String::cast(pairs->get(i))); | 106 Handle<String> name(String::cast(pairs->get(i))); |
| 107 Handle<Object> initial_value(pairs->get(i + 1), isolate); | 107 Handle<Object> initial_value(pairs->get(i + 1), isolate); |
| 108 | 108 |
| 109 // We have to declare a global const property. To capture we only | 109 // We have to declare a global const property. To capture we only |
| 110 // assign to it when evaluating the assignment for "const x = | 110 // assign to it when evaluating the assignment for "const x = |
| 111 // <expr>" the initial value is the hole. | 111 // <expr>" the initial value is the hole. |
| 112 bool is_var = initial_value->IsUndefined(); | 112 bool is_var = initial_value->IsUndefined(isolate); |
| 113 bool is_const = initial_value->IsTheHole(); | 113 bool is_const = initial_value->IsTheHole(isolate); |
| 114 bool is_function = initial_value->IsSharedFunctionInfo(); | 114 bool is_function = initial_value->IsSharedFunctionInfo(); |
| 115 DCHECK_EQ(1, | 115 DCHECK_EQ(1, |
| 116 BoolToInt(is_var) + BoolToInt(is_const) + BoolToInt(is_function)); | 116 BoolToInt(is_var) + BoolToInt(is_const) + BoolToInt(is_function)); |
| 117 | 117 |
| 118 Handle<Object> value; | 118 Handle<Object> value; |
| 119 if (is_function) { | 119 if (is_function) { |
| 120 // Copy the function and update its context. Use it as value. | 120 // Copy the function and update its context. Use it as value. |
| 121 Handle<SharedFunctionInfo> shared = | 121 Handle<SharedFunctionInfo> shared = |
| 122 Handle<SharedFunctionInfo>::cast(initial_value); | 122 Handle<SharedFunctionInfo>::cast(initial_value); |
| 123 Handle<JSFunction> function = | 123 Handle<JSFunction> function = |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 213 PropertyAttributes attr) { | 213 PropertyAttributes attr) { |
| 214 // Declarations are always made in a function, eval or script context, or | 214 // Declarations are always made in a function, eval or script context, or |
| 215 // a declaration block scope. | 215 // a declaration block scope. |
| 216 // In the case of eval code, the context passed is the context of the caller, | 216 // In the case of eval code, the context passed is the context of the caller, |
| 217 // which may be some nested context and not the declaration context. | 217 // which may be some nested context and not the declaration context. |
| 218 Handle<Context> context_arg(isolate->context(), isolate); | 218 Handle<Context> context_arg(isolate->context(), isolate); |
| 219 Handle<Context> context(context_arg->declaration_context(), isolate); | 219 Handle<Context> context(context_arg->declaration_context(), isolate); |
| 220 | 220 |
| 221 // TODO(verwaest): Unify the encoding indicating "var" with DeclareGlobals. | 221 // TODO(verwaest): Unify the encoding indicating "var" with DeclareGlobals. |
| 222 bool is_var = *initial_value == NULL; | 222 bool is_var = *initial_value == NULL; |
| 223 bool is_const = initial_value->IsTheHole(); | 223 bool is_const = initial_value->IsTheHole(isolate); |
| 224 bool is_function = initial_value->IsJSFunction(); | 224 bool is_function = initial_value->IsJSFunction(); |
| 225 DCHECK_EQ(1, | 225 DCHECK_EQ(1, |
| 226 BoolToInt(is_var) + BoolToInt(is_const) + BoolToInt(is_function)); | 226 BoolToInt(is_var) + BoolToInt(is_const) + BoolToInt(is_function)); |
| 227 | 227 |
| 228 int index; | 228 int index; |
| 229 PropertyAttributes attributes; | 229 PropertyAttributes attributes; |
| 230 BindingFlags binding_flags; | 230 BindingFlags binding_flags; |
| 231 | 231 |
| 232 if ((attr & EVAL_DECLARED) != 0) { | 232 if ((attr & EVAL_DECLARED) != 0) { |
| 233 // Check for a conflict with a lexically scoped variable | 233 // Check for a conflict with a lexically scoped variable |
| (...skipping 534 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 768 CONVERT_ARG_HANDLE_CHECKED(FixedArray, descriptions, 0); | 768 CONVERT_ARG_HANDLE_CHECKED(FixedArray, descriptions, 0); |
| 769 Context* host_context = isolate->context(); | 769 Context* host_context = isolate->context(); |
| 770 | 770 |
| 771 for (int i = 0; i < descriptions->length(); ++i) { | 771 for (int i = 0; i < descriptions->length(); ++i) { |
| 772 Handle<ModuleInfo> description(ModuleInfo::cast(descriptions->get(i))); | 772 Handle<ModuleInfo> description(ModuleInfo::cast(descriptions->get(i))); |
| 773 int host_index = description->host_index(); | 773 int host_index = description->host_index(); |
| 774 Handle<Context> context(Context::cast(host_context->get(host_index))); | 774 Handle<Context> context(Context::cast(host_context->get(host_index))); |
| 775 Handle<JSModule> module(context->module()); | 775 Handle<JSModule> module(context->module()); |
| 776 | 776 |
| 777 for (int j = 0; j < description->length(); ++j) { | 777 for (int j = 0; j < description->length(); ++j) { |
| 778 Handle<String> name(description->name(j)); | 778 Handle<String> name(description->name(j), isolate); |
| 779 VariableMode mode = description->mode(j); | 779 VariableMode mode = description->mode(j); |
| 780 int index = description->index(j); | 780 int index = description->index(j); |
| 781 switch (mode) { | 781 switch (mode) { |
| 782 case VAR: | 782 case VAR: |
| 783 case LET: | 783 case LET: |
| 784 case CONST: | 784 case CONST: |
| 785 case CONST_LEGACY: { | 785 case CONST_LEGACY: { |
| 786 PropertyAttributes attr = | 786 PropertyAttributes attr = |
| 787 IsImmutableVariableMode(mode) ? FROZEN : SEALED; | 787 IsImmutableVariableMode(mode) ? FROZEN : SEALED; |
| 788 Handle<AccessorInfo> info = | 788 Handle<AccessorInfo> info = |
| 789 Accessors::MakeModuleExport(name, index, attr); | 789 Accessors::MakeModuleExport(name, index, attr); |
| 790 Handle<Object> result = | 790 Handle<Object> result = |
| 791 JSObject::SetAccessor(module, info).ToHandleChecked(); | 791 JSObject::SetAccessor(module, info).ToHandleChecked(); |
| 792 DCHECK(!result->IsUndefined()); | 792 DCHECK(!result->IsUndefined(isolate)); |
| 793 USE(result); | 793 USE(result); |
| 794 break; | 794 break; |
| 795 } | 795 } |
| 796 case TEMPORARY: | 796 case TEMPORARY: |
| 797 case DYNAMIC: | 797 case DYNAMIC: |
| 798 case DYNAMIC_GLOBAL: | 798 case DYNAMIC_GLOBAL: |
| 799 case DYNAMIC_LOCAL: | 799 case DYNAMIC_LOCAL: |
| 800 UNREACHABLE(); | 800 UNREACHABLE(); |
| 801 } | 801 } |
| 802 } | 802 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 861 | 861 |
| 862 if (index != Context::kNotFound) { | 862 if (index != Context::kNotFound) { |
| 863 DCHECK(holder->IsContext()); | 863 DCHECK(holder->IsContext()); |
| 864 // If the "property" we were looking for is a local variable, the | 864 // If the "property" we were looking for is a local variable, the |
| 865 // receiver is the global object; see ECMA-262, 3rd., 10.1.6 and 10.2.3. | 865 // receiver is the global object; see ECMA-262, 3rd., 10.1.6 and 10.2.3. |
| 866 Handle<Object> receiver = isolate->factory()->undefined_value(); | 866 Handle<Object> receiver = isolate->factory()->undefined_value(); |
| 867 Handle<Object> value = handle(Context::cast(*holder)->get(index), isolate); | 867 Handle<Object> value = handle(Context::cast(*holder)->get(index), isolate); |
| 868 // Check for uninitialized bindings. | 868 // Check for uninitialized bindings. |
| 869 switch (flags) { | 869 switch (flags) { |
| 870 case BINDING_CHECK_INITIALIZED: | 870 case BINDING_CHECK_INITIALIZED: |
| 871 if (value->IsTheHole()) { | 871 if (value->IsTheHole(isolate)) { |
| 872 THROW_NEW_ERROR(isolate, | 872 THROW_NEW_ERROR(isolate, |
| 873 NewReferenceError(MessageTemplate::kNotDefined, name), | 873 NewReferenceError(MessageTemplate::kNotDefined, name), |
| 874 Object); | 874 Object); |
| 875 } | 875 } |
| 876 // FALLTHROUGH | 876 // FALLTHROUGH |
| 877 case BINDING_IS_INITIALIZED: | 877 case BINDING_IS_INITIALIZED: |
| 878 DCHECK(!value->IsTheHole()); | 878 DCHECK(!value->IsTheHole(isolate)); |
| 879 if (receiver_return) *receiver_return = receiver; | 879 if (receiver_return) *receiver_return = receiver; |
| 880 return value; | 880 return value; |
| 881 case MISSING_BINDING: | 881 case MISSING_BINDING: |
| 882 break; | 882 break; |
| 883 } | 883 } |
| 884 UNREACHABLE(); | 884 UNREACHABLE(); |
| 885 } | 885 } |
| 886 | 886 |
| 887 // Otherwise, if the slot was found the holder is a context extension | 887 // Otherwise, if the slot was found the holder is a context extension |
| 888 // object, subject of a with, or a global object. We read the named | 888 // object, subject of a with, or a global object. We read the named |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 RUNTIME_FUNCTION(Runtime_StoreLookupSlot_Strict) { | 1021 RUNTIME_FUNCTION(Runtime_StoreLookupSlot_Strict) { |
| 1022 HandleScope scope(isolate); | 1022 HandleScope scope(isolate); |
| 1023 DCHECK_EQ(2, args.length()); | 1023 DCHECK_EQ(2, args.length()); |
| 1024 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 1024 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 1025 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); | 1025 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
| 1026 RETURN_RESULT_OR_FAILURE(isolate, StoreLookupSlot(name, value, STRICT)); | 1026 RETURN_RESULT_OR_FAILURE(isolate, StoreLookupSlot(name, value, STRICT)); |
| 1027 } | 1027 } |
| 1028 | 1028 |
| 1029 } // namespace internal | 1029 } // namespace internal |
| 1030 } // namespace v8 | 1030 } // namespace v8 |
| OLD | NEW |