Chromium Code Reviews| 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 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 357 function->shared()->set_native(true); | 357 function->shared()->set_native(true); |
| 358 } | 358 } |
| 359 | 359 |
| 360 void InstallFunction(Handle<JSObject> target, Handle<JSFunction> function, | 360 void InstallFunction(Handle<JSObject> target, Handle<JSFunction> function, |
| 361 Handle<Name> name, | 361 Handle<Name> name, |
| 362 PropertyAttributes attributes = DONT_ENUM) { | 362 PropertyAttributes attributes = DONT_ENUM) { |
| 363 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); | 363 Handle<String> name_string = Name::ToFunctionName(name).ToHandleChecked(); |
| 364 InstallFunction(target, name, function, name_string, attributes); | 364 InstallFunction(target, name, function, name_string, attributes); |
| 365 } | 365 } |
| 366 | 366 |
| 367 Handle<JSFunction> InstallGetter(Handle<JSObject> target, | |
| 368 Handle<Name> property_name, | |
| 369 Handle<JSFunction> getter, | |
| 370 PropertyAttributes attributes = DONT_ENUM) { | |
| 371 Handle<Object> setter = target->GetIsolate()->factory()->undefined_value(); | |
| 372 JSObject::DefineAccessor(target, property_name, getter, setter, attributes) | |
| 373 .Check(); | |
| 374 getter->shared()->set_native(true); | |
| 375 return getter; | |
| 376 } | |
| 377 | |
| 378 Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, | 367 Handle<JSFunction> CreateFunction(Isolate* isolate, Handle<String> name, |
| 379 InstanceType type, int instance_size, | 368 InstanceType type, int instance_size, |
| 380 MaybeHandle<JSObject> maybe_prototype, | 369 MaybeHandle<JSObject> maybe_prototype, |
| 381 Builtins::Name call, | 370 Builtins::Name call, |
| 382 bool strict_function_map = false) { | 371 bool strict_function_map = false) { |
| 383 Factory* factory = isolate->factory(); | 372 Factory* factory = isolate->factory(); |
| 384 Handle<Code> call_code(isolate->builtins()->builtin(call)); | 373 Handle<Code> call_code(isolate->builtins()->builtin(call)); |
| 385 Handle<JSObject> prototype; | 374 Handle<JSObject> prototype; |
| 386 return maybe_prototype.ToHandle(&prototype) | 375 return maybe_prototype.ToHandle(&prototype) |
| 387 ? factory->NewFunction(name, call_code, prototype, type, | 376 ? factory->NewFunction(name, call_code, prototype, type, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 453 | 442 |
| 454 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, | 443 Handle<JSFunction> SimpleInstallFunction(Handle<JSObject> base, |
| 455 const char* name, Builtins::Name call, | 444 const char* name, Builtins::Name call, |
| 456 int len, bool adapt, | 445 int len, bool adapt, |
| 457 BuiltinFunctionId id) { | 446 BuiltinFunctionId id) { |
| 458 Handle<JSFunction> fun = SimpleInstallFunction(base, name, call, len, adapt); | 447 Handle<JSFunction> fun = SimpleInstallFunction(base, name, call, len, adapt); |
| 459 fun->shared()->set_builtin_function_id(id); | 448 fun->shared()->set_builtin_function_id(id); |
| 460 return fun; | 449 return fun; |
| 461 } | 450 } |
| 462 | 451 |
| 452 void SimpleInstallGetterSetter(Handle<JSObject> base, Handle<String> name, | |
| 453 Builtins::Name call_getter, | |
| 454 Builtins::Name call_setter, | |
| 455 PropertyAttributes attribs) { | |
| 456 Isolate* const isolate = base->GetIsolate(); | |
| 457 | |
| 458 Handle<String> getter_name = | |
| 459 Name::ToFunctionName(name, isolate->factory()->get_string()) | |
| 460 .ToHandleChecked(); | |
| 461 Handle<JSFunction> getter = | |
| 462 SimpleCreateFunction(isolate, getter_name, call_getter, 0, false); | |
| 463 getter->shared()->set_native(true); | |
| 464 | |
| 465 Handle<String> setter_name = | |
| 466 Name::ToFunctionName(name, isolate->factory()->set_string()) | |
| 467 .ToHandleChecked(); | |
| 468 Handle<JSFunction> setter = | |
| 469 SimpleCreateFunction(isolate, setter_name, call_setter, 0, false); | |
| 470 setter->shared()->set_native(true); | |
| 471 | |
| 472 JSObject::DefineAccessor(base, name, getter, setter, attribs).Check(); | |
| 473 } | |
| 474 | |
| 475 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, | |
| 476 Handle<String> name, | |
| 477 Handle<Name> property_name, | |
| 478 Builtins::Name call, bool adapt) { | |
| 479 Isolate* const isolate = base->GetIsolate(); | |
| 480 | |
| 481 Handle<String> getter_name = | |
| 482 Name::ToFunctionName(name, isolate->factory()->get_string()) | |
| 483 .ToHandleChecked(); | |
| 484 Handle<JSFunction> getter = | |
| 485 SimpleCreateFunction(isolate, getter_name, call, 0, adapt); | |
| 486 getter->shared()->set_native(true); | |
| 487 | |
| 488 Handle<Object> setter = isolate->factory()->undefined_value(); | |
| 489 | |
| 490 JSObject::DefineAccessor(base, property_name, getter, setter, DONT_ENUM) | |
| 491 .Check(); | |
| 492 | |
| 493 return getter; | |
| 494 } | |
| 495 | |
| 463 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, | 496 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, |
| 464 Handle<String> name, Builtins::Name call, | 497 Handle<String> name, Builtins::Name call, |
| 465 bool adapt) { | 498 bool adapt) { |
| 466 Isolate* const isolate = base->GetIsolate(); | 499 return SimpleInstallGetter(base, name, name, call, adapt); |
| 467 Handle<String> fun_name = | |
| 468 Name::ToFunctionName(name, isolate->factory()->get_string()) | |
| 469 .ToHandleChecked(); | |
| 470 Handle<JSFunction> fun = | |
| 471 SimpleCreateFunction(isolate, fun_name, call, 0, adapt); | |
| 472 InstallGetter(base, name, fun); | |
| 473 return fun; | |
| 474 } | 500 } |
| 475 | 501 |
| 476 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, | 502 Handle<JSFunction> SimpleInstallGetter(Handle<JSObject> base, |
| 477 Handle<String> name, Builtins::Name call, | 503 Handle<String> name, Builtins::Name call, |
| 478 bool adapt, BuiltinFunctionId id) { | 504 bool adapt, BuiltinFunctionId id) { |
| 479 Handle<JSFunction> fun = SimpleInstallGetter(base, name, call, adapt); | 505 Handle<JSFunction> fun = SimpleInstallGetter(base, name, call, adapt); |
| 480 fun->shared()->set_builtin_function_id(id); | 506 fun->shared()->set_builtin_function_id(id); |
| 481 return fun; | 507 return fun; |
| 482 } | 508 } |
| 483 | 509 |
| (...skipping 1168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1652 prototype, Builtins::kRegExpConstructor); | 1678 prototype, Builtins::kRegExpConstructor); |
| 1653 InstallWithIntrinsicDefaultProto(isolate, regexp_fun, | 1679 InstallWithIntrinsicDefaultProto(isolate, regexp_fun, |
| 1654 Context::REGEXP_FUNCTION_INDEX); | 1680 Context::REGEXP_FUNCTION_INDEX); |
| 1655 | 1681 |
| 1656 Handle<SharedFunctionInfo> shared(regexp_fun->shared(), isolate); | 1682 Handle<SharedFunctionInfo> shared(regexp_fun->shared(), isolate); |
| 1657 shared->SetConstructStub(*isolate->builtins()->RegExpConstructor()); | 1683 shared->SetConstructStub(*isolate->builtins()->RegExpConstructor()); |
| 1658 shared->set_instance_class_name(isolate->heap()->RegExp_string()); | 1684 shared->set_instance_class_name(isolate->heap()->RegExp_string()); |
| 1659 shared->DontAdaptArguments(); | 1685 shared->DontAdaptArguments(); |
| 1660 shared->set_length(2); | 1686 shared->set_length(2); |
| 1661 | 1687 |
| 1662 // RegExp.prototype setup. | 1688 { |
| 1689 // RegExp.prototype setup. | |
| 1663 | 1690 |
| 1664 // Install the "constructor" property on the {prototype}. | 1691 // Install the "constructor" property on the {prototype}. |
| 1665 JSObject::AddProperty(prototype, factory->constructor_string(), regexp_fun, | 1692 JSObject::AddProperty(prototype, factory->constructor_string(), |
| 1666 DONT_ENUM); | 1693 regexp_fun, DONT_ENUM); |
| 1667 | 1694 |
| 1668 SimpleInstallFunction(prototype, "exec", Builtins::kRegExpPrototypeExec, 1, | 1695 SimpleInstallFunction(prototype, "exec", Builtins::kRegExpPrototypeExec, |
| 1669 true, DONT_ENUM); | 1696 1, true, DONT_ENUM); |
| 1697 | |
| 1698 SimpleInstallGetter(prototype, factory->flags_string(), | |
| 1699 Builtins::kRegExpPrototypeFlagsGetter, true); | |
| 1700 SimpleInstallGetter(prototype, factory->global_string(), | |
| 1701 Builtins::kRegExpPrototypeGlobalGetter, true); | |
| 1702 SimpleInstallGetter(prototype, factory->ignoreCase_string(), | |
| 1703 Builtins::kRegExpPrototypeIgnoreCaseGetter, true); | |
| 1704 SimpleInstallGetter(prototype, factory->multiline_string(), | |
| 1705 Builtins::kRegExpPrototypeMultilineGetter, true); | |
| 1706 SimpleInstallGetter(prototype, factory->source_string(), | |
| 1707 Builtins::kRegExpPrototypeSourceGetter, false); | |
| 1708 SimpleInstallGetter(prototype, factory->sticky_string(), | |
| 1709 Builtins::kRegExpPrototypeStickyGetter, true); | |
| 1710 SimpleInstallGetter(prototype, factory->unicode_string(), | |
| 1711 Builtins::kRegExpPrototypeUnicodeGetter, true); | |
| 1712 } | |
| 1713 | |
| 1714 { | |
| 1715 // RegExp getters and setters. | |
| 1716 | |
| 1717 // TODO(jgruber): This should really be DONT_ENUM | DONT_DELETE. | |
| 1718 // However, that currently breaks layout test expectations. Note that | |
| 1719 // Firefox sets a couple of these as enumerable. | |
| 1720 // On the other hand, installing attributes as DONT_ENUM matches the draft | |
| 1721 // specification at | |
|
Yang
2016/10/06 07:56:13
Good to know.
| |
| 1722 // https://github.com/claudepache/es-regexp-legacy-static-properties. | |
| 1723 const PropertyAttributes no_enum = DONT_ENUM; | |
| 1724 | |
| 1725 SimpleInstallGetter(regexp_fun, | |
| 1726 factory->InternalizeUtf8String("[Symbol.species]"), | |
| 1727 factory->species_symbol(), | |
| 1728 Builtins::kRegExpPrototypeSpeciesGetter, false); | |
| 1729 | |
| 1730 // Static properties set by a successful match. | |
| 1731 | |
| 1732 SimpleInstallGetterSetter(regexp_fun, factory->input_string(), | |
| 1733 Builtins::kRegExpInputGetter, | |
| 1734 Builtins::kRegExpInputSetter, DONT_DELETE); | |
| 1735 SimpleInstallGetterSetter( | |
| 1736 regexp_fun, factory->InternalizeUtf8String("$_"), | |
| 1737 Builtins::kRegExpInputGetter, Builtins::kRegExpInputSetter, no_enum); | |
| 1738 | |
| 1739 SimpleInstallGetterSetter( | |
| 1740 regexp_fun, factory->InternalizeUtf8String("lastMatch"), | |
| 1741 Builtins::kRegExpLastMatchGetter, Builtins::kEmptyFunction, no_enum); | |
| 1742 SimpleInstallGetterSetter( | |
| 1743 regexp_fun, factory->InternalizeUtf8String("$&"), | |
| 1744 Builtins::kRegExpLastMatchGetter, Builtins::kEmptyFunction, no_enum); | |
| 1745 | |
| 1746 SimpleInstallGetterSetter( | |
| 1747 regexp_fun, factory->InternalizeUtf8String("lastParen"), | |
| 1748 Builtins::kRegExpLastParenGetter, Builtins::kEmptyFunction, no_enum); | |
| 1749 SimpleInstallGetterSetter( | |
| 1750 regexp_fun, factory->InternalizeUtf8String("$+"), | |
| 1751 Builtins::kRegExpLastParenGetter, Builtins::kEmptyFunction, no_enum); | |
| 1752 | |
| 1753 SimpleInstallGetterSetter(regexp_fun, | |
| 1754 factory->InternalizeUtf8String("leftContext"), | |
| 1755 Builtins::kRegExpLeftContextGetter, | |
| 1756 Builtins::kEmptyFunction, no_enum); | |
| 1757 SimpleInstallGetterSetter(regexp_fun, | |
| 1758 factory->InternalizeUtf8String("$`"), | |
| 1759 Builtins::kRegExpLeftContextGetter, | |
| 1760 Builtins::kEmptyFunction, no_enum); | |
| 1761 | |
| 1762 SimpleInstallGetterSetter(regexp_fun, | |
| 1763 factory->InternalizeUtf8String("rightContext"), | |
| 1764 Builtins::kRegExpRightContextGetter, | |
| 1765 Builtins::kEmptyFunction, no_enum); | |
| 1766 SimpleInstallGetterSetter(regexp_fun, | |
| 1767 factory->InternalizeUtf8String("$'"), | |
| 1768 Builtins::kRegExpRightContextGetter, | |
| 1769 Builtins::kEmptyFunction, no_enum); | |
| 1770 | |
| 1771 #define INSTALL_CAPTURE_GETTER(i) \ | |
| 1772 SimpleInstallGetterSetter(regexp_fun, \ | |
| 1773 factory->InternalizeUtf8String("$" #i), \ | |
| 1774 Builtins::kRegExpCapture##i##Getter, \ | |
| 1775 Builtins::kEmptyFunction, DONT_DELETE) | |
| 1776 INSTALL_CAPTURE_GETTER(1); | |
| 1777 INSTALL_CAPTURE_GETTER(2); | |
| 1778 INSTALL_CAPTURE_GETTER(3); | |
| 1779 INSTALL_CAPTURE_GETTER(4); | |
| 1780 INSTALL_CAPTURE_GETTER(5); | |
| 1781 INSTALL_CAPTURE_GETTER(6); | |
| 1782 INSTALL_CAPTURE_GETTER(7); | |
| 1783 INSTALL_CAPTURE_GETTER(8); | |
| 1784 INSTALL_CAPTURE_GETTER(9); | |
| 1785 #undef INSTALL_CAPTURE_GETTER | |
| 1786 } | |
| 1670 | 1787 |
| 1671 DCHECK(regexp_fun->has_initial_map()); | 1788 DCHECK(regexp_fun->has_initial_map()); |
| 1672 Handle<Map> initial_map(regexp_fun->initial_map()); | 1789 Handle<Map> initial_map(regexp_fun->initial_map()); |
| 1673 | 1790 |
| 1674 DCHECK_EQ(0, initial_map->GetInObjectProperties()); | 1791 DCHECK_EQ(0, initial_map->GetInObjectProperties()); |
| 1675 | 1792 |
| 1676 Map::EnsureDescriptorSlack(initial_map, 1); | 1793 Map::EnsureDescriptorSlack(initial_map, 1); |
| 1677 | 1794 |
| 1678 // ECMA-262, section 15.10.7.5. | 1795 // ECMA-262, section 15.10.7.5. |
| 1679 PropertyAttributes writable = | 1796 PropertyAttributes writable = |
| (...skipping 2527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4207 } | 4324 } |
| 4208 | 4325 |
| 4209 | 4326 |
| 4210 // Called when the top-level V8 mutex is destroyed. | 4327 // Called when the top-level V8 mutex is destroyed. |
| 4211 void Bootstrapper::FreeThreadResources() { | 4328 void Bootstrapper::FreeThreadResources() { |
| 4212 DCHECK(!IsActive()); | 4329 DCHECK(!IsActive()); |
| 4213 } | 4330 } |
| 4214 | 4331 |
| 4215 } // namespace internal | 4332 } // namespace internal |
| 4216 } // namespace v8 | 4333 } // namespace v8 |
| OLD | NEW |