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 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
315 for method in interface.operations | 315 for method in interface.operations |
316 if method.name]) # Skip anonymous special operations (metho
ds) | 316 if method.name]) # Skip anonymous special operations (metho
ds) |
317 if interface.partial_interfaces: | 317 if interface.partial_interfaces: |
318 assert len(interface.partial_interfaces) == len(set(interface.partial_in
terfaces)) | 318 assert len(interface.partial_interfaces) == len(set(interface.partial_in
terfaces)) |
319 for partial_interface in interface.partial_interfaces: | 319 for partial_interface in interface.partial_interfaces: |
320 methods.extend([v8_methods.method_context(interface, operation, is_v
isible=False) | 320 methods.extend([v8_methods.method_context(interface, operation, is_v
isible=False) |
321 for operation in partial_interface.operations | 321 for operation in partial_interface.operations |
322 if operation.name]) | 322 if operation.name]) |
323 compute_method_overloads_context(interface, methods) | 323 compute_method_overloads_context(interface, methods) |
324 | 324 |
325 def generated_method(return_type, name, arguments=None, extended_attributes=
None): | 325 def generated_method(return_type, name, arguments=None, extended_attributes=
None, implemented_as=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 if implemented_as is None: |
| 334 implemented_as = name + 'ForBinding' |
| 335 operation.extended_attributes['ImplementedAs'] = implemented_as |
333 return v8_methods.method_context(interface, operation) | 336 return v8_methods.method_context(interface, operation) |
334 | 337 |
335 def generated_argument(idl_type, name, is_optional=False, extended_attribute
s=None): | 338 def generated_argument(idl_type, name, is_optional=False, extended_attribute
s=None): |
336 argument = IdlArgument(interface.idl_name) | 339 argument = IdlArgument(interface.idl_name) |
337 argument.idl_type = idl_type | 340 argument.idl_type = idl_type |
338 argument.name = name | 341 argument.name = name |
339 argument.is_optional = is_optional | 342 argument.is_optional = is_optional |
340 if extended_attributes: | 343 if extended_attributes: |
341 argument.extended_attributes.update(extended_attributes) | 344 argument.extended_attributes.update(extended_attributes) |
342 return argument | 345 return argument |
(...skipping 25 matching lines...) Expand all Loading... |
368 used_extended_attributes.update({ | 371 used_extended_attributes.update({ |
369 'RaisesException': None, | 372 'RaisesException': None, |
370 'CallWith': 'ScriptState', | 373 'CallWith': 'ScriptState', |
371 }) | 374 }) |
372 | 375 |
373 forEach_extended_attributes = used_extended_attributes.copy() | 376 forEach_extended_attributes = used_extended_attributes.copy() |
374 forEach_extended_attributes.update({ | 377 forEach_extended_attributes.update({ |
375 'CallWith': ['ScriptState', 'ThisValue'], | 378 'CallWith': ['ScriptState', 'ThisValue'], |
376 }) | 379 }) |
377 | 380 |
378 def generated_iterator_method(name): | 381 def generated_iterator_method(name, implemented_as=None): |
379 return generated_method( | 382 return generated_method( |
380 return_type=IdlType('Iterator'), | 383 return_type=IdlType('Iterator'), |
381 name=name, | 384 name=name, |
382 extended_attributes=used_extended_attributes) | 385 extended_attributes=used_extended_attributes, |
| 386 implemented_as=implemented_as) |
383 | 387 |
384 iterator_method = generated_iterator_method('iterator') | 388 iterator_method = generated_iterator_method('iterator', implemented_as='
iterator') |
385 | 389 |
386 if interface.iterable or interface.maplike or interface.setlike: | 390 if interface.iterable or interface.maplike or interface.setlike: |
387 implicit_methods = [ | 391 implicit_methods = [ |
388 generated_iterator_method('keys'), | 392 generated_iterator_method('keys'), |
389 generated_iterator_method('values'), | 393 generated_iterator_method('values'), |
390 generated_iterator_method('entries'), | 394 generated_iterator_method('entries'), |
391 | 395 |
392 # void forEach(Function callback, [Default=Undefined] optional a
ny thisArg) | 396 # void forEach(Function callback, [Default=Undefined] optional a
ny thisArg) |
393 generated_method(IdlType('void'), 'forEach', | 397 generated_method(IdlType('void'), 'forEach', |
394 arguments=[generated_argument(IdlType('Function
'), 'callback'), | 398 arguments=[generated_argument(IdlType('Function
'), 'callback'), |
395 generated_argument(IdlType('any'), '
thisArg', | 399 generated_argument(IdlType('any'), '
thisArg', |
396 is_optional=True, | 400 is_optional=True, |
397 extended_attribut
es={'Default': 'Undefined'})], | 401 extended_attribut
es={'Default': 'Undefined'})], |
398 extended_attributes=forEach_extended_attributes
), | 402 extended_attributes=forEach_extended_attributes
), |
399 ] | 403 ] |
400 | 404 |
| 405 if interface.maplike: |
| 406 key_argument = generated_argument(interface.maplike.key_type, 'k
ey') |
| 407 value_argument = generated_argument(interface.maplike.value_type
, 'value') |
| 408 |
| 409 implicit_methods.extend([ |
| 410 generated_method(IdlType('boolean'), 'has', |
| 411 arguments=[key_argument], |
| 412 extended_attributes=used_extended_attribute
s), |
| 413 generated_method(IdlType('any'), 'get', |
| 414 arguments=[key_argument], |
| 415 extended_attributes=used_extended_attribute
s), |
| 416 ]) |
| 417 |
| 418 if not interface.maplike.is_read_only: |
| 419 implicit_methods.extend([ |
| 420 generated_method(IdlType('void'), 'clear', |
| 421 extended_attributes=used_extended_attri
butes), |
| 422 generated_method(IdlType('boolean'), 'delete', |
| 423 arguments=[key_argument], |
| 424 extended_attributes=used_extended_attri
butes), |
| 425 generated_method(IdlType(interface.name), 'set', |
| 426 arguments=[key_argument, value_argument
], |
| 427 extended_attributes=used_extended_attri
butes), |
| 428 ]) |
| 429 |
| 430 if interface.setlike: |
| 431 value_argument = generated_argument(interface.setlike.value_type
, 'value') |
| 432 |
| 433 implicit_methods.extend([ |
| 434 generated_method(IdlType('boolean'), 'has', |
| 435 arguments=[value_argument], |
| 436 extended_attributes=used_extended_attribute
s), |
| 437 ]) |
| 438 |
| 439 if not interface.setlike.is_read_only: |
| 440 implicit_methods.extend([ |
| 441 generated_method(IdlType(interface.name), 'add', |
| 442 arguments=[value_argument], |
| 443 extended_attributes=used_extended_attri
butes), |
| 444 generated_method(IdlType('void'), 'clear', |
| 445 extended_attributes=used_extended_attri
butes), |
| 446 generated_method(IdlType('boolean'), 'delete', |
| 447 arguments=[value_argument], |
| 448 extended_attributes=used_extended_attri
butes), |
| 449 ]) |
| 450 |
401 methods_by_name = {} | 451 methods_by_name = {} |
402 for method in methods: | 452 for method in methods: |
403 methods_by_name.setdefault(method['name'], []).append(method) | 453 methods_by_name.setdefault(method['name'], []).append(method) |
404 | 454 |
405 for implicit_method in implicit_methods: | 455 for implicit_method in implicit_methods: |
406 if implicit_method['name'] in methods_by_name: | 456 if implicit_method['name'] in methods_by_name: |
407 # FIXME: Check that the existing method is compatible. | 457 # FIXME: Check that the existing method is compatible. |
408 continue | 458 continue |
409 methods.append(implicit_method) | 459 methods.append(implicit_method) |
410 | 460 |
411 # FIXME: maplike<> and setlike<> should also imply the presence of a | 461 # FIXME: maplike<> and setlike<> should also imply the presence of a |
412 # subset of keys(), values(), entries(), forEach(), has(), get(), add(), | 462 # 'size' attribute. |
413 # set(), delete() and clear(), and a 'size' attribute. | |
414 | 463 |
415 # Stringifier | 464 # Stringifier |
416 if interface.stringifier: | 465 if interface.stringifier: |
417 stringifier = interface.stringifier | 466 stringifier = interface.stringifier |
418 stringifier_ext_attrs = stringifier.extended_attributes.copy() | 467 stringifier_ext_attrs = stringifier.extended_attributes.copy() |
419 if stringifier.attribute: | 468 if stringifier.attribute: |
420 stringifier_ext_attrs['ImplementedAs'] = stringifier.attribute.name | 469 stringifier_ext_attrs['ImplementedAs'] = stringifier.attribute.name |
421 elif stringifier.operation: | 470 elif stringifier.operation: |
422 stringifier_ext_attrs['ImplementedAs'] = stringifier.operation.name | 471 stringifier_ext_attrs['ImplementedAs'] = stringifier.operation.name |
423 methods.append(generated_method( | 472 methods.append(generated_method( |
424 return_type=IdlType('DOMString'), | 473 return_type=IdlType('DOMString'), |
425 name='toString', | 474 name='toString', |
426 extended_attributes=stringifier_ext_attrs)) | 475 extended_attributes=stringifier_ext_attrs, |
| 476 implemented_as='toString')) |
427 | 477 |
428 conditionally_enabled_methods = [] | 478 conditionally_enabled_methods = [] |
429 custom_registration_methods = [] | 479 custom_registration_methods = [] |
430 method_configuration_methods = [] | 480 method_configuration_methods = [] |
431 | 481 |
432 for method in methods: | 482 for method in methods: |
433 # Skip all but one method in each set of overloaded methods. | 483 # Skip all but one method in each set of overloaded methods. |
434 if 'overload_index' in method and 'overloads' not in method: | 484 if 'overload_index' in method and 'overloads' not in method: |
435 continue | 485 continue |
436 | 486 |
(...skipping 808 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1245 if str(idl_type) != 'boolean': | 1295 if str(idl_type) != 'boolean': |
1246 raise Exception( | 1296 raise Exception( |
1247 'Only deleters with boolean type are allowed, but type is "%s"' % | 1297 'Only deleters with boolean type are allowed, but type is "%s"' % |
1248 idl_type) | 1298 idl_type) |
1249 extended_attributes = deleter.extended_attributes | 1299 extended_attributes = deleter.extended_attributes |
1250 return { | 1300 return { |
1251 'is_custom': 'Custom' in extended_attributes, | 1301 'is_custom': 'Custom' in extended_attributes, |
1252 'is_raises_exception': 'RaisesException' in extended_attributes, | 1302 'is_raises_exception': 'RaisesException' in extended_attributes, |
1253 'name': cpp_name(deleter), | 1303 'name': cpp_name(deleter), |
1254 } | 1304 } |
OLD | NEW |