OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/builtins/builtins-constructor.h" | 5 #include "src/builtins/builtins-constructor.h" |
6 #include "src/builtins/builtins-utils.h" | 6 #include "src/builtins/builtins-utils.h" |
7 #include "src/builtins/builtins.h" | 7 #include "src/builtins/builtins.h" |
8 #include "src/code-factory.h" | 8 #include "src/code-factory.h" |
9 #include "src/code-stub-assembler.h" | 9 #include "src/code-stub-assembler.h" |
10 #include "src/interface-descriptors.h" | 10 #include "src/interface-descriptors.h" |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 | 147 |
148 return result; | 148 return result; |
149 } | 149 } |
150 | 150 |
151 TF_BUILTIN(FastNewClosure, ConstructorBuiltinsAssembler) { | 151 TF_BUILTIN(FastNewClosure, ConstructorBuiltinsAssembler) { |
152 Node* shared = Parameter(FastNewClosureDescriptor::kSharedFunctionInfo); | 152 Node* shared = Parameter(FastNewClosureDescriptor::kSharedFunctionInfo); |
153 Node* context = Parameter(FastNewClosureDescriptor::kContext); | 153 Node* context = Parameter(FastNewClosureDescriptor::kContext); |
154 Return(EmitFastNewClosure(shared, context)); | 154 Return(EmitFastNewClosure(shared, context)); |
155 } | 155 } |
156 | 156 |
| 157 Node* ConstructorBuiltinsAssembler::EmitFastNewFunctionContext( |
| 158 Node* function, Node* slots, Node* context, ScopeType scope_type) { |
| 159 slots = ChangeUint32ToWord(slots); |
| 160 |
| 161 // TODO(ishell): Use CSA::OptimalParameterMode() here. |
| 162 CodeStubAssembler::ParameterMode mode = CodeStubAssembler::INTPTR_PARAMETERS; |
| 163 Node* min_context_slots = IntPtrConstant(Context::MIN_CONTEXT_SLOTS); |
| 164 Node* length = IntPtrAdd(slots, min_context_slots); |
| 165 Node* size = GetFixedArrayAllocationSize(length, FAST_ELEMENTS, mode); |
| 166 |
| 167 // Create a new closure from the given function info in new space |
| 168 Node* function_context = Allocate(size); |
| 169 |
| 170 Heap::RootListIndex context_type; |
| 171 switch (scope_type) { |
| 172 case EVAL_SCOPE: |
| 173 context_type = Heap::kEvalContextMapRootIndex; |
| 174 break; |
| 175 case FUNCTION_SCOPE: |
| 176 context_type = Heap::kFunctionContextMapRootIndex; |
| 177 break; |
| 178 default: |
| 179 UNREACHABLE(); |
| 180 } |
| 181 StoreMapNoWriteBarrier(function_context, context_type); |
| 182 StoreObjectFieldNoWriteBarrier(function_context, Context::kLengthOffset, |
| 183 SmiTag(length)); |
| 184 |
| 185 // Set up the fixed slots. |
| 186 StoreFixedArrayElement(function_context, Context::CLOSURE_INDEX, function, |
| 187 SKIP_WRITE_BARRIER); |
| 188 StoreFixedArrayElement(function_context, Context::PREVIOUS_INDEX, context, |
| 189 SKIP_WRITE_BARRIER); |
| 190 StoreFixedArrayElement(function_context, Context::EXTENSION_INDEX, |
| 191 TheHoleConstant(), SKIP_WRITE_BARRIER); |
| 192 |
| 193 // Copy the native context from the previous context. |
| 194 Node* native_context = LoadNativeContext(context); |
| 195 StoreFixedArrayElement(function_context, Context::NATIVE_CONTEXT_INDEX, |
| 196 native_context, SKIP_WRITE_BARRIER); |
| 197 |
| 198 // Initialize the rest of the slots to undefined. |
| 199 Node* undefined = UndefinedConstant(); |
| 200 BuildFastFixedArrayForEach( |
| 201 function_context, FAST_ELEMENTS, min_context_slots, length, |
| 202 [this, undefined](Node* context, Node* offset) { |
| 203 StoreNoWriteBarrier(MachineRepresentation::kTagged, context, offset, |
| 204 undefined); |
| 205 }, |
| 206 mode); |
| 207 |
| 208 return function_context; |
| 209 } |
| 210 |
| 211 // static |
| 212 int ConstructorBuiltinsAssembler::MaximumFunctionContextSlots() { |
| 213 return FLAG_test_small_max_function_context_stub_size ? kSmallMaximumSlots |
| 214 : kMaximumSlots; |
| 215 } |
| 216 |
| 217 TF_BUILTIN(FastNewFunctionContext_Eval, ConstructorBuiltinsAssembler) { |
| 218 Node* function = Parameter(FastNewFunctionContextDescriptor::kFunction); |
| 219 Node* slots = Parameter(FastNewFunctionContextDescriptor::kSlots); |
| 220 Node* context = Parameter(FastNewFunctionContextDescriptor::kContext); |
| 221 Return(EmitFastNewFunctionContext(function, slots, context, |
| 222 ScopeType::EVAL_SCOPE)); |
| 223 } |
| 224 |
| 225 TF_BUILTIN(FastNewFunctionContext_Function, ConstructorBuiltinsAssembler) { |
| 226 Node* function = Parameter(FastNewFunctionContextDescriptor::kFunction); |
| 227 Node* slots = Parameter(FastNewFunctionContextDescriptor::kSlots); |
| 228 Node* context = Parameter(FastNewFunctionContextDescriptor::kContext); |
| 229 Return(EmitFastNewFunctionContext(function, slots, context, |
| 230 ScopeType::FUNCTION_SCOPE)); |
| 231 } |
| 232 |
| 233 Handle<Code> Builtins::NewFunctionContext(ScopeType scope_type) { |
| 234 switch (scope_type) { |
| 235 case ScopeType::EVAL_SCOPE: |
| 236 return FastNewFunctionContext_Eval(); |
| 237 case ScopeType::FUNCTION_SCOPE: |
| 238 return FastNewFunctionContext_Function(); |
| 239 default: |
| 240 UNREACHABLE(); |
| 241 } |
| 242 return Handle<Code>::null(); |
| 243 } |
| 244 |
157 } // namespace internal | 245 } // namespace internal |
158 } // namespace v8 | 246 } // namespace v8 |
OLD | NEW |