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 1199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1210 arg2); \ | 1210 arg2); \ |
1211 } | 1211 } |
1212 DEFINE_ERROR(Error, error) | 1212 DEFINE_ERROR(Error, error) |
1213 DEFINE_ERROR(EvalError, eval_error) | 1213 DEFINE_ERROR(EvalError, eval_error) |
1214 DEFINE_ERROR(RangeError, range_error) | 1214 DEFINE_ERROR(RangeError, range_error) |
1215 DEFINE_ERROR(ReferenceError, reference_error) | 1215 DEFINE_ERROR(ReferenceError, reference_error) |
1216 DEFINE_ERROR(SyntaxError, syntax_error) | 1216 DEFINE_ERROR(SyntaxError, syntax_error) |
1217 DEFINE_ERROR(TypeError, type_error) | 1217 DEFINE_ERROR(TypeError, type_error) |
1218 #undef DEFINE_ERROR | 1218 #undef DEFINE_ERROR |
1219 | 1219 |
1220 | |
1221 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, | 1220 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, |
1222 Handle<SharedFunctionInfo> info, | 1221 Handle<SharedFunctionInfo> info, |
1223 Handle<Context> context, | 1222 Handle<Object> context_or_undefined, |
1224 PretenureFlag pretenure) { | 1223 PretenureFlag pretenure) { |
1225 AllocationSpace space = pretenure == TENURED ? OLD_SPACE : NEW_SPACE; | 1224 AllocationSpace space = pretenure == TENURED ? OLD_SPACE : NEW_SPACE; |
1226 Handle<JSFunction> function = New<JSFunction>(map, space); | 1225 Handle<JSFunction> function = New<JSFunction>(map, space); |
| 1226 DCHECK(context_or_undefined->IsContext() || |
| 1227 context_or_undefined->IsUndefined(isolate())); |
1227 | 1228 |
1228 function->initialize_properties(); | 1229 function->initialize_properties(); |
1229 function->initialize_elements(); | 1230 function->initialize_elements(); |
1230 function->set_shared(*info); | 1231 function->set_shared(*info); |
1231 function->set_code(info->code()); | 1232 function->set_code(info->code()); |
1232 function->set_context(*context); | 1233 function->set_context(*context_or_undefined); |
1233 function->set_prototype_or_initial_map(*the_hole_value()); | 1234 function->set_prototype_or_initial_map(*the_hole_value()); |
1234 function->set_literals(LiteralsArray::cast(*empty_literals_array())); | 1235 function->set_literals(LiteralsArray::cast(*empty_literals_array())); |
1235 function->set_next_function_link(*undefined_value(), SKIP_WRITE_BARRIER); | 1236 function->set_next_function_link(*undefined_value(), SKIP_WRITE_BARRIER); |
1236 isolate()->heap()->InitializeJSObjectBody(*function, *map, JSFunction::kSize); | 1237 isolate()->heap()->InitializeJSObjectBody(*function, *map, JSFunction::kSize); |
1237 return function; | 1238 return function; |
1238 } | 1239 } |
1239 | 1240 |
1240 | 1241 |
1241 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, | 1242 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, |
1242 Handle<String> name, | 1243 Handle<String> name, |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1355 Handle<Context> context, | 1356 Handle<Context> context, |
1356 PretenureFlag pretenure) { | 1357 PretenureFlag pretenure) { |
1357 int map_index = | 1358 int map_index = |
1358 Context::FunctionMapIndex(info->language_mode(), info->kind()); | 1359 Context::FunctionMapIndex(info->language_mode(), info->kind()); |
1359 Handle<Map> initial_map(Map::cast(context->native_context()->get(map_index))); | 1360 Handle<Map> initial_map(Map::cast(context->native_context()->get(map_index))); |
1360 | 1361 |
1361 return NewFunctionFromSharedFunctionInfo(initial_map, info, context, | 1362 return NewFunctionFromSharedFunctionInfo(initial_map, info, context, |
1362 pretenure); | 1363 pretenure); |
1363 } | 1364 } |
1364 | 1365 |
1365 | |
1366 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( | 1366 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( |
1367 Handle<Map> initial_map, Handle<SharedFunctionInfo> info, | 1367 Handle<Map> initial_map, Handle<SharedFunctionInfo> info, |
1368 Handle<Context> context, PretenureFlag pretenure) { | 1368 Handle<Object> context_or_undefined, PretenureFlag pretenure) { |
1369 DCHECK_EQ(JS_FUNCTION_TYPE, initial_map->instance_type()); | 1369 DCHECK_EQ(JS_FUNCTION_TYPE, initial_map->instance_type()); |
1370 Handle<JSFunction> result = | 1370 Handle<JSFunction> result = |
1371 NewFunction(initial_map, info, context, pretenure); | 1371 NewFunction(initial_map, info, context_or_undefined, pretenure); |
1372 | 1372 |
1373 if (info->ic_age() != isolate()->heap()->global_ic_age()) { | 1373 if (info->ic_age() != isolate()->heap()->global_ic_age()) { |
1374 info->ResetForNewContext(isolate()->heap()->global_ic_age()); | 1374 info->ResetForNewContext(isolate()->heap()->global_ic_age()); |
1375 } | 1375 } |
1376 | 1376 |
1377 // Give compiler a chance to pre-initialize. | 1377 if (context_or_undefined->IsContext()) { |
1378 Compiler::PostInstantiation(result, pretenure); | 1378 // Give compiler a chance to pre-initialize. |
| 1379 Compiler::PostInstantiation(result, pretenure); |
| 1380 } |
1379 | 1381 |
1380 return result; | 1382 return result; |
1381 } | 1383 } |
1382 | 1384 |
1383 | 1385 |
1384 Handle<ScopeInfo> Factory::NewScopeInfo(int length) { | 1386 Handle<ScopeInfo> Factory::NewScopeInfo(int length) { |
1385 Handle<FixedArray> array = NewFixedArray(length, TENURED); | 1387 Handle<FixedArray> array = NewFixedArray(length, TENURED); |
1386 array->set_map_no_write_barrier(*scope_info_map()); | 1388 array->set_map_no_write_barrier(*scope_info_map()); |
1387 Handle<ScopeInfo> scope_info = Handle<ScopeInfo>::cast(array); | 1389 Handle<ScopeInfo> scope_info = Handle<ScopeInfo>::cast(array); |
1388 return scope_info; | 1390 return scope_info; |
(...skipping 988 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2377 } | 2379 } |
2378 | 2380 |
2379 | 2381 |
2380 Handle<Object> Factory::ToBoolean(bool value) { | 2382 Handle<Object> Factory::ToBoolean(bool value) { |
2381 return value ? true_value() : false_value(); | 2383 return value ? true_value() : false_value(); |
2382 } | 2384 } |
2383 | 2385 |
2384 | 2386 |
2385 } // namespace internal | 2387 } // namespace internal |
2386 } // namespace v8 | 2388 } // namespace v8 |
OLD | NEW |