| 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/factory.h" | 5 #include "src/factory.h" |
| 6 | 6 |
| 7 #include "src/allocation-site-scopes.h" | 7 #include "src/allocation-site-scopes.h" |
| 8 #include "src/base/bits.h" | 8 #include "src/base/bits.h" |
| 9 #include "src/bootstrapper.h" | 9 #include "src/bootstrapper.h" |
| 10 #include "src/conversions.h" | 10 #include "src/conversions.h" |
| (...skipping 1260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1271 bool is_strict) { | 1271 bool is_strict) { |
| 1272 Handle<Map> map = is_strict | 1272 Handle<Map> map = is_strict |
| 1273 ? isolate()->strict_function_without_prototype_map() | 1273 ? isolate()->strict_function_without_prototype_map() |
| 1274 : isolate()->sloppy_function_without_prototype_map(); | 1274 : isolate()->sloppy_function_without_prototype_map(); |
| 1275 return NewFunction(map, name, code); | 1275 return NewFunction(map, name, code); |
| 1276 } | 1276 } |
| 1277 | 1277 |
| 1278 | 1278 |
| 1279 Handle<JSFunction> Factory::NewFunction(Handle<String> name, Handle<Code> code, | 1279 Handle<JSFunction> Factory::NewFunction(Handle<String> name, Handle<Code> code, |
| 1280 Handle<Object> prototype, | 1280 Handle<Object> prototype, |
| 1281 bool is_strict) { | |
| 1282 Handle<Map> map = is_strict ? isolate()->strict_function_map() | |
| 1283 : isolate()->sloppy_function_map(); | |
| 1284 Handle<JSFunction> result = NewFunction(map, name, code); | |
| 1285 result->set_prototype_or_initial_map(*prototype); | |
| 1286 return result; | |
| 1287 } | |
| 1288 | |
| 1289 | |
| 1290 Handle<JSFunction> Factory::NewFunction(Handle<String> name, Handle<Code> code, | |
| 1291 Handle<Object> prototype, | |
| 1292 InstanceType type, int instance_size, | 1281 InstanceType type, int instance_size, |
| 1293 bool is_strict) { | 1282 bool is_strict) { |
| 1294 // Allocate the function | 1283 // Allocate the function |
| 1295 Handle<JSFunction> function = NewFunction(name, code, prototype, is_strict); | 1284 Handle<Map> map = is_strict ? isolate()->strict_function_map() |
| 1285 : isolate()->sloppy_function_map(); |
| 1286 Handle<JSFunction> function = NewFunction(map, name, code); |
| 1287 DCHECK(prototype->IsTheHole(isolate()) || prototype->IsNull(isolate()) || |
| 1288 prototype->IsJSReceiver()); |
| 1289 function->set_prototype_or_initial_map(*prototype); |
| 1296 | 1290 |
| 1291 // TODO(verwaest): Do we need to eagerly allocate the map here? |
| 1297 ElementsKind elements_kind = | 1292 ElementsKind elements_kind = |
| 1298 type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS; | 1293 type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS; |
| 1299 Handle<Map> initial_map = NewMap(type, instance_size, elements_kind); | 1294 Handle<Map> initial_map = NewMap(type, instance_size, elements_kind); |
| 1300 // TODO(littledan): Why do we have this is_generator test when | 1295 prototype = JSFunction::GetPrototype(isolate(), function); |
| 1301 // NewFunctionPrototype already handles finding an appropriately | |
| 1302 // shared prototype? | |
| 1303 if (!function->shared()->is_resumable()) { | |
| 1304 if (prototype->IsTheHole(isolate())) { | |
| 1305 prototype = NewFunctionPrototype(function); | |
| 1306 } | |
| 1307 } | |
| 1308 | |
| 1309 JSFunction::SetInitialMap(function, initial_map, | 1296 JSFunction::SetInitialMap(function, initial_map, |
| 1310 Handle<JSReceiver>::cast(prototype)); | 1297 Handle<JSReceiver>::cast(prototype)); |
| 1311 | 1298 |
| 1312 return function; | 1299 return function; |
| 1313 } | 1300 } |
| 1314 | 1301 |
| 1315 | 1302 |
| 1316 Handle<JSFunction> Factory::NewFunction(Handle<String> name, | 1303 Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
| 1317 Handle<Code> code, | 1304 Handle<Code> code, |
| 1318 InstanceType type, | 1305 InstanceType type, |
| (...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2379 } | 2366 } |
| 2380 | 2367 |
| 2381 | 2368 |
| 2382 Handle<Object> Factory::ToBoolean(bool value) { | 2369 Handle<Object> Factory::ToBoolean(bool value) { |
| 2383 return value ? true_value() : false_value(); | 2370 return value ? true_value() : false_value(); |
| 2384 } | 2371 } |
| 2385 | 2372 |
| 2386 | 2373 |
| 2387 } // namespace internal | 2374 } // namespace internal |
| 2388 } // namespace v8 | 2375 } // namespace v8 |
| OLD | NEW |