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

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

Issue 313993002: Bindings: Add ScalarValueString support (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Review feedback Created 6 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/tests/idls/TestObject.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 return base_idl_type 160 return base_idl_type
161 if base_idl_type in CPP_INT_TYPES: 161 if base_idl_type in CPP_INT_TYPES:
162 return 'int' 162 return 'int'
163 if base_idl_type in CPP_UNSIGNED_TYPES: 163 if base_idl_type in CPP_UNSIGNED_TYPES:
164 return 'unsigned' 164 return 'unsigned'
165 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES: 165 if base_idl_type in CPP_SPECIAL_CONVERSION_RULES:
166 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type] 166 return CPP_SPECIAL_CONVERSION_RULES[base_idl_type]
167 167
168 if base_idl_type in NON_WRAPPER_TYPES: 168 if base_idl_type in NON_WRAPPER_TYPES:
169 return 'RefPtr<%s>' % base_idl_type 169 return 'RefPtr<%s>' % base_idl_type
170 if base_idl_type in ('DOMString', 'ByteString'): 170 if base_idl_type in ('DOMString', 'ByteString', 'ScalarValueString'):
171 if not used_as_argument: 171 if not used_as_argument:
172 return 'String' 172 return 'String'
173 return 'V8StringResource<%s>' % string_mode() 173 return 'V8StringResource<%s>' % string_mode()
174 174
175 if idl_type.is_typed_array_type and used_as_argument: 175 if idl_type.is_typed_array_type and used_as_argument:
176 return base_idl_type + '*' 176 return base_idl_type + '*'
177 if idl_type.is_interface_type: 177 if idl_type.is_interface_type:
178 implemented_as_class = idl_type.implemented_as 178 implemented_as_class = idl_type.implemented_as
179 if used_as_argument: 179 if used_as_argument:
180 return implemented_as_class + '*' 180 return implemented_as_class + '*'
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 369
370 ################################################################################ 370 ################################################################################
371 # V8 -> C++ 371 # V8 -> C++
372 ################################################################################ 372 ################################################################################
373 373
374 V8_VALUE_TO_CPP_VALUE = { 374 V8_VALUE_TO_CPP_VALUE = {
375 # Basic 375 # Basic
376 'Date': 'toCoreDate({v8_value})', 376 'Date': 'toCoreDate({v8_value})',
377 'DOMString': '{v8_value}', 377 'DOMString': '{v8_value}',
378 'ByteString': 'toByteString({arguments})', 378 'ByteString': 'toByteString({arguments})',
379 'ScalarValueString': 'toScalarValueString({arguments})',
379 'boolean': '{v8_value}->BooleanValue()', 380 'boolean': '{v8_value}->BooleanValue()',
380 'float': 'static_cast<float>({v8_value}->NumberValue())', 381 'float': 'static_cast<float>({v8_value}->NumberValue())',
381 'unrestricted float': 'static_cast<float>({v8_value}->NumberValue())', 382 'unrestricted float': 'static_cast<float>({v8_value}->NumberValue())',
382 'double': 'static_cast<double>({v8_value}->NumberValue())', 383 'double': 'static_cast<double>({v8_value}->NumberValue())',
383 'unrestricted double': 'static_cast<double>({v8_value}->NumberValue())', 384 'unrestricted double': 'static_cast<double>({v8_value}->NumberValue())',
384 'byte': 'toInt8({arguments})', 385 'byte': 'toInt8({arguments})',
385 'octet': 'toUInt8({arguments})', 386 'octet': 'toUInt8({arguments})',
386 'short': 'toInt16({arguments})', 387 'short': 'toInt16({arguments})',
387 'unsigned short': 'toUInt16({arguments})', 388 'unsigned short': 'toUInt16({arguments})',
388 'long': 'toInt32({arguments})', 389 'long': 'toInt32({arguments})',
(...skipping 20 matching lines...) Expand all
409 if array_or_sequence_type: 410 if array_or_sequence_type:
410 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v 8_value, index) 411 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v 8_value, index)
411 412
412 # Simple types 413 # Simple types
413 idl_type = idl_type.preprocessed_type 414 idl_type = idl_type.preprocessed_type
414 add_includes_for_type(idl_type) 415 add_includes_for_type(idl_type)
415 base_idl_type = idl_type.base_type 416 base_idl_type = idl_type.base_type
416 417
417 if 'EnforceRange' in extended_attributes: 418 if 'EnforceRange' in extended_attributes:
418 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) 419 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState'])
419 elif idl_type.is_integer_type or idl_type.name == 'ByteString': # NormalCon version 420 elif (idl_type.is_integer_type or # NormalConversion
421 idl_type.name in ('ByteString', 'ScalarValueString')):
420 arguments = ', '.join([v8_value, 'exceptionState']) 422 arguments = ', '.join([v8_value, 'exceptionState'])
421 else: 423 else:
422 arguments = v8_value 424 arguments = v8_value
423 425
424 if base_idl_type in V8_VALUE_TO_CPP_VALUE: 426 if base_idl_type in V8_VALUE_TO_CPP_VALUE:
425 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] 427 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type]
426 elif idl_type.is_typed_array_type: 428 elif idl_type.is_typed_array_type:
427 cpp_expression_format = ( 429 cpp_expression_format = (
428 '{v8_value}->Is{idl_type}() ? ' 430 '{v8_value}->Is{idl_type}() ? '
429 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value}) ) : 0') 431 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value}) ) : 0')
(...skipping 27 matching lines...) Expand all
457 459
458 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True): 460 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True):
459 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" 461 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value."""
460 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, used_as_argument=True) 462 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, used_as_argument=True)
461 463
462 idl_type = idl_type.preprocessed_type 464 idl_type = idl_type.preprocessed_type
463 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex) 465 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex)
464 args = [variable_name, cpp_value] 466 args = [variable_name, cpp_value]
465 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type : 467 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type :
466 macro = 'TOSTRING_VOID' 468 macro = 'TOSTRING_VOID'
467 elif idl_type.is_integer_type or idl_type.name == 'ByteString': 469 elif (idl_type.is_integer_type or
470 idl_type.name in ('ByteString', 'ScalarValueString')):
468 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' 471 macro = 'TONATIVE_VOID_EXCEPTIONSTATE'
469 args.append('exceptionState') 472 args.append('exceptionState')
470 else: 473 else:
471 macro = 'TONATIVE_VOID' 474 macro = 'TONATIVE_VOID'
472 475
473 # Macros come in several variants, to minimize expensive creation of 476 # Macros come in several variants, to minimize expensive creation of
474 # v8::TryCatch. 477 # v8::TryCatch.
475 suffix = '' 478 suffix = ''
476 479
477 if declare_variable: 480 if declare_variable:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
569 572
570 IdlType.v8_conversion_type = v8_conversion_type 573 IdlType.v8_conversion_type = v8_conversion_type
571 574
572 575
573 V8_SET_RETURN_VALUE = { 576 V8_SET_RETURN_VALUE = {
574 'boolean': 'v8SetReturnValueBool(info, {cpp_value})', 577 'boolean': 'v8SetReturnValueBool(info, {cpp_value})',
575 'int': 'v8SetReturnValueInt(info, {cpp_value})', 578 'int': 'v8SetReturnValueInt(info, {cpp_value})',
576 'unsigned': 'v8SetReturnValueUnsigned(info, {cpp_value})', 579 'unsigned': 'v8SetReturnValueUnsigned(info, {cpp_value})',
577 'DOMString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())', 580 'DOMString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())',
578 'ByteString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())' , 581 'ByteString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())' ,
582 'ScalarValueString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsol ate())',
579 # [TreatNullReturnValueAs] 583 # [TreatNullReturnValueAs]
580 'StringOrNull': 'v8SetReturnValueStringOrNull(info, {cpp_value}, info.GetIso late())', 584 'StringOrNull': 'v8SetReturnValueStringOrNull(info, {cpp_value}, info.GetIso late())',
581 'StringOrUndefined': 'v8SetReturnValueStringOrUndefined(info, {cpp_value}, i nfo.GetIsolate())', 585 'StringOrUndefined': 'v8SetReturnValueStringOrUndefined(info, {cpp_value}, i nfo.GetIsolate())',
582 'void': '', 586 'void': '',
583 # No special v8SetReturnValue* function (set value directly) 587 # No special v8SetReturnValue* function (set value directly)
584 'float': 'v8SetReturnValue(info, {cpp_value})', 588 'float': 'v8SetReturnValue(info, {cpp_value})',
585 'unrestricted float': 'v8SetReturnValue(info, {cpp_value})', 589 'unrestricted float': 'v8SetReturnValue(info, {cpp_value})',
586 'double': 'v8SetReturnValue(info, {cpp_value})', 590 'double': 'v8SetReturnValue(info, {cpp_value})',
587 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})', 591 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})',
588 # No special v8SetReturnValue* function, but instead convert value to V8 592 # No special v8SetReturnValue* function, but instead convert value to V8
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
649 IdlUnionType.release = property( 653 IdlUnionType.release = property(
650 lambda self: [member_type.is_interface_type 654 lambda self: [member_type.is_interface_type
651 for member_type in self.member_types]) 655 for member_type in self.member_types])
652 656
653 657
654 CPP_VALUE_TO_V8_VALUE = { 658 CPP_VALUE_TO_V8_VALUE = {
655 # Built-in types 659 # Built-in types
656 'Date': 'v8DateOrNaN({cpp_value}, {isolate})', 660 'Date': 'v8DateOrNaN({cpp_value}, {isolate})',
657 'DOMString': 'v8String({isolate}, {cpp_value})', 661 'DOMString': 'v8String({isolate}, {cpp_value})',
658 'ByteString': 'v8String({isolate}, {cpp_value})', 662 'ByteString': 'v8String({isolate}, {cpp_value})',
663 'ScalarValueString': 'v8String({isolate}, {cpp_value})',
659 'boolean': 'v8Boolean({cpp_value}, {isolate})', 664 'boolean': 'v8Boolean({cpp_value}, {isolate})',
660 'int': 'v8::Integer::New({isolate}, {cpp_value})', 665 'int': 'v8::Integer::New({isolate}, {cpp_value})',
661 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', 666 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})',
662 'float': 'v8::Number::New({isolate}, {cpp_value})', 667 'float': 'v8::Number::New({isolate}, {cpp_value})',
663 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})', 668 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})',
664 'double': 'v8::Number::New({isolate}, {cpp_value})', 669 'double': 'v8::Number::New({isolate}, {cpp_value})',
665 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})', 670 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})',
666 'void': 'v8Undefined()', 671 'void': 'v8Undefined()',
667 # Special cases 672 # Special cases
668 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))', 673 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))',
669 'ScriptValue': '{cpp_value}.v8Value()', 674 'ScriptValue': '{cpp_value}.v8Value()',
670 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))', 675 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))',
671 # General 676 # General
672 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})', 677 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})',
673 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', 678 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})',
674 } 679 }
675 680
676 681
677 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='info.Holder()', extended_attributes=None): 682 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='info.Holder()', extended_attributes=None):
678 """Returns an expression that converts a C++ value to a V8 value.""" 683 """Returns an expression that converts a C++ value to a V8 value."""
679 # the isolate parameter is needed for callback interfaces 684 # the isolate parameter is needed for callback interfaces
680 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) 685 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes)
681 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) 686 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes)
682 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] 687 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type]
683 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) 688 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context)
684 return statement 689 return statement
685 690
686 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value 691 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value
OLDNEW
« no previous file with comments | « Source/bindings/scripts/v8_methods.py ('k') | Source/bindings/tests/idls/TestObject.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698