OLD | NEW |
---|---|
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 Loading... | |
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 Loading... | |
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, default_value=None , extended_attributes=None): | |
haraken
2015/01/27 01:56:30
It looks like default_value is unused.
Jens Widell
2015/01/27 07:19:23
Yes, not needed at the moment. Not on the radar th
| |
336 argument = IdlArgument(interface.idl_name) | |
337 argument.idl_type = idl_type | |
338 argument.name = name | |
339 argument.is_optional = is_optional | |
340 argument.default_value = default_value | |
341 if extended_attributes: | |
342 argument.extended_attributes.update(extended_attributes) | |
343 return argument | |
344 | |
335 # [Iterable], iterable<>, maplike<> and setlike<> | 345 # [Iterable], iterable<>, maplike<> and setlike<> |
336 iterator_method = None | 346 iterator_method = None |
337 # FIXME: support Iterable in partial interfaces. However, we don't | 347 # FIXME: support Iterable in partial interfaces. However, we don't |
338 # need to support iterator overloads between interface and | 348 # need to support iterator overloads between interface and |
339 # partial interface definitions. | 349 # partial interface definitions. |
340 # http://heycam.github.io/webidl/#idl-overloading | 350 # http://heycam.github.io/webidl/#idl-overloading |
341 if (not interface.is_partial | 351 if (not interface.is_partial |
342 and (interface.iterable or interface.maplike or interface.setlike | 352 and (interface.iterable or interface.maplike or interface.setlike |
343 or 'Iterable' in extended_attributes)): | 353 or 'Iterable' in extended_attributes)): |
344 | 354 |
345 used_extended_attributes = {} | 355 used_extended_attributes = {} |
346 | 356 |
347 if interface.iterable: | 357 if interface.iterable: |
348 used_extended_attributes.update(interface.iterable.extended_attribut es) | 358 used_extended_attributes.update(interface.iterable.extended_attribut es) |
349 elif interface.maplike: | 359 elif interface.maplike: |
350 used_extended_attributes.update(interface.maplike.extended_attribute s) | 360 used_extended_attributes.update(interface.maplike.extended_attribute s) |
351 elif interface.setlike: | 361 elif interface.setlike: |
352 used_extended_attributes.update(interface.setlike.extended_attribute s) | 362 used_extended_attributes.update(interface.setlike.extended_attribute s) |
353 | 363 |
354 if 'RaisesException' in used_extended_attributes: | 364 if 'RaisesException' in used_extended_attributes: |
355 raise ValueError('[RaisesException] is implied for iterable<>/maplik e<>/setlike<>') | 365 raise ValueError('[RaisesException] is implied for iterable<>/maplik e<>/setlike<>') |
356 if 'CallWith' in used_extended_attributes: | 366 if 'CallWith' in used_extended_attributes: |
357 raise ValueError('[CallWith=ScriptState] is implied for iterable<>/m aplike<>/setlike<>') | 367 raise ValueError('[CallWith=ScriptState] is implied for iterable<>/m aplike<>/setlike<>') |
358 | 368 |
359 used_extended_attributes.update({ | 369 used_extended_attributes.update({ |
360 'RaisesException': None, | 370 'RaisesException': None, |
361 'CallWith': 'ScriptState', | 371 'CallWith': 'ScriptState', |
362 }) | 372 }) |
363 | 373 |
374 forEach_extended_attributes = used_extended_attributes.copy() | |
haraken
2015/01/27 01:56:30
Can't we just use used_extended_attributes? In oth
Jens Widell
2015/01/27 07:19:23
I am essentially using used_extended_attributes. I
| |
375 forEach_extended_attributes.update({ | |
376 'CallWith': ['ScriptState', 'ThisValue'], | |
377 }) | |
378 | |
364 def generated_iterator_method(name): | 379 def generated_iterator_method(name): |
365 return generated_method( | 380 return generated_method( |
366 return_type=IdlType('Iterator'), | 381 return_type=IdlType('Iterator'), |
367 name=name, | 382 name=name, |
368 extended_attributes=used_extended_attributes) | 383 extended_attributes=used_extended_attributes) |
369 | 384 |
370 iterator_method = generated_iterator_method('iterator') | 385 iterator_method = generated_iterator_method('iterator') |
371 | 386 |
372 if interface.iterable or interface.maplike or interface.setlike: | 387 if interface.iterable or interface.maplike or interface.setlike: |
373 methods.extend([ | 388 methods.extend([ |
374 generated_iterator_method('keys'), | 389 generated_iterator_method('keys'), |
375 generated_iterator_method('values'), | 390 generated_iterator_method('values'), |
376 generated_iterator_method('entries'), | 391 generated_iterator_method('entries'), |
392 | |
393 # void forEach(Function callback, [Default=Undefined] optional a ny thisArg) | |
394 generated_method(IdlType('void'), 'forEach', | |
395 arguments=[generated_argument(IdlType('Function '), 'callback'), | |
396 generated_argument(IdlType('any'), ' thisArg', | |
397 is_optional=True, | |
398 extended_attribut es={'Default': 'Undefined'})], | |
399 extended_attributes=forEach_extended_attributes ), | |
377 ]) | 400 ]) |
378 | 401 |
379 # FIXME: maplike<> and setlike<> should also imply the presence of a | 402 # FIXME: maplike<> and setlike<> should also imply the presence of a |
380 # subset of keys(), values(), entries(), forEach(), has(), get(), add(), | 403 # subset of keys(), values(), entries(), forEach(), has(), get(), add(), |
381 # set(), delete() and clear(), and a 'size' attribute. | 404 # set(), delete() and clear(), and a 'size' attribute. |
382 | 405 |
383 # Stringifier | 406 # Stringifier |
384 if interface.stringifier: | 407 if interface.stringifier: |
385 stringifier = interface.stringifier | 408 stringifier = interface.stringifier |
386 stringifier_ext_attrs = stringifier.extended_attributes.copy() | 409 stringifier_ext_attrs = stringifier.extended_attributes.copy() |
(...skipping 924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1311 deleter = next( | 1334 deleter = next( |
1312 method | 1335 method |
1313 for method in interface.operations | 1336 for method in interface.operations |
1314 if ('deleter' in method.specials and | 1337 if ('deleter' in method.specials and |
1315 len(method.arguments) == 1 and | 1338 len(method.arguments) == 1 and |
1316 str(method.arguments[0].idl_type) == 'DOMString')) | 1339 str(method.arguments[0].idl_type) == 'DOMString')) |
1317 except StopIteration: | 1340 except StopIteration: |
1318 return None | 1341 return None |
1319 | 1342 |
1320 return property_deleter(deleter) | 1343 return property_deleter(deleter) |
OLD | NEW |