| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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/api.h" | 5 #include "src/api.h" |
| 6 | 6 |
| 7 #include <string.h> // For memcpy, strlen. | 7 #include <string.h> // For memcpy, strlen. |
| 8 #ifdef V8_USE_ADDRESS_SANITIZER | 8 #ifdef V8_USE_ADDRESS_SANITIZER |
| 9 #include <sanitizer/asan_interface.h> | 9 #include <sanitizer/asan_interface.h> |
| 10 #endif // V8_USE_ADDRESS_SANITIZER | 10 #endif // V8_USE_ADDRESS_SANITIZER |
| (...skipping 1517 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1528 void ObjectTemplate::SetAccessor(v8::Local<Name> name, | 1528 void ObjectTemplate::SetAccessor(v8::Local<Name> name, |
| 1529 AccessorNameGetterCallback getter, | 1529 AccessorNameGetterCallback getter, |
| 1530 AccessorNameSetterCallback setter, | 1530 AccessorNameSetterCallback setter, |
| 1531 v8::Local<Value> data, AccessControl settings, | 1531 v8::Local<Value> data, AccessControl settings, |
| 1532 PropertyAttribute attribute, | 1532 PropertyAttribute attribute, |
| 1533 v8::Local<AccessorSignature> signature) { | 1533 v8::Local<AccessorSignature> signature) { |
| 1534 TemplateSetAccessor(this, name, getter, setter, data, settings, attribute, | 1534 TemplateSetAccessor(this, name, getter, setter, data, settings, attribute, |
| 1535 signature, i::FLAG_disable_old_api_accessors); | 1535 signature, i::FLAG_disable_old_api_accessors); |
| 1536 } | 1536 } |
| 1537 | 1537 |
| 1538 | |
| 1539 template <typename Getter, typename Setter, typename Query, typename Deleter, | 1538 template <typename Getter, typename Setter, typename Query, typename Deleter, |
| 1540 typename Enumerator> | 1539 typename Enumerator> |
| 1541 static void ObjectTemplateSetNamedPropertyHandler(ObjectTemplate* templ, | 1540 static i::Handle<i::InterceptorInfo> CreateInterceptorInfo( |
| 1542 Getter getter, Setter setter, | 1541 i::Isolate* isolate, Getter getter, Setter setter, Query query, |
| 1543 Query query, Deleter remover, | 1542 Deleter remover, Enumerator enumerator, Local<Value> data, |
| 1544 Enumerator enumerator, | 1543 PropertyHandlerFlags flags) { |
| 1545 Local<Value> data, | |
| 1546 PropertyHandlerFlags flags) { | |
| 1547 i::Isolate* isolate = Utils::OpenHandle(templ)->GetIsolate(); | |
| 1548 ENTER_V8(isolate); | |
| 1549 i::HandleScope scope(isolate); | |
| 1550 auto cons = EnsureConstructor(isolate, templ); | |
| 1551 EnsureNotInstantiated(cons, "ObjectTemplateSetNamedPropertyHandler"); | |
| 1552 auto obj = i::Handle<i::InterceptorInfo>::cast( | 1544 auto obj = i::Handle<i::InterceptorInfo>::cast( |
| 1553 isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE)); | 1545 isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE)); |
| 1554 obj->set_flags(0); | 1546 obj->set_flags(0); |
| 1555 | 1547 |
| 1556 if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); | 1548 if (getter != 0) SET_FIELD_WRAPPED(obj, set_getter, getter); |
| 1557 if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); | 1549 if (setter != 0) SET_FIELD_WRAPPED(obj, set_setter, setter); |
| 1558 if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); | 1550 if (query != 0) SET_FIELD_WRAPPED(obj, set_query, query); |
| 1559 if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); | 1551 if (remover != 0) SET_FIELD_WRAPPED(obj, set_deleter, remover); |
| 1560 if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); | 1552 if (enumerator != 0) SET_FIELD_WRAPPED(obj, set_enumerator, enumerator); |
| 1561 obj->set_can_intercept_symbols( | 1553 obj->set_can_intercept_symbols( |
| 1562 !(static_cast<int>(flags) & | 1554 !(static_cast<int>(flags) & |
| 1563 static_cast<int>(PropertyHandlerFlags::kOnlyInterceptStrings))); | 1555 static_cast<int>(PropertyHandlerFlags::kOnlyInterceptStrings))); |
| 1564 obj->set_all_can_read(static_cast<int>(flags) & | 1556 obj->set_all_can_read(static_cast<int>(flags) & |
| 1565 static_cast<int>(PropertyHandlerFlags::kAllCanRead)); | 1557 static_cast<int>(PropertyHandlerFlags::kAllCanRead)); |
| 1566 obj->set_non_masking(static_cast<int>(flags) & | 1558 obj->set_non_masking(static_cast<int>(flags) & |
| 1567 static_cast<int>(PropertyHandlerFlags::kNonMasking)); | 1559 static_cast<int>(PropertyHandlerFlags::kNonMasking)); |
| 1568 | 1560 |
| 1569 if (data.IsEmpty()) { | 1561 if (data.IsEmpty()) { |
| 1570 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 1562 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1571 } | 1563 } |
| 1572 obj->set_data(*Utils::OpenHandle(*data)); | 1564 obj->set_data(*Utils::OpenHandle(*data)); |
| 1565 return obj; |
| 1566 } |
| 1567 |
| 1568 template <typename Getter, typename Setter, typename Query, typename Deleter, |
| 1569 typename Enumerator> |
| 1570 static void ObjectTemplateSetNamedPropertyHandler(ObjectTemplate* templ, |
| 1571 Getter getter, Setter setter, |
| 1572 Query query, Deleter remover, |
| 1573 Enumerator enumerator, |
| 1574 Local<Value> data, |
| 1575 PropertyHandlerFlags flags) { |
| 1576 i::Isolate* isolate = Utils::OpenHandle(templ)->GetIsolate(); |
| 1577 ENTER_V8(isolate); |
| 1578 i::HandleScope scope(isolate); |
| 1579 auto cons = EnsureConstructor(isolate, templ); |
| 1580 EnsureNotInstantiated(cons, "ObjectTemplateSetNamedPropertyHandler"); |
| 1581 auto obj = CreateInterceptorInfo(isolate, getter, setter, query, remover, |
| 1582 enumerator, data, flags); |
| 1573 cons->set_named_property_handler(*obj); | 1583 cons->set_named_property_handler(*obj); |
| 1574 } | 1584 } |
| 1575 | 1585 |
| 1576 | 1586 |
| 1577 void ObjectTemplate::SetNamedPropertyHandler( | 1587 void ObjectTemplate::SetNamedPropertyHandler( |
| 1578 NamedPropertyGetterCallback getter, NamedPropertySetterCallback setter, | 1588 NamedPropertyGetterCallback getter, NamedPropertySetterCallback setter, |
| 1579 NamedPropertyQueryCallback query, NamedPropertyDeleterCallback remover, | 1589 NamedPropertyQueryCallback query, NamedPropertyDeleterCallback remover, |
| 1580 NamedPropertyEnumeratorCallback enumerator, Local<Value> data) { | 1590 NamedPropertyEnumeratorCallback enumerator, Local<Value> data) { |
| 1581 ObjectTemplateSetNamedPropertyHandler( | 1591 ObjectTemplateSetNamedPropertyHandler( |
| 1582 this, getter, setter, query, remover, enumerator, data, | 1592 this, getter, setter, query, remover, enumerator, data, |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1609 i::HandleScope scope(isolate); | 1619 i::HandleScope scope(isolate); |
| 1610 auto cons = EnsureConstructor(isolate, this); | 1620 auto cons = EnsureConstructor(isolate, this); |
| 1611 EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetAccessCheckCallback"); | 1621 EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetAccessCheckCallback"); |
| 1612 | 1622 |
| 1613 i::Handle<i::Struct> struct_info = | 1623 i::Handle<i::Struct> struct_info = |
| 1614 isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE); | 1624 isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE); |
| 1615 i::Handle<i::AccessCheckInfo> info = | 1625 i::Handle<i::AccessCheckInfo> info = |
| 1616 i::Handle<i::AccessCheckInfo>::cast(struct_info); | 1626 i::Handle<i::AccessCheckInfo>::cast(struct_info); |
| 1617 | 1627 |
| 1618 SET_FIELD_WRAPPED(info, set_callback, callback); | 1628 SET_FIELD_WRAPPED(info, set_callback, callback); |
| 1629 info->set_named_interceptor(nullptr); |
| 1630 info->set_indexed_interceptor(nullptr); |
| 1619 | 1631 |
| 1620 if (data.IsEmpty()) { | 1632 if (data.IsEmpty()) { |
| 1621 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | 1633 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1622 } | 1634 } |
| 1623 info->set_data(*Utils::OpenHandle(*data)); | 1635 info->set_data(*Utils::OpenHandle(*data)); |
| 1624 | 1636 |
| 1625 cons->set_access_check_info(*info); | 1637 cons->set_access_check_info(*info); |
| 1626 cons->set_needs_access_check(true); | 1638 cons->set_needs_access_check(true); |
| 1627 } | 1639 } |
| 1628 | 1640 |
| 1641 void ObjectTemplate::SetAccessCheckCallbackAndHandler( |
| 1642 AccessCheckCallback callback, |
| 1643 const NamedPropertyHandlerConfiguration& named_handler, |
| 1644 const IndexedPropertyHandlerConfiguration& indexed_handler, |
| 1645 Local<Value> data) { |
| 1646 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 1647 ENTER_V8(isolate); |
| 1648 i::HandleScope scope(isolate); |
| 1649 auto cons = EnsureConstructor(isolate, this); |
| 1650 EnsureNotInstantiated( |
| 1651 cons, "v8::ObjectTemplate::SetAccessCheckCallbackWithHandler"); |
| 1652 |
| 1653 i::Handle<i::Struct> struct_info = |
| 1654 isolate->factory()->NewStruct(i::ACCESS_CHECK_INFO_TYPE); |
| 1655 i::Handle<i::AccessCheckInfo> info = |
| 1656 i::Handle<i::AccessCheckInfo>::cast(struct_info); |
| 1657 |
| 1658 SET_FIELD_WRAPPED(info, set_callback, callback); |
| 1659 auto named_interceptor = CreateInterceptorInfo( |
| 1660 isolate, named_handler.getter, named_handler.setter, named_handler.query, |
| 1661 named_handler.deleter, named_handler.enumerator, named_handler.data, |
| 1662 named_handler.flags); |
| 1663 info->set_named_interceptor(*named_interceptor); |
| 1664 auto indexed_interceptor = CreateInterceptorInfo( |
| 1665 isolate, indexed_handler.getter, indexed_handler.setter, |
| 1666 indexed_handler.query, indexed_handler.deleter, |
| 1667 indexed_handler.enumerator, indexed_handler.data, indexed_handler.flags); |
| 1668 info->set_indexed_interceptor(*indexed_interceptor); |
| 1669 |
| 1670 if (data.IsEmpty()) { |
| 1671 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
| 1672 } |
| 1673 info->set_data(*Utils::OpenHandle(*data)); |
| 1674 |
| 1675 cons->set_access_check_info(*info); |
| 1676 cons->set_needs_access_check(true); |
| 1677 } |
| 1678 |
| 1629 void ObjectTemplate::SetHandler( | 1679 void ObjectTemplate::SetHandler( |
| 1630 const IndexedPropertyHandlerConfiguration& config) { | 1680 const IndexedPropertyHandlerConfiguration& config) { |
| 1631 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 1681 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 1632 ENTER_V8(isolate); | 1682 ENTER_V8(isolate); |
| 1633 i::HandleScope scope(isolate); | 1683 i::HandleScope scope(isolate); |
| 1634 auto cons = EnsureConstructor(isolate, this); | 1684 auto cons = EnsureConstructor(isolate, this); |
| 1635 EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetHandler"); | 1685 EnsureNotInstantiated(cons, "v8::ObjectTemplate::SetHandler"); |
| 1636 auto obj = i::Handle<i::InterceptorInfo>::cast( | 1686 auto obj = CreateInterceptorInfo( |
| 1637 isolate->factory()->NewStruct(i::INTERCEPTOR_INFO_TYPE)); | 1687 isolate, config.getter, config.setter, config.query, config.deleter, |
| 1638 obj->set_flags(0); | 1688 config.enumerator, config.data, config.flags); |
| 1639 | |
| 1640 if (config.getter != 0) SET_FIELD_WRAPPED(obj, set_getter, config.getter); | |
| 1641 if (config.setter != 0) SET_FIELD_WRAPPED(obj, set_setter, config.setter); | |
| 1642 if (config.query != 0) SET_FIELD_WRAPPED(obj, set_query, config.query); | |
| 1643 if (config.deleter != 0) SET_FIELD_WRAPPED(obj, set_deleter, config.deleter); | |
| 1644 if (config.enumerator != 0) { | |
| 1645 SET_FIELD_WRAPPED(obj, set_enumerator, config.enumerator); | |
| 1646 } | |
| 1647 obj->set_all_can_read(static_cast<int>(config.flags) & | |
| 1648 static_cast<int>(PropertyHandlerFlags::kAllCanRead)); | |
| 1649 | |
| 1650 v8::Local<v8::Value> data = config.data; | |
| 1651 if (data.IsEmpty()) { | |
| 1652 data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); | |
| 1653 } | |
| 1654 obj->set_data(*Utils::OpenHandle(*data)); | |
| 1655 cons->set_indexed_property_handler(*obj); | 1689 cons->set_indexed_property_handler(*obj); |
| 1656 } | 1690 } |
| 1657 | 1691 |
| 1658 | 1692 |
| 1659 void ObjectTemplate::SetCallAsFunctionHandler(FunctionCallback callback, | 1693 void ObjectTemplate::SetCallAsFunctionHandler(FunctionCallback callback, |
| 1660 Local<Value> data) { | 1694 Local<Value> data) { |
| 1661 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 1695 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
| 1662 ENTER_V8(isolate); | 1696 ENTER_V8(isolate); |
| 1663 i::HandleScope scope(isolate); | 1697 i::HandleScope scope(isolate); |
| 1664 auto cons = EnsureConstructor(isolate, this); | 1698 auto cons = EnsureConstructor(isolate, this); |
| (...skipping 7213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8878 Address callback_address = | 8912 Address callback_address = |
| 8879 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8913 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
| 8880 VMState<EXTERNAL> state(isolate); | 8914 VMState<EXTERNAL> state(isolate); |
| 8881 ExternalCallbackScope call_scope(isolate, callback_address); | 8915 ExternalCallbackScope call_scope(isolate, callback_address); |
| 8882 callback(info); | 8916 callback(info); |
| 8883 } | 8917 } |
| 8884 | 8918 |
| 8885 | 8919 |
| 8886 } // namespace internal | 8920 } // namespace internal |
| 8887 } // namespace v8 | 8921 } // namespace v8 |
| OLD | NEW |