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 1228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1239 int instance_size, | 1239 int instance_size, |
1240 Handle<Code> code, | 1240 Handle<Code> code, |
1241 bool force_initial_map) { | 1241 bool force_initial_map) { |
1242 // Allocate the function | 1242 // Allocate the function |
1243 Handle<JSFunction> function = NewFunction(name, code, maybe_prototype); | 1243 Handle<JSFunction> function = NewFunction(name, code, maybe_prototype); |
1244 | 1244 |
1245 if (force_initial_map || | 1245 if (force_initial_map || |
1246 type != JS_OBJECT_TYPE || | 1246 type != JS_OBJECT_TYPE || |
1247 instance_size != JSObject::kHeaderSize) { | 1247 instance_size != JSObject::kHeaderSize) { |
1248 Handle<Object> prototype = maybe_prototype.ToHandleChecked(); | 1248 Handle<Object> prototype = maybe_prototype.ToHandleChecked(); |
1249 Handle<Map> initial_map = NewMap(type, instance_size); | 1249 Handle<Map> initial_map = NewMap( |
1250 if (prototype->IsJSObject()) { | 1250 type, instance_size, GetInitialFastElementsKind()); |
1251 JSObject::SetLocalPropertyIgnoreAttributes( | 1251 if (prototype->IsTheHole() && !function->shared()->is_generator()) { |
1252 Handle<JSObject>::cast(prototype), | |
1253 constructor_string(), | |
1254 function, | |
1255 DONT_ENUM).Assert(); | |
1256 } else if (!function->shared()->is_generator()) { | |
1257 prototype = NewFunctionPrototype(function); | 1252 prototype = NewFunctionPrototype(function); |
1258 } | 1253 } |
1259 initial_map->set_prototype(*prototype); | 1254 initial_map->set_prototype(*prototype); |
1260 function->set_initial_map(*initial_map); | 1255 function->set_initial_map(*initial_map); |
1261 initial_map->set_constructor(*function); | 1256 initial_map->set_constructor(*function); |
1262 } else { | 1257 } else { |
1263 ASSERT(!function->has_initial_map()); | 1258 ASSERT(!function->has_initial_map()); |
1264 ASSERT(!function->has_prototype()); | 1259 ASSERT(!function->has_prototype()); |
1265 } | 1260 } |
1266 | 1261 |
1267 return function; | 1262 return function; |
1268 } | 1263 } |
1269 | 1264 |
1270 | 1265 |
1271 Handle<JSFunction> Factory::NewFunction(Handle<String> name, | 1266 Handle<JSFunction> Factory::NewFunction(Handle<String> name, |
1272 InstanceType type, | 1267 InstanceType type, |
1273 int instance_size, | 1268 int instance_size, |
1274 Handle<Code> code, | 1269 Handle<Code> code, |
1275 bool force_initial_map) { | 1270 bool force_initial_map) { |
1276 return NewFunction( | 1271 return NewFunction( |
1277 the_hole_value(), name, type, instance_size, code, force_initial_map); | 1272 the_hole_value(), name, type, instance_size, code, force_initial_map); |
1278 } | 1273 } |
1279 | 1274 |
1280 | 1275 |
1281 Handle<JSFunction> Factory::NewFunctionWithPrototype(Handle<String> name, | |
1282 InstanceType type, | |
1283 int instance_size, | |
1284 Handle<JSObject> prototype, | |
1285 Handle<Code> code, | |
1286 bool force_initial_map) { | |
1287 // Allocate the function. | |
1288 Handle<JSFunction> function = NewFunction(name, code, prototype); | |
1289 | |
1290 if (force_initial_map || | |
1291 type != JS_OBJECT_TYPE || | |
1292 instance_size != JSObject::kHeaderSize) { | |
1293 Handle<Map> initial_map = NewMap(type, | |
1294 instance_size, | |
1295 GetInitialFastElementsKind()); | |
1296 function->set_initial_map(*initial_map); | |
1297 initial_map->set_constructor(*function); | |
1298 } | |
1299 | |
1300 JSFunction::SetPrototype(function, prototype); | |
1301 return function; | |
1302 } | |
1303 | |
1304 | |
1305 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { | 1276 Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) { |
1306 // Make sure to use globals from the function's context, since the function | 1277 // Make sure to use globals from the function's context, since the function |
1307 // can be from a different context. | 1278 // can be from a different context. |
1308 Handle<Context> native_context(function->context()->native_context()); | 1279 Handle<Context> native_context(function->context()->native_context()); |
1309 Handle<Map> new_map; | 1280 Handle<Map> new_map; |
1310 if (function->shared()->is_generator()) { | 1281 if (function->shared()->is_generator()) { |
1311 // Generator prototypes can share maps since they don't have "constructor" | 1282 // Generator prototypes can share maps since they don't have "constructor" |
1312 // properties. | 1283 // properties. |
1313 new_map = handle(native_context->generator_object_prototype_map()); | 1284 new_map = handle(native_context->generator_object_prototype_map()); |
1314 } else { | 1285 } else { |
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2144 result->shared()->set_function_data(*obj); | 2115 result->shared()->set_function_data(*obj); |
2145 result->shared()->set_construct_stub(*construct_stub); | 2116 result->shared()->set_construct_stub(*construct_stub); |
2146 result->shared()->DontAdaptArguments(); | 2117 result->shared()->DontAdaptArguments(); |
2147 | 2118 |
2148 if (obj->remove_prototype()) { | 2119 if (obj->remove_prototype()) { |
2149 ASSERT(result->shared()->IsApiFunction()); | 2120 ASSERT(result->shared()->IsApiFunction()); |
2150 ASSERT(!result->has_initial_map()); | 2121 ASSERT(!result->has_initial_map()); |
2151 ASSERT(!result->has_prototype()); | 2122 ASSERT(!result->has_prototype()); |
2152 return result; | 2123 return result; |
2153 } | 2124 } |
| 2125 |
| 2126 JSObject::SetLocalPropertyIgnoreAttributes( |
| 2127 handle(JSObject::cast(result->prototype())), |
| 2128 constructor_string(), |
| 2129 result, |
| 2130 DONT_ENUM).Assert(); |
| 2131 |
2154 // Down from here is only valid for API functions that can be used as a | 2132 // Down from here is only valid for API functions that can be used as a |
2155 // constructor (don't set the "remove prototype" flag). | 2133 // constructor (don't set the "remove prototype" flag). |
2156 | 2134 |
2157 Handle<Map> map(result->initial_map()); | 2135 Handle<Map> map(result->initial_map()); |
2158 | 2136 |
2159 // Mark as undetectable if needed. | 2137 // Mark as undetectable if needed. |
2160 if (obj->undetectable()) { | 2138 if (obj->undetectable()) { |
2161 map->set_is_undetectable(); | 2139 map->set_is_undetectable(); |
2162 } | 2140 } |
2163 | 2141 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2346 return Handle<Object>::null(); | 2324 return Handle<Object>::null(); |
2347 } | 2325 } |
2348 | 2326 |
2349 | 2327 |
2350 Handle<Object> Factory::ToBoolean(bool value) { | 2328 Handle<Object> Factory::ToBoolean(bool value) { |
2351 return value ? true_value() : false_value(); | 2329 return value ? true_value() : false_value(); |
2352 } | 2330 } |
2353 | 2331 |
2354 | 2332 |
2355 } } // namespace v8::internal | 2333 } } // namespace v8::internal |
OLD | NEW |