| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "src/accessors.h" | 9 #include "src/accessors.h" |
| 10 #include "src/arguments.h" | 10 #include "src/arguments.h" |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 int flags, Handle<TypeFeedbackVector> feedback_vector) { | 132 int flags, Handle<TypeFeedbackVector> feedback_vector) { |
| 133 HandleScope scope(isolate); | 133 HandleScope scope(isolate); |
| 134 Handle<JSGlobalObject> global(isolate->global_object()); | 134 Handle<JSGlobalObject> global(isolate->global_object()); |
| 135 Handle<Context> context(isolate->context()); | 135 Handle<Context> context(isolate->context()); |
| 136 | 136 |
| 137 // Traverse the name/value pairs and set the properties. | 137 // Traverse the name/value pairs and set the properties. |
| 138 int length = declarations->length(); | 138 int length = declarations->length(); |
| 139 FOR_WITH_HANDLE_SCOPE(isolate, int, i = 0, i, i < length, i += 4, { | 139 FOR_WITH_HANDLE_SCOPE(isolate, int, i = 0, i, i < length, i += 4, { |
| 140 Handle<String> name(String::cast(declarations->get(i)), isolate); | 140 Handle<String> name(String::cast(declarations->get(i)), isolate); |
| 141 FeedbackVectorSlot slot(Smi::cast(declarations->get(i + 1))->value()); | 141 FeedbackVectorSlot slot(Smi::cast(declarations->get(i + 1))->value()); |
| 142 Handle<Object> possibly_literal_slot(declarations->get(i + 2), isolate); |
| 142 Handle<Object> initial_value(declarations->get(i + 3), isolate); | 143 Handle<Object> initial_value(declarations->get(i + 3), isolate); |
| 143 | 144 |
| 144 bool is_var = initial_value->IsUndefined(isolate); | 145 bool is_var = initial_value->IsUndefined(isolate); |
| 145 bool is_function = initial_value->IsSharedFunctionInfo(); | 146 bool is_function = initial_value->IsSharedFunctionInfo(); |
| 146 DCHECK_EQ(1, BoolToInt(is_var) + BoolToInt(is_function)); | 147 DCHECK_EQ(1, BoolToInt(is_var) + BoolToInt(is_function)); |
| 147 | 148 |
| 148 Handle<Object> value; | 149 Handle<Object> value; |
| 149 if (is_function) { | 150 if (is_function) { |
| 151 DCHECK(possibly_literal_slot->IsSmi()); |
| 150 // Copy the function and update its context. Use it as value. | 152 // Copy the function and update its context. Use it as value. |
| 151 Handle<SharedFunctionInfo> shared = | 153 Handle<SharedFunctionInfo> shared = |
| 152 Handle<SharedFunctionInfo>::cast(initial_value); | 154 Handle<SharedFunctionInfo>::cast(initial_value); |
| 155 FeedbackVectorSlot literals_slot( |
| 156 Smi::cast(*possibly_literal_slot)->value()); |
| 157 Handle<Cell> literals(Cell::cast(feedback_vector->Get(literals_slot)), |
| 158 isolate); |
| 153 Handle<JSFunction> function = | 159 Handle<JSFunction> function = |
| 154 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, | 160 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 155 TENURED); | 161 shared, context, literals, TENURED); |
| 156 value = function; | 162 value = function; |
| 157 } else { | 163 } else { |
| 158 value = isolate->factory()->undefined_value(); | 164 value = isolate->factory()->undefined_value(); |
| 159 } | 165 } |
| 160 | 166 |
| 161 // Compute the property attributes. According to ECMA-262, | 167 // Compute the property attributes. According to ECMA-262, |
| 162 // the property must be non-configurable except in eval. | 168 // the property must be non-configurable except in eval. |
| 163 bool is_native = DeclareGlobalsNativeFlag::decode(flags); | 169 bool is_native = DeclareGlobalsNativeFlag::decode(flags); |
| 164 bool is_eval = DeclareGlobalsEvalFlag::decode(flags); | 170 bool is_eval = DeclareGlobalsEvalFlag::decode(flags); |
| 165 int attr = NONE; | 171 int attr = NONE; |
| (...skipping 439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 for (int index = 0; index < length; ++index) { | 611 for (int index = 0; index < length; ++index) { |
| 606 result->set(index, frame[offset - index], mode); | 612 result->set(index, frame[offset - index], mode); |
| 607 } | 613 } |
| 608 return *result; | 614 return *result; |
| 609 } | 615 } |
| 610 | 616 |
| 611 RUNTIME_FUNCTION(Runtime_NewClosure) { | 617 RUNTIME_FUNCTION(Runtime_NewClosure) { |
| 612 HandleScope scope(isolate); | 618 HandleScope scope(isolate); |
| 613 DCHECK_EQ(3, args.length()); | 619 DCHECK_EQ(3, args.length()); |
| 614 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); | 620 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); |
| 621 CONVERT_ARG_HANDLE_CHECKED(TypeFeedbackVector, vector, 1); |
| 622 CONVERT_SMI_ARG_CHECKED(index, 2); |
| 615 Handle<Context> context(isolate->context(), isolate); | 623 Handle<Context> context(isolate->context(), isolate); |
| 624 FeedbackVectorSlot slot = TypeFeedbackVector::ToSlot(index); |
| 625 Handle<Cell> literals(Cell::cast(vector->Get(slot)), isolate); |
| 616 Handle<JSFunction> function = | 626 Handle<JSFunction> function = |
| 617 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, | 627 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 618 NOT_TENURED); | 628 shared, context, literals, NOT_TENURED); |
| 619 return *function; | 629 return *function; |
| 620 } | 630 } |
| 621 | 631 |
| 622 | 632 |
| 623 RUNTIME_FUNCTION(Runtime_NewClosure_Tenured) { | 633 RUNTIME_FUNCTION(Runtime_NewClosure_Tenured) { |
| 624 HandleScope scope(isolate); | 634 HandleScope scope(isolate); |
| 625 DCHECK_EQ(3, args.length()); | 635 DCHECK_EQ(3, args.length()); |
| 626 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); | 636 CONVERT_ARG_HANDLE_CHECKED(SharedFunctionInfo, shared, 0); |
| 637 CONVERT_ARG_HANDLE_CHECKED(TypeFeedbackVector, vector, 1); |
| 638 CONVERT_SMI_ARG_CHECKED(index, 2); |
| 627 Handle<Context> context(isolate->context(), isolate); | 639 Handle<Context> context(isolate->context(), isolate); |
| 640 FeedbackVectorSlot slot = TypeFeedbackVector::ToSlot(index); |
| 641 Handle<Cell> literals(Cell::cast(vector->Get(slot)), isolate); |
| 628 // The caller ensures that we pretenure closures that are assigned | 642 // The caller ensures that we pretenure closures that are assigned |
| 629 // directly to properties. | 643 // directly to properties. |
| 630 Handle<JSFunction> function = | 644 Handle<JSFunction> function = |
| 631 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, | 645 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context, |
| 632 TENURED); | 646 literals, TENURED); |
| 633 return *function; | 647 return *function; |
| 634 } | 648 } |
| 635 | 649 |
| 636 static Object* FindNameClash(Handle<ScopeInfo> scope_info, | 650 static Object* FindNameClash(Handle<ScopeInfo> scope_info, |
| 637 Handle<JSGlobalObject> global_object, | 651 Handle<JSGlobalObject> global_object, |
| 638 Handle<ScriptContextTable> script_context) { | 652 Handle<ScriptContextTable> script_context) { |
| 639 Isolate* isolate = scope_info->GetIsolate(); | 653 Isolate* isolate = scope_info->GetIsolate(); |
| 640 for (int var = 0; var < scope_info->ContextLocalCount(); var++) { | 654 for (int var = 0; var < scope_info->ContextLocalCount(); var++) { |
| 641 Handle<String> name(scope_info->ContextLocalName(var)); | 655 Handle<String> name(scope_info->ContextLocalName(var)); |
| 642 VariableMode mode = scope_info->ContextLocalMode(var); | 656 VariableMode mode = scope_info->ContextLocalMode(var); |
| (...skipping 335 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 RUNTIME_FUNCTION(Runtime_StoreLookupSlot_Strict) { | 992 RUNTIME_FUNCTION(Runtime_StoreLookupSlot_Strict) { |
| 979 HandleScope scope(isolate); | 993 HandleScope scope(isolate); |
| 980 DCHECK_EQ(2, args.length()); | 994 DCHECK_EQ(2, args.length()); |
| 981 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); | 995 CONVERT_ARG_HANDLE_CHECKED(String, name, 0); |
| 982 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); | 996 CONVERT_ARG_HANDLE_CHECKED(Object, value, 1); |
| 983 RETURN_RESULT_OR_FAILURE(isolate, StoreLookupSlot(name, value, STRICT)); | 997 RETURN_RESULT_OR_FAILURE(isolate, StoreLookupSlot(name, value, STRICT)); |
| 984 } | 998 } |
| 985 | 999 |
| 986 } // namespace internal | 1000 } // namespace internal |
| 987 } // namespace v8 | 1001 } // namespace v8 |
| OLD | NEW |