Index: bindings/scripts/v8_attributes.py |
diff --git a/bindings/scripts/v8_attributes.py b/bindings/scripts/v8_attributes.py |
index 6dcb2d5aa471a3c3457d76df3c367d0403b8dcd1..bb61ef9c648598eea08c526ff3041e1baf71216d 100644 |
--- a/bindings/scripts/v8_attributes.py |
+++ b/bindings/scripts/v8_attributes.py |
@@ -41,7 +41,7 @@ import v8_utilities |
from v8_utilities import capitalize, cpp_name, has_extended_attribute, has_extended_attribute_value, scoped_name, strip_suffix, uncapitalize |
-def generate_attribute(interface, attribute): |
+def attribute_context(interface, attribute): |
idl_type = attribute.idl_type |
base_idl_type = idl_type.base_type |
extended_attributes = attribute.extended_attributes |
@@ -52,12 +52,6 @@ def generate_attribute(interface, attribute): |
is_check_security_for_node = 'CheckSecurity' in extended_attributes |
if is_check_security_for_node: |
includes.add('bindings/common/BindingSecurity.h') |
- # [Custom] |
- has_custom_getter = ('Custom' in extended_attributes and |
- extended_attributes['Custom'] in [None, 'Getter']) |
- has_custom_setter = (not attribute.is_read_only and |
- 'Custom' in extended_attributes and |
- extended_attributes['Custom'] in [None, 'Setter']) |
# [CustomElementCallbacks], [Reflect] |
is_custom_element_callbacks = 'CustomElementCallbacks' in extended_attributes |
is_reflect = 'Reflect' in extended_attributes |
@@ -66,53 +60,45 @@ def generate_attribute(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) |
- # [RaisesException], [RaisesException=Setter] |
- is_setter_raises_exception = ( |
- 'RaisesException' in extended_attributes and |
- extended_attributes['RaisesException'] in [None, 'Setter']) |
# [TypeChecking] |
- has_type_checking_interface = ( |
- (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or |
- has_extended_attribute_value(attribute, 'TypeChecking', 'Interface')) and |
- idl_type.is_wrapper_type) |
- has_type_checking_nullable = ( |
- (has_extended_attribute_value(interface, 'TypeChecking', 'Nullable') or |
- has_extended_attribute_value(attribute, 'TypeChecking', 'Nullable')) and |
- idl_type.is_wrapper_type) |
has_type_checking_unrestricted = ( |
(has_extended_attribute_value(interface, 'TypeChecking', 'Unrestricted') or |
has_extended_attribute_value(attribute, 'TypeChecking', 'Unrestricted')) and |
idl_type.name in ('Float', 'Double')) |
+ # [ImplementedInPrivateScript] |
+ is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_attributes |
+ if is_implemented_in_private_script: |
+ includes.add('bindings/core/v8/PrivateScriptRunner.h') |
+ includes.add('core/frame/LocalFrame.h') |
+ includes.add('platform/ScriptForbiddenScope.h') |
+ |
+ # [OnlyExposedToPrivateScript] |
+ is_only_exposed_to_private_script = 'OnlyExposedToPrivateScript' in extended_attributes |
if (base_idl_type == 'EventHandler' and |
interface.name in ['Window', 'WorkerGlobalScope'] and |
attribute.name == 'onerror'): |
- includes.add('bindings/v8/V8ErrorHandler.h') |
+ includes.add('bindings/core/v8/V8ErrorHandler.h') |
- contents = { |
+ context = { |
'access_control_list': access_control_list(attribute), |
'activity_logging_world_list_for_getter': v8_utilities.activity_logging_world_list(attribute, 'Getter'), # [ActivityLogging] |
'activity_logging_world_list_for_setter': v8_utilities.activity_logging_world_list(attribute, 'Setter'), # [ActivityLogging] |
'activity_logging_include_old_value_for_setter': 'LogPreviousValue' in extended_attributes, # [ActivityLogging] |
'activity_logging_world_check': v8_utilities.activity_logging_world_check(attribute), # [ActivityLogging] |
+ 'argument_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
'cached_attribute_validation_method': extended_attributes.get('CachedAttribute'), |
'conditional_string': v8_utilities.conditional_string(attribute), |
'constructor_type': idl_type.constructor_type_name |
if is_constructor_attribute(attribute) else None, |
'cpp_name': cpp_name(attribute), |
'cpp_type': idl_type.cpp_type, |
- 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value(cpp_value='original', creation_context='info.Holder()'), |
+ 'cpp_type_initializer': idl_type.cpp_type_initializer, |
'deprecate_as': v8_utilities.deprecate_as(attribute), # [DeprecateAs] |
'enum_validation_expression': idl_type.enum_validation_expression, |
- 'has_custom_getter': has_custom_getter, |
- 'has_custom_setter': has_custom_setter, |
- 'has_setter_exception_state': |
- is_setter_raises_exception or has_type_checking_interface or |
- has_type_checking_nullable or has_type_checking_unrestricted or |
- idl_type.is_integer_type or |
- idl_type.name in ('ByteString', 'ScalarValueString'), |
- 'has_type_checking_interface': has_type_checking_interface, |
- 'has_type_checking_nullable': has_type_checking_nullable, |
+ 'exposed_test': v8_utilities.exposed(attribute, interface), # [Exposed] |
+ 'has_custom_getter': has_custom_getter(attribute), |
+ 'has_custom_setter': has_custom_setter(attribute), |
'has_type_checking_unrestricted': has_type_checking_unrestricted, |
'idl_type': str(idl_type), # need trailing [] on array for Dictionary::ConversionContext::setConversionType |
'is_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'CallWith', 'ExecutionContext'), |
@@ -123,24 +109,27 @@ def generate_attribute(interface, attribute): |
'is_getter_raises_exception': # [RaisesException] |
'RaisesException' in extended_attributes and |
extended_attributes['RaisesException'] in (None, 'Getter'), |
+ 'is_implemented_in_private_script': is_implemented_in_private_script, |
'is_initialized_by_event_constructor': |
'InitializedByEventConstructor' in extended_attributes, |
'is_keep_alive_for_gc': is_keep_alive_for_gc(interface, attribute), |
- 'is_nullable': attribute.idl_type.is_nullable, |
+ 'is_nullable': idl_type.is_nullable, |
+ 'is_explicit_nullable': idl_type.is_explicit_nullable, |
'is_partial_interface_member': |
'PartialInterfaceImplementedAs' in extended_attributes, |
'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, |
'is_read_only': attribute.is_read_only, |
'is_reflect': is_reflect, |
'is_replaceable': 'Replaceable' in attribute.extended_attributes, |
- 'is_setter_call_with_execution_context': v8_utilities.has_extended_attribute_value(attribute, 'SetterCallWith', 'ExecutionContext'), |
- 'is_setter_raises_exception': is_setter_raises_exception, |
'is_static': attribute.is_static, |
'is_url': 'URL' in extended_attributes, |
'is_unforgeable': 'Unforgeable' in extended_attributes, |
'measure_as': v8_utilities.measure_as(attribute), # [MeasureAs] |
'name': attribute.name, |
+ 'only_exposed_to_private_script': is_only_exposed_to_private_script, |
'per_context_enabled_function': v8_utilities.per_context_enabled_function_name(attribute), # [PerContextEnabled] |
+ 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( |
+ extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->isolate()', used_in_private_script=True), |
'property_attributes': property_attributes(attribute), |
'put_forwards': 'PutForwards' in extended_attributes, |
'reflect_empty': extended_attributes.get('ReflectEmpty'), |
@@ -148,36 +137,36 @@ def generate_attribute(interface, attribute): |
'reflect_missing': extended_attributes.get('ReflectMissing'), |
'reflect_only': extended_attributes['ReflectOnly'].split('|') |
if 'ReflectOnly' in extended_attributes else None, |
- 'setter_callback': setter_callback_name(interface, attribute), |
- 'v8_type': v8_types.v8_type(base_idl_type), |
'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(attribute), # [RuntimeEnabled] |
+ 'setter_callback': setter_callback_name(interface, attribute), |
+ 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script), |
'world_suffixes': ['', 'ForMainWorld'] |
if 'PerWorldBindings' in extended_attributes |
else [''], # [PerWorldBindings] |
} |
if is_constructor_attribute(attribute): |
- generate_constructor_getter(interface, attribute, contents) |
- return contents |
- if not has_custom_getter: |
- generate_getter(interface, attribute, contents) |
- if (not has_custom_setter and |
+ constructor_getter_context(interface, attribute, context) |
+ return context |
+ if not has_custom_getter(attribute): |
+ getter_context(interface, attribute, context) |
+ if (not has_custom_setter(attribute) and |
(not attribute.is_read_only or 'PutForwards' in extended_attributes)): |
- generate_setter(interface, attribute, contents) |
+ setter_context(interface, attribute, context) |
- return contents |
+ return context |
################################################################################ |
# Getter |
################################################################################ |
-def generate_getter(interface, attribute, contents): |
+def getter_context(interface, attribute, context): |
idl_type = attribute.idl_type |
base_idl_type = idl_type.base_type |
extended_attributes = attribute.extended_attributes |
- cpp_value = getter_expression(interface, attribute, contents) |
+ cpp_value = getter_expression(interface, attribute, context) |
# Normally we can inline the function call into the return statement to |
# avoid the overhead of using a Ref<> temporary, but for some cases |
# (nullable types, EventHandler, [CachedAttribute], or if there are |
@@ -185,46 +174,65 @@ def generate_getter(interface, attribute, contents): |
# FIXME: check if compilers are smart enough to inline this, and if so, |
# always use a local variable (for readability and CG simplicity). |
release = False |
- if (idl_type.is_nullable or |
+ if 'ImplementedInPrivateScript' in extended_attributes: |
+ if (not idl_type.is_wrapper_type and |
+ not idl_type.is_basic_type): |
+ raise Exception('Private scripts supports only primitive types and DOM wrappers.') |
+ |
+ context['cpp_value_original'] = cpp_value |
+ cpp_value = 'result' |
+ # EventHandler has special handling |
+ if base_idl_type != 'EventHandler': |
+ release = idl_type.release |
+ elif (idl_type.is_explicit_nullable or |
base_idl_type == 'EventHandler' or |
'CachedAttribute' in extended_attributes or |
+ 'LogPreviousValue' in extended_attributes or |
'ReflectOnly' in extended_attributes or |
- contents['is_getter_raises_exception']): |
- contents['cpp_value_original'] = cpp_value |
- cpp_value = 'v8Value' |
+ context['is_keep_alive_for_gc'] or |
+ context['is_getter_raises_exception']): |
+ context['cpp_value_original'] = cpp_value |
+ cpp_value = 'cppValue' |
# EventHandler has special handling |
- if base_idl_type != 'EventHandler' and idl_type.is_interface_type: |
- release = True |
+ if base_idl_type != 'EventHandler': |
+ release = idl_type.release |
def v8_set_return_value_statement(for_main_world=False): |
- if contents['is_keep_alive_for_gc']: |
+ if context['is_keep_alive_for_gc']: |
return 'v8SetReturnValue(info, wrapper)' |
return idl_type.v8_set_return_value(cpp_value, extended_attributes=extended_attributes, script_wrappable='impl', release=release, for_main_world=for_main_world) |
- contents.update({ |
+ context.update({ |
'cpp_value': cpp_value, |
- 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value(cpp_value=cpp_value, creation_context='info.Holder()'), |
+ 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
+ cpp_value=cpp_value, creation_context='info.Holder()', |
+ extended_attributes=extended_attributes), |
'v8_set_return_value_for_main_world': v8_set_return_value_statement(for_main_world=True), |
'v8_set_return_value': v8_set_return_value_statement(), |
}) |
-def getter_expression(interface, attribute, contents): |
+def getter_expression(interface, attribute, context): |
arguments = [] |
this_getter_base_name = getter_base_name(interface, attribute, arguments) |
getter_name = scoped_name(interface, attribute, this_getter_base_name) |
+ if 'ImplementedInPrivateScript' in attribute.extended_attributes: |
+ arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrentContext())') |
+ arguments.append('impl') |
+ arguments.append('&result') |
arguments.extend(v8_utilities.call_with_arguments( |
attribute.extended_attributes.get('CallWith'))) |
# Members of IDL partial interface definitions are implemented in C++ as |
# static member functions, which for instance members (non-static members) |
# take *impl as their first argument |
if ('PartialInterfaceImplementedAs' in attribute.extended_attributes and |
+ not 'ImplementedInPrivateScript' in attribute.extended_attributes and |
not attribute.is_static): |
arguments.append('*impl') |
- if attribute.idl_type.is_nullable and not contents['has_type_checking_nullable']: |
+ if attribute.idl_type.is_explicit_nullable: |
arguments.append('isNull') |
- if contents['is_getter_raises_exception']: |
+ if context['is_getter_raises_exception']: |
arguments.append('exceptionState') |
return '%s(%s)' % (getter_name, ', '.join(arguments)) |
@@ -238,6 +246,10 @@ CONTENT_ATTRIBUTE_GETTER_NAMES = { |
def getter_base_name(interface, attribute, arguments): |
extended_attributes = attribute.extended_attributes |
+ |
+ if 'ImplementedInPrivateScript' in extended_attributes: |
+ return '%sAttributeGetter' % uncapitalize(cpp_name(attribute)) |
+ |
if 'Reflect' not in extended_attributes: |
return uncapitalize(cpp_name(attribute)) |
@@ -282,33 +294,56 @@ def is_keep_alive_for_gc(interface, attribute): |
# Setter |
################################################################################ |
-def generate_setter(interface, attribute, contents): |
- def target_attribute(): |
+def setter_context(interface, attribute, context): |
+ if 'PutForwards' in attribute.extended_attributes: |
+ # Use target interface and attribute in place of original interface and |
+ # attribute from this point onwards. |
target_interface_name = attribute.idl_type.base_type |
- target_attribute_name = extended_attributes['PutForwards'] |
- target_interface = interfaces[target_interface_name] |
+ target_attribute_name = attribute.extended_attributes['PutForwards'] |
+ interface = interfaces[target_interface_name] |
try: |
- return next(attribute |
- for attribute in target_interface.attributes |
- if attribute.name == target_attribute_name) |
+ attribute = next(candidate |
+ for candidate in interface.attributes |
+ if candidate.name == target_attribute_name) |
except StopIteration: |
raise Exception('[PutForward] target not found:\n' |
'Attribute "%s" is not present in interface "%s"' % |
(target_attribute_name, target_interface_name)) |
extended_attributes = attribute.extended_attributes |
+ idl_type = attribute.idl_type |
- if 'PutForwards' in extended_attributes: |
- # Use target attribute in place of original attribute |
- attribute = target_attribute() |
+ # [RaisesException], [RaisesException=Setter] |
+ is_setter_raises_exception = ( |
+ 'RaisesException' in extended_attributes and |
+ extended_attributes['RaisesException'] in [None, 'Setter']) |
+ # [TypeChecking=Interface] |
+ has_type_checking_interface = ( |
+ (has_extended_attribute_value(interface, 'TypeChecking', 'Interface') or |
+ has_extended_attribute_value(attribute, 'TypeChecking', 'Interface')) and |
+ idl_type.is_wrapper_type) |
- contents.update({ |
- 'cpp_setter': setter_expression(interface, attribute, contents), |
- 'v8_value_to_local_cpp_value': attribute.idl_type.v8_value_to_local_cpp_value(extended_attributes, 'v8Value', 'cppValue'), |
+ context.update({ |
+ 'has_setter_exception_state': |
+ is_setter_raises_exception or has_type_checking_interface or |
+ context['has_type_checking_unrestricted'] or |
+ idl_type.may_raise_exception_on_conversion, |
+ 'has_type_checking_interface': has_type_checking_interface, |
+ 'is_setter_call_with_execution_context': v8_utilities.has_extended_attribute_value( |
+ attribute, 'SetterCallWith', 'ExecutionContext'), |
+ 'is_setter_raises_exception': is_setter_raises_exception, |
+ 'private_script_cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
+ 'cppValue', isolate='scriptState->isolate()', |
+ creation_context='scriptState->context()->Global()'), |
+ 'v8_value_to_local_cpp_value': idl_type.v8_value_to_local_cpp_value( |
+ extended_attributes, 'v8Value', 'cppValue'), |
}) |
+ # setter_expression() depends on context values we set above. |
+ context['cpp_setter'] = setter_expression(interface, attribute, context) |
+ |
-def setter_expression(interface, attribute, contents): |
+def setter_expression(interface, attribute, context): |
extended_attributes = attribute.extended_attributes |
arguments = v8_utilities.call_with_arguments( |
extended_attributes.get('SetterCallWith') or |
@@ -321,25 +356,30 @@ def setter_expression(interface, attribute, contents): |
# static member functions, which for instance members (non-static members) |
# take *impl as their first argument |
if ('PartialInterfaceImplementedAs' in extended_attributes and |
+ not 'ImplementedInPrivateScript' in extended_attributes and |
not attribute.is_static): |
arguments.append('*impl') |
idl_type = attribute.idl_type |
- if idl_type.base_type == 'EventHandler': |
+ if 'ImplementedInPrivateScript' in extended_attributes: |
+ arguments.append('toFrameIfNotDetached(info.GetIsolate()->GetCurrentContext())') |
+ arguments.append('impl') |
+ arguments.append('cppValue') |
+ elif idl_type.base_type == 'EventHandler': |
getter_name = scoped_name(interface, attribute, cpp_name(attribute)) |
- contents['event_handler_getter_expression'] = '%s(%s)' % ( |
+ context['event_handler_getter_expression'] = '%s(%s)' % ( |
getter_name, ', '.join(arguments)) |
if (interface.name in ['Window', 'WorkerGlobalScope'] and |
attribute.name == 'onerror'): |
- includes.add('bindings/v8/V8ErrorHandler.h') |
+ includes.add('bindings/core/v8/V8ErrorHandler.h') |
arguments.append('V8EventListenerList::findOrCreateWrapper<V8ErrorHandler>(v8Value, true, V8ScriptState::current(info.GetIsolate()))') |
else: |
arguments.append('V8EventListenerList::getEventListener(V8ScriptState::current(info.GetIsolate()), v8Value, true, ListenerFindOrCreate)') |
- elif idl_type.is_interface_type and not idl_type.array_type: |
+ elif idl_type.is_interface_type: |
# FIXME: should be able to eliminate WTF::getPtr in most or all cases |
arguments.append('WTF::getPtr(cppValue)') |
else: |
arguments.append('cppValue') |
- if contents['is_setter_raises_exception']: |
+ if context['is_setter_raises_exception']: |
arguments.append('exceptionState') |
return '%s(%s)' % (setter_name, ', '.join(arguments)) |
@@ -353,6 +393,9 @@ CONTENT_ATTRIBUTE_SETTER_NAMES = { |
def setter_base_name(interface, attribute, arguments): |
+ if 'ImplementedInPrivateScript' in attribute.extended_attributes: |
+ return '%sAttributeSetter' % uncapitalize(cpp_name(attribute)) |
+ |
if 'Reflect' not in attribute.extended_attributes: |
return 'set%s' % capitalize(cpp_name(attribute)) |
arguments.append(scoped_content_attribute_name(interface, attribute)) |
@@ -365,8 +408,17 @@ def setter_base_name(interface, attribute, arguments): |
def scoped_content_attribute_name(interface, attribute): |
content_attribute_name = attribute.extended_attributes['Reflect'] or attribute.name.lower() |
- namespace = 'SVGNames' if interface.name.startswith('SVG') else 'HTMLNames' |
- includes.add('%s.h' % namespace) |
+ if interface.name.startswith('SVG'): |
+ # SVG's xmlbase/xmlspace/xmllang need special behavior, i.e. |
+ # it is in XMLNames namespace and the generated attribute has no xml prefix. |
+ if attribute.name.startswith('xml'): |
+ namespace = 'XMLNames' |
+ content_attribute_name = content_attribute_name[3:] |
+ else: |
+ namespace = 'SVGNames' |
+ else: |
+ namespace = 'HTMLNames' |
+ includes.add('core/%s.h' % namespace) |
return '%s::%sAttr' % (namespace, content_attribute_name) |
@@ -381,8 +433,7 @@ def setter_callback_name(interface, attribute): |
if (('Replaceable' in extended_attributes and |
'PutForwards' not in extended_attributes) or |
is_constructor_attribute(attribute)): |
- # FIXME: rename to ForceSetAttributeOnThisCallback, since also used for Constructors |
- return '{0}V8Internal::{0}ReplaceableAttributeSetterCallback'.format(cpp_class_name) |
+ return '{0}V8Internal::{0}ForceSetAttributeOnThisCallback'.format(cpp_class_name) |
if attribute.is_read_only and 'PutForwards' not in extended_attributes: |
return '0' |
return '%sV8Internal::%sAttributeSetterCallback' % (cpp_class_name, attribute.name) |
@@ -418,6 +469,21 @@ def property_attributes(attribute): |
return property_attributes_list or ['v8::None'] |
+# [Custom], [Custom=Getter] |
+def has_custom_getter(attribute): |
+ extended_attributes = attribute.extended_attributes |
+ return ('Custom' in extended_attributes and |
+ extended_attributes['Custom'] in [None, 'Getter']) |
+ |
+ |
+# [Custom], [Custom=Setter] |
+def has_custom_setter(attribute): |
+ extended_attributes = attribute.extended_attributes |
+ return (not attribute.is_read_only and |
+ 'Custom' in extended_attributes and |
+ extended_attributes['Custom'] in [None, 'Setter']) |
+ |
+ |
################################################################################ |
# Constructors |
################################################################################ |
@@ -429,8 +495,8 @@ idl_types.IdlType.constructor_type_name = property( |
def is_constructor_attribute(attribute): |
# FIXME: replace this with [ConstructorAttribute] extended attribute |
- return attribute.idl_type.base_type.endswith('Constructor') |
+ return attribute.idl_type.name.endswith('Constructor') |
-def generate_constructor_getter(interface, attribute, contents): |
- contents['needs_constructor_getter_callback'] = contents['measure_as'] or contents['deprecate_as'] |
+def constructor_getter_context(interface, attribute, context): |
+ context['needs_constructor_getter_callback'] = context['measure_as'] or context['deprecate_as'] |