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 "conversions.h" | 7 #include "conversions.h" |
8 #include "isolate-inl.h" | 8 #include "isolate-inl.h" |
9 #include "macro-assembler.h" | 9 #include "macro-assembler.h" |
10 | 10 |
(...skipping 1215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1226 | 1226 |
1227 Handle<JSFunction> Factory::NewFunction(Handle<String> name) { | 1227 Handle<JSFunction> Factory::NewFunction(Handle<String> name) { |
1228 return NewFunction(name, the_hole_value(), MaybeHandle<Code>()); | 1228 return NewFunction(name, the_hole_value(), MaybeHandle<Code>()); |
1229 } | 1229 } |
1230 | 1230 |
1231 | 1231 |
1232 Handle<JSFunction> Factory::NewFunction(MaybeHandle<Object> maybe_prototype, | 1232 Handle<JSFunction> Factory::NewFunction(MaybeHandle<Object> maybe_prototype, |
1233 Handle<String> name, | 1233 Handle<String> name, |
1234 InstanceType type, | 1234 InstanceType type, |
1235 int instance_size, | 1235 int instance_size, |
1236 Handle<Code> code, | 1236 Handle<Code> code) { |
1237 bool force_initial_map) { | |
1238 // Allocate the function | 1237 // Allocate the function |
1239 Handle<JSFunction> function = NewFunction(name, maybe_prototype, code); | 1238 Handle<JSFunction> function = NewFunction(name, maybe_prototype, code); |
1240 | 1239 |
1241 if (force_initial_map || | 1240 if (!maybe_prototype.is_null() || |
1242 type != JS_OBJECT_TYPE || | 1241 type != JS_OBJECT_TYPE || |
1243 instance_size != JSObject::kHeaderSize) { | 1242 instance_size != JSObject::kHeaderSize) { |
1244 Handle<Object> prototype = maybe_prototype.ToHandleChecked(); | 1243 Handle<Object> prototype = maybe_prototype.ToHandleChecked(); |
1245 Handle<Map> initial_map = NewMap( | 1244 Handle<Map> initial_map = NewMap( |
1246 type, instance_size, GetInitialFastElementsKind()); | 1245 type, instance_size, GetInitialFastElementsKind()); |
1247 if (prototype->IsTheHole() && !function->shared()->is_generator()) { | 1246 if (prototype->IsTheHole() && !function->shared()->is_generator()) { |
1248 prototype = NewFunctionPrototype(function); | 1247 prototype = NewFunctionPrototype(function); |
1249 } | 1248 } |
1250 initial_map->set_prototype(*prototype); | 1249 initial_map->set_prototype(*prototype); |
1251 function->set_initial_map(*initial_map); | 1250 function->set_initial_map(*initial_map); |
1252 initial_map->set_constructor(*function); | 1251 initial_map->set_constructor(*function); |
1253 } else { | 1252 } else { |
1254 ASSERT(!function->has_initial_map()); | 1253 ASSERT(!function->has_initial_map()); |
1255 ASSERT(!function->has_prototype()); | 1254 ASSERT(!function->has_prototype()); |
1256 } | 1255 } |
1257 | 1256 |
1258 return function; | 1257 return function; |
1259 } | 1258 } |
1260 | 1259 |
1261 | 1260 |
1262 Handle<JSFunction> Factory::NewFunction(Handle<String> name, | 1261 Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
1263 InstanceType type, | 1262 InstanceType type, |
1264 int instance_size, | 1263 int instance_size, |
1265 Handle<Code> code, | 1264 Handle<Code> code) { |
1266 bool force_initial_map) { | 1265 return NewFunction(the_hole_value(), name, type, instance_size, code); |
1267 return NewFunction( | |
1268 the_hole_value(), name, type, instance_size, code, force_initial_map); | |
1269 } | 1266 } |
1270 | 1267 |
1271 | 1268 |
1272 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { | 1269 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { |
1273 // Make sure to use globals from the function's context, since the function | 1270 // Make sure to use globals from the function's context, since the function |
1274 // can be from a different context. | 1271 // can be from a different context. |
1275 Handle<Context> native_context(function->context()->native_context()); | 1272 Handle<Context> native_context(function->context()->native_context()); |
1276 Handle<Map> new_map; | 1273 Handle<Map> new_map; |
1277 if (function->shared()->is_generator()) { | 1274 if (function->shared()->is_generator()) { |
1278 // Generator prototypes can share maps since they don't have "constructor" | 1275 // Generator prototypes can share maps since they don't have "constructor" |
(...skipping 813 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2092 default: | 2089 default: |
2093 UNREACHABLE(); | 2090 UNREACHABLE(); |
2094 type = JS_OBJECT_TYPE; // Keep the compiler happy. | 2091 type = JS_OBJECT_TYPE; // Keep the compiler happy. |
2095 break; | 2092 break; |
2096 } | 2093 } |
2097 | 2094 |
2098 MaybeHandle<Object> maybe_prototype = prototype; | 2095 MaybeHandle<Object> maybe_prototype = prototype; |
2099 if (obj->remove_prototype()) maybe_prototype = MaybeHandle<Object>(); | 2096 if (obj->remove_prototype()) maybe_prototype = MaybeHandle<Object>(); |
2100 | 2097 |
2101 Handle<JSFunction> result = NewFunction( | 2098 Handle<JSFunction> result = NewFunction( |
2102 maybe_prototype, Factory::empty_string(), type, | 2099 maybe_prototype, Factory::empty_string(), type, instance_size, code); |
2103 instance_size, code, !obj->remove_prototype()); | |
2104 | 2100 |
2105 result->shared()->set_length(obj->length()); | 2101 result->shared()->set_length(obj->length()); |
2106 Handle<Object> class_name(obj->class_name(), isolate()); | 2102 Handle<Object> class_name(obj->class_name(), isolate()); |
2107 if (class_name->IsString()) { | 2103 if (class_name->IsString()) { |
2108 result->shared()->set_instance_class_name(*class_name); | 2104 result->shared()->set_instance_class_name(*class_name); |
2109 result->shared()->set_name(*class_name); | 2105 result->shared()->set_name(*class_name); |
2110 } | 2106 } |
2111 result->shared()->set_function_data(*obj); | 2107 result->shared()->set_function_data(*obj); |
2112 result->shared()->set_construct_stub(*construct_stub); | 2108 result->shared()->set_construct_stub(*construct_stub); |
2113 result->shared()->DontAdaptArguments(); | 2109 result->shared()->DontAdaptArguments(); |
(...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2320 return Handle<Object>::null(); | 2316 return Handle<Object>::null(); |
2321 } | 2317 } |
2322 | 2318 |
2323 | 2319 |
2324 Handle<Object> Factory::ToBoolean(bool value) { | 2320 Handle<Object> Factory::ToBoolean(bool value) { |
2325 return value ? true_value() : false_value(); | 2321 return value ? true_value() : false_value(); |
2326 } | 2322 } |
2327 | 2323 |
2328 | 2324 |
2329 } } // namespace v8::internal | 2325 } } // namespace v8::internal |
OLD | NEW |