| OLD | NEW |
| 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 Loading... |
| 32 This is a rewrite of the Perl IDL compiler in Python, but is not complete. | 32 This is a rewrite of the Perl IDL compiler in Python, but is not complete. |
| 33 Once it is complete, we will switch all IDL files over to Python at once. | 33 Once it is complete, we will switch all IDL files over to Python at once. |
| 34 Until then, please work on the Perl IDL compiler. | 34 Until then, please work on the Perl IDL compiler. |
| 35 For details, see bug http://crbug.com/239771 | 35 For details, see bug http://crbug.com/239771 |
| 36 """ | 36 """ |
| 37 | 37 |
| 38 import v8_attributes | 38 import v8_attributes |
| 39 from v8_globals import includes | 39 from v8_globals import includes |
| 40 import v8_methods | 40 import v8_methods |
| 41 import v8_types | 41 import v8_types |
| 42 from v8_types import inherits_interface | 42 from v8_types import inherits_interface, is_interface_type |
| 43 import v8_utilities | 43 import v8_utilities |
| 44 from v8_utilities import capitalize, conditional_string, cpp_name, has_extended_
attribute_value, runtime_enabled_function_name | 44 from v8_utilities import capitalize, conditional_string, cpp_name, has_extended_
attribute_value, runtime_enabled_function_name |
| 45 | 45 |
| 46 | 46 |
| 47 INTERFACE_H_INCLUDES = set([ | 47 INTERFACE_H_INCLUDES = set([ |
| 48 'bindings/v8/V8Binding.h', | 48 'bindings/v8/V8Binding.h', |
| 49 'bindings/v8/V8DOMWrapper.h', | 49 'bindings/v8/V8DOMWrapper.h', |
| 50 'bindings/v8/WrapperTypeInfo.h', | 50 'bindings/v8/WrapperTypeInfo.h', |
| 51 ]) | 51 ]) |
| 52 INTERFACE_CPP_INCLUDES = set([ | 52 INTERFACE_CPP_INCLUDES = set([ |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 }) | 227 }) |
| 228 | 228 |
| 229 template_contents.update({ | 229 template_contents.update({ |
| 230 'indexed_property_getter': indexed_property_getter(interface), | 230 'indexed_property_getter': indexed_property_getter(interface), |
| 231 'indexed_property_setter': indexed_property_setter(interface), | 231 'indexed_property_setter': indexed_property_setter(interface), |
| 232 'indexed_property_deleter': indexed_property_deleter(interface), | 232 'indexed_property_deleter': indexed_property_deleter(interface), |
| 233 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, | 233 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, |
| 234 'named_property_getter': named_property_getter(interface), | 234 'named_property_getter': named_property_getter(interface), |
| 235 'named_property_setter': named_property_setter(interface), | 235 'named_property_setter': named_property_setter(interface), |
| 236 'named_property_deleter': named_property_deleter(interface), | 236 'named_property_deleter': named_property_deleter(interface), |
| 237 'is_override_builtins': 'OverrideBuiltins' in extended_attributes, | |
| 238 }) | 237 }) |
| 239 | 238 |
| 240 return template_contents | 239 return template_contents |
| 241 | 240 |
| 242 | 241 |
| 243 # [DeprecateAs], [Reflect], [RuntimeEnabled] | 242 # [DeprecateAs], [Reflect], [RuntimeEnabled] |
| 244 def generate_constant(constant): | 243 def generate_constant(constant): |
| 245 # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted | 244 # (Blink-only) string literals are unquoted in tokenizer, must be re-quoted |
| 246 # in C++. | 245 # in C++. |
| 247 if constant.idl_type == 'DOMString': | 246 if constant.idl_type == 'DOMString': |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 if v8_types.array_or_sequence_type(idl_type): | 375 if v8_types.array_or_sequence_type(idl_type): |
| 377 return '%s->IsArray()' % cpp_value | 376 return '%s->IsArray()' % cpp_value |
| 378 if v8_types.is_callback_interface(idl_type): | 377 if v8_types.is_callback_interface(idl_type): |
| 379 return ' || '.join(['%s->IsNull()' % cpp_value, | 378 return ' || '.join(['%s->IsNull()' % cpp_value, |
| 380 '%s->IsFunction()' % cpp_value]) | 379 '%s->IsFunction()' % cpp_value]) |
| 381 if v8_types.is_wrapper_type(idl_type): | 380 if v8_types.is_wrapper_type(idl_type): |
| 382 type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'
.format(idl_type=idl_type, cpp_value=cpp_value) | 381 type_check = 'V8{idl_type}::hasInstance({cpp_value}, info.GetIsolate())'
.format(idl_type=idl_type, cpp_value=cpp_value) |
| 383 if argument['is_nullable']: | 382 if argument['is_nullable']: |
| 384 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) | 383 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) |
| 385 return type_check | 384 return type_check |
| 386 if v8_types.is_interface_type(idl_type): | 385 if is_interface_type(idl_type): |
| 387 # Non-wrapper types are just objects: we don't distinguish type | 386 # Non-wrapper types are just objects: we don't distinguish type |
| 388 type_check = '%s->IsObject()' % cpp_value | 387 type_check = '%s->IsObject()' % cpp_value |
| 389 if argument['is_nullable']: | 388 if argument['is_nullable']: |
| 390 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) | 389 type_check = ' || '.join(['%s->IsNull()' % cpp_value, type_check]) |
| 391 return type_check | 390 return type_check |
| 392 return None | 391 return None |
| 393 | 392 |
| 394 | 393 |
| 395 ################################################################################ | 394 ################################################################################ |
| 396 # Constructors | 395 # Constructors |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 485 | 484 |
| 486 ################################################################################ | 485 ################################################################################ |
| 487 # Special operations (methods) | 486 # Special operations (methods) |
| 488 # http://heycam.github.io/webidl/#idl-special-operations | 487 # http://heycam.github.io/webidl/#idl-special-operations |
| 489 ################################################################################ | 488 ################################################################################ |
| 490 | 489 |
| 491 def property_getter(getter): | 490 def property_getter(getter): |
| 492 def is_null_expression(idl_type): | 491 def is_null_expression(idl_type): |
| 493 if idl_type == 'DOMString': | 492 if idl_type == 'DOMString': |
| 494 return 'element.isNull()' | 493 return 'element.isNull()' |
| 495 return None | 494 if is_interface_type(idl_type): |
| 495 return '!element' |
| 496 return '' |
| 496 | 497 |
| 497 idl_type = getter.idl_type | 498 idl_type = getter.idl_type |
| 498 extended_attributes = getter.extended_attributes | 499 extended_attributes = getter.extended_attributes |
| 500 element = 'element.release()' if is_interface_type(idl_type) else 'element' |
| 501 |
| 499 return { | 502 return { |
| 500 'cpp_type': v8_types.cpp_type(idl_type), | 503 'cpp_type': v8_types.cpp_type(idl_type), |
| 501 'is_custom': | 504 'is_custom': |
| 502 'Custom' in extended_attributes and | 505 'Custom' in extended_attributes and |
| 503 (not extended_attributes['Custom'] or | 506 (not extended_attributes['Custom'] or |
| 504 has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')), | 507 has_extended_attribute_value(getter, 'Custom', 'PropertyGetter')), |
| 505 'is_custom_property_enumerator': has_extended_attribute_value( | 508 'is_custom_property_enumerator': has_extended_attribute_value( |
| 506 getter, 'Custom', 'PropertyEnumerator'), | 509 getter, 'Custom', 'PropertyEnumerator'), |
| 507 'is_custom_property_query': has_extended_attribute_value( | 510 'is_custom_property_query': has_extended_attribute_value( |
| 508 getter, 'Custom', 'PropertyQuery'), | 511 getter, 'Custom', 'PropertyQuery'), |
| 509 'is_enumerable': 'NotEnumerable' not in extended_attributes, | 512 'is_enumerable': 'NotEnumerable' not in extended_attributes, |
| 510 'is_null_expression': is_null_expression(idl_type), | 513 'is_null_expression': is_null_expression(idl_type), |
| 511 'is_raises_exception': 'RaisesException' in extended_attributes, | 514 'is_raises_exception': 'RaisesException' in extended_attributes, |
| 512 'name': cpp_name(getter), | 515 'name': cpp_name(getter), |
| 513 'v8_set_return_value': v8_types.v8_set_return_value(idl_type, 'element',
extended_attributes=extended_attributes, script_wrappable='collection'), | 516 'v8_set_return_value': v8_types.v8_set_return_value(idl_type, element, e
xtended_attributes=extended_attributes, script_wrappable='collection'), |
| 514 } | 517 } |
| 515 | 518 |
| 516 | 519 |
| 517 def property_setter(setter): | 520 def property_setter(setter): |
| 518 idl_type = setter.arguments[1].idl_type | 521 idl_type = setter.arguments[1].idl_type |
| 519 extended_attributes = setter.extended_attributes | 522 extended_attributes = setter.extended_attributes |
| 523 is_raises_exception = 'RaisesException' in extended_attributes |
| 520 return { | 524 return { |
| 521 'has_strict_type_checking': | 525 'has_strict_type_checking': |
| 522 'StrictTypeChecking' in extended_attributes and | 526 'StrictTypeChecking' in extended_attributes and |
| 523 v8_types.is_wrapper_type(idl_type), | 527 v8_types.is_wrapper_type(idl_type), |
| 524 'idl_type': idl_type, | 528 'idl_type': idl_type, |
| 525 'is_custom': 'Custom' in extended_attributes, | 529 'is_custom': 'Custom' in extended_attributes, |
| 526 'is_raises_exception': 'RaisesException' in extended_attributes, | 530 'has_exception_state': is_raises_exception or |
| 531 v8_types.is_integer_type(idl_type), |
| 532 'is_raises_exception': is_raises_exception, |
| 527 'name': cpp_name(setter), | 533 'name': cpp_name(setter), |
| 528 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value( | 534 'v8_value_to_local_cpp_value': v8_types.v8_value_to_local_cpp_value( |
| 529 idl_type, extended_attributes, 'jsValue', 'propertyValue'), | 535 idl_type, extended_attributes, 'jsValue', 'propertyValue'), |
| 530 } | 536 } |
| 531 | 537 |
| 532 | 538 |
| 533 def property_deleter(deleter): | 539 def property_deleter(deleter): |
| 534 idl_type = deleter.idl_type | 540 idl_type = deleter.idl_type |
| 535 if idl_type != 'boolean': | 541 if idl_type != 'boolean': |
| 536 raise Exception( | 542 raise Exception( |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 deleter = next( | 647 deleter = next( |
| 642 method | 648 method |
| 643 for method in interface.operations | 649 for method in interface.operations |
| 644 if ('deleter' in method.specials and | 650 if ('deleter' in method.specials and |
| 645 len(method.arguments) == 1 and | 651 len(method.arguments) == 1 and |
| 646 method.arguments[0].idl_type == 'DOMString')) | 652 method.arguments[0].idl_type == 'DOMString')) |
| 647 except StopIteration: | 653 except StopIteration: |
| 648 return None | 654 return None |
| 649 | 655 |
| 650 return property_deleter(deleter) | 656 return property_deleter(deleter) |
| OLD | NEW |