Commit c8d9294a authored by Marina Sakai's avatar Marina Sakai Committed by Commit Bot

Remove a macro-generated function for a private property of MessageEvent and...

Remove a macro-generated function for a private property of MessageEvent and all the macros in v8_private_property.h

This CL removes a macro-generated function for a private property of MessageEvent, and replaces it with the new API GetSymbol, which uses an instance address of V8PrivateProperty::SymbolKey as a key to get Symbol.

Now we can remove all the macros in v8_private_property.h.

Bug: 715418
Change-Id: Id4ce8e9cc45deea7e9e8bf2064bc44b8559cc0be
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1899227Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Marina Sakai <marinasakai@google.com>
Cr-Commit-Position: refs/heads/master@{#713286}
parent 51331fc7
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
#include "third_party/blink/renderer/bindings/modules/v8/v8_extendable_message_event.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_extendable_message_event.h"
#include "third_party/blink/renderer/bindings/modules/v8/v8_extendable_message_event_init.h" #include "third_party/blink/renderer/bindings/modules/v8/v8_extendable_message_event_init.h"
#include "third_party/blink/renderer/core/events/message_event.h"
#include "third_party/blink/renderer/platform/bindings/exception_messages.h" #include "third_party/blink/renderer/platform/bindings/exception_messages.h"
#include "third_party/blink/renderer/platform/bindings/v8_private_property.h"
namespace blink { namespace blink {
...@@ -49,7 +49,9 @@ void V8ExtendableMessageEvent::ConstructorCustom( ...@@ -49,7 +49,9 @@ void V8ExtendableMessageEvent::ConstructorCustom(
// |data| as a private value to avoid cyclic references. // |data| as a private value to avoid cyclic references.
if (event_init_dict->hasData()) { if (event_init_dict->hasData()) {
v8::Local<v8::Value> v8_data = event_init_dict->data().V8Value(); v8::Local<v8::Value> v8_data = event_init_dict->data().V8Value();
V8PrivateProperty::GetMessageEventCachedData(isolate).Set(wrapper, v8_data); V8PrivateProperty::GetSymbol(isolate,
kPrivatePropertyMessageEventCachedData)
.Set(wrapper, v8_data);
if (DOMWrapperWorld::Current(isolate).IsIsolatedWorld()) { if (DOMWrapperWorld::Current(isolate).IsIsolatedWorld()) {
impl->SetSerializedData( impl->SetSerializedData(
SerializedScriptValue::SerializeAndSwallowExceptions(isolate, SerializedScriptValue::SerializeAndSwallowExceptions(isolate,
...@@ -64,8 +66,8 @@ void V8ExtendableMessageEvent::DataAttributeGetterCustom( ...@@ -64,8 +66,8 @@ void V8ExtendableMessageEvent::DataAttributeGetterCustom(
ExtendableMessageEvent* event = ExtendableMessageEvent* event =
V8ExtendableMessageEvent::ToImpl(info.Holder()); V8ExtendableMessageEvent::ToImpl(info.Holder());
v8::Isolate* isolate = info.GetIsolate(); v8::Isolate* isolate = info.GetIsolate();
auto private_cached_data = auto private_cached_data = V8PrivateProperty::GetSymbol(
V8PrivateProperty::GetMessageEventCachedData(isolate); isolate, kPrivatePropertyMessageEventCachedData);
v8::Local<v8::Value> result; v8::Local<v8::Value> result;
if (private_cached_data.GetOrUndefined(info.Holder()).ToLocal(&result) && if (private_cached_data.GetOrUndefined(info.Holder()).ToLocal(&result) &&
!result->IsUndefined()) { !result->IsUndefined()) {
......
...@@ -34,10 +34,12 @@ ...@@ -34,10 +34,12 @@
#include "third_party/blink/renderer/core/frame/user_activation.h" #include "third_party/blink/renderer/core/frame/user_activation.h"
#include "third_party/blink/renderer/core/html/portal/html_portal_element.h" #include "third_party/blink/renderer/core/html/portal/html_portal_element.h"
#include "third_party/blink/renderer/platform/bindings/exception_state.h" #include "third_party/blink/renderer/platform/bindings/exception_state.h"
#include "third_party/blink/renderer/platform/bindings/v8_private_property.h"
namespace blink { namespace blink {
// extern
const V8PrivateProperty::SymbolKey kPrivatePropertyMessageEventCachedData;
static inline bool IsValidSource(EventTarget* source) { static inline bool IsValidSource(EventTarget* source) {
return !source || source->ToDOMWindow() || source->ToMessagePort() || return !source || source->ToDOMWindow() || source->ToMessagePort() ||
source->ToServiceWorker() || source->ToPortalHost() || source->ToServiceWorker() || source->ToPortalHost() ||
...@@ -358,14 +360,16 @@ v8::Local<v8::Object> MessageEvent::AssociateWithWrapper( ...@@ -358,14 +360,16 @@ v8::Local<v8::Object> MessageEvent::AssociateWithWrapper(
case kDataTypeSerializedScriptValue: case kDataTypeSerializedScriptValue:
break; break;
case kDataTypeString: case kDataTypeString:
V8PrivateProperty::GetMessageEventCachedData(isolate).Set( V8PrivateProperty::GetSymbol(isolate,
wrapper, V8String(isolate, data_as_string_.data())); kPrivatePropertyMessageEventCachedData)
.Set(wrapper, V8String(isolate, data_as_string_.data()));
break; break;
case kDataTypeBlob: case kDataTypeBlob:
break; break;
case kDataTypeArrayBuffer: case kDataTypeArrayBuffer:
V8PrivateProperty::GetMessageEventCachedData(isolate).Set( V8PrivateProperty::GetSymbol(isolate,
wrapper, ToV8(data_as_array_buffer_, wrapper, isolate)); kPrivatePropertyMessageEventCachedData)
.Set(wrapper, ToV8(data_as_array_buffer_, wrapper, isolate));
break; break;
} }
......
...@@ -41,6 +41,7 @@ ...@@ -41,6 +41,7 @@
#include "third_party/blink/renderer/core/fileapi/blob.h" #include "third_party/blink/renderer/core/fileapi/blob.h"
#include "third_party/blink/renderer/core/messaging/message_port.h" #include "third_party/blink/renderer/core/messaging/message_port.h"
#include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h" #include "third_party/blink/renderer/core/typed_arrays/dom_array_buffer.h"
#include "third_party/blink/renderer/platform/bindings/v8_private_property.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h" #include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
namespace blink { namespace blink {
...@@ -243,6 +244,9 @@ class CORE_EXPORT MessageEvent final : public Event { ...@@ -243,6 +244,9 @@ class CORE_EXPORT MessageEvent final : public Event {
bool allow_autoplay_ = false; bool allow_autoplay_ = false;
}; };
extern CORE_EXPORT const V8PrivateProperty::SymbolKey
kPrivatePropertyMessageEventCachedData;
} // namespace blink } // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_MESSAGE_EVENT_H_ #endif // THIRD_PARTY_BLINK_RENDERER_CORE_EVENTS_MESSAGE_EVENT_H_
...@@ -20,29 +20,16 @@ namespace blink { ...@@ -20,29 +20,16 @@ namespace blink {
class ScriptWrappable; class ScriptWrappable;
// TODO(peria): Remove properties just to keep V8 objects alive. // Provides access to V8's private properties with a symbol key.
// e.g. IDBCursor.Request.
// Apply |X| for each pair of (InterfaceName, PrivateKeyName).
#define V8_PRIVATE_PROPERTY_FOR_EACH(X) \
X(MessageEvent, CachedData) \
// The getter's name for a private property.
#define V8_PRIVATE_PROPERTY_GETTER_NAME(InterfaceName, PrivateKeyName) \
Get##InterfaceName##PrivateKeyName
// Provides access to V8's private properties.
// //
// Usage 1) Path to use a pre-registered symbol. // static const V8PrivateProperty::SymbolKey kPrivateProperty;
// auto private_property = V8PrivateProperty::GetDOMExceptionError(isolate); // auto private_property = V8PrivateProperty::GetSymbol(
// isolate, kPrivateProperty);
// v8::Local<v8::Object> object = ...; // v8::Local<v8::Object> object = ...;
// v8::Local<v8::Value> value; // v8::Local<v8::Value> value;
// if (!private_property.GetOrUndefined(object).ToLocal(&value)) return; // if (!private_property.GetOrUndefined(object).ToLocal(&value)) return;
// value = ...; // value = ...;
// private_property.Set(object, value); // private_property.Set(object, value);
//
// Usage 2) Access with a symbol key.
// static const SymbolKey key;
// auto private_property = V8PrivateProperty::GetSymbol(isolate, key);
// ... // ...
class PLATFORM_EXPORT V8PrivateProperty { class PLATFORM_EXPORT V8PrivateProperty {
USING_FAST_MALLOC(V8PrivateProperty); USING_FAST_MALLOC(V8PrivateProperty);
...@@ -121,17 +108,6 @@ class PLATFORM_EXPORT V8PrivateProperty { ...@@ -121,17 +108,6 @@ class PLATFORM_EXPORT V8PrivateProperty {
SymbolKey& operator=(const SymbolKey&) = delete; SymbolKey& operator=(const SymbolKey&) = delete;
}; };
#define V8_PRIVATE_PROPERTY_DEFINE_GETTER(InterfaceName, KeyName) \
static Symbol V8_PRIVATE_PROPERTY_GETTER_NAME(/* // NOLINT */ \
InterfaceName, KeyName)( \
v8::Isolate * isolate) { \
static const SymbolKey private_property_key; \
return GetSymbol(isolate, private_property_key); \
}
V8_PRIVATE_PROPERTY_FOR_EACH(V8_PRIVATE_PROPERTY_DEFINE_GETTER)
#undef V8_PRIVATE_PROPERTY_DEFINE_GETTER
// TODO(peria): Do not use this specialized hack. See a TODO comment // TODO(peria): Do not use this specialized hack. See a TODO comment
// on m_symbolWindowDocumentCachedAccessor. // on m_symbolWindowDocumentCachedAccessor.
static Symbol GetWindowDocumentCachedAccessor(v8::Isolate* isolate); static Symbol GetWindowDocumentCachedAccessor(v8::Isolate* isolate);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment