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 | |
379 Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, | 368 Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, |
380 InstanceType type, int instance_size, | 369 InstanceType type, int instance_size, |
381 MaybeHandle<JSObject> maybe_prototype, | 370 MaybeHandle<JSObject> maybe_prototype, |
382 Builtins::Name call, | 371 Builtins::Name call, |
383 bool strict_function_map = false) { | 372 bool strict_function_map = false) { |
384 Factory* factory = isolate->factory(); | 373 Factory* factory = isolate->factory(); |
385 Handle<Code> call_code(isolate->builtins()->builtin(call)); | 374 Handle<Code> call_code(isolate->builtins()->builtin(call)); |
386 Handle<JSObject> prototype; | 375 Handle<JSObject> prototype; |
387 return maybe_prototype.ToHandle(&prototype) | 376 return maybe_prototype.ToHandle(&prototype) |
388 ? factory->NewFunction(name, call_code, prototype, type, | 377 ? factory->NewFunction(name, call_code, prototype, type, |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 | 443 |
455 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, | 444 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, |
456 const char* name, Builtins::Name call, | 445 const char* name, Builtins::Name call, |
457 int len, bool adapt, | 446 int len, bool adapt, |
458 BuiltinFunctionId id) { | 447 BuiltinFunctionId id) { |
459 Handle<JSFunction> fun = SimpleInstallFunction(base, name, call, len, adapt); | 448 Handle<JSFunction> fun = SimpleInstallFunction(base, name, call, len, adapt); |
460 fun->shared()->set_builtin_function_id(id); | 449 fun->shared()->set_builtin_function_id(id); |
461 return fun; | 450 return fun; |
462 } | 451 } |
463 | 452 |
| 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 |
464 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, | 497 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, |
465 Handle<String> name, Builtins::Name call, | 498 Handle<String> name, Builtins::Name call, |
466 bool adapt) { | 499 bool adapt) { |
467 Isolate* const isolate = base->GetIsolate(); | 500 return SimpleInstallGetter(base, name, name, call, adapt); |
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; | |
475 } | 501 } |
476 | 502 |
477 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, | 503 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, |
478 Handle<String> name, Builtins::Name call, | 504 Handle<String> name, Builtins::Name call, |
479 bool adapt, BuiltinFunctionId id) { | 505 bool adapt, BuiltinFunctionId id) { |
480 Handle<JSFunction> fun = SimpleInstallGetter(base, name, call, adapt); | 506 Handle<JSFunction> fun = SimpleInstallGetter(base, name, call, adapt); |
481 fun->shared()->set_builtin_function_id(id); | 507 fun->shared()->set_builtin_function_id(id); |
482 return fun; | 508 return fun; |
483 } | 509 } |
484 | 510 |
(...skipping 1095 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1580 isolate->initial_object_prototype(), Builtins::kRegExpConstructor); | 1606 isolate->initial_object_prototype(), Builtins::kRegExpConstructor); |
1581 InstallWithIntrinsicDefaultProto(isolate, regexp_fun, | 1607 InstallWithIntrinsicDefaultProto(isolate, regexp_fun, |
1582 Context::REGEXP_FUNCTION_INDEX); | 1608 Context::REGEXP_FUNCTION_INDEX); |
1583 | 1609 |
1584 Handle<SharedFunctionInfo> shared(regexp_fun->shared(), isolate); | 1610 Handle<SharedFunctionInfo> shared(regexp_fun->shared(), isolate); |
1585 shared->SetConstructStub(*isolate->builtins()->RegExpConstructor()); | 1611 shared->SetConstructStub(*isolate->builtins()->RegExpConstructor()); |
1586 shared->set_instance_class_name(isolate->heap()->RegExp_string()); | 1612 shared->set_instance_class_name(isolate->heap()->RegExp_string()); |
1587 shared->DontAdaptArguments(); | 1613 shared->DontAdaptArguments(); |
1588 shared->set_length(2); | 1614 shared->set_length(2); |
1589 | 1615 |
1590 Handle<JSObject> proto = | 1616 { |
1591 factory->NewJSObject(isolate->object_function(), TENURED); | 1617 // RegExp.prototype setup. |
1592 JSObject::AddProperty(proto, factory->constructor_string(), regexp_fun, | 1618 |
1593 DONT_ENUM); | 1619 Handle<JSObject> proto = |
1594 Accessors::FunctionSetPrototype(regexp_fun, proto).Assert(); | 1620 factory->NewJSObject(isolate->object_function(), TENURED); |
| 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. |
1595 | 1717 |
1596 DCHECK(regexp_fun->has_initial_map()); | 1718 DCHECK(regexp_fun->has_initial_map()); |
1597 Handle<Map> initial_map(regexp_fun->initial_map()); | 1719 Handle<Map> initial_map(regexp_fun->initial_map()); |
1598 | 1720 |
1599 DCHECK_EQ(0, initial_map->GetInObjectProperties()); | 1721 DCHECK_EQ(0, initial_map->GetInObjectProperties()); |
1600 | 1722 |
1601 Map::EnsureDescriptorSlack(initial_map, 1); | 1723 Map::EnsureDescriptorSlack(initial_map, 1); |
1602 | 1724 |
1603 // ECMA-262, section 15.10.7.5. | 1725 // ECMA-262, section 15.10.7.5. |
1604 PropertyAttributes writable = | 1726 PropertyAttributes writable = |
(...skipping 2497 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4102 } | 4224 } |
4103 | 4225 |
4104 | 4226 |
4105 // Called when the top-level V8 mutex is destroyed. | 4227 // Called when the top-level V8 mutex is destroyed. |
4106 void Bootstrapper::FreeThreadResources() { | 4228 void Bootstrapper::FreeThreadResources() { |
4107 DCHECK(!IsActive()); | 4229 DCHECK(!IsActive()); |
4108 } | 4230 } |
4109 | 4231 |
4110 } // namespace internal | 4232 } // namespace internal |
4111 } // namespace v8 | 4233 } // namespace v8 |
OLD | NEW |