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 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 'CompareHow': 'Range::CompareHow', | 106 'CompareHow': 'Range::CompareHow', |
107 'Date': 'double', | 107 'Date': 'double', |
108 'Dictionary': 'Dictionary', | 108 'Dictionary': 'Dictionary', |
109 'EventHandler': 'EventListener*', | 109 'EventHandler': 'EventListener*', |
110 'MediaQueryListListener': 'RefPtrWillBeRawPtr<MediaQueryListListener>', | 110 'MediaQueryListListener': 'RefPtrWillBeRawPtr<MediaQueryListListener>', |
111 'Promise': 'ScriptPromise', | 111 'Promise': 'ScriptPromise', |
112 'ScriptValue': 'ScriptValue', | 112 'ScriptValue': 'ScriptValue', |
113 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345 529 | 113 # FIXME: Eliminate custom bindings for XPathNSResolver http://crbug.com/345 529 |
114 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', | 114 'XPathNSResolver': 'RefPtrWillBeRawPtr<XPathNSResolver>', |
115 'boolean': 'bool', | 115 'boolean': 'bool', |
116 'unrestricted double': 'double', | |
117 'unrestricted float': 'float', | |
116 } | 118 } |
117 | 119 |
118 | 120 |
119 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False, used_in _cpp_sequence=False): | 121 def cpp_type(idl_type, extended_attributes=None, used_as_argument=False, used_in _cpp_sequence=False): |
120 """Returns C++ type corresponding to IDL type. | 122 """Returns C++ type corresponding to IDL type. |
121 | 123 |
122 |idl_type| argument is of type IdlType, while return value is a string | 124 |idl_type| argument is of type IdlType, while return value is a string |
123 | 125 |
124 Args: | 126 Args: |
125 idl_type: | 127 idl_type: |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 | 346 |
345 ################################################################################ | 347 ################################################################################ |
346 # V8 -> C++ | 348 # V8 -> C++ |
347 ################################################################################ | 349 ################################################################################ |
348 | 350 |
349 V8_VALUE_TO_CPP_VALUE = { | 351 V8_VALUE_TO_CPP_VALUE = { |
350 # Basic | 352 # Basic |
351 'Date': 'toCoreDate({v8_value})', | 353 'Date': 'toCoreDate({v8_value})', |
352 'DOMString': '{v8_value}', | 354 'DOMString': '{v8_value}', |
353 'boolean': '{v8_value}->BooleanValue()', | 355 'boolean': '{v8_value}->BooleanValue()', |
354 'float': 'static_cast<float>({v8_value}->NumberValue())', | 356 'float': 'static_cast<float>({v8_value}->NumberValue())', |
Nils Barth (inactive)
2014/04/25 05:40:15
We should have a toFloat wrapper function, right?
haraken
2014/04/25 06:16:16
I'm neutral. If we need to write static_cast<float
Nils Barth (inactive)
2014/04/25 07:16:07
Nope, this is the only place, so no need!
| |
357 'unrestricted float': 'static_cast<float>({v8_value}->NumberValue())', | |
355 'double': 'static_cast<double>({v8_value}->NumberValue())', | 358 'double': 'static_cast<double>({v8_value}->NumberValue())', |
359 'unrestricted double': 'static_cast<double>({v8_value}->NumberValue())', | |
356 'byte': 'toInt8({arguments})', | 360 'byte': 'toInt8({arguments})', |
357 'octet': 'toUInt8({arguments})', | 361 'octet': 'toUInt8({arguments})', |
358 'short': 'toInt16({arguments})', | 362 'short': 'toInt16({arguments})', |
359 'unsigned short': 'toUInt16({arguments})', | 363 'unsigned short': 'toUInt16({arguments})', |
360 'long': 'toInt32({arguments})', | 364 'long': 'toInt32({arguments})', |
361 'unsigned long': 'toUInt32({arguments})', | 365 'unsigned long': 'toUInt32({arguments})', |
362 'long long': 'toInt64({arguments})', | 366 'long long': 'toInt64({arguments})', |
363 'unsigned long long': 'toUInt64({arguments})', | 367 'unsigned long long': 'toUInt64({arguments})', |
364 # Interface types | 368 # Interface types |
365 'CompareHow': 'static_cast<Range::CompareHow>({v8_value}->Int32Value())', | 369 'CompareHow': 'static_cast<Range::CompareHow>({v8_value}->Int32Value())', |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
536 'boolean': 'v8SetReturnValueBool(info, {cpp_value})', | 540 'boolean': 'v8SetReturnValueBool(info, {cpp_value})', |
537 'int': 'v8SetReturnValueInt(info, {cpp_value})', | 541 'int': 'v8SetReturnValueInt(info, {cpp_value})', |
538 'unsigned': 'v8SetReturnValueUnsigned(info, {cpp_value})', | 542 'unsigned': 'v8SetReturnValueUnsigned(info, {cpp_value})', |
539 'DOMString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())', | 543 'DOMString': 'v8SetReturnValueString(info, {cpp_value}, info.GetIsolate())', |
540 # [TreatNullReturnValueAs] | 544 # [TreatNullReturnValueAs] |
541 'StringOrNull': 'v8SetReturnValueStringOrNull(info, {cpp_value}, info.GetIso late())', | 545 'StringOrNull': 'v8SetReturnValueStringOrNull(info, {cpp_value}, info.GetIso late())', |
542 'StringOrUndefined': 'v8SetReturnValueStringOrUndefined(info, {cpp_value}, i nfo.GetIsolate())', | 546 'StringOrUndefined': 'v8SetReturnValueStringOrUndefined(info, {cpp_value}, i nfo.GetIsolate())', |
543 'void': '', | 547 'void': '', |
544 # No special v8SetReturnValue* function (set value directly) | 548 # No special v8SetReturnValue* function (set value directly) |
545 'float': 'v8SetReturnValue(info, {cpp_value})', | 549 'float': 'v8SetReturnValue(info, {cpp_value})', |
550 'unrestricted float': 'v8SetReturnValue(info, {cpp_value})', | |
546 'double': 'v8SetReturnValue(info, {cpp_value})', | 551 'double': 'v8SetReturnValue(info, {cpp_value})', |
552 'unrestricted double': 'v8SetReturnValue(info, {cpp_value})', | |
547 # No special v8SetReturnValue* function, but instead convert value to V8 | 553 # No special v8SetReturnValue* function, but instead convert value to V8 |
548 # and then use general v8SetReturnValue. | 554 # and then use general v8SetReturnValue. |
549 'array': 'v8SetReturnValue(info, {cpp_value})', | 555 'array': 'v8SetReturnValue(info, {cpp_value})', |
550 'Date': 'v8SetReturnValue(info, {cpp_value})', | 556 'Date': 'v8SetReturnValue(info, {cpp_value})', |
551 'EventHandler': 'v8SetReturnValue(info, {cpp_value})', | 557 'EventHandler': 'v8SetReturnValue(info, {cpp_value})', |
552 'ScriptValue': 'v8SetReturnValue(info, {cpp_value})', | 558 'ScriptValue': 'v8SetReturnValue(info, {cpp_value})', |
553 'SerializedScriptValue': 'v8SetReturnValue(info, {cpp_value})', | 559 'SerializedScriptValue': 'v8SetReturnValue(info, {cpp_value})', |
554 # DOMWrapper | 560 # DOMWrapper |
555 'DOMWrapperForMainWorld': 'v8SetReturnValueForMainWorld(info, WTF::getPtr({c pp_value}))', | 561 'DOMWrapperForMainWorld': 'v8SetReturnValueForMainWorld(info, WTF::getPtr({c pp_value}))', |
556 'DOMWrapperFast': 'v8SetReturnValueFast(info, WTF::getPtr({cpp_value}), {scr ipt_wrappable})', | 562 'DOMWrapperFast': 'v8SetReturnValueFast(info, WTF::getPtr({cpp_value}), {scr ipt_wrappable})', |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
608 IdlUnionType.release = property( | 614 IdlUnionType.release = property( |
609 lambda self: [member_type.is_interface_type | 615 lambda self: [member_type.is_interface_type |
610 for member_type in self.member_types]) | 616 for member_type in self.member_types]) |
611 | 617 |
612 | 618 |
613 CPP_VALUE_TO_V8_VALUE = { | 619 CPP_VALUE_TO_V8_VALUE = { |
614 # Built-in types | 620 # Built-in types |
615 'Date': 'v8DateOrNaN({cpp_value}, {isolate})', | 621 'Date': 'v8DateOrNaN({cpp_value}, {isolate})', |
616 'DOMString': 'v8String({isolate}, {cpp_value})', | 622 'DOMString': 'v8String({isolate}, {cpp_value})', |
617 'boolean': 'v8Boolean({cpp_value}, {isolate})', | 623 'boolean': 'v8Boolean({cpp_value}, {isolate})', |
618 'int': 'v8::Integer::New({isolate}, {cpp_value})', | 624 'int': 'v8::Integer::New({isolate}, {cpp_value})', |
Nils Barth (inactive)
2014/04/25 05:40:15
v8Integer wrapper function? (etc.)
haraken
2014/04/25 06:16:16
This is no :) We don't want to have an unnecessary
Nils Barth (inactive)
2014/04/25 07:16:07
Got it, thanks!
| |
619 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', | 625 'unsigned': 'v8::Integer::NewFromUnsigned({isolate}, {cpp_value})', |
620 'float': 'v8::Number::New({isolate}, {cpp_value})', | 626 'float': 'v8::Number::New({isolate}, {cpp_value})', |
627 'unrestricted float': 'v8::Number::New({isolate}, {cpp_value})', | |
621 'double': 'v8::Number::New({isolate}, {cpp_value})', | 628 'double': 'v8::Number::New({isolate}, {cpp_value})', |
629 'unrestricted double': 'v8::Number::New({isolate}, {cpp_value})', | |
622 'void': 'v8Undefined()', | 630 'void': 'v8Undefined()', |
623 # Special cases | 631 # Special cases |
624 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))', | 632 'EventHandler': '{cpp_value} ? v8::Handle<v8::Value>(V8AbstractEventListener ::cast({cpp_value})->getListenerObject(impl->executionContext())) : v8::Handle<v 8::Value>(v8::Null({isolate}))', |
625 'ScriptValue': '{cpp_value}.v8Value()', | 633 'ScriptValue': '{cpp_value}.v8Value()', |
626 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))', | 634 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Han dle<v8::Value>(v8::Null({isolate}))', |
627 # General | 635 # General |
628 'array': 'v8Array({cpp_value}, {isolate})', | 636 'array': 'v8Array({cpp_value}, {isolate})', |
629 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', | 637 'DOMWrapper': 'toV8({cpp_value}, {creation_context}, {isolate})', |
630 } | 638 } |
631 | 639 |
632 | 640 |
633 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None): | 641 def cpp_value_to_v8_value(idl_type, cpp_value, isolate='info.GetIsolate()', crea tion_context='', extended_attributes=None): |
634 """Returns an expression that converts a C++ value to a V8 value.""" | 642 """Returns an expression that converts a C++ value to a V8 value.""" |
635 # the isolate parameter is needed for callback interfaces | 643 # the isolate parameter is needed for callback interfaces |
636 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) | 644 idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, ext ended_attributes) |
637 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) | 645 this_v8_conversion_type = idl_type.v8_conversion_type(extended_attributes) |
638 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] | 646 format_string = CPP_VALUE_TO_V8_VALUE[this_v8_conversion_type] |
639 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) | 647 statement = format_string.format(cpp_value=cpp_value, isolate=isolate, creat ion_context=creation_context) |
640 return statement | 648 return statement |
641 | 649 |
642 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value | 650 IdlType.cpp_value_to_v8_value = cpp_value_to_v8_value |
OLD | NEW |