Chromium Code Reviews| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 | 135 |
| 136 def sequence_type(idl_type): | 136 def sequence_type(idl_type): |
| 137 matched = re.match(r'sequence<([\w\s]+)>', idl_type) | 137 matched = re.match(r'sequence<([\w\s]+)>', idl_type) |
| 138 return matched and matched.group(1) | 138 return matched and matched.group(1) |
| 139 | 139 |
| 140 | 140 |
| 141 def is_union_type(idl_type): | 141 def is_union_type(idl_type): |
| 142 return isinstance(idl_type, idl_definitions.IdlUnionType) | 142 return isinstance(idl_type, idl_definitions.IdlUnionType) |
| 143 | 143 |
| 144 | 144 |
| 145 def is_integer_type(idl_type): | |
| 146 return any(idl_type in s for s in [CPP_INT_TYPES, CPP_UNSIGNED_TYPES, CPP_LO NG_LONG_TYPES]) | |
|
Nils Barth (inactive)
2014/01/06 02:58:09
Simpler:
return idl_type in CPP_INT_TYPES | CPP_UN
sof
2014/01/06 21:01:25
Adopted wholesale; the transformation added here i
| |
| 147 | |
| 145 ################################################################################ | 148 ################################################################################ |
| 146 # V8-specific type handling | 149 # V8-specific type handling |
| 147 ################################################################################ | 150 ################################################################################ |
| 148 | 151 |
| 149 DOM_NODE_TYPES = set([ | 152 DOM_NODE_TYPES = set([ |
| 150 'Attr', | 153 'Attr', |
| 151 'CDATASection', | 154 'CDATASection', |
| 152 'CharacterData', | 155 'CharacterData', |
| 153 'Comment', | 156 'Comment', |
| 154 'Document', | 157 'Document', |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 ]) | 233 ]) |
| 231 CPP_SPECIAL_CONVERSION_RULES = { | 234 CPP_SPECIAL_CONVERSION_RULES = { |
| 232 'CompareHow': 'Range::CompareHow', | 235 'CompareHow': 'Range::CompareHow', |
| 233 'Date': 'double', | 236 'Date': 'double', |
| 234 'Dictionary': 'Dictionary', | 237 'Dictionary': 'Dictionary', |
| 235 'EventHandler': 'EventListener*', | 238 'EventHandler': 'EventListener*', |
| 236 'Promise': 'ScriptPromise', | 239 'Promise': 'ScriptPromise', |
| 237 'ScriptValue': 'ScriptValue', | 240 'ScriptValue': 'ScriptValue', |
| 238 'boolean': 'bool', | 241 'boolean': 'bool', |
| 239 } | 242 } |
| 243 CPP_LONG_LONG_TYPES = set([ | |
|
Nils Barth (inactive)
2014/01/06 02:58:09
Could you put this set up *above* CPP_SPECIAL_CONV
sof
2014/01/06 21:01:25
Removed.
| |
| 244 'long long', | |
| 245 'unsigned long long', | |
| 246 ]) | |
| 240 | 247 |
| 241 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False): | 248 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False): |
| 242 """Returns C++ type corresponding to IDL type.""" | 249 """Returns C++ type corresponding to IDL type.""" |
| 243 def string_mode(): | 250 def string_mode(): |
| 244 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString', | 251 # FIXME: the Web IDL spec requires 'EmptyString', not 'NullString', |
| 245 # but we use NullString for performance. | 252 # but we use NullString for performance. |
| 246 if extended_attributes.get('TreatNullAs') != 'NullString': | 253 if extended_attributes.get('TreatNullAs') != 'NullString': |
| 247 return '' | 254 return '' |
| 248 if extended_attributes.get('TreatUndefinedAs') != 'NullString': | 255 if extended_attributes.get('TreatUndefinedAs') != 'NullString': |
| 249 return 'WithNullCheck' | 256 return 'WithNullCheck' |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 370 | 377 |
| 371 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index): | 378 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index): |
| 372 this_array_or_sequence_type = array_or_sequence_type(idl_type) | 379 this_array_or_sequence_type = array_or_sequence_type(idl_type) |
| 373 if this_array_or_sequence_type: | 380 if this_array_or_sequence_type: |
| 374 return v8_value_to_cpp_value_array_or_sequence(this_array_or_sequence_ty pe, v8_value, index) | 381 return v8_value_to_cpp_value_array_or_sequence(this_array_or_sequence_ty pe, v8_value, index) |
| 375 | 382 |
| 376 idl_type = preprocess_idl_type(idl_type) | 383 idl_type = preprocess_idl_type(idl_type) |
| 377 add_includes_for_type(idl_type) | 384 add_includes_for_type(idl_type) |
| 378 | 385 |
| 379 if 'EnforceRange' in extended_attributes: | 386 if 'EnforceRange' in extended_attributes: |
| 380 arguments = ', '.join([v8_value, 'EnforceRange', 'ok']) | 387 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) |
| 381 else: # NormalConversion | 388 elif is_integer_type(idl_type): # NormalConversion |
|
Nils Barth (inactive)
2014/01/06 02:58:09
Comment '# NormalConversion' should go on the defa
sof
2014/01/06 21:01:25
Isn't this the correct placement for it? i.e., thi
Nils Barth (inactive)
2014/01/07 02:11:35
OIC, you're right - sorry, thanks!
(NormalConversi
| |
| 389 arguments = ', '.join([v8_value, 'exceptionState']) | |
| 390 else: | |
| 382 arguments = v8_value | 391 arguments = v8_value |
| 383 | 392 |
| 384 if idl_type in V8_VALUE_TO_CPP_VALUE: | 393 if idl_type in V8_VALUE_TO_CPP_VALUE: |
| 385 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[idl_type] | 394 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[idl_type] |
| 386 elif is_typed_array_type(idl_type): | 395 elif is_typed_array_type(idl_type): |
| 387 cpp_expression_format = ( | 396 cpp_expression_format = ( |
| 388 '{v8_value}->Is{idl_type}() ? ' | 397 '{v8_value}->Is{idl_type}() ? ' |
| 389 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value}) ) : 0') | 398 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value}) ) : 0') |
| 390 else: | 399 else: |
| 391 cpp_expression_format = ( | 400 cpp_expression_format = ( |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 414 return expression | 423 return expression |
| 415 | 424 |
| 416 | 425 |
| 417 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None): | 426 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None): |
| 418 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" | 427 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" |
| 419 this_cpp_type = cpp_type(idl_type, extended_attributes=extended_attributes, used_as_argument=True) | 428 this_cpp_type = cpp_type(idl_type, extended_attributes=extended_attributes, used_as_argument=True) |
| 420 | 429 |
| 421 idl_type = preprocess_idl_type(idl_type) | 430 idl_type = preprocess_idl_type(idl_type) |
| 422 if idl_type == 'DOMString': | 431 if idl_type == 'DOMString': |
| 423 format_string = 'V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID({cpp_type}, {varia ble_name}, {cpp_value})' | 432 format_string = 'V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID({cpp_type}, {varia ble_name}, {cpp_value})' |
| 424 elif 'EnforceRange' in extended_attributes: | 433 elif is_integer_type(idl_type): |
| 425 format_string = 'V8TRYCATCH_WITH_TYPECHECK_VOID({cpp_type}, {variable_na me}, {cpp_value}, info.GetIsolate())' | 434 format_string = 'V8TRYCATCH_EXCEPTION_VOID({cpp_type}, {variable_name}, {cpp_value}, exceptionState)' |
| 426 else: | 435 else: |
| 427 format_string = 'V8TRYCATCH_VOID({cpp_type}, {variable_name}, {cpp_value })' | 436 format_string = 'V8TRYCATCH_VOID({cpp_type}, {variable_name}, {cpp_value })' |
| 428 | 437 |
| 429 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex) | 438 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex) |
| 430 return format_string.format(cpp_type=this_cpp_type, cpp_value=cpp_value, var iable_name=variable_name) | 439 return format_string.format(cpp_type=this_cpp_type, cpp_value=cpp_value, var iable_name=variable_name) |
| 431 | 440 |
| 432 | 441 |
| 433 ################################################################################ | 442 ################################################################################ |
| 434 # C++ -> V8 | 443 # C++ -> V8 |
| 435 ################################################################################ | 444 ################################################################################ |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 575 | 584 |
| 576 | 585 |
| 577 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None): | 586 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None): |
| 578 """Returns an expression that converts a C++ value to a V8 value.""" | 587 """Returns an expression that converts a C++ value to a V8 value.""" |
| 579 # the isolate parameter is needed for callback interfaces | 588 # the isolate parameter is needed for callback interfaces |
| 580 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) | 589 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) |
| 581 this_v8_conversion_type = v8_conversion_type(idl_type, extended_attributes) | 590 this_v8_conversion_type = v8_conversion_type(idl_type, extended_attributes) |
| 582 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] | 591 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] |
| 583 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) | 592 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) |
| 584 return statement | 593 return statement |
| OLD | NEW |