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

Side by Side Diff: Source/bindings/scripts/unstable/v8_types.py

Issue 121113004: Improve handling of failed integer type conversions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 11 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
OLDNEW
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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 ################################################################################ 50 ################################################################################
51 51
52 BASIC_TYPES = set([ 52 BASIC_TYPES = set([
53 # Built-in, non-composite, non-object data types 53 # Built-in, non-composite, non-object data types
54 # http://www.w3.org/TR/WebIDL/#dfn-primitive-type 54 # http://www.w3.org/TR/WebIDL/#dfn-primitive-type
55 'boolean', 55 'boolean',
56 'float', 56 'float',
57 # unrestricted float is not supported 57 # unrestricted float is not supported
58 'double', 58 'double',
59 # unrestricted double is not supported 59 # unrestricted double is not supported
60 # integer types 60 # http://www.w3.org/TR/WebIDL/#idl-types
61 'DOMString',
62 'Date',
63 # http://www.w3.org/TR/WebIDL/#es-type-mapping
64 'void',
65 ])
66 INTEGER_TYPES = set([
61 # http://www.w3.org/TR/WebIDL/#dfn-integer-type 67 # http://www.w3.org/TR/WebIDL/#dfn-integer-type
62 'byte', 68 'byte',
63 'octet', 69 'octet',
64 'short', 70 'short',
65 'unsigned short', 71 'unsigned short',
66 # int and unsigned are not IDL types 72 # int and unsigned are not IDL types
67 'long', 73 'long',
68 'unsigned long', 74 'unsigned long',
69 'long long', 75 'long long',
70 'unsigned long long', 76 'unsigned long long',
71 # http://www.w3.org/TR/WebIDL/#idl-types
72 'DOMString',
73 'Date',
74 # http://www.w3.org/TR/WebIDL/#es-type-mapping
75 'void',
76 ]) 77 ])
78 BASIC_TYPES.update(INTEGER_TYPES)
77 79
78 enum_types = {} # name -> values 80 enum_types = {} # name -> values
79 callback_function_types = set() 81 callback_function_types = set()
80 82
81 83
82 def array_or_sequence_type(idl_type): 84 def array_or_sequence_type(idl_type):
83 return array_type(idl_type) or sequence_type(idl_type) 85 return array_type(idl_type) or sequence_type(idl_type)
84 86
85 87
86 def array_type(idl_type): 88 def array_type(idl_type):
87 matched = re.match(r'([\w\s]+)\[\]', idl_type) 89 matched = re.match(r'([\w\s]+)\[\]', idl_type)
88 return matched and matched.group(1) 90 return matched and matched.group(1)
89 91
90 92
91 def is_basic_type(idl_type): 93 def is_basic_type(idl_type):
92 return idl_type in BASIC_TYPES 94 return idl_type in BASIC_TYPES
93 95
94 96
97 def is_integer_type(idl_type):
98 return idl_type in INTEGER_TYPES
99
100
95 def is_callback_function_type(idl_type): 101 def is_callback_function_type(idl_type):
96 return idl_type in callback_function_types 102 return idl_type in callback_function_types
97 103
98 104
99 def set_callback_function_types(callback_functions): 105 def set_callback_function_types(callback_functions):
100 callback_function_types.update(callback_functions.keys()) 106 callback_function_types.update(callback_functions.keys())
101 107
102 108
103 def is_composite_type(idl_type): 109 def is_composite_type(idl_type):
104 return (idl_type == 'any' or 110 return (idl_type == 'any' or
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 376
371 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index): 377 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) 378 this_array_or_sequence_type = array_or_sequence_type(idl_type)
373 if this_array_or_sequence_type: 379 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) 380 return v8_value_to_cpp_value_array_or_sequence(this_array_or_sequence_ty pe, v8_value, index)
375 381
376 idl_type = preprocess_idl_type(idl_type) 382 idl_type = preprocess_idl_type(idl_type)
377 add_includes_for_type(idl_type) 383 add_includes_for_type(idl_type)
378 384
379 if 'EnforceRange' in extended_attributes: 385 if 'EnforceRange' in extended_attributes:
380 arguments = ', '.join([v8_value, 'EnforceRange', 'ok']) 386 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState'])
381 else: # NormalConversion 387 elif is_integer_type(idl_type): # NormalConversion
388 arguments = ', '.join([v8_value, 'exceptionState'])
389 else:
382 arguments = v8_value 390 arguments = v8_value
383 391
384 if idl_type in V8_VALUE_TO_CPP_VALUE: 392 if idl_type in V8_VALUE_TO_CPP_VALUE:
385 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[idl_type] 393 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[idl_type]
386 elif is_typed_array_type(idl_type): 394 elif is_typed_array_type(idl_type):
387 cpp_expression_format = ( 395 cpp_expression_format = (
388 '{v8_value}->Is{idl_type}() ? ' 396 '{v8_value}->Is{idl_type}() ? '
389 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value}) ) : 0') 397 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value}) ) : 0')
390 else: 398 else:
391 cpp_expression_format = ( 399 cpp_expression_format = (
(...skipping 22 matching lines...) Expand all
414 return expression 422 return expression
415 423
416 424
417 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None): 425 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.""" 426 """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) 427 this_cpp_type = cpp_type(idl_type, extended_attributes=extended_attributes, used_as_argument=True)
420 428
421 idl_type = preprocess_idl_type(idl_type) 429 idl_type = preprocess_idl_type(idl_type)
422 if idl_type == 'DOMString': 430 if idl_type == 'DOMString':
423 format_string = 'V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID({cpp_type}, {varia ble_name}, {cpp_value})' 431 format_string = 'V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID({cpp_type}, {varia ble_name}, {cpp_value})'
424 elif 'EnforceRange' in extended_attributes: 432 elif is_integer_type(idl_type):
425 format_string = 'V8TRYCATCH_WITH_TYPECHECK_VOID({cpp_type}, {variable_na me}, {cpp_value}, info.GetIsolate())' 433 format_string = 'V8TRYCATCH_EXCEPTION_VOID({cpp_type}, {variable_name}, {cpp_value}, exceptionState)'
426 else: 434 else:
427 format_string = 'V8TRYCATCH_VOID({cpp_type}, {variable_name}, {cpp_value })' 435 format_string = 'V8TRYCATCH_VOID({cpp_type}, {variable_name}, {cpp_value })'
428 436
429 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex) 437 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) 438 return format_string.format(cpp_type=this_cpp_type, cpp_value=cpp_value, var iable_name=variable_name)
431 439
432 440
433 ################################################################################ 441 ################################################################################
434 # C++ -> V8 442 # C++ -> V8
435 ################################################################################ 443 ################################################################################
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 583
576 584
577 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None): 585 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.""" 586 """Returns an expression that converts a C++ value to a V8 value."""
579 # the isolate parameter is needed for callback interfaces 587 # 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) 588 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) 589 this_v8_conversion_type = v8_conversion_type(idl_type, extended_attributes)
582 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] 590 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) 591 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context)
584 return statement 592 return statement
OLDNEW
« no previous file with comments | « Source/bindings/scripts/unstable/v8_methods.py ('k') | Source/bindings/templates/attributes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698