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

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

Issue 807263007: IDL: Add forEach() method to iterable<>/maplike<>/setlike<> interfaces (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: adjust test expectations 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/idl_definitions.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 # coding=utf-8 2 # coding=utf-8
3 # 3 #
4 # Redistribution and use in source and binary forms, with or without 4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are 5 # modification, are permitted provided that the following conditions are
6 # met: 6 # met:
7 # 7 #
8 # * Redistributions of source code must retain the above copyright 8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer. 9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above 10 # * Redistributions in binary form must reproduce the above
(...skipping 19 matching lines...) Expand all
30 """Generate template values for an interface. 30 """Generate template values for an interface.
31 31
32 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 32 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
33 """ 33 """
34 34
35 from collections import defaultdict 35 from collections import defaultdict
36 import itertools 36 import itertools
37 from operator import itemgetter 37 from operator import itemgetter
38 38
39 import idl_definitions 39 import idl_definitions
40 from idl_definitions import IdlOperation 40 from idl_definitions import IdlOperation, IdlArgument
41 import idl_types 41 import idl_types
42 from idl_types import IdlType, inherits_interface 42 from idl_types import IdlType, inherits_interface
43 import v8_attributes 43 import v8_attributes
44 from v8_globals import includes 44 from v8_globals import includes
45 import v8_methods 45 import v8_methods
46 import v8_types 46 import v8_types
47 from v8_types import cpp_ptr_type, cpp_template_type 47 from v8_types import cpp_ptr_type, cpp_template_type
48 import v8_utilities 48 import v8_utilities
49 from v8_utilities import (cpp_name_or_partial, capitalize, conditional_string, c pp_name, gc_type, 49 from v8_utilities import (cpp_name_or_partial, capitalize, conditional_string, c pp_name, gc_type,
50 has_extended_attribute_value, runtime_enabled_function _name, 50 has_extended_attribute_value, runtime_enabled_function _name,
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 def generated_method(return_type, name, arguments=None, extended_attributes= None): 325 def generated_method(return_type, name, arguments=None, extended_attributes= None):
326 operation = IdlOperation(interface.idl_name) 326 operation = IdlOperation(interface.idl_name)
327 operation.idl_type = return_type 327 operation.idl_type = return_type
328 operation.name = name 328 operation.name = name
329 if arguments: 329 if arguments:
330 operation.arguments = arguments 330 operation.arguments = arguments
331 if extended_attributes: 331 if extended_attributes:
332 operation.extended_attributes.update(extended_attributes) 332 operation.extended_attributes.update(extended_attributes)
333 return v8_methods.method_context(interface, operation) 333 return v8_methods.method_context(interface, operation)
334 334
335 def generated_argument(idl_type, name, is_optional=False, extended_attribute s=None):
336 argument = IdlArgument(interface.idl_name)
337 argument.idl_type = idl_type
338 argument.name = name
339 argument.is_optional = is_optional
340 if extended_attributes:
341 argument.extended_attributes.update(extended_attributes)
342 return argument
343
335 # [Iterable], iterable<>, maplike<> and setlike<> 344 # [Iterable], iterable<>, maplike<> and setlike<>
336 iterator_method = None 345 iterator_method = None
337 # FIXME: support Iterable in partial interfaces. However, we don't 346 # FIXME: support Iterable in partial interfaces. However, we don't
338 # need to support iterator overloads between interface and 347 # need to support iterator overloads between interface and
339 # partial interface definitions. 348 # partial interface definitions.
340 # http://heycam.github.io/webidl/#idl-overloading 349 # http://heycam.github.io/webidl/#idl-overloading
341 if (not interface.is_partial 350 if (not interface.is_partial
342 and (interface.iterable or interface.maplike or interface.setlike 351 and (interface.iterable or interface.maplike or interface.setlike
343 or 'Iterable' in extended_attributes)): 352 or 'Iterable' in extended_attributes)):
344 353
345 used_extended_attributes = {} 354 used_extended_attributes = {}
346 355
347 if interface.iterable: 356 if interface.iterable:
348 used_extended_attributes.update(interface.iterable.extended_attribut es) 357 used_extended_attributes.update(interface.iterable.extended_attribut es)
349 elif interface.maplike: 358 elif interface.maplike:
350 used_extended_attributes.update(interface.maplike.extended_attribute s) 359 used_extended_attributes.update(interface.maplike.extended_attribute s)
351 elif interface.setlike: 360 elif interface.setlike:
352 used_extended_attributes.update(interface.setlike.extended_attribute s) 361 used_extended_attributes.update(interface.setlike.extended_attribute s)
353 362
354 if 'RaisesException' in used_extended_attributes: 363 if 'RaisesException' in used_extended_attributes:
355 raise ValueError('[RaisesException] is implied for iterable<>/maplik e<>/setlike<>') 364 raise ValueError('[RaisesException] is implied for iterable<>/maplik e<>/setlike<>')
356 if 'CallWith' in used_extended_attributes: 365 if 'CallWith' in used_extended_attributes:
357 raise ValueError('[CallWith=ScriptState] is implied for iterable<>/m aplike<>/setlike<>') 366 raise ValueError('[CallWith=ScriptState] is implied for iterable<>/m aplike<>/setlike<>')
358 367
359 used_extended_attributes.update({ 368 used_extended_attributes.update({
360 'RaisesException': None, 369 'RaisesException': None,
361 'CallWith': 'ScriptState', 370 'CallWith': 'ScriptState',
362 }) 371 })
363 372
373 forEach_extended_attributes = used_extended_attributes.copy()
374 forEach_extended_attributes.update({
375 'CallWith': ['ScriptState', 'ThisValue'],
376 })
377
364 def generated_iterator_method(name): 378 def generated_iterator_method(name):
365 return generated_method( 379 return generated_method(
366 return_type=IdlType('Iterator'), 380 return_type=IdlType('Iterator'),
367 name=name, 381 name=name,
368 extended_attributes=used_extended_attributes) 382 extended_attributes=used_extended_attributes)
369 383
370 iterator_method = generated_iterator_method('iterator') 384 iterator_method = generated_iterator_method('iterator')
371 385
372 if interface.iterable or interface.maplike or interface.setlike: 386 if interface.iterable or interface.maplike or interface.setlike:
373 methods.extend([ 387 methods.extend([
374 generated_iterator_method('keys'), 388 generated_iterator_method('keys'),
375 generated_iterator_method('values'), 389 generated_iterator_method('values'),
376 generated_iterator_method('entries'), 390 generated_iterator_method('entries'),
391
392 # void forEach(Function callback, [Default=Undefined] optional a ny thisArg)
393 generated_method(IdlType('void'), 'forEach',
394 arguments=[generated_argument(IdlType('Function '), 'callback'),
395 generated_argument(IdlType('any'), ' thisArg',
396 is_optional=True,
397 extended_attribut es={'Default': 'Undefined'})],
398 extended_attributes=forEach_extended_attributes ),
377 ]) 399 ])
378 400
379 # FIXME: maplike<> and setlike<> should also imply the presence of a 401 # FIXME: maplike<> and setlike<> should also imply the presence of a
380 # subset of keys(), values(), entries(), forEach(), has(), get(), add(), 402 # subset of keys(), values(), entries(), forEach(), has(), get(), add(),
381 # set(), delete() and clear(), and a 'size' attribute. 403 # set(), delete() and clear(), and a 'size' attribute.
382 404
383 # Stringifier 405 # Stringifier
384 if interface.stringifier: 406 if interface.stringifier:
385 stringifier = interface.stringifier 407 stringifier = interface.stringifier
386 stringifier_ext_attrs = stringifier.extended_attributes.copy() 408 stringifier_ext_attrs = stringifier.extended_attributes.copy()
(...skipping 826 matching lines...) Expand 10 before | Expand all | Expand 10 after
1213 if str(idl_type) != 'boolean': 1235 if str(idl_type) != 'boolean':
1214 raise Exception( 1236 raise Exception(
1215 'Only deleters with boolean type are allowed, but type is "%s"' % 1237 'Only deleters with boolean type are allowed, but type is "%s"' %
1216 idl_type) 1238 idl_type)
1217 extended_attributes = deleter.extended_attributes 1239 extended_attributes = deleter.extended_attributes
1218 return { 1240 return {
1219 'is_custom': 'Custom' in extended_attributes, 1241 'is_custom': 'Custom' in extended_attributes,
1220 'is_raises_exception': 'RaisesException' in extended_attributes, 1242 'is_raises_exception': 'RaisesException' in extended_attributes,
1221 'name': cpp_name(deleter), 1243 'name': cpp_name(deleter),
1222 } 1244 }
OLDNEW
« no previous file with comments | « Source/bindings/scripts/idl_definitions.py ('k') | Source/bindings/scripts/v8_utilities.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698