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

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: 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
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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 358
359 ################################################################################ 359 ################################################################################
360 # V8 -> C++ 360 # V8 -> C++
361 ################################################################################ 361 ################################################################################
362 362
363 V8_VALUE_TO_CPP_VALUE = { 363 V8_VALUE_TO_CPP_VALUE = {
364 # Basic 364 # Basic
365 'Date': 'toCoreDate({v8_value})', 365 'Date': 'toCoreDate({v8_value})',
366 'DOMString': '{v8_value}', 366 'DOMString': '{v8_value}',
367 'ByteString': 'toByteString({arguments})', 367 'ByteString': 'toByteString({arguments})',
368 'ScalarValueString': 'toScalarValueString({arguments})',
368 'boolean': '{v8_value}->BooleanValue()', 369 'boolean': '{v8_value}->BooleanValue()',
369 'float': 'static_cast<float>({v8_value}->NumberValue())', 370 'float': 'static_cast<float>({v8_value}->NumberValue())',
370 'unrestricted float': 'static_cast<float>({v8_value}->NumberValue())', 371 'unrestricted float': 'static_cast<float>({v8_value}->NumberValue())',
371 'double': 'static_cast<double>({v8_value}->NumberValue())', 372 'double': 'static_cast<double>({v8_value}->NumberValue())',
372 'unrestricted double': 'static_cast<double>({v8_value}->NumberValue())', 373 'unrestricted double': 'static_cast<double>({v8_value}->NumberValue())',
373 'byte': 'toInt8({arguments})', 374 'byte': 'toInt8({arguments})',
374 'octet': 'toUInt8({arguments})', 375 'octet': 'toUInt8({arguments})',
375 'short': 'toInt16({arguments})', 376 'short': 'toInt16({arguments})',
376 'unsigned short': 'toUInt16({arguments})', 377 'unsigned short': 'toUInt16({arguments})',
377 'long': 'toInt32({arguments})', 378 'long': 'toInt32({arguments})',
(...skipping 20 matching lines...) Expand all
398 if array_or_sequence_type: 399 if array_or_sequence_type:
399 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v 8_value, index) 400 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v 8_value, index)
400 401
401 # Simple types 402 # Simple types
402 idl_type = idl_type.preprocessed_type 403 idl_type = idl_type.preprocessed_type
403 add_includes_for_type(idl_type) 404 add_includes_for_type(idl_type)
404 base_idl_type = idl_type.base_type 405 base_idl_type = idl_type.base_type
405 406
406 if 'EnforceRange' in extended_attributes: 407 if 'EnforceRange' in extended_attributes:
407 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState']) 408 arguments = ', '.join([v8_value, 'EnforceRange', 'exceptionState'])
408 elif idl_type.is_integer_type or idl_type.name == 'ByteString': # NormalCon version 409 elif idl_type.is_integer_type or idl_type.name in ('ByteString', 'ScalarValu eString'): # NormalConversion
Nils Barth (inactive) 2014/06/11 03:54:26 ditto
jsbell 2014/06/12 17:45:55 Done.
409 arguments = ', '.join([v8_value, 'exceptionState']) 410 arguments = ', '.join([v8_value, 'exceptionState'])
410 else: 411 else:
411 arguments = v8_value 412 arguments = v8_value
412 413
413 if base_idl_type in V8_VALUE_TO_CPP_VALUE: 414 if base_idl_type in V8_VALUE_TO_CPP_VALUE:
414 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type] 415 cpp_expression_format = V8_VALUE_TO_CPP_VALUE[base_idl_type]
415 elif idl_type.is_typed_array_type: 416 elif idl_type.is_typed_array_type:
416 cpp_expression_format = ( 417 cpp_expression_format = (
417 '{v8_value}->Is{idl_type}() ? ' 418 '{v8_value}->Is{idl_type}() ? '
418 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value}) ) : 0') 419 'V8{idl_type}::toNative(v8::Handle<v8::{idl_type}>::Cast({v8_value}) ) : 0')
(...skipping 27 matching lines...) Expand all
446 447
447 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True): 448 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True):
448 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" 449 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value."""
449 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, used_as_argument=True) 450 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, used_as_argument=True)
450 451
451 idl_type = idl_type.preprocessed_type 452 idl_type = idl_type.preprocessed_type
452 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex) 453 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex)
453 args = [variable_name, cpp_value] 454 args = [variable_name, cpp_value]
454 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type : 455 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type :
455 macro = 'TOSTRING_VOID' 456 macro = 'TOSTRING_VOID'
456 elif idl_type.is_integer_type or idl_type.name == 'ByteString': 457 elif idl_type.is_integer_type or idl_type.name in ('ByteString', 'ScalarValu eString'):
Nils Barth (inactive) 2014/06/11 03:54:26 ditto
jsbell 2014/06/12 17:45:55 Done.
457 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' 458 macro = 'TONATIVE_VOID_EXCEPTIONSTATE'
458 args.append('exceptionState') 459 args.append('exceptionState')
459 else: 460 else:
460 macro = 'TONATIVE_VOID' 461 macro = 'TONATIVE_VOID'
461 462
462 # Macros come in several variants, to minimize expensive creation of 463 # Macros come in several variants, to minimize expensive creation of
463 # v8::TryCatch. 464 # v8::TryCatch.
464 suffix = '' 465 suffix = ''
465 466
466 if declare_variable: 467 if declare_variable:
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
558 559
559 IdlType.v8_conversion_type = v8_conversion_type 560 IdlType.v8_conversion_type = v8_conversion_type
560 561
561 562
562 V8_SET_RETURN_VALUE = { 563 V8_SET_RETURN_VALUE = {
563 'boolean': 'v8SetReturnValueBool(info, {cpp_value})', 564 'boolean': 'v8SetReturnValueBool(info, {cpp_value})',
564 'int': 'v8SetReturnValueInt(info, {cpp_value})', 565 'int': 'v8SetReturnValueInt(info, {cpp_value})',
565 'unsigned': 'v8SetReturnValueUnsigned(info, {cpp_value})', 566 'unsigned': 'v8SetReturnValueUnsigned(info, {cpp_value})',
566 'DOMString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())', 567 'DOMString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())',
567 'ByteString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())' , 568 'ByteString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())' ,
569 'ScalarValueString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsol ate())',
568 # [TreatNullReturnValueAs] 570 # [TreatNullReturnValueAs]
569 'StringOrNull': 'v8SetReturnValueStringOrNull(info, {cpp_value}, info.GetIso late())', 571 'StringOrNull': 'v8SetReturnValueStringOrNull(info, {cpp_value}, info.GetIso late())',
570 'StringOrUndefined': 'v8SetReturnValueStringOrUndefined(info, {cpp_value}, i nfo.GetIsolate())', 572 'StringOrUndefined': 'v8SetReturnValueStringOrUndefined(info, {cpp_value}, i nfo.GetIsolate())',
571 'void': '', 573 'void': '',
572 # No special v8SetReturnValue* function (set value directly) 574 # No special v8SetReturnValue* function (set value directly)
573 'float': 'v8SetReturnValue(info, {cpp_value})', 575 'float': 'v8SetReturnValue(info, {cpp_value})',
574 'unrestricted float': 'v8SetReturnValue(info, {cpp_value})', 576 'unrestricted float': 'v8SetReturnValue(info, {cpp_value})',
575 'double': 'v8SetReturnValue(info, {cpp_value})', 577 'double': 'v8SetReturnValue(info, {cpp_value})',
576 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})', 578 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})',
577 # No special v8SetReturnValue* function, but instead convert value to V8 579 # No special v8SetReturnValue* function, but instead convert value to V8
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
638 IdlUnionType.release = property( 640 IdlUnionType.release = property(
639 lambda self: [member_type.is_interface_type 641 lambda self: [member_type.is_interface_type
640 for member_type in self.member_types]) 642 for member_type in self.member_types])
641 643
642 644
643 CPP_VALUE_TO_V8_VALUE = { 645 CPP_VALUE_TO_V8_VALUE = {
644 # Built-in types 646 # Built-in types
645 'Date': 'v8DateOrNaN({cpp_value}, {isolate})', 647 'Date': 'v8DateOrNaN({cpp_value}, {isolate})',
646 'DOMString': 'v8String({isolate}, {cpp_value})', 648 'DOMString': 'v8String({isolate}, {cpp_value})',
647 'ByteString': 'v8String({isolate}, {cpp_value})', 649 'ByteString': 'v8String({isolate}, {cpp_value})',
650 'ScalarValueString': 'v8String({isolate}, {cpp_value})',
648 'boolean': 'v8Boolean({cpp_value}, {isolate})', 651 'boolean': 'v8Boolean({cpp_value}, {isolate})',
649 'int': 'v8::Integer::New({isolate}, {cpp_value})', 652 'int': 'v8::Integer::New({isolate}, {cpp_value})',
650 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', 653 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})',
651 'float': 'v8::Number::New({isolate}, {cpp_value})', 654 'float': 'v8::Number::New({isolate}, {cpp_value})',
652 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})', 655 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})',
653 'double': 'v8::Number::New({isolate}, {cpp_value})', 656 'double': 'v8::Number::New({isolate}, {cpp_value})',
654 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})', 657 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})',
655 'void': 'v8Undefined()', 658 'void': 'v8Undefined()',
656 # Special cases 659 # Special cases
657 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))', 660 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))',
658 'ScriptValue': '{cpp_value}.v8Value()', 661 'ScriptValue': '{cpp_value}.v8Value()',
659 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))', 662 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))',
660 # General 663 # General
661 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})', 664 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})',
662 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', 665 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})',
663 } 666 }
664 667
665 668
666 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='info.Holder()', extended_attributes=None): 669 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='info.Holder()', extended_attributes=None):
667 """Returns an expression that converts a C++ value to a V8 value.""" 670 """Returns an expression that converts a C++ value to a V8 value."""
668 # the isolate parameter is needed for callback interfaces 671 # the isolate parameter is needed for callback interfaces
669 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) 672 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes)
670 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) 673 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes)
671 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] 674 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type]
672 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) 675 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context)
673 return statement 676 return statement
674 677
675 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value 678 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698