 Chromium Code Reviews
 Chromium Code Reviews Issue 357413003:
  IDL: Drop redundant null check for string and wrapper type attributes  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master
    
  
    Issue 357413003:
  IDL: Drop redundant null check for string and wrapper type attributes  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/blink.git@master| 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 540 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 551 return 'array' | 551 return 'array' | 
| 552 | 552 | 
| 553 # Simple types | 553 # Simple types | 
| 554 base_idl_type = idl_type.base_type | 554 base_idl_type = idl_type.base_type | 
| 555 # Basic types, without additional includes | 555 # Basic types, without additional includes | 
| 556 if base_idl_type in CPP_INT_TYPES: | 556 if base_idl_type in CPP_INT_TYPES: | 
| 557 return 'int' | 557 return 'int' | 
| 558 if base_idl_type in CPP_UNSIGNED_TYPES: | 558 if base_idl_type in CPP_UNSIGNED_TYPES: | 
| 559 return 'unsigned' | 559 return 'unsigned' | 
| 560 if idl_type.is_string_type: | 560 if idl_type.is_string_type: | 
| 561 if idl_type.is_nullable: | |
| 562 return 'StringOrNull' | |
| 561 if 'TreatReturnedNullStringAs' not in extended_attributes: | 563 if 'TreatReturnedNullStringAs' not in extended_attributes: | 
| 562 return base_idl_type | 564 return base_idl_type | 
| 563 treat_returned_null_string_as = extended_attributes['TreatReturnedNullSt ringAs'] | 565 treat_returned_null_string_as = extended_attributes['TreatReturnedNullSt ringAs'] | 
| 564 if treat_returned_null_string_as == 'Null': | 566 if treat_returned_null_string_as == 'Null': | 
| 565 return 'StringOrNull' | 567 return 'StringOrNull' | 
| 566 if treat_returned_null_string_as == 'Undefined': | 568 if treat_returned_null_string_as == 'Undefined': | 
| 567 return 'StringOrUndefined' | 569 return 'StringOrUndefined' | 
| 568 raise 'Unrecognized TreatReturnNullStringAs value: "%s"' % treat_returne d_null_string_as | 570 raise 'Unrecognized TreatReturnNullStringAs value: "%s"' % treat_returne d_null_string_as | 
| 569 if idl_type.is_basic_type or base_idl_type == 'ScriptValue': | 571 if idl_type.is_basic_type or base_idl_type == 'ScriptValue': | 
| 570 return base_idl_type | 572 return base_idl_type | 
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 669 'ByteString': 'v8String({isolate}, {cpp_value})', | 671 'ByteString': 'v8String({isolate}, {cpp_value})', | 
| 670 'ScalarValueString': 'v8String({isolate}, {cpp_value})', | 672 'ScalarValueString': 'v8String({isolate}, {cpp_value})', | 
| 671 'boolean': 'v8Boolean({cpp_value}, {isolate})', | 673 'boolean': 'v8Boolean({cpp_value}, {isolate})', | 
| 672 'int': 'v8::Integer::New({isolate}, {cpp_value})', | 674 'int': 'v8::Integer::New({isolate}, {cpp_value})', | 
| 673 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', | 675 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', | 
| 674 'float': 'v8::Number::New({isolate}, {cpp_value})', | 676 'float': 'v8::Number::New({isolate}, {cpp_value})', | 
| 675 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})', | 677 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})', | 
| 676 'double': 'v8::Number::New({isolate}, {cpp_value})', | 678 'double': 'v8::Number::New({isolate}, {cpp_value})', | 
| 677 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})', | 679 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})', | 
| 678 'void': 'v8Undefined()', | 680 'void': 'v8Undefined()', | 
| 681 # [TreatNullReturnValueAs] | |
| 682 'StringOrNull': '!{cpp_value}.isNull() ? v8String({isolate}, {cpp_value}) : v8::Handle<v8::Value>(v8::Null({isolate}))', | |
| 
haraken
2014/07/01 00:57:33
Flip the order and avoid a negation.
{cpp_value}.
 
Jens Widell
2014/07/01 06:43:22
Done.
 | |
| 683 'StringOrUndefined': '!{cpp_value}.isNull() ? v8String({isolate}, {cpp_value }) : v8Undefined()', | |
| 
haraken
2014/07/01 00:57:33
Ditto.
BTW, who needs StringOrUndefined? The beha
 
Jens Widell
2014/07/01 06:43:22
A bit strange, yes. Kicks in with [TreatReturnedNu
 | |
| 679 # Special cases | 684 # Special cases | 
| 680 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))', | 685 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))', | 
| 681 'ScriptValue': '{cpp_value}.v8Value()', | 686 'ScriptValue': '{cpp_value}.v8Value()', | 
| 682 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))', | 687 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))', | 
| 683 # General | 688 # General | 
| 684 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})', | 689 'array': 'v8Array({cpp_value}, {creation_context}, {isolate})', | 
| 685 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', | 690 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', | 
| 686 } | 691 } | 
| 687 | 692 | 
| 688 | 693 | 
| (...skipping 11 matching lines...) Expand all Loading... | |
| 700 | 705 | 
| 701 def literal_cpp_value(idl_type, idl_literal): | 706 def literal_cpp_value(idl_type, idl_literal): | 
| 702 """Converts an expression that is a valid C++ literal for this type.""" | 707 """Converts an expression that is a valid C++ literal for this type.""" | 
| 703 # FIXME: add validation that idl_type and idl_literal are compatible | 708 # FIXME: add validation that idl_type and idl_literal are compatible | 
| 704 literal_value = str(idl_literal) | 709 literal_value = str(idl_literal) | 
| 705 if idl_type.base_type in CPP_UNSIGNED_TYPES: | 710 if idl_type.base_type in CPP_UNSIGNED_TYPES: | 
| 706 return literal_value + 'u' | 711 return literal_value + 'u' | 
| 707 return literal_value | 712 return literal_value | 
| 708 | 713 | 
| 709 IdlType.literal_cpp_value = literal_cpp_value | 714 IdlType.literal_cpp_value = literal_cpp_value | 
| OLD | NEW |