Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(60)

Side by Side Diff: src/bootstrapper.cc

Issue 2305573002: [regexp] Port RegExp getters and setters (Closed)
Patch Set: Fix for layout test expectations Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/builtins/builtins.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 // TODO(jgruber): This should really be DONT_ENUM | DONT_DELETE.
1645 // However, that currently breaks layout test expectations. Note that
1646 // Firefox sets a couple of these as enumerable.
1647 const PropertyAttributes no_enum = DONT_ENUM;
1648
1649 SimpleInstallGetter(regexp_fun,
1650 factory->InternalizeUtf8String("[Symbol.species]"),
1651 factory->species_symbol(),
1652 Builtins::kRegExpPrototypeSpeciesGetter, false);
1653
1654 // Static properties set by a successful match.
1655
1656 SimpleInstallGetterSetter(regexp_fun, factory->input_string(),
1657 Builtins::kRegExpPrototypeInputGetter,
1658 Builtins::kRegExpPrototypeInputSetter,
1659 DONT_DELETE);
1660 SimpleInstallGetterSetter(regexp_fun,
1661 factory->InternalizeUtf8String("$_"),
1662 Builtins::kRegExpPrototypeInputGetter,
1663 Builtins::kRegExpPrototypeInputSetter, no_enum);
1664
1665 SimpleInstallGetterSetter(regexp_fun,
1666 factory->InternalizeUtf8String("lastMatch"),
1667 Builtins::kRegExpPrototypeLastMatchGetter,
1668 Builtins::kEmptyFunction, no_enum);
1669 SimpleInstallGetterSetter(regexp_fun,
1670 factory->InternalizeUtf8String("$&"),
1671 Builtins::kRegExpPrototypeLastMatchGetter,
1672 Builtins::kEmptyFunction, no_enum);
1673
1674 SimpleInstallGetterSetter(regexp_fun,
1675 factory->InternalizeUtf8String("lastParen"),
1676 Builtins::kRegExpPrototypeLastParenGetter,
1677 Builtins::kEmptyFunction, no_enum);
1678 SimpleInstallGetterSetter(regexp_fun,
1679 factory->InternalizeUtf8String("$+"),
1680 Builtins::kRegExpPrototypeLastParenGetter,
1681 Builtins::kEmptyFunction, no_enum);
1682
1683 SimpleInstallGetterSetter(regexp_fun,
1684 factory->InternalizeUtf8String("leftContext"),
1685 Builtins::kRegExpPrototypeLeftContextGetter,
1686 Builtins::kEmptyFunction, no_enum);
1687 SimpleInstallGetterSetter(regexp_fun,
1688 factory->InternalizeUtf8String("$`"),
1689 Builtins::kRegExpPrototypeLeftContextGetter,
1690 Builtins::kEmptyFunction, no_enum);
1691
1692 SimpleInstallGetterSetter(regexp_fun,
1693 factory->InternalizeUtf8String("rightContext"),
1694 Builtins::kRegExpPrototypeRightContextGetter,
1695 Builtins::kEmptyFunction, no_enum);
1696 SimpleInstallGetterSetter(regexp_fun,
1697 factory->InternalizeUtf8String("$'"),
1698 Builtins::kRegExpPrototypeRightContextGetter,
1699 Builtins::kEmptyFunction, no_enum);
1700
1701 #define INSTALL_CAPTURE_GETTER(i) \
1702 SimpleInstallGetterSetter(regexp_fun, \
1703 factory->InternalizeUtf8String("$" #i), \
1704 Builtins::kRegExpPrototypeCapture##i##Getter, \
1705 Builtins::kEmptyFunction, DONT_DELETE)
1706 INSTALL_CAPTURE_GETTER(1);
1707 INSTALL_CAPTURE_GETTER(2);
1708 INSTALL_CAPTURE_GETTER(3);
1709 INSTALL_CAPTURE_GETTER(4);
1710 INSTALL_CAPTURE_GETTER(5);
1711 INSTALL_CAPTURE_GETTER(6);
1712 INSTALL_CAPTURE_GETTER(7);
1713 INSTALL_CAPTURE_GETTER(8);
1714 INSTALL_CAPTURE_GETTER(9);
1715 #undef INSTALL_CAPTURE_GETTER
1716 }
1717
1718 // TODO(jgruber): shared->set_force_inline on getters.
1595 1719
1596 DCHECK(regexp_fun->has_initial_map()); 1720 DCHECK(regexp_fun->has_initial_map());
1597 Handle<Map> initial_map(regexp_fun->initial_map()); 1721 Handle<Map> initial_map(regexp_fun->initial_map());
1598 1722
1599 DCHECK_EQ(0, initial_map->GetInObjectProperties()); 1723 DCHECK_EQ(0, initial_map->GetInObjectProperties());
1600 1724
1601 Map::EnsureDescriptorSlack(initial_map, 1); 1725 Map::EnsureDescriptorSlack(initial_map, 1);
1602 1726
1603 // ECMA-262, section 15.10.7.5. 1727 // ECMA-262, section 15.10.7.5.
1604 PropertyAttributes writable = 1728 PropertyAttributes writable =
(...skipping 2497 matching lines...) Expand 10 before | Expand all | Expand 10 after
4102 } 4226 }
4103 4227
4104 4228
4105 // Called when the top-level V8 mutex is destroyed. 4229 // Called when the top-level V8 mutex is destroyed.
4106 void Bootstrapper::FreeThreadResources() { 4230 void Bootstrapper::FreeThreadResources() {
4107 DCHECK(!IsActive()); 4231 DCHECK(!IsActive());
4108 } 4232 }
4109 4233
4110 } // namespace internal 4234 } // namespace internal
4111 } // namespace v8 4235 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/builtins/builtins.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698