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 "factory.h" | 5 #include "factory.h" |
6 | 6 |
7 #include "macro-assembler.h" | 7 #include "macro-assembler.h" |
8 #include "isolate-inl.h" | 8 #include "isolate-inl.h" |
9 #include "v8conversions.h" | 9 #include "v8conversions.h" |
10 | 10 |
(...skipping 1233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1244 return result; | 1244 return result; |
1245 } | 1245 } |
1246 | 1246 |
1247 | 1247 |
1248 Handle<JSFunction> Factory::NewFunction(Handle<String> name, | 1248 Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
1249 InstanceType type, | 1249 InstanceType type, |
1250 int instance_size, | 1250 int instance_size, |
1251 Handle<Code> code, | 1251 Handle<Code> code, |
1252 bool force_initial_map) { | 1252 bool force_initial_map) { |
1253 // Allocate the function | 1253 // Allocate the function |
1254 Handle<JSFunction> function = NewFunction(name, the_hole_value()); | 1254 Handle<JSFunction> function = NewFunction(name, code, the_hole_value()); |
1255 | |
1256 // Set up the code pointer in both the shared function info and in | |
1257 // the function itself. | |
1258 function->shared()->set_code(*code); | |
1259 function->set_code(*code); | |
1260 | 1255 |
1261 if (force_initial_map || | 1256 if (force_initial_map || |
1262 type != JS_OBJECT_TYPE || | 1257 type != JS_OBJECT_TYPE || |
1263 instance_size != JSObject::kHeaderSize) { | 1258 instance_size != JSObject::kHeaderSize) { |
1264 Handle<Map> initial_map = NewMap(type, instance_size); | 1259 Handle<Map> initial_map = NewMap(type, instance_size); |
1265 Handle<JSObject> prototype = NewFunctionPrototype(function); | 1260 Handle<JSObject> prototype = NewFunctionPrototype(function); |
1266 initial_map->set_prototype(*prototype); | 1261 initial_map->set_prototype(*prototype); |
1267 function->set_initial_map(*initial_map); | 1262 function->set_initial_map(*initial_map); |
1268 initial_map->set_constructor(*function); | 1263 initial_map->set_constructor(*function); |
1269 } else { | 1264 } else { |
1270 ASSERT(!function->has_initial_map()); | 1265 ASSERT(!function->has_initial_map()); |
1271 ASSERT(!function->has_prototype()); | 1266 ASSERT(!function->has_prototype()); |
1272 } | 1267 } |
1273 | 1268 |
1274 return function; | 1269 return function; |
1275 } | 1270 } |
1276 | 1271 |
1277 | 1272 |
1278 Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name, | 1273 Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name, |
1279 InstanceType type, | 1274 InstanceType type, |
1280 int instance_size, | 1275 int instance_size, |
1281 Handle<JSObject> prototype, | 1276 Handle<JSObject> prototype, |
1282 Handle<Code> code, | 1277 Handle<Code> code, |
1283 bool force_initial_map) { | 1278 bool force_initial_map) { |
1284 // Allocate the function. | 1279 // Allocate the function. |
1285 Handle<JSFunction> function = NewFunction(name, prototype); | 1280 Handle<JSFunction> function = NewFunction(name, code, prototype); |
1286 | |
1287 // Set up the code pointer in both the shared function info and in | |
1288 // the function itself. | |
1289 function->shared()->set_code(*code); | |
1290 function->set_code(*code); | |
1291 | 1281 |
1292 if (force_initial_map || | 1282 if (force_initial_map || |
1293 type != JS_OBJECT_TYPE || | 1283 type != JS_OBJECT_TYPE || |
1294 instance_size != JSObject::kHeaderSize) { | 1284 instance_size != JSObject::kHeaderSize) { |
1295 Handle<Map> initial_map = NewMap(type, | 1285 Handle<Map> initial_map = NewMap(type, |
1296 instance_size, | 1286 instance_size, |
1297 GetInitialFastElementsKind()); | 1287 GetInitialFastElementsKind()); |
1298 function->set_initial_map(*initial_map); | 1288 function->set_initial_map(*initial_map); |
1299 initial_map->set_constructor(*function); | 1289 initial_map->set_constructor(*function); |
1300 } | 1290 } |
(...skipping 699 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2000 PretenureFlag pretenure) { | 1990 PretenureFlag pretenure) { |
2001 Handle<Map> map = MapForNewFunction(isolate(), info, maybe_prototype); | 1991 Handle<Map> map = MapForNewFunction(isolate(), info, maybe_prototype); |
2002 AllocationSpace space = pretenure == TENURED ? OLD_POINTER_SPACE : NEW_SPACE; | 1992 AllocationSpace space = pretenure == TENURED ? OLD_POINTER_SPACE : NEW_SPACE; |
2003 Handle<JSFunction> result = New<JSFunction>(map, space); | 1993 Handle<JSFunction> result = New<JSFunction>(map, space); |
2004 InitializeFunction(result, info, context, maybe_prototype); | 1994 InitializeFunction(result, info, context, maybe_prototype); |
2005 return result; | 1995 return result; |
2006 } | 1996 } |
2007 | 1997 |
2008 | 1998 |
2009 Handle<JSFunction> Factory::NewFunction(Handle<String> name, | 1999 Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
2010 Handle<Object> prototype) { | 2000 Handle<Code> code, |
| 2001 MaybeHandle<Object> maybe_prototype) { |
| 2002 Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name); |
| 2003 info->set_code(*code); |
| 2004 Handle<Context> context(isolate()->context()->native_context()); |
| 2005 return NewFunction(info, context, maybe_prototype); |
| 2006 } |
| 2007 |
| 2008 |
| 2009 Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name, |
| 2010 Handle<Object> prototype) { |
2011 Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name); | 2011 Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name); |
2012 Handle<Context> context(isolate()->context()->native_context()); | 2012 Handle<Context> context(isolate()->context()->native_context()); |
2013 return NewFunction(info, context, prototype); | 2013 return NewFunction(info, context, prototype); |
2014 } | 2014 } |
2015 | 2015 |
2016 | 2016 |
2017 Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name, | |
2018 Handle<Code> code) { | |
2019 Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name); | |
2020 info->set_code(*code); | |
2021 Handle<Context> context(isolate()->context()->native_context()); | |
2022 return NewFunction(info, context, MaybeHandle<Object>()); | |
2023 } | |
2024 | |
2025 | |
2026 #ifdef ENABLE_DEBUGGER_SUPPORT | 2017 #ifdef ENABLE_DEBUGGER_SUPPORT |
2027 Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) { | 2018 Handle<DebugInfo> Factory::NewDebugInfo(Handle<SharedFunctionInfo> shared) { |
2028 // Get the original code of the function. | 2019 // Get the original code of the function. |
2029 Handle<Code> code(shared->code()); | 2020 Handle<Code> code(shared->code()); |
2030 | 2021 |
2031 // Create a copy of the code before allocating the debug info object to avoid | 2022 // Create a copy of the code before allocating the debug info object to avoid |
2032 // allocation while setting up the debug info object. | 2023 // allocation while setting up the debug info object. |
2033 Handle<Code> original_code(*Factory::CopyCode(code)); | 2024 Handle<Code> original_code(*Factory::CopyCode(code)); |
2034 | 2025 |
2035 // Allocate initial fixed array for active break points before allocating the | 2026 // Allocate initial fixed array for active break points before allocating the |
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2317 if (String::Equals(name, infinity_string())) return infinity_value(); | 2308 if (String::Equals(name, infinity_string())) return infinity_value(); |
2318 return Handle<Object>::null(); | 2309 return Handle<Object>::null(); |
2319 } | 2310 } |
2320 | 2311 |
2321 | 2312 |
2322 Handle<Object> Factory::ToBoolean(bool value) { | 2313 Handle<Object> Factory::ToBoolean(bool value) { |
2323 return value ? true_value() : false_value(); | 2314 return value ? true_value() : false_value(); |
2324 } | 2315 } |
2325 | 2316 |
2326 } } // namespace v8::internal | 2317 } } // namespace v8::internal |
OLD | NEW |