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/conversions.h" | 10 #include "src/conversions.h" |
10 #include "src/isolate-inl.h" | 11 #include "src/isolate-inl.h" |
11 #include "src/macro-assembler.h" | 12 #include "src/macro-assembler.h" |
12 | 13 |
13 namespace v8 { | 14 namespace v8 { |
14 namespace internal { | 15 namespace internal { |
15 | 16 |
16 | 17 |
17 template<typename T> | 18 template<typename T> |
18 Handle<T> Factory::New(Handle<Map> map, AllocationSpace space) { | 19 Handle<T> Factory::New(Handle<Map> map, AllocationSpace space) { |
(...skipping 1254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1273 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, | 1274 Handle<JSFunction> Factory::NewFunction(Handle<Map> map, |
1274 Handle<String> name, | 1275 Handle<String> name, |
1275 MaybeHandle<Code> code) { | 1276 MaybeHandle<Code> code) { |
1276 Handle<Context> context(isolate()->native_context()); | 1277 Handle<Context> context(isolate()->native_context()); |
1277 Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name, code); | 1278 Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name, code); |
1278 DCHECK(is_sloppy(info->language_mode()) && | 1279 DCHECK(is_sloppy(info->language_mode()) && |
1279 (map.is_identical_to(isolate()->sloppy_function_map()) || | 1280 (map.is_identical_to(isolate()->sloppy_function_map()) || |
1280 map.is_identical_to( | 1281 map.is_identical_to( |
1281 isolate()->sloppy_function_without_prototype_map()) || | 1282 isolate()->sloppy_function_without_prototype_map()) || |
1282 map.is_identical_to( | 1283 map.is_identical_to( |
1283 isolate()->sloppy_function_with_readonly_prototype_map()))); | 1284 isolate()->sloppy_function_with_readonly_prototype_map()) || |
| 1285 map.is_identical_to(isolate()->strict_function_map()))); |
1284 return NewFunction(map, info, context); | 1286 return NewFunction(map, info, context); |
1285 } | 1287 } |
1286 | 1288 |
1287 | 1289 |
1288 Handle<JSFunction> Factory::NewFunction(Handle<String> name) { | 1290 Handle<JSFunction> Factory::NewFunction(Handle<String> name) { |
1289 return NewFunction( | 1291 return NewFunction( |
1290 isolate()->sloppy_function_map(), name, MaybeHandle<Code>()); | 1292 isolate()->sloppy_function_map(), name, MaybeHandle<Code>()); |
1291 } | 1293 } |
1292 | 1294 |
1293 | 1295 |
1294 Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name, | 1296 Handle<JSFunction> Factory::NewFunctionWithoutPrototype(Handle<String> name, |
1295 Handle<Code> code) { | 1297 Handle<Code> code, |
1296 return NewFunction( | 1298 bool is_strict) { |
1297 isolate()->sloppy_function_without_prototype_map(), name, code); | 1299 Handle<Map> map = is_strict |
| 1300 ? isolate()->strict_function_without_prototype_map() |
| 1301 : isolate()->sloppy_function_without_prototype_map(); |
| 1302 return NewFunction(map, name, code); |
1298 } | 1303 } |
1299 | 1304 |
1300 | 1305 |
1301 Handle<JSFunction> Factory::NewFunction(Handle<String> name, | 1306 Handle<JSFunction> Factory::NewFunction(Handle<String> name, Handle<Code> code, |
1302 Handle<Code> code, | |
1303 Handle<Object> prototype, | 1307 Handle<Object> prototype, |
1304 bool read_only_prototype) { | 1308 bool read_only_prototype, |
1305 Handle<Map> map = read_only_prototype | 1309 bool is_strict) { |
1306 ? isolate()->sloppy_function_with_readonly_prototype_map() | 1310 // In strict mode, readonly strict map is only available during bootstrap |
1307 : isolate()->sloppy_function_map(); | 1311 DCHECK(!is_strict || !read_only_prototype || |
| 1312 isolate()->bootstrapper()->IsActive()); |
| 1313 Handle<Map> map = |
| 1314 is_strict ? isolate()->strict_function_map() |
| 1315 : read_only_prototype |
| 1316 ? isolate()->sloppy_function_with_readonly_prototype_map() |
| 1317 : isolate()->sloppy_function_map(); |
1308 Handle<JSFunction> result = NewFunction(map, name, code); | 1318 Handle<JSFunction> result = NewFunction(map, name, code); |
1309 result->set_prototype_or_initial_map(*prototype); | 1319 result->set_prototype_or_initial_map(*prototype); |
1310 return result; | 1320 return result; |
1311 } | 1321 } |
1312 | 1322 |
1313 | 1323 |
1314 Handle<JSFunction> Factory::NewFunction(Handle<String> name, Handle<Code> code, | 1324 Handle<JSFunction> Factory::NewFunction(Handle<String> name, Handle<Code> code, |
1315 Handle<Object> prototype, | 1325 Handle<Object> prototype, |
1316 InstanceType type, int instance_size, | 1326 InstanceType type, int instance_size, |
1317 bool read_only_prototype, | 1327 bool read_only_prototype, |
1318 bool install_constructor) { | 1328 bool install_constructor, |
| 1329 bool is_strict) { |
1319 // Allocate the function | 1330 // Allocate the function |
1320 Handle<JSFunction> function = NewFunction( | 1331 Handle<JSFunction> function = |
1321 name, code, prototype, read_only_prototype); | 1332 NewFunction(name, code, prototype, read_only_prototype, is_strict); |
1322 | 1333 |
1323 ElementsKind elements_kind = | 1334 ElementsKind elements_kind = |
1324 type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS; | 1335 type == JS_ARRAY_TYPE ? FAST_SMI_ELEMENTS : FAST_HOLEY_SMI_ELEMENTS; |
1325 Handle<Map> initial_map = NewMap(type, instance_size, elements_kind); | 1336 Handle<Map> initial_map = NewMap(type, instance_size, elements_kind); |
1326 if (!function->shared()->is_generator()) { | 1337 if (!function->shared()->is_generator()) { |
1327 if (prototype->IsTheHole()) { | 1338 if (prototype->IsTheHole()) { |
1328 prototype = NewFunctionPrototype(function); | 1339 prototype = NewFunctionPrototype(function); |
1329 } else if (install_constructor) { | 1340 } else if (install_constructor) { |
1330 JSObject::AddProperty(Handle<JSObject>::cast(prototype), | 1341 JSObject::AddProperty(Handle<JSObject>::cast(prototype), |
1331 constructor_string(), function, DONT_ENUM); | 1342 constructor_string(), function, DONT_ENUM); |
(...skipping 1010 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2342 return Handle<Object>::null(); | 2353 return Handle<Object>::null(); |
2343 } | 2354 } |
2344 | 2355 |
2345 | 2356 |
2346 Handle<Object> Factory::ToBoolean(bool value) { | 2357 Handle<Object> Factory::ToBoolean(bool value) { |
2347 return value ? true_value() : false_value(); | 2358 return value ? true_value() : false_value(); |
2348 } | 2359 } |
2349 | 2360 |
2350 | 2361 |
2351 } } // namespace v8::internal | 2362 } } // namespace v8::internal |
OLD | NEW |