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

Unified Diff: Source/bindings/scripts/v8_special_accessors.py

Issue 17572008: WIP IDL compiler rewrite (Closed) Base URL: https://chromium.googlesource.com/chromium/blink@master
Patch Set: Branch: const + primitive type readonly attributes Created 7 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/scripts/v8_interface_header.py ('k') | Source/bindings/scripts/v8_types.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/scripts/v8_special_accessors.py
diff --git a/Source/bindings/scripts/v8_special_accessors.py b/Source/bindings/scripts/v8_special_accessors.py
new file mode 100644
index 0000000000000000000000000000000000000000..0c153f31046955d4c486dd04f498e125282a38dd
--- /dev/null
+++ b/Source/bindings/scripts/v8_special_accessors.py
@@ -0,0 +1,360 @@
+# Copyright (C) 2013 Google Inc. All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are
+# met:
+#
+# * Redistributions of source code must retain the above copyright
+# notice, this list of conditions and the following disclaimer.
+# * Redistributions in binary form must reproduce the above
+# copyright notice, this list of conditions and the following disclaimer
+# in the documentation and/or other materials provided with the
+# distribution.
+# * Neither the name of Google Inc. nor the names of its
+# contributors may be used to endorse or promote products derived from
+# this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+# 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+from v8_types import get_is_null_expression, get_native_type, has_custom_implementation, is_union_type
+from v8_utilities import get_raises_exception, implemented_as_cpp_name
+from v8_values import get_js_value_to_native_statement, get_native_to_js_value_statement, get_pass_owner_expression
+
+
+# GenerateMethodCall in perl
+def get_function_call_statements(return_type, variable_name, function_expression, first_argument, raises_exceptions=False):
+ arguments = [first_argument]
+ if raises_exceptions:
+ arguments.append('es')
+ if is_union_type(return_type):
+ code = ''
+ for i, union_member_type in enumerate(return_type.union_member_types):
+ native_type = get_native_type(union_member_type)
+ union_member_number = i
+ union_member_variable = '%s%d' % (variable_name, union_member_number)
+ union_member_enabled_variable = '%s%dEnabled' % (variable_name, union_member_number)
+ union_member_native_value = get_pass_owner_expression(union_member_type, union_member_variable)
+ code += ' bool %s = false;\n' % union_member_enabled_variable
+ code += ' %s %s;\n' % (native_type, union_member_variable)
+ arguments.append(union_member_enabled_variable)
+ arguments.append(union_member_variable)
+ code += ' %s(%s);' % (function_expression, ', '.join(arguments))
+ return code
+ else:
+ native_type = get_native_type(return_type)
+ return ' %s %s = %s(%s);' % (native_type, variable_name, function_expression, ', '.join(arguments))
+
+
+def get_indexed_property_getter_parameter(interface):
+ cpp_class_name = implemented_as_cpp_name(interface)
+ indexed_getter_function = get_indexed_getter_operation(interface)
+ includes = []
+ callback_name = '0'
+ function_call = ''
+ return_type_is_union = ''
+ return_js_value_statement = ''
+ is_null_expression = ''
+ raises_exceptions = False
+ is_custom = False
+ not_enumerable = False
+
+ if indexed_getter_function:
+# js_to_native_statement, js_value_to_native_includes = get_js_value_to_native_statement(parameter.data_type, parameter.extended_attributes, js_value, parameter.name, 'args.GetIsolate()')
+# my $methodCallCode = GenerateMethodCall($returnType, 'element', 'collection->${methodName}', 'index', $raisesExceptions)
+# function_call_parameter, function_call_includes = get_function_call_parameter(indexed_getter_function)
+# includes += function_call_includes
+
+ is_custom = 'Custom' in indexed_getter_function.extended_attributes
+ raises_exceptions = get_raises_exception(indexed_getter_function)
+ function_call = get_function_call_statements(indexed_getter_function.data_type, 'element', 'collection->' + implemented_as_cpp_name(indexed_getter_function), 'index', raises_exceptions=raises_exceptions)
+ return_type_is_union = False
+ native_value = get_pass_owner_expression(indexed_getter_function.data_type, 'element')
+ return_js_value_statement, return_js_value_includes = get_native_to_js_value_statement(indexed_getter_function.data_type, indexed_getter_function.extended_attributes, native_value, creation_context='info.Holder()', isolate='info.GetIsolate()', callback_info='info', script_wrappable='collection', used_as_return_value=True)
+ includes += return_js_value_includes
+ is_null_expression = get_is_null_expression(indexed_getter_function.data_type, 'element')
+ callback_name = '%sV8Internal::indexedPropertyGetterCallback' % cpp_class_name
+ not_enumerable = 'NotEnumerable' in indexed_getter_function.extended_attributes
+
+ parameter = {
+ 'enabled': indexed_getter_function,
+ 'callback_name': callback_name,
+ 'is_custom': is_custom,
+ 'function_call': function_call,
+# 'function_call_parameter': function_call_parameter,
+ 'return_type_is_union': return_type_is_union,
+ 'return_js_value_statement': return_js_value_statement,
+ 'is_null_expression': is_null_expression,
+ 'raises_exceptions': raises_exceptions,
+ 'not_enumerable': not_enumerable,
+ }
+ return parameter, includes
+
+
+def get_indexed_property_setter_parameter(interface):
+ cpp_class_name = implemented_as_cpp_name(interface)
+ indexed_setter_function = get_indexed_setter_operation(interface)
+ includes = []
+ callback_name = '0'
+ is_custom = False
+ condition_and_statements = []
+ raises_exceptions = False
+ js_to_native_statement = ''
+
+ if indexed_setter_function:
+ method_name = implemented_as_cpp_name(indexed_setter_function)
+ callback_name = '%sV8Internal::indexedPropertySetterCallback' % cpp_class_name
+ is_custom = 'Custom' in indexed_setter_function.extended_attributes
+ raises_exceptions = 'RaisesException' in indexed_setter_function.extended_attributes
+ treat_null_as = indexed_setter_function.arguments[1].extended_attributes.get('TreatNullAs')
+ treat_undefined_as = indexed_setter_function.arguments[1].extended_attributes.get('TreatUndefinedAs')
+ js_value = 'value'
+ native_variable_name = 'propertyValue'
+ js_to_native_statement, js_to_native_includes = get_js_value_to_native_statement(indexed_setter_function.arguments[1].data_type, indexed_setter_function.extended_attributes, js_value, native_variable_name, 'info.GetIsolate()')
+ if not is_custom:
+ includes += js_to_native_includes
+
+ extra_arguments = []
+ if raises_exceptions:
+ extra_arguments = ['es']
+ if treat_null_as and treat_null_as != 'NullString':
+ arguments = ['index']
+ if raises_exceptions:
+ arguments += extra_arguments
+ condition_and_statements.append({'condition': 'value->IsNull()', 'statement': 'collection->%s(%s);' % (treat_null_as, ', '.join(arguments))})
+ if treat_undefined_as and treat_undefined_as != 'NullString':
+ arguments = ['index']
+ if raises_exceptions:
+ arguments += extra_arguments
+ condition_and_statements.append({'condition': 'value->IsUndefined()', 'statement': 'collection->%s(%s);' % (treat_undefined_as, ', '.join(arguments))})
+ arguments = ['index', 'propertyValue']
+ if raises_exceptions:
+ arguments += extra_arguments
+ condition_and_statements.append({'condition': '', 'statement': 'collection->%s(%s);' % (method_name, ', '.join(arguments))})
+ parameter = {
+ 'enabled': indexed_setter_function,
+ 'callback_name': callback_name,
+ 'is_custom': is_custom,
+ 'condition_and_statements': condition_and_statements,
+ 'raises_exceptions': raises_exceptions,
+ 'js_to_native_statement': js_to_native_statement,
+ }
+ return parameter, includes
+
+
+def get_indexed_property_deleter_parameter(interface):
+ cpp_class_name = implemented_as_cpp_name(interface)
+ indexed_deleter_function = get_indexed_deleter_operation(interface)
+ includes = []
+ callback_name = '0'
+ is_custom = False
+ if indexed_deleter_function:
+ callback_name = '%sV8Internal::indexedPropertyDeleterCallback' % cpp_class_name
+ is_custom = 'Custom' in indexed_deleter_function.extended_attributes
+ parameter = {
+ 'enabled': indexed_deleter_function,
+ 'callback_name': callback_name,
+ 'is_custom': is_custom,
+ }
+ return parameter, includes
+
+
+def get_named_property_getter_parameter(interface):
+ cpp_class_name = implemented_as_cpp_name(interface)
+ named_getter_function = get_named_getter_operation(interface)
+ includes = []
+ callback_name = '0'
+ function_call = ''
+ return_type_is_union = ''
+ return_js_value_statement = ''
+ is_null_expression = ''
+ raises_exceptions = False
+ is_custom = False
+ not_enumerable = False
+ return_js_value_code = ''
+ is_null_expression = ''
+ raises_exceptions = False
+ override_builtins = False
+ is_return_type_union = False
+
+ if named_getter_function:
+ is_return_type_union = is_union_type(named_getter_function.data_type)
+ override_builtins = 'OverrideBuiltins' in named_getter_function.extended_attributes
+ raises_exceptions = 'RaisesException' in named_getter_function.extended_attributes
+ is_custom = 'Custom' in named_getter_function.extended_attributes
+ callback_name = '%sV8Internal::namedPropertyGetterCallback' % cpp_class_name
+ not_enumerable = 'NotEnumerable' in named_getter_function.extended_attributes
+ function_call = get_function_call_statements(named_getter_function.data_type, 'element', 'collection->' + implemented_as_cpp_name(named_getter_function), 'propertyName', raises_exceptions=raises_exceptions)
+ is_null_expression = get_is_null_expression(named_getter_function.data_type, 'element')
+ native_value = get_pass_owner_expression(named_getter_function.data_type, 'element')
+ return_js_value_code, return_js_value_includes = get_native_to_js_value_statement(named_getter_function.data_type, named_getter_function.extended_attributes, native_value, creation_context='info.Holder()', script_wrappable='collection', isolate='info.GetIsolate()', callback_info='info', used_as_return_value=True, indent=' ')
+ if not is_custom:
+ includes += return_js_value_includes
+
+ parameter = {
+ 'enabled': named_getter_function,
+ 'callback_name': callback_name,
+ 'not_enumerable': not_enumerable,
+ 'is_custom': is_custom,
+ 'override_builtins': override_builtins,
+ 'function_call': function_call,
+ 'is_null_expression': is_null_expression,
+ 'return_js_value_code': return_js_value_code,
+ 'is_return_type_union': is_return_type_union,
+ }
+ return parameter, includes
+
+
+def get_named_property_setter_parameter(interface):
+ cpp_class_name = implemented_as_cpp_name(interface)
+ named_setter_function = get_named_setter_operation(interface)
+ includes = []
+ callback_name = '0'
+ is_custom = False
+ if named_setter_function:
+ is_custom = 'Custom' in named_setter_function.extended_attributes
+ callback_name = '%sV8Internal::namedPropertySetterCallback' % cpp_class_name
+ parameter = {
+ 'enabled': named_setter_function,
+ 'callback_name': callback_name,
+ 'is_custom': is_custom,
+ }
+ return parameter, includes
+
+
+def get_named_property_deleter_parameter(interface):
+ cpp_class_name = implemented_as_cpp_name(interface)
+ named_deleter_function = get_named_deleter_operation(interface)
+ includes = []
+ callback_name = '0'
+ is_custom = False
+ if named_deleter_function:
+ is_custom = 'Custom' in named_deleter_function.extended_attributes
+ callback_name = '%sV8Internal::namedPropertyDeleterCallback' % cpp_class_name
+ parameter = {
+ 'enabled': named_deleter_function,
+ 'callback_name': callback_name,
+ 'is_custom': is_custom,
+ }
+ return parameter, includes
+
+
+def get_special_accessors_parameter(interface):
+ includes = []
+ cpp_class_name = implemented_as_cpp_name(interface)
+
+ indexed_getter_parameter, indexed_getter_includes = get_indexed_property_getter_parameter(interface)
+ includes += indexed_getter_includes
+ indexed_setter_parameter, indexed_setter_includes = get_indexed_property_setter_parameter(interface)
+ includes += indexed_setter_includes
+ indexed_deleter_parameter, indexed_deleter_includes = get_indexed_property_deleter_parameter(interface)
+ includes += indexed_deleter_includes
+
+ named_getter_parameter, named_getter_includes = get_named_property_getter_parameter(interface)
+ includes += named_getter_includes
+ named_setter_parameter, named_setter_includes = get_named_property_setter_parameter(interface)
+ includes += named_setter_includes
+ named_deleter_parameter, named_deleter_includes = get_named_property_deleter_parameter(interface)
+ includes += named_deleter_includes
+
+ has_indexed_enumerator = indexed_getter_parameter['enabled']
+ has_indexed_query = False
+ if indexed_getter_parameter['not_enumerable']:
+ has_indexed_enumerator = False
+ has_named_enumerator = named_getter_parameter['enabled']
+ if named_getter_parameter['not_enumerable']:
+ has_named_enumerator = False
+ has_named_query = has_named_enumerator
+
+ indexed_enumerator_parameter = {
+ 'enabled': has_indexed_enumerator,
+ 'callback_name': has_indexed_enumerator and 'indexedPropertyEnumerator<%s>' % cpp_class_name or '0',
+ }
+ indexed_query_parameter = {
+ 'enabled': has_indexed_query,
+ 'callback_name': has_indexed_query and '%sV8Internal::indexedPropertyQueryCallback' % cpp_class_name or '0',
+ }
+ named_enumerator_parameter = {
+ 'enabled': has_named_enumerator,
+ 'callback_name': has_named_enumerator and '%sV8Internal::namedPropertyEnumeratorCallback' % cpp_class_name or '0',
+ }
+ named_query_parameter = {
+ 'enabled': has_named_query,
+ 'callback_name': has_named_query and '%sV8Internal::namedPropertyQueryCallback' % cpp_class_name or '0',
+ }
+
+ set_on = 'Instance'
+ if interface.name == 'Window':
+ set_on = 'Prototype'
+
+ parameter = {
+ 'set_on': set_on,
+ 'indexed': {
+ 'getter': indexed_getter_parameter,
+ 'setter': indexed_setter_parameter,
+ 'deleter': indexed_deleter_parameter,
+ 'enumerator': indexed_enumerator_parameter,
+ 'query': indexed_query_parameter,
+ },
+ 'named': {
+ 'getter': named_getter_parameter,
+ 'setter': named_setter_parameter,
+ 'deleter': named_deleter_parameter,
+ 'enumerator': named_enumerator_parameter,
+ 'query': named_query_parameter,
+ },
+ }
+ return parameter, includes
+
+
+def get_special_accessor_operation_for_type(interface, special, first_parameter_type, number_of_parameters):
+ for operation in interface.operations:
+ if (special in operation.specials and
+ len(operation.arguments) == number_of_parameters and
+ operation.arguments[0].data_type == first_parameter_type):
+ return operation
+ return None
+
+
+def get_indexed_getter_operation(interface):
+ return get_special_accessor_operation_for_type(interface, 'getter', 'unsigned long', 1)
+
+
+def get_indexed_setter_operation(interface):
+ return get_special_accessor_operation_for_type(interface, 'setter', 'unsigned long', 2)
+
+
+def get_indexed_deleter_operation(interface):
+ return get_special_accessor_operation_for_type(interface, 'deleter', 'unsigned long', 1)
+
+
+def get_named_getter_operation(interface):
+ return get_special_accessor_operation_for_type(interface, 'getter', 'DOMString', 1)
+
+
+def get_named_setter_operation(interface):
+ return get_special_accessor_operation_for_type(interface, 'setter', 'DOMString', 2)
+
+
+def get_named_deleter_operation(interface):
+ return get_special_accessor_operation_for_type(interface, 'deleter', 'DOMString', 1)
+
+
+def has_custom_accessors(interface):
+ return {
+ 'has_custom_indexed_getter': has_custom_implementation(get_indexed_getter_operation(interface)),
+ 'has_custom_indexed_setter': has_custom_implementation(get_indexed_setter_operation(interface)),
+ 'has_custom_indexed_deleter': has_custom_implementation(get_indexed_deleter_operation(interface)),
+ 'has_custom_named_getter': has_custom_implementation(get_named_getter_operation(interface)),
+ 'has_custom_named_setter': has_custom_implementation(get_named_setter_operation(interface)),
+ 'has_custom_named_deleter': has_custom_implementation(get_named_deleter_operation(interface)),
+ }
« no previous file with comments | « Source/bindings/scripts/v8_interface_header.py ('k') | Source/bindings/scripts/v8_types.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698