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/accessors.h" |
7 #include "src/allocation-site-scopes.h" | 8 #include "src/allocation-site-scopes.h" |
8 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
9 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
10 #include "src/conversions.h" | 11 #include "src/conversions.h" |
11 #include "src/isolate-inl.h" | 12 #include "src/isolate-inl.h" |
12 #include "src/macro-assembler.h" | 13 #include "src/macro-assembler.h" |
13 | 14 |
14 namespace v8 { | 15 namespace v8 { |
15 namespace internal { | 16 namespace internal { |
16 | 17 |
(...skipping 2371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2388 return default_string(); | 2389 return default_string(); |
2389 case ToPrimitiveHint::kNumber: | 2390 case ToPrimitiveHint::kNumber: |
2390 return number_string(); | 2391 return number_string(); |
2391 case ToPrimitiveHint::kString: | 2392 case ToPrimitiveHint::kString: |
2392 return string_string(); | 2393 return string_string(); |
2393 } | 2394 } |
2394 UNREACHABLE(); | 2395 UNREACHABLE(); |
2395 return Handle<String>::null(); | 2396 return Handle<String>::null(); |
2396 } | 2397 } |
2397 | 2398 |
| 2399 Handle<Map> Factory::CreateSloppyFunctionMap(FunctionMode function_mode) { |
| 2400 Handle<Map> map = NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
| 2401 SetFunctionInstanceDescriptor(map, function_mode); |
| 2402 map->set_is_constructor(IsFunctionModeWithPrototype(function_mode)); |
| 2403 map->set_is_callable(); |
| 2404 return map; |
| 2405 } |
| 2406 |
| 2407 void Factory::SetFunctionInstanceDescriptor(Handle<Map> map, |
| 2408 FunctionMode function_mode) { |
| 2409 int size = IsFunctionModeWithPrototype(function_mode) ? 5 : 4; |
| 2410 Map::EnsureDescriptorSlack(map, size); |
| 2411 |
| 2412 PropertyAttributes ro_attribs = |
| 2413 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 2414 PropertyAttributes roc_attribs = |
| 2415 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
| 2416 |
| 2417 STATIC_ASSERT(JSFunction::kLengthDescriptorIndex == 0); |
| 2418 Handle<AccessorInfo> length = |
| 2419 Accessors::FunctionLengthInfo(isolate(), roc_attribs); |
| 2420 { // Add length. |
| 2421 AccessorConstantDescriptor d(Handle<Name>(Name::cast(length->name())), |
| 2422 length, roc_attribs); |
| 2423 map->AppendDescriptor(&d); |
| 2424 } |
| 2425 |
| 2426 STATIC_ASSERT(JSFunction::kNameDescriptorIndex == 1); |
| 2427 Handle<AccessorInfo> name = |
| 2428 Accessors::FunctionNameInfo(isolate(), ro_attribs); |
| 2429 { // Add name. |
| 2430 AccessorConstantDescriptor d(Handle<Name>(Name::cast(name->name())), name, |
| 2431 roc_attribs); |
| 2432 map->AppendDescriptor(&d); |
| 2433 } |
| 2434 Handle<AccessorInfo> args = |
| 2435 Accessors::FunctionArgumentsInfo(isolate(), ro_attribs); |
| 2436 { // Add arguments. |
| 2437 AccessorConstantDescriptor d(Handle<Name>(Name::cast(args->name())), args, |
| 2438 ro_attribs); |
| 2439 map->AppendDescriptor(&d); |
| 2440 } |
| 2441 Handle<AccessorInfo> caller = |
| 2442 Accessors::FunctionCallerInfo(isolate(), ro_attribs); |
| 2443 { // Add caller. |
| 2444 AccessorConstantDescriptor d(Handle<Name>(Name::cast(caller->name())), |
| 2445 caller, ro_attribs); |
| 2446 map->AppendDescriptor(&d); |
| 2447 } |
| 2448 if (IsFunctionModeWithPrototype(function_mode)) { |
| 2449 if (function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE) { |
| 2450 ro_attribs = static_cast<PropertyAttributes>(ro_attribs & ~READ_ONLY); |
| 2451 } |
| 2452 Handle<AccessorInfo> prototype = |
| 2453 Accessors::FunctionPrototypeInfo(isolate(), ro_attribs); |
| 2454 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), |
| 2455 prototype, ro_attribs); |
| 2456 map->AppendDescriptor(&d); |
| 2457 } |
| 2458 } |
| 2459 |
| 2460 Handle<Map> Factory::CreateStrictFunctionMap( |
| 2461 FunctionMode function_mode, Handle<JSFunction> empty_function) { |
| 2462 Handle<Map> map = NewMap(JS_FUNCTION_TYPE, JSFunction::kSize); |
| 2463 SetStrictFunctionInstanceDescriptor(map, function_mode); |
| 2464 map->set_is_constructor(IsFunctionModeWithPrototype(function_mode)); |
| 2465 map->set_is_callable(); |
| 2466 Map::SetPrototype(map, empty_function); |
| 2467 return map; |
| 2468 } |
| 2469 |
| 2470 void Factory::SetStrictFunctionInstanceDescriptor(Handle<Map> map, |
| 2471 FunctionMode function_mode) { |
| 2472 int size = IsFunctionModeWithPrototype(function_mode) ? 3 : 2; |
| 2473 Map::EnsureDescriptorSlack(map, size); |
| 2474 |
| 2475 PropertyAttributes rw_attribs = |
| 2476 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); |
| 2477 PropertyAttributes ro_attribs = |
| 2478 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 2479 PropertyAttributes roc_attribs = |
| 2480 static_cast<PropertyAttributes>(DONT_ENUM | READ_ONLY); |
| 2481 |
| 2482 DCHECK(function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE || |
| 2483 function_mode == FUNCTION_WITH_READONLY_PROTOTYPE || |
| 2484 function_mode == FUNCTION_WITHOUT_PROTOTYPE); |
| 2485 STATIC_ASSERT(JSFunction::kLengthDescriptorIndex == 0); |
| 2486 { // Add length. |
| 2487 Handle<AccessorInfo> length = |
| 2488 Accessors::FunctionLengthInfo(isolate(), roc_attribs); |
| 2489 AccessorConstantDescriptor d(handle(Name::cast(length->name())), length, |
| 2490 roc_attribs); |
| 2491 map->AppendDescriptor(&d); |
| 2492 } |
| 2493 |
| 2494 STATIC_ASSERT(JSFunction::kNameDescriptorIndex == 1); |
| 2495 { // Add name. |
| 2496 Handle<AccessorInfo> name = |
| 2497 Accessors::FunctionNameInfo(isolate(), roc_attribs); |
| 2498 AccessorConstantDescriptor d(handle(Name::cast(name->name())), name, |
| 2499 roc_attribs); |
| 2500 map->AppendDescriptor(&d); |
| 2501 } |
| 2502 if (IsFunctionModeWithPrototype(function_mode)) { |
| 2503 // Add prototype. |
| 2504 PropertyAttributes attribs = |
| 2505 function_mode == FUNCTION_WITH_WRITEABLE_PROTOTYPE ? rw_attribs |
| 2506 : ro_attribs; |
| 2507 Handle<AccessorInfo> prototype = |
| 2508 Accessors::FunctionPrototypeInfo(isolate(), attribs); |
| 2509 AccessorConstantDescriptor d(Handle<Name>(Name::cast(prototype->name())), |
| 2510 prototype, attribs); |
| 2511 map->AppendDescriptor(&d); |
| 2512 } |
| 2513 } |
| 2514 |
2398 } // namespace internal | 2515 } // namespace internal |
2399 } // namespace v8 | 2516 } // namespace v8 |
OLD | NEW |