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

Side by Side Diff: Source/bindings/scripts/v8_methods.py

Issue 900533003: IDL: Support [Unforgeable] on interface definitions (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « Source/bindings/scripts/v8_attributes.py ('k') | Source/bindings/scripts/v8_utilities.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 21 matching lines...) Expand all
32 Extends IdlTypeBase and IdlUnionType with property |union_arguments|. 32 Extends IdlTypeBase and IdlUnionType with property |union_arguments|.
33 33
34 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 34 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
35 """ 35 """
36 36
37 from idl_definitions import IdlArgument, IdlOperation 37 from idl_definitions import IdlArgument, IdlOperation
38 from idl_types import IdlTypeBase, IdlUnionType, inherits_interface 38 from idl_types import IdlTypeBase, IdlUnionType, inherits_interface
39 from v8_globals import includes 39 from v8_globals import includes
40 import v8_types 40 import v8_types
41 import v8_utilities 41 import v8_utilities
42 from v8_utilities import has_extended_attribute_value 42 from v8_utilities import has_extended_attribute_value, is_unforgeable
43 43
44 44
45 # Methods with any of these require custom method registration code in the 45 # Methods with any of these require custom method registration code in the
46 # interface's configure*Template() function. 46 # interface's configure*Template() function.
47 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([ 47 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES = frozenset([
48 'DoNotCheckSecurity', 48 'DoNotCheckSecurity',
49 'DoNotCheckSignature', 49 'DoNotCheckSignature',
50 'NotEnumerable', 50 'NotEnumerable',
51 'Unforgeable', 51 'Unforgeable',
52 ]) 52 ])
(...skipping 15 matching lines...) Expand all
68 idl_type = method.idl_type 68 idl_type = method.idl_type
69 is_static = method.is_static 69 is_static = method.is_static
70 name = method.name 70 name = method.name
71 71
72 idl_type.add_includes_for_type() 72 idl_type.add_includes_for_type()
73 this_cpp_value = cpp_value(interface, method, len(arguments)) 73 this_cpp_value = cpp_value(interface, method, len(arguments))
74 74
75 def function_template(): 75 def function_template():
76 if is_static: 76 if is_static:
77 return 'functionTemplate' 77 return 'functionTemplate'
78 if 'Unforgeable' in extended_attributes: 78 if is_unforgeable(interface, method):
79 return 'instanceTemplate' 79 return 'instanceTemplate'
80 return 'prototypeTemplate' 80 return 'prototypeTemplate'
81 81
82 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_ attributes 82 is_implemented_in_private_script = 'ImplementedInPrivateScript' in extended_ attributes
83 if is_implemented_in_private_script: 83 if is_implemented_in_private_script:
84 includes.add('bindings/core/v8/PrivateScriptRunner.h') 84 includes.add('bindings/core/v8/PrivateScriptRunner.h')
85 includes.add('core/frame/LocalFrame.h') 85 includes.add('core/frame/LocalFrame.h')
86 includes.add('platform/ScriptForbiddenScope.h') 86 includes.add('platform/ScriptForbiddenScope.h')
87 87
88 # [OnlyExposedToPrivateScript] 88 # [OnlyExposedToPrivateScript]
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type) 124 'cpp_type': (v8_types.cpp_template_type('Nullable', idl_type.cpp_type)
125 if idl_type.is_explicit_nullable else idl_type.cpp_type), 125 if idl_type.is_explicit_nullable else idl_type.cpp_type),
126 'cpp_value': this_cpp_value, 126 'cpp_value': this_cpp_value,
127 'cpp_type_initializer': idl_type.cpp_type_initializer, 127 'cpp_type_initializer': idl_type.cpp_type_initializer,
128 'custom_registration_extended_attributes': 128 'custom_registration_extended_attributes':
129 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection( 129 CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES.intersection(
130 extended_attributes.iterkeys()), 130 extended_attributes.iterkeys()),
131 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs] 131 'deprecate_as': v8_utilities.deprecate_as(method), # [DeprecateAs]
132 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed] 132 'exposed_test': v8_utilities.exposed(method, interface), # [Exposed]
133 'function_template': function_template(), 133 'function_template': function_template(),
134 'has_custom_registration': is_static or 134 'has_custom_registration':
135 is_static or
136 is_unforgeable(interface, method) or
135 v8_utilities.has_extended_attribute( 137 v8_utilities.has_extended_attribute(
136 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES), 138 method, CUSTOM_REGISTRATION_EXTENDED_ATTRIBUTES),
137 'has_exception_state': 139 'has_exception_state':
138 is_raises_exception or 140 is_raises_exception or
139 is_check_security_for_frame or 141 is_check_security_for_frame or
140 is_check_security_for_window or 142 is_check_security_for_window or
141 any(argument for argument in arguments 143 any(argument for argument in arguments
142 if (argument.idl_type.name == 'SerializedScriptValue' or 144 if (argument.idl_type.name == 'SerializedScriptValue' or
143 argument_conversion_needs_exception_state(method, argument)) ), 145 argument_conversion_needs_exception_state(method, argument)) ),
144 'idl_type': idl_type.base_type, 146 'idl_type': idl_type.base_type,
145 'is_call_with_execution_context': has_extended_attribute_value(method, ' CallWith', 'ExecutionContext'), 147 'is_call_with_execution_context': has_extended_attribute_value(method, ' CallWith', 'ExecutionContext'),
146 'is_call_with_script_arguments': is_call_with_script_arguments, 148 'is_call_with_script_arguments': is_call_with_script_arguments,
147 'is_call_with_script_state': is_call_with_script_state, 149 'is_call_with_script_state': is_call_with_script_state,
148 'is_check_security_for_frame': is_check_security_for_frame, 150 'is_check_security_for_frame': is_check_security_for_frame,
149 'is_check_security_for_node': is_check_security_for_node, 151 'is_check_security_for_node': is_check_security_for_node,
150 'is_check_security_for_window': is_check_security_for_window, 152 'is_check_security_for_window': is_check_security_for_window,
151 'is_custom': 'Custom' in extended_attributes, 153 'is_custom': 'Custom' in extended_attributes,
152 'is_custom_element_callbacks': is_custom_element_callbacks, 154 'is_custom_element_callbacks': is_custom_element_callbacks,
153 'is_do_not_check_security': is_do_not_check_security, 155 'is_do_not_check_security': is_do_not_check_security,
154 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute s, 156 'is_do_not_check_signature': 'DoNotCheckSignature' in extended_attribute s,
155 'is_explicit_nullable': idl_type.is_explicit_nullable, 157 'is_explicit_nullable': idl_type.is_explicit_nullable,
156 'is_implemented_in_private_script': is_implemented_in_private_script, 158 'is_implemented_in_private_script': is_implemented_in_private_script,
157 'is_partial_interface_member': 159 'is_partial_interface_member':
158 'PartialInterfaceImplementedAs' in extended_attributes, 160 'PartialInterfaceImplementedAs' in extended_attributes,
159 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes, 161 'is_per_world_bindings': 'PerWorldBindings' in extended_attributes,
160 'is_raises_exception': is_raises_exception, 162 'is_raises_exception': is_raises_exception,
161 'is_read_only': 'Unforgeable' in extended_attributes, 163 'is_read_only': is_unforgeable(interface, method),
162 'is_static': is_static, 164 'is_static': is_static,
163 'is_variadic': arguments and arguments[-1].is_variadic, 165 'is_variadic': arguments and arguments[-1].is_variadic,
164 'measure_as': v8_utilities.measure_as(method), # [MeasureAs] 166 'measure_as': v8_utilities.measure_as(method), # [MeasureAs]
165 'name': name, 167 'name': name,
166 'number_of_arguments': len(arguments), 168 'number_of_arguments': len(arguments),
167 'number_of_required_arguments': len([ 169 'number_of_required_arguments': len([
168 argument for argument in arguments 170 argument for argument in arguments
169 if not (argument.is_optional or argument.is_variadic)]), 171 if not (argument.is_optional or argument.is_variadic)]),
170 'number_of_required_or_variadic_arguments': len([ 172 'number_of_required_or_variadic_arguments': len([
171 argument for argument in arguments 173 argument for argument in arguments
172 if not argument.is_optional]), 174 if not argument.is_optional]),
173 'only_exposed_to_private_script': is_only_exposed_to_private_script, 175 'only_exposed_to_private_script': is_only_exposed_to_private_script,
174 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(method), # [PerContextEnabled] 176 'per_context_enabled_function': v8_utilities.per_context_enabled_functio n_name(method), # [PerContextEnabled]
175 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local _cpp_value( 177 'private_script_v8_value_to_local_cpp_value': idl_type.v8_value_to_local _cpp_value(
176 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is olate()', used_in_private_script=True), 178 extended_attributes, 'v8Value', 'cppValue', isolate='scriptState->is olate()', used_in_private_script=True),
177 'property_attributes': property_attributes(method), 179 'property_attributes': property_attributes(interface, method),
178 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled] 180 'runtime_enabled_function': v8_utilities.runtime_enabled_function_name(m ethod), # [RuntimeEnabled]
179 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script), 181 'should_be_exposed_to_script': not (is_implemented_in_private_script and is_only_exposed_to_private_script),
180 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature', 182 'signature': 'v8::Local<v8::Signature>()' if is_static or 'DoNotCheckSig nature' in extended_attributes else 'defaultSignature',
181 'use_output_parameter_for_result': idl_type.use_output_parameter_for_res ult, 183 'use_output_parameter_for_result': idl_type.use_output_parameter_for_res ult,
182 'use_local_result': use_local_result(method), 184 'use_local_result': use_local_result(method),
183 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value), 185 'v8_set_return_value': v8_set_return_value(interface.name, method, this_ cpp_value),
184 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True), 186 'v8_set_return_value_for_main_world': v8_set_return_value(interface.name , method, this_cpp_value, for_main_world=True),
185 'visible': is_visible, 187 'visible': is_visible,
186 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings], 188 'world_suffixes': ['', 'ForMainWorld'] if 'PerWorldBindings' in extended _attributes else [''], # [PerWorldBindings],
187 } 189 }
(...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 name, index=index, declare_varia ble=False, 379 name, index=index, declare_varia ble=False,
378 return_promise=return_promise, 380 return_promise=return_promise,
379 restricted_float=restricted_floa t) 381 restricted_float=restricted_floa t)
380 382
381 383
382 ################################################################################ 384 ################################################################################
383 # Auxiliary functions 385 # Auxiliary functions
384 ################################################################################ 386 ################################################################################
385 387
386 # [NotEnumerable] 388 # [NotEnumerable]
387 def property_attributes(method): 389 def property_attributes(interface, method):
388 extended_attributes = method.extended_attributes 390 extended_attributes = method.extended_attributes
389 property_attributes_list = [] 391 property_attributes_list = []
390 if 'NotEnumerable' in extended_attributes: 392 if 'NotEnumerable' in extended_attributes:
391 property_attributes_list.append('v8::DontEnum') 393 property_attributes_list.append('v8::DontEnum')
392 if 'Unforgeable' in extended_attributes: 394 if is_unforgeable(interface, method):
393 property_attributes_list.append('v8::ReadOnly') 395 property_attributes_list.append('v8::ReadOnly')
394 if property_attributes_list: 396 if property_attributes_list:
395 property_attributes_list.insert(0, 'v8::DontDelete') 397 property_attributes_list.insert(0, 'v8::DontDelete')
396 return property_attributes_list 398 return property_attributes_list
397 399
398 400
399 def argument_set_default_value(argument): 401 def argument_set_default_value(argument):
400 idl_type = argument.idl_type 402 idl_type = argument.idl_type
401 default_value = argument.default_value 403 default_value = argument.default_value
402 if not default_value: 404 if not default_value:
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 448
447 IdlOperation.returns_promise = property(method_returns_promise) 449 IdlOperation.returns_promise = property(method_returns_promise)
448 450
449 451
450 def argument_conversion_needs_exception_state(method, argument): 452 def argument_conversion_needs_exception_state(method, argument):
451 idl_type = argument.idl_type 453 idl_type = argument.idl_type
452 return (idl_type.v8_conversion_needs_exception_state or 454 return (idl_type.v8_conversion_needs_exception_state or
453 argument.is_variadic or 455 argument.is_variadic or
454 (method.returns_promise and (idl_type.is_string_type or 456 (method.returns_promise and (idl_type.is_string_type or
455 idl_type.is_enum))) 457 idl_type.is_enum)))
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_attributes.py ('k') | Source/bindings/scripts/v8_utilities.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698