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