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/bootstrapper.h" | 5 #include "src/bootstrapper.h" |
6 | 6 |
7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
8 #include "src/api-natives.h" | 8 #include "src/api-natives.h" |
9 #include "src/base/ieee754.h" | 9 #include "src/base/ieee754.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
358 function->shared()->set_native(true); | 358 function->shared()->set_native(true); |
359 } | 359 } |
360 | 360 |
361 void InstallFunction(Handle<JSObject> target, Handle<JSFunction> function, | 361 void InstallFunction(Handle<JSObject> target, Handle<JSFunction> function, |
362 Handle<Name> name, | 362 Handle<Name> name, |
363 PropertyAttributes attributes = DONT_ENUM) { | 363 PropertyAttributes attributes = DONT_ENUM) { |
364 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); | 364 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); |
365 InstallFunction(target, name, function, name_string, attributes); | 365 InstallFunction(target, name, function, name_string, attributes); |
366 } | 366 } |
367 | 367 |
| 368 Handle<JSFunction> InstallGetter(Handle<JSObject> target, |
| 369 Handle<Name> property_name, |
| 370 Handle<JSFunction> getter, |
| 371 PropertyAttributes attributes = DONT_ENUM) { |
| 372 Handle<Object> setter = target->GetIsolate()->factory()->undefined_value(); |
| 373 JSObject::DefineAccessor(target, property_name, getter, setter, attributes) |
| 374 .Check(); |
| 375 getter->shared()->set_native(true); |
| 376 return getter; |
| 377 } |
| 378 |
368 Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, | 379 Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, |
369 InstanceType type, int instance_size, | 380 InstanceType type, int instance_size, |
370 MaybeHandle<JSObject> maybe_prototype, | 381 MaybeHandle<JSObject> maybe_prototype, |
371 Builtins::Name call, | 382 Builtins::Name call, |
372 bool strict_function_map = false) { | 383 bool strict_function_map = false) { |
373 Factory* factory = isolate->factory(); | 384 Factory* factory = isolate->factory(); |
374 Handle<Code> call_code(isolate->builtins()->builtin(call)); | 385 Handle<Code> call_code(isolate->builtins()->builtin(call)); |
375 Handle<JSObject> prototype; | 386 Handle<JSObject> prototype; |
376 return maybe_prototype.ToHandle(&prototype) | 387 return maybe_prototype.ToHandle(&prototype) |
377 ? factory->NewFunction(name, call_code, prototype, type, | 388 ? factory->NewFunction(name, call_code, prototype, type, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
443 | 454 |
444 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, | 455 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, |
445 const char* name, Builtins::Name call, | 456 const char* name, Builtins::Name call, |
446 int len, bool adapt, | 457 int len, bool adapt, |
447 BuiltinFunctionId id) { | 458 BuiltinFunctionId id) { |
448 Handle<JSFunction> fun = SimpleInstallFunction(base, name, call, len, adapt); | 459 Handle<JSFunction> fun = SimpleInstallFunction(base, name, call, len, adapt); |
449 fun->shared()->set_builtin_function_id(id); | 460 fun->shared()->set_builtin_function_id(id); |
450 return fun; | 461 return fun; |
451 } | 462 } |
452 | 463 |
453 void SimpleInstallGetterSetter(Handle<JSObject> base, Handle<String> name, | |
454 Builtins::Name call_getter, | |
455 Builtins::Name call_setter, | |
456 PropertyAttributes attribs) { | |
457 Isolate* const isolate = base->GetIsolate(); | |
458 | |
459 Handle<String> getter_name = | |
460 Name::ToFunctionName(name, isolate->factory()->get_string()) | |
461 .ToHandleChecked(); | |
462 Handle<JSFunction> getter = | |
463 SimpleCreateFunction(isolate, getter_name, call_getter, 0, false); | |
464 getter->shared()->set_native(true); | |
465 | |
466 Handle<String> setter_name = | |
467 Name::ToFunctionName(name, isolate->factory()->set_string()) | |
468 .ToHandleChecked(); | |
469 Handle<JSFunction> setter = | |
470 SimpleCreateFunction(isolate, setter_name, call_setter, 0, false); | |
471 setter->shared()->set_native(true); | |
472 | |
473 JSObject::DefineAccessor(base, name, getter, setter, attribs).Check(); | |
474 } | |
475 | |
476 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, | |
477 Handle<String> name, | |
478 Handle<Name> property_name, | |
479 Builtins::Name call, bool adapt) { | |
480 Isolate* const isolate = base->GetIsolate(); | |
481 | |
482 Handle<String> getter_name = | |
483 Name::ToFunctionName(name, isolate->factory()->get_string()) | |
484 .ToHandleChecked(); | |
485 Handle<JSFunction> getter = | |
486 SimpleCreateFunction(isolate, getter_name, call, 0, adapt); | |
487 getter->shared()->set_native(true); | |
488 | |
489 Handle<Object> setter = isolate->factory()->undefined_value(); | |
490 | |
491 JSObject::DefineAccessor(base, property_name, getter, setter, DONT_ENUM) | |
492 .Check(); | |
493 | |
494 return getter; | |
495 } | |
496 | |
497 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, | 464 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, |
498 Handle<String> name, Builtins::Name call, | 465 Handle<String> name, Builtins::Name call, |
499 bool adapt) { | 466 bool adapt) { |
500 return SimpleInstallGetter(base, name, name, call, adapt); | 467 Isolate* const isolate = base->GetIsolate(); |
| 468 Handle<String> fun_name = |
| 469 Name::ToFunctionName(name, isolate->factory()->get_string()) |
| 470 .ToHandleChecked(); |
| 471 Handle<JSFunction> fun = |
| 472 SimpleCreateFunction(isolate, fun_name, call, 0, adapt); |
| 473 InstallGetter(base, name, fun); |
| 474 return fun; |
501 } | 475 } |
502 | 476 |
503 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, | 477 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, |
504 Handle<String> name, Builtins::Name call, | 478 Handle<String> name, Builtins::Name call, |
505 bool adapt, BuiltinFunctionId id) { | 479 bool adapt, BuiltinFunctionId id) { |
506 Handle<JSFunction> fun = SimpleInstallGetter(base, name, call, adapt); | 480 Handle<JSFunction> fun = SimpleInstallGetter(base, name, call, adapt); |
507 fun->shared()->set_builtin_function_id(id); | 481 fun->shared()->set_builtin_function_id(id); |
508 return fun; | 482 return fun; |
509 } | 483 } |
510 | 484 |
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1606 isolate->initial_object_prototype(), Builtins::kRegExpConstructor); | 1580 isolate->initial_object_prototype(), Builtins::kRegExpConstructor); |
1607 InstallWithIntrinsicDefaultProto(isolate, regexp_fun, | 1581 InstallWithIntrinsicDefaultProto(isolate, regexp_fun, |
1608 Context::REGEXP_FUNCTION_INDEX); | 1582 Context::REGEXP_FUNCTION_INDEX); |
1609 | 1583 |
1610 Handle<SharedFunctionInfo> shared(regexp_fun->shared(), isolate); | 1584 Handle<SharedFunctionInfo> shared(regexp_fun->shared(), isolate); |
1611 shared->SetConstructStub(*isolate->builtins()->RegExpConstructor()); | 1585 shared->SetConstructStub(*isolate->builtins()->RegExpConstructor()); |
1612 shared->set_instance_class_name(isolate->heap()->RegExp_string()); | 1586 shared->set_instance_class_name(isolate->heap()->RegExp_string()); |
1613 shared->DontAdaptArguments(); | 1587 shared->DontAdaptArguments(); |
1614 shared->set_length(2); | 1588 shared->set_length(2); |
1615 | 1589 |
1616 { | 1590 Handle<JSObject> proto = |
1617 // RegExp.prototype setup. | 1591 factory->NewJSObject(isolate->object_function(), TENURED); |
1618 | 1592 JSObject::AddProperty(proto, factory->constructor_string(), regexp_fun, |
1619 Handle<JSObject> proto = | 1593 DONT_ENUM); |
1620 factory->NewJSObject(isolate->object_function(), TENURED); | 1594 Accessors::FunctionSetPrototype(regexp_fun, proto).Assert(); |
1621 JSObject::AddProperty(proto, factory->constructor_string(), regexp_fun, | |
1622 DONT_ENUM); | |
1623 Accessors::FunctionSetPrototype(regexp_fun, proto).Assert(); | |
1624 | |
1625 SimpleInstallGetter(proto, factory->flags_string(), | |
1626 Builtins::kRegExpPrototypeFlagsGetter, false); | |
1627 SimpleInstallGetter(proto, factory->global_string(), | |
1628 Builtins::kRegExpPrototypeGlobalGetter, false); | |
1629 SimpleInstallGetter(proto, factory->ignoreCase_string(), | |
1630 Builtins::kRegExpPrototypeIgnoreCaseGetter, false); | |
1631 SimpleInstallGetter(proto, factory->multiline_string(), | |
1632 Builtins::kRegExpPrototypeMultilineGetter, false); | |
1633 SimpleInstallGetter(proto, factory->source_string(), | |
1634 Builtins::kRegExpPrototypeSourceGetter, false); | |
1635 SimpleInstallGetter(proto, factory->sticky_string(), | |
1636 Builtins::kRegExpPrototypeStickyGetter, false); | |
1637 SimpleInstallGetter(proto, factory->unicode_string(), | |
1638 Builtins::kRegExpPrototypeUnicodeGetter, false); | |
1639 } | |
1640 | |
1641 { | |
1642 // RegExp getters and setters. | |
1643 | |
1644 const PropertyAttributes no_enum_no_delete = | |
1645 static_cast<PropertyAttributes>(DONT_ENUM | DONT_DELETE); | |
1646 | |
1647 SimpleInstallGetter(regexp_fun, | |
1648 factory->InternalizeUtf8String("[Symbol.species]"), | |
1649 factory->species_symbol(), | |
1650 Builtins::kRegExpPrototypeSpeciesGetter, false); | |
1651 | |
1652 // Static properties set by a successful match. | |
1653 | |
1654 SimpleInstallGetterSetter(regexp_fun, factory->input_string(), | |
1655 Builtins::kRegExpPrototypeInputGetter, | |
1656 Builtins::kRegExpPrototypeInputSetter, | |
1657 DONT_DELETE); | |
1658 SimpleInstallGetterSetter( | |
1659 regexp_fun, factory->InternalizeUtf8String("$_"), | |
1660 Builtins::kRegExpPrototypeInputGetter, | |
1661 Builtins::kRegExpPrototypeInputSetter, no_enum_no_delete); | |
1662 | |
1663 SimpleInstallGetterSetter(regexp_fun, | |
1664 factory->InternalizeUtf8String("lastMatch"), | |
1665 Builtins::kRegExpPrototypeLastMatchGetter, | |
1666 Builtins::kEmptyFunction, no_enum_no_delete); | |
1667 SimpleInstallGetterSetter(regexp_fun, | |
1668 factory->InternalizeUtf8String("$&"), | |
1669 Builtins::kRegExpPrototypeLastMatchGetter, | |
1670 Builtins::kEmptyFunction, no_enum_no_delete); | |
1671 | |
1672 SimpleInstallGetterSetter(regexp_fun, | |
1673 factory->InternalizeUtf8String("lastParen"), | |
1674 Builtins::kRegExpPrototypeLastParenGetter, | |
1675 Builtins::kEmptyFunction, no_enum_no_delete); | |
1676 SimpleInstallGetterSetter(regexp_fun, | |
1677 factory->InternalizeUtf8String("$+"), | |
1678 Builtins::kRegExpPrototypeLastParenGetter, | |
1679 Builtins::kEmptyFunction, no_enum_no_delete); | |
1680 | |
1681 SimpleInstallGetterSetter(regexp_fun, | |
1682 factory->InternalizeUtf8String("leftContext"), | |
1683 Builtins::kRegExpPrototypeLeftContextGetter, | |
1684 Builtins::kEmptyFunction, no_enum_no_delete); | |
1685 SimpleInstallGetterSetter(regexp_fun, | |
1686 factory->InternalizeUtf8String("$`"), | |
1687 Builtins::kRegExpPrototypeLeftContextGetter, | |
1688 Builtins::kEmptyFunction, no_enum_no_delete); | |
1689 | |
1690 SimpleInstallGetterSetter(regexp_fun, | |
1691 factory->InternalizeUtf8String("rightContext"), | |
1692 Builtins::kRegExpPrototypeRightContextGetter, | |
1693 Builtins::kEmptyFunction, no_enum_no_delete); | |
1694 SimpleInstallGetterSetter(regexp_fun, | |
1695 factory->InternalizeUtf8String("$'"), | |
1696 Builtins::kRegExpPrototypeRightContextGetter, | |
1697 Builtins::kEmptyFunction, no_enum_no_delete); | |
1698 | |
1699 #define INSTALL_CAPTURE_GETTER(i) \ | |
1700 SimpleInstallGetterSetter(regexp_fun, \ | |
1701 factory->InternalizeUtf8String("$" #i), \ | |
1702 Builtins::kRegExpPrototypeCapture##i##Getter, \ | |
1703 Builtins::kEmptyFunction, DONT_DELETE) | |
1704 INSTALL_CAPTURE_GETTER(1); | |
1705 INSTALL_CAPTURE_GETTER(2); | |
1706 INSTALL_CAPTURE_GETTER(3); | |
1707 INSTALL_CAPTURE_GETTER(4); | |
1708 INSTALL_CAPTURE_GETTER(5); | |
1709 INSTALL_CAPTURE_GETTER(6); | |
1710 INSTALL_CAPTURE_GETTER(7); | |
1711 INSTALL_CAPTURE_GETTER(8); | |
1712 INSTALL_CAPTURE_GETTER(9); | |
1713 #undef INSTALL_CAPTURE_GETTER | |
1714 } | |
1715 | |
1716 // TODO(jgruber): shared->set_force_inline on getters. | |
1717 | 1595 |
1718 DCHECK(regexp_fun->has_initial_map()); | 1596 DCHECK(regexp_fun->has_initial_map()); |
1719 Handle<Map> initial_map(regexp_fun->initial_map()); | 1597 Handle<Map> initial_map(regexp_fun->initial_map()); |
1720 | 1598 |
1721 DCHECK_EQ(0, initial_map->GetInObjectProperties()); | 1599 DCHECK_EQ(0, initial_map->GetInObjectProperties()); |
1722 | 1600 |
1723 Map::EnsureDescriptorSlack(initial_map, 1); | 1601 Map::EnsureDescriptorSlack(initial_map, 1); |
1724 | 1602 |
1725 // ECMA-262, section 15.10.7.5. | 1603 // ECMA-262, section 15.10.7.5. |
1726 PropertyAttributes writable = | 1604 PropertyAttributes writable = |
(...skipping 2497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4224 } | 4102 } |
4225 | 4103 |
4226 | 4104 |
4227 // Called when the top-level V8 mutex is destroyed. | 4105 // Called when the top-level V8 mutex is destroyed. |
4228 void Bootstrapper::FreeThreadResources() { | 4106 void Bootstrapper::FreeThreadResources() { |
4229 DCHECK(!IsActive()); | 4107 DCHECK(!IsActive()); |
4230 } | 4108 } |
4231 | 4109 |
4232 } // namespace internal | 4110 } // namespace internal |
4233 } // namespace v8 | 4111 } // namespace v8 |
OLD | NEW |