Skip to content

Commit

Permalink
binding: Makes [SaveSameObject] use V8PrivateProperty.
Browse files Browse the repository at this point in the history
Migrates from V8HiddenValue to V8PrivateProperty in [SaveSameObject]
implementation.

BUG=

Review-Url: https://codereview.chromium.org/2022013002
Cr-Commit-Position: refs/heads/master@{#396815}
  • Loading branch information
yuki3 authored and Commit bot committed May 31, 2016
1 parent 3b5a4e4 commit 29d1fbe
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
10 changes: 7 additions & 3 deletions third_party/WebKit/Source/bindings/scripts/v8_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ def attribute_context(interface, attribute):
# [PerWorldBindings]
if 'PerWorldBindings' in extended_attributes:
assert idl_type.is_wrapper_type or 'LogActivity' in extended_attributes, '[PerWorldBindings] should only be used with wrapper types: %s.%s' % (interface.name, attribute.name)
# [SaveSameObject]
is_save_same_object = (
'SameObject' in attribute.extended_attributes and
'SaveSameObject' in attribute.extended_attributes)
if is_save_same_object:
includes.add('bindings/core/v8/V8PrivateProperty.h')

if (base_idl_type == 'EventHandler' and
interface.name in ['Window', 'WorkerGlobalScope'] and
Expand Down Expand Up @@ -135,9 +141,7 @@ def attribute_context(interface, attribute):
'is_read_only': attribute.is_read_only,
'is_reflect': is_reflect,
'is_replaceable': 'Replaceable' in attribute.extended_attributes,
'is_save_same_object': (
'SameObject' in attribute.extended_attributes and
'SaveSameObject' in attribute.extended_attributes),
'is_save_same_object': is_save_same_object,
'is_static': attribute.is_static,
'is_url': 'URL' in extended_attributes,
'is_unforgeable': is_unforgeable(interface, attribute),
Expand Down
12 changes: 9 additions & 3 deletions third_party/WebKit/Source/bindings/templates/attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,15 @@ const v8::FunctionCallbackInfo<v8::Value>& info
{% endif %}
{# impl #}
{% if attribute.is_save_same_object %}
v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "sameobject_{{attribute.name}}");
{% set same_object_private_symbol = 'SameObject' + interface_name + attribute.name[0]|capitalize + attribute.name[1:] %}
// If you see a compile error that
// V8PrivateProperty::get{{same_object_private_symbol}}
// is not defined, then you need to register your attribute at
// V8_PRIVATE_PROPERTY_FOR_EACH defined in V8PrivateProperty.h as
// X(SameObject, {{interface_name}}{{attribute.name[0]|capitalize}}{{attribute.name[1:]}})
auto privateSameObject = V8PrivateProperty::getSameObject{{interface_name}}{{attribute.name[0]|capitalize}}{{attribute.name[1:]}}(info.GetIsolate());
{
v8::Local<v8::Value> v8Value = V8HiddenValue::getHiddenValue(ScriptState::current(info.GetIsolate()), holder, propertyName);
v8::Local<v8::Value> v8Value = privateSameObject.get(info.GetIsolate()->GetCurrentContext(), holder);
if (!v8Value.IsEmpty()) {
v8SetReturnValue(info, v8Value);
return;
Expand Down Expand Up @@ -134,7 +140,7 @@ const v8::FunctionCallbackInfo<v8::Value>& info
{{attribute.v8_set_return_value}};
{% endif %}
{% if attribute.is_save_same_object %}
V8HiddenValue::setHiddenValue(ScriptState::current(info.GetIsolate()), holder, propertyName, info.GetReturnValue().Get());
privateSameObject.set(info.GetIsolate()->GetCurrentContext(), holder, info.GetReturnValue().Get());
{% endif %}
}
{% endmacro %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "bindings/core/v8/V8Node.h"
#include "bindings/core/v8/V8NodeFilter.h"
#include "bindings/core/v8/V8ObjectConstructor.h"
#include "bindings/core/v8/V8PrivateProperty.h"
#include "bindings/core/v8/V8ShadowRoot.h"
#include "bindings/core/v8/V8TestCallbackInterface.h"
#include "bindings/core/v8/V8TestDictionary.h"
Expand Down Expand Up @@ -4539,9 +4540,14 @@ static void sameObjectAttributeAttributeGetterCallback(const v8::FunctionCallbac
static void saveSameObjectAttributeAttributeGetter(const v8::FunctionCallbackInfo<v8::Value>& info)
{
v8::Local<v8::Object> holder = info.Holder();
v8::Local<v8::String> propertyName = v8AtomicString(info.GetIsolate(), "sameobject_saveSameObjectAttribute");
// If you see a compile error that
// V8PrivateProperty::getSameObjectTestObjectSaveSameObjectAttribute
// is not defined, then you need to register your attribute at
// V8_PRIVATE_PROPERTY_FOR_EACH defined in V8PrivateProperty.h as
// X(SameObject, TestObjectSaveSameObjectAttribute)
auto privateSameObject = V8PrivateProperty::getSameObjectTestObjectSaveSameObjectAttribute(info.GetIsolate());
{
v8::Local<v8::Value> v8Value = V8HiddenValue::getHiddenValue(ScriptState::current(info.GetIsolate()), holder, propertyName);
v8::Local<v8::Value> v8Value = privateSameObject.get(info.GetIsolate()->GetCurrentContext(), holder);
if (!v8Value.IsEmpty()) {
v8SetReturnValue(info, v8Value);
return;
Expand All @@ -4556,7 +4562,7 @@ static void saveSameObjectAttributeAttributeGetter(const v8::FunctionCallbackInf
V8HiddenValue::setHiddenValue(ScriptState::current(info.GetIsolate()), holder, v8AtomicString(info.GetIsolate(), "saveSameObjectAttribute"), v8Value);
v8SetReturnValue(info, v8Value);
}
V8HiddenValue::setHiddenValue(ScriptState::current(info.GetIsolate()), holder, propertyName, info.GetReturnValue().Get());
privateSameObject.set(info.GetIsolate()->GetCurrentContext(), holder, info.GetReturnValue().Get());
}

static void saveSameObjectAttributeAttributeGetterCallback(const v8::FunctionCallbackInfo<v8::Value>& info)
Expand Down

0 comments on commit 29d1fbe

Please sign in to comment.