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

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

Issue 362993004: Implement Blink-in-JS for DOM attributes (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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 393 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 'MediaQueryListListener': 'MediaQueryListListener::create(ScriptState::curre nt({isolate}), ScriptValue(ScriptState::current({isolate}), {v8_value}))', 404 'MediaQueryListListener': 'MediaQueryListListener::create(ScriptState::curre nt({isolate}), ScriptValue(ScriptState::current({isolate}), {v8_value}))',
405 'NodeFilter': 'toNodeFilter({v8_value}, info.Holder(), ScriptState::current( {isolate}))', 405 'NodeFilter': 'toNodeFilter({v8_value}, info.Holder(), ScriptState::current( {isolate}))',
406 'Promise': 'ScriptPromise::cast(ScriptState::current({isolate}), {v8_value}) ', 406 'Promise': 'ScriptPromise::cast(ScriptState::current({isolate}), {v8_value}) ',
407 'SerializedScriptValue': 'SerializedScriptValue::create({v8_value}, {isolate })', 407 'SerializedScriptValue': 'SerializedScriptValue::create({v8_value}, {isolate })',
408 'ScriptValue': 'ScriptValue(ScriptState::current({isolate}), {v8_value})', 408 'ScriptValue': 'ScriptValue(ScriptState::current({isolate}), {v8_value})',
409 'Window': 'toDOMWindow({v8_value}, {isolate})', 409 'Window': 'toDOMWindow({v8_value}, {isolate})',
410 'XPathNSResolver': 'toXPathNSResolver({v8_value}, {isolate})', 410 'XPathNSResolver': 'toXPathNSResolver({v8_value}, {isolate})',
411 } 411 }
412 412
413 413
414 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index, isolat e='info.GetIsolate()'): 414 def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, index, isolat e):
415 if idl_type.name == 'void': 415 if idl_type.name == 'void':
416 return '' 416 return ''
417 417
418 # Composite types 418 # Composite types
419 array_or_sequence_type = idl_type.array_or_sequence_type 419 array_or_sequence_type = idl_type.array_or_sequence_type
420 if array_or_sequence_type: 420 if array_or_sequence_type:
421 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v 8_value, index) 421 return v8_value_to_cpp_value_array_or_sequence(array_or_sequence_type, v 8_value, index)
422 422
423 # Simple types 423 # Simple types
424 idl_type = idl_type.preprocessed_type 424 idl_type = idl_type.preprocessed_type
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
459 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ e}, V8{array_or_sequence_type}>({v8_value}, {index}, {isolate}))' 459 expression_format = '(to{ref_ptr_type}NativeArray<{array_or_sequence_typ e}, V8{array_or_sequence_type}>({v8_value}, {index}, {isolate}))'
460 add_includes_for_type(array_or_sequence_type) 460 add_includes_for_type(array_or_sequence_type)
461 else: 461 else:
462 ref_ptr_type = None 462 ref_ptr_type = None
463 this_cpp_type = array_or_sequence_type.cpp_type 463 this_cpp_type = array_or_sequence_type.cpp_type
464 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, {iso late})' 464 expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {index}, {iso late})'
465 expression = expression_format.format(array_or_sequence_type=array_or_sequen ce_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_type, v8 _value=v8_value, isolate=isolate) 465 expression = expression_format.format(array_or_sequence_type=array_or_sequen ce_type.name, cpp_type=this_cpp_type, index=index, ref_ptr_type=ref_ptr_type, v8 _value=v8_value, isolate=isolate)
466 return expression 466 return expression
467 467
468 468
469 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True): 469 def v8_value_to_local_cpp_value(idl_type, extended_attributes, v8_value, variabl e_name, index=None, declare_variable=True, isolate='info.GetIsolate()', used_in_ private_script=False):
470 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value.""" 470 """Returns an expression that converts a V8 value to a C++ value and stores it as a local value."""
471
472 # FIXME: Support union type.
473 if idl_type.is_union_type:
474 return ''
475
471 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True) 476 this_cpp_type = idl_type.cpp_type_args(extended_attributes=extended_attribut es, raw_type=True)
472 477
473 idl_type = idl_type.preprocessed_type 478 idl_type = idl_type.preprocessed_type
474 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex) 479 cpp_value = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, i ndex, isolate)
475 args = [variable_name, cpp_value] 480 args = [variable_name, cpp_value]
476 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type : 481 if idl_type.base_type == 'DOMString' and not idl_type.array_or_sequence_type :
477 macro = 'TOSTRING_VOID' 482 macro = 'TOSTRING_DEFAULT' if used_in_private_script else 'TOSTRING_VOID '
478 elif idl_type.may_raise_exception_on_conversion: 483 elif idl_type.may_raise_exception_on_conversion:
479 macro = 'TONATIVE_VOID_EXCEPTIONSTATE' 484 macro = 'TONATIVE_DEFAULT_EXCEPTIONSTATE' if used_in_private_script else 'TONATIVE_VOID_EXCEPTIONSTATE'
Jens Widell 2014/07/03 13:23:26 This might be somewhat nicer if we had "TONATIVE_(
haraken 2014/07/11 04:29:56 I took a look at this. I agree that "TONATIVE_(|EX
480 args.append('exceptionState') 485 args.append('exceptionState')
481 else: 486 else:
482 macro = 'TONATIVE_VOID' 487 macro = 'TONATIVE_DEFAULT' if used_in_private_script else 'TONATIVE_VOID '
488
489 if used_in_private_script:
490 args.append('false')
483 491
484 # Macros come in several variants, to minimize expensive creation of 492 # Macros come in several variants, to minimize expensive creation of
485 # v8::TryCatch. 493 # v8::TryCatch.
486 suffix = '' 494 suffix = ''
487 495
488 if declare_variable: 496 if declare_variable:
489 args.insert(0, this_cpp_type) 497 args.insert(0, this_cpp_type)
490 else: 498 else:
491 suffix += '_INTERNAL' 499 suffix += '_INTERNAL'
492 500
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
561 if idl_type.is_string_type: 569 if idl_type.is_string_type:
562 if idl_type.is_nullable: 570 if idl_type.is_nullable:
563 return 'StringOrNull' 571 return 'StringOrNull'
564 if 'TreatReturnedNullStringAs' not in extended_attributes: 572 if 'TreatReturnedNullStringAs' not in extended_attributes:
565 return base_idl_type 573 return base_idl_type
566 treat_returned_null_string_as = extended_attributes['TreatReturnedNullSt ringAs'] 574 treat_returned_null_string_as = extended_attributes['TreatReturnedNullSt ringAs']
567 if treat_returned_null_string_as == 'Null': 575 if treat_returned_null_string_as == 'Null':
568 return 'StringOrNull' 576 return 'StringOrNull'
569 if treat_returned_null_string_as == 'Undefined': 577 if treat_returned_null_string_as == 'Undefined':
570 return 'StringOrUndefined' 578 return 'StringOrUndefined'
571 raise 'Unrecognized TreatReturnNullStringAs value: "%s"' % treat_returne d_null_string_as 579 raise 'Unrecognized TreatReturnedNullStringAs value: "%s"' % treat_retur ned_null_string_as
572 if idl_type.is_basic_type or base_idl_type == 'ScriptValue': 580 if idl_type.is_basic_type or base_idl_type == 'ScriptValue':
573 return base_idl_type 581 return base_idl_type
574 582
575 # Data type with potential additional includes 583 # Data type with potential additional includes
576 add_includes_for_type(idl_type) 584 add_includes_for_type(idl_type)
577 if base_idl_type in V8_SET_RETURN_VALUE: # Special v8SetReturnValue treatme nt 585 if base_idl_type in V8_SET_RETURN_VALUE: # Special v8SetReturnValue treatme nt
578 return base_idl_type 586 return base_idl_type
579 587
580 # Pointer type 588 # Pointer type
581 return 'DOMWrapper' 589 return 'DOMWrapper'
582 590
583 IdlType.v8_conversion_type = v8_conversion_type 591 IdlType.v8_conversion_type = v8_conversion_type
584 592
585 593
586 V8_SET_RETURN_VALUE = { 594 V8_SET_RETURN_VALUE = {
587 'boolean': 'v8SetReturnValueBool(info, {cpp_value})', 595 'boolean': 'v8SetReturnValueBool(info, {cpp_value})',
588 'int': 'v8SetReturnValueInt(info, {cpp_value})', 596 'int': 'v8SetReturnValueInt(info, {cpp_value})',
589 'unsigned': 'v8SetReturnValueUnsigned(info, {cpp_value})', 597 'unsigned': 'v8SetReturnValueUnsigned(info, {cpp_value})',
590 'DOMString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())', 598 'DOMString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())',
591 'ByteString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())' , 599 'ByteString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())' ,
592 'ScalarValueString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsol ate())', 600 'ScalarValueString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsol ate())',
593 # [TreatNullReturnValueAs] 601 # [TreatReturnedNullStringAs]
594 'StringOrNull': 'v8SetReturnValueStringOrNull(info, {cpp_value}, info.GetIso late())', 602 'StringOrNull': 'v8SetReturnValueStringOrNull(info, {cpp_value}, info.GetIso late())',
595 'StringOrUndefined': 'v8SetReturnValueStringOrUndefined(info, {cpp_value}, i nfo.GetIsolate())', 603 'StringOrUndefined': 'v8SetReturnValueStringOrUndefined(info, {cpp_value}, i nfo.GetIsolate())',
596 'void': '', 604 'void': '',
597 # No special v8SetReturnValue* function (set value directly) 605 # No special v8SetReturnValue* function (set value directly)
598 'float': 'v8SetReturnValue(info, {cpp_value})', 606 'float': 'v8SetReturnValue(info, {cpp_value})',
599 'unrestricted float': 'v8SetReturnValue(info, {cpp_value})', 607 'unrestricted float': 'v8SetReturnValue(info, {cpp_value})',
600 'double': 'v8SetReturnValue(info, {cpp_value})', 608 'double': 'v8SetReturnValue(info, {cpp_value})',
601 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})', 609 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})',
602 # No special v8SetReturnValue* function, but instead convert value to V8 610 # No special v8SetReturnValue* function, but instead convert value to V8
603 # and then use general v8SetReturnValue. 611 # and then use general v8SetReturnValue.
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 'ByteString': 'v8String({isolate}, {cpp_value})', 680 'ByteString': 'v8String({isolate}, {cpp_value})',
673 'ScalarValueString': 'v8String({isolate}, {cpp_value})', 681 'ScalarValueString': 'v8String({isolate}, {cpp_value})',
674 'boolean': 'v8Boolean({cpp_value}, {isolate})', 682 'boolean': 'v8Boolean({cpp_value}, {isolate})',
675 'int': 'v8::Integer::New({isolate}, {cpp_value})', 683 'int': 'v8::Integer::New({isolate}, {cpp_value})',
676 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', 684 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})',
677 'float': 'v8::Number::New({isolate}, {cpp_value})', 685 'float': 'v8::Number::New({isolate}, {cpp_value})',
678 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})', 686 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})',
679 'double': 'v8::Number::New({isolate}, {cpp_value})', 687 'double': 'v8::Number::New({isolate}, {cpp_value})',
680 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})', 688 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})',
681 'void': 'v8Undefined()', 689 'void': 'v8Undefined()',
682 # [TreatNullReturnValueAs] 690 # [TreatReturnedNullStringAs]
683 'StringOrNull': '{cpp_value}.isNull() ? v8::Handle<v8::Value>(v8::Null({isol ate})) : v8String({isolate}, {cpp_value})', 691 'StringOrNull': '{cpp_value}.isNull() ? v8::Handle<v8::Value>(v8::Null({isol ate})) : v8String({isolate}, {cpp_value})',
684 'StringOrUndefined': '{cpp_value}.isNull() ? v8Undefined() : v8String({isola te}, {cpp_value})', 692 'StringOrUndefined': '{cpp_value}.isNull() ? v8Undefined() : v8String({isola te}, {cpp_value})',
685 # Special cases 693 # Special cases
686 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))', 694 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))',
687 'ScriptValue': '{cpp_value}.v8Value()', 695 'ScriptValue': '{cpp_value}.v8Value()',
688 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))', 696 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))',
689 # General 697 # General
690 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})', 698 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})',
691 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', 699 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})',
692 } 700 }
(...skipping 13 matching lines...) Expand all
706 714
707 def literal_cpp_value(idl_type, idl_literal): 715 def literal_cpp_value(idl_type, idl_literal):
708 """Converts an expression that is a valid C++ literal for this type.""" 716 """Converts an expression that is a valid C++ literal for this type."""
709 # FIXME: add validation that idl_type and idl_literal are compatible 717 # FIXME: add validation that idl_type and idl_literal are compatible
710 literal_value = str(idl_literal) 718 literal_value = str(idl_literal)
711 if idl_type.base_type in CPP_UNSIGNED_TYPES: 719 if idl_type.base_type in CPP_UNSIGNED_TYPES:
712 return literal_value + 'u' 720 return literal_value + 'u'
713 return literal_value 721 return literal_value
714 722
715 IdlType.literal_cpp_value = literal_cpp_value 723 IdlType.literal_cpp_value = literal_cpp_value
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698