Chromium Code Reviews| Index: Source/bindings/scripts/unstable/v8_types.py |
| diff --git a/Source/bindings/scripts/unstable/v8_types.py b/Source/bindings/scripts/unstable/v8_types.py |
| index 041a6d8767f5ae8f8002e7b6d51cd21fd269f6ad..5da0828d672ca289f1168a61d5bfcf9d2e66b6d5 100644 |
| --- a/Source/bindings/scripts/unstable/v8_types.py |
| +++ b/Source/bindings/scripts/unstable/v8_types.py |
| @@ -35,37 +35,19 @@ Until then, please work on the Perl IDL compiler. |
| For details, see bug http://crbug.com/239771 |
| """ |
| +import posixpath |
| import re |
| -CPP_TYPE_SAME_AS_IDL_TYPE = set([ |
| - 'double', |
| - 'float', |
| - 'int', # FIXME: int is not an IDL type |
| - 'long long', |
| - 'unsigned long long', |
| -]) |
| -CPP_INT_TYPES = set([ |
| - 'byte', |
| - 'long', |
| - 'short', |
| -]) |
| -CPP_UNSIGNED_TYPES = set([ |
| - 'octet', |
| - 'unsigned int', |
| - 'unsigned long', |
| - 'unsigned short', |
| -]) |
| -# Promise is not yet in the Web IDL spec but is going to be speced |
| -# as primitive types in the future. |
| -# Since V8 dosn't provide Promise primitive object currently, |
| -# PRIMITIVE_TYPES doesn't contain Promise. |
| -CPP_TYPE_SPECIAL_CONVERSION_RULES = { |
| - 'boolean': 'bool', |
| - 'DOMString': 'const String&', |
| - 'Promise': 'ScriptPromise', |
| -} |
| +# FIXME: turn on after landing dependency |
| +# from code_generator_idl_reader import idl_file_rel_dir_posix, implemented_as_cpp_name_from_idl_type |
| +import idl_definitions # for UnionType |
| + |
| +################################################################################ |
| +# IDL types |
| +################################################################################ |
| + |
| PRIMITIVE_TYPES = set([ |
| - # http://www.w3.org/TR/WebIDL/#dfn-primitive-type |
| + # http://www.w3.org/TR/WebIDL/#dfn-primitive-type |
| 'boolean', |
| 'float', |
| # unrestricted float is not supported |
| @@ -86,21 +68,30 @@ PRIMITIVE_TYPES = set([ |
| 'Date', |
| 'void', |
| ]) |
| -CPP_VALUE_TO_V8_VALUE_DICT = { |
| - 'boolean': 'v8Boolean({cpp_value}, {isolate})', |
| - # long long and unsigned long long are not representable in ECMAScript. |
| - 'long long': 'v8::Number::New({isolate}, static_cast<double>({cpp_value}))', |
| - 'unsigned long long': 'v8::Number::New({isolate}, static_cast<double>({cpp_value}))', |
| - 'float': 'v8::Number::New({isolate}, {cpp_value})', |
| - 'double': 'v8::Number::New({isolate}, {cpp_value})', |
| - 'DOMTimeStamp': 'v8::Number::New({isolate}, static_cast<double>({cpp_value}))', |
| - 'DOMString': 'v8String({cpp_value}, {isolate})', |
| -} |
| -CPP_VALUE_TO_V8_VALUE_ARRAY_OR_SEQUENCE_TYPE = 'v8Array({cpp_value}, {isolate})' |
| -CPP_VALUE_TO_V8_VALUE_DEFAULT = 'toV8({cpp_value}, {creation_context}, {isolate})' |
| -V8_SET_RETURN_VALUE_DICT = { |
| - 'unsigned': 'v8SetReturnValueUnsigned({callback_info}, {cpp_value});', |
| -} |
| +NON_WRAPPER_TYPES = set([ |
| + 'DOMString', |
| + ]) |
| +DOM_NODE_TYPES = set([ |
| + 'Attr', |
| + 'CDATASection', |
| + 'CharacterData', |
| + 'Comment', |
| + 'Document', |
| + 'DocumentFragment', |
| + 'DocumentType', |
| + 'Element', |
| + 'Entity', |
| + 'HTMLDocument', |
| + 'Node', |
| + 'Notation', |
| + 'ProcessingInstruction', |
| + 'ShadowRoot', |
| + 'SVGDocument', |
| + 'Text', |
| + 'TestNode', |
| +]) |
| + |
| +callback_function_types = set() |
| def array_or_sequence_type(idl_type): |
| @@ -112,75 +103,378 @@ def array_type(idl_type): |
| return matched and matched.group(1) |
| +def callback_function_type(idl_type): |
| + return idl_type in callback_function_types |
| + |
| + |
| +def set_callback_function_types(callback_functions): |
| + callback_function_types.update(callback_functions.keys()) |
| + |
| + |
| +def dom_node_type(idl_type): |
| + return (idl_type in DOM_NODE_TYPES or |
| + (idl_type.startswith(('HTML', 'SVG')) and |
| + idl_type.endswith('Element'))) |
| + |
| + |
| def primitive_type(idl_type): |
| return idl_type in PRIMITIVE_TYPES |
| +def ref_ptr_type(idl_type): |
| + return not( |
| + array_type(idl_type) or |
| + callback_function_type(idl_type) or |
| + primitive_type(idl_type) or |
| + sequence_type(idl_type) or |
| + union_type(idl_type) or |
| + idl_type in ['any', 'DOMString']) |
|
haraken
2013/09/20 15:21:35
Maybe you can put 'any' to NON_WRAPPER_TYPES, and
Nils Barth (inactive)
2013/09/24 02:34:01
This is ref_ptr_type, not wrapper_type:
'any'(/'Pr
haraken
2013/09/24 05:36:57
Actually I cannot answer without investigation.
H
Nils Barth (inactive)
2013/09/24 23:52:03
"Primitive type" is a technical term, and only inc
|
| + |
| + |
| def sequence_type(idl_type): |
| matched = re.match(r'sequence<([\w\s]+)>', idl_type) |
| return matched and matched.group(1) |
| -def v8_type(interface_type): |
| - return 'V8' + interface_type |
| +def union_type(idl_type): |
| + return isinstance(idl_type, idl_definitions.IdlUnionType) |
| -def cpp_type(idl_type, pointer_type=None): |
| - """Returns the C++ type corresponding to the IDL type. |
| +def wrapper_type(idl_type): |
| + return ref_ptr_type(idl_type) |
| - If unidentified, fall back to a pointer. |
| - Args: |
| - idl_type: IDL type |
| - pointer_type: If specified, return 'pointer_type<idl_type>' |
| - (e.g. RefPtr<Foo>, PassRefPtr<Foo>) |
| - else defaults to returning raw pointer form (e.g. 'Foo*'). |
| - """ |
| +################################################################################ |
| +# C++ types |
| +################################################################################ |
| + |
| +CPP_TYPE_SAME_AS_IDL_TYPE = set([ |
| + 'double', |
| + 'float', |
| + 'long long', |
| + 'unsigned long long', |
| +]) |
| +CPP_INT_TYPES = set([ |
|
haraken
2013/09/20 15:21:35
Nit: CPP_INT_TYPES => CPP_SIGNED_TYPES
Nils Barth (inactive)
2013/09/24 02:34:01
That's nicely symmetric, but we use 'int' in the g
|
| + 'byte', |
| + 'long', |
| + 'short', |
| +]) |
| +CPP_UNSIGNED_TYPES = set([ |
| + 'octet', |
| + 'unsigned int', |
| + 'unsigned long', |
| + 'unsigned short', |
| +]) |
| + |
| + |
| +def cpp_type(idl_type, extended_attributes=None, used_as_argument=False): |
| + """Returns C++ type corresponding to IDL type.""" |
| + extended_attributes = extended_attributes or {} |
| if idl_type in CPP_TYPE_SAME_AS_IDL_TYPE: |
| return idl_type |
| if idl_type in CPP_INT_TYPES: |
| return 'int' |
| if idl_type in CPP_UNSIGNED_TYPES: |
| return 'unsigned' |
| - if idl_type in CPP_TYPE_SPECIAL_CONVERSION_RULES: |
| - return CPP_TYPE_SPECIAL_CONVERSION_RULES[idl_type] |
| - this_array_or_sequence_type = array_or_sequence_type(idl_type) |
| - if this_array_or_sequence_type: |
| - return 'const Vector<{cpp_type} >&'.format(cpp_type=cpp_type(this_array_or_sequence_type, 'RefPtr')) |
| - if pointer_type: |
| - return '{pointer_type}<{idl_type}>'.format(pointer_type=pointer_type, idl_type=idl_type) |
| - return idl_type + '*' # raw pointer |
| - |
| - |
| -def cpp_value_to_v8_value(idl_type, cpp_value, isolate, creation_context=''): |
| - """Returns an expression converting a C++ value to a V8 value.""" |
| - if idl_type in CPP_VALUE_TO_V8_VALUE_DICT: |
| - expression_format_string = CPP_VALUE_TO_V8_VALUE_DICT[idl_type] |
| - elif primitive_type(idl_type): # primitive but not in dict |
| - raise Exception('unexpected IDL type %s' % idl_type) |
| - elif array_or_sequence_type(idl_type): |
| - expression_format_string = CPP_VALUE_TO_V8_VALUE_ARRAY_OR_SEQUENCE_TYPE |
| + if idl_type == 'boolean': |
| + return 'bool' |
| + if idl_type == 'Promise': |
| + return 'ScriptPromise' |
| + if idl_type == 'DOMString': |
| + return cpp_string_type(extended_attributes, used_as_argument) |
| + if callback_function_type(idl_type): |
| + return 'ScriptValue' |
| + if union_type(idl_type): |
| + raise Exception('UnionType is not supported') |
| + # FIXME: fix Perl code reading: |
| + # return "RefPtr<${type}>" if IsRefPtrType($type) and not $isParameter; |
| + if ref_ptr_type(idl_type): |
| + if used_as_argument: |
| + return cpp_template_type('PassRefPtr', idl_type) |
| + return cpp_template_type('RefPtr', idl_type) |
| + # Default, assume native type is a pointer with same type name as idl type |
| + return idl_type + '*' |
| + |
| + |
| +def cpp_template_type(template, inner_type): |
| + """Returns C++ template specialized to type, with space added if needed.""" |
| + if inner_type.endswith('>'): |
| + format_string = '{template}<{inner_type} >' |
| else: |
| - expression_format_string = CPP_VALUE_TO_V8_VALUE_DEFAULT |
| - return expression_format_string.format(cpp_value=cpp_value, creation_context=creation_context, isolate=isolate) |
| + format_string = '{template}<{inner_type}>' |
| + return format_string.format(template=template, inner_type=inner_type) |
| -def v8_set_return_value(idl_type, cpp_value, callback_info=''): |
| - """Returns a statement converting a C++ value to a V8 value and setting it as a return value.""" |
| - this_cpp_type = cpp_type(idl_type) |
| - if this_cpp_type in V8_SET_RETURN_VALUE_DICT: |
| - expression_format_string = V8_SET_RETURN_VALUE_DICT[this_cpp_type] |
| +def cpp_string_type(extended_attributes, used_as_parameter): |
| + if not used_as_parameter: |
| + # FIXME: Support [TreatReturnedNullStringAs] |
|
haraken
2013/09/20 15:21:35
I begin to think that this FIXME isn't needed. If
Nils Barth (inactive)
2013/09/24 02:34:01
Got it, removed (one other place too).
(This is ha
|
| + return 'String' |
| + # FIXME: Rename NullString to EmptyString (here and in .idl files), per spec |
|
haraken
2013/09/20 15:21:35
This is not a naming problem but an implementation
Nils Barth (inactive)
2013/09/24 02:34:01
(Removing this function for now; will add and addr
haraken
2013/09/24 05:36:57
Sorry for not being clear. This shouldn't be a FIX
Nils Barth (inactive)
2013/09/24 23:52:03
Got it, thanks!
I've documented at:
https://sites.
|
| + if (extended_attributes.get('TreatNullAs') == 'NullString' and |
| + extended_attributes.get('TreatUndefinedAs') == 'NullString'): |
| + mode = 'WithUndefinedOrNullCheck' |
| + elif (extended_attributes.get('TreatNullAs') == 'NullString' or |
| + 'Reflect' in extended_attributes): |
| + mode = 'WithNullCheck' |
| + elif (extended_attributes.get('TreatUndefinedAs') == 'NullString'): |
| + raise Exception('[TreatUndefinedAs=NullString] not supported without [TreatNullAs=NullString]') |
| else: |
| - raise Exception('unexpected IDL type %s' % idl_type) |
| - return expression_format_string.format(callback_info=callback_info, cpp_value=cpp_value) |
| + mode = '' |
| + return 'V8StringResource<%s>' % mode |
| + |
| + |
| +def v8_type(interface_type): |
| + return 'V8' + interface_type |
| + |
| + |
| +################################################################################ |
| +# Includes |
| +################################################################################ |
| + |
| + |
| +def includes_for_cpp_class(class_name, relative_dir_posix): |
| + return set([posixpath.join('bindings', relative_dir_posix, class_name + '.h')]) |
| + |
| + |
| +def skip_include_header(idl_type): |
| + return (primitive_type(idl_type) or |
| + callback_function_type(idl_type) or |
| + idl_type == 'DOMString') |
| def includes_for_type(idl_type): |
| - if primitive_type(idl_type) or idl_type == 'DOMString': |
| + if skip_include_header(idl_type): |
| return set() |
| if idl_type == 'Promise': |
| return set(['ScriptPromise.h']) |
| + if idl_type in ['EventListener', 'EventHandler']: |
| + return set(['core/dom/EventListener.h']) |
| this_array_or_sequence_type = array_or_sequence_type(idl_type) |
| if this_array_or_sequence_type: |
| return includes_for_type(this_array_or_sequence_type) |
| return set(['V8%s.h' % idl_type]) |
| + |
| + |
| +def header_files_for_interface(interface_name, cpp_class_name): |
|
haraken
2013/09/20 15:21:35
header_files_for_interface => includes_for_interfa
Nils Barth (inactive)
2013/09/24 02:34:01
Good point both ways; done.
(Removed, will rename
|
| + # FIXME: some cases, such as typed arrays |
| + return [] |
| + |
| + |
| +################################################################################ |
| +# V8 -> C++ |
| +################################################################################ |
| + |
| +V8_VALUE_TO_CPP_VALUE = { |
| + # Primitive types |
| + 'boolean': '{v8_value}->BooleanValue()', |
| + 'float': 'static_cast<float>({v8_value}->NumberValue())', |
| + 'double': 'static_cast<double>({v8_value}->NumberValue())', |
| + 'byte': 'toInt8({arguments})', |
| + 'octet': 'toUInt8({arguments})', |
| + 'short': 'toInt32({arguments})', |
| + 'unsigned short': 'toUInt32({arguments})', |
| + 'long': 'toInt32({arguments})', |
| + 'unsigned long': 'toUInt32({arguments})', |
| + 'long long': 'toInt64({arguments})', |
| + 'unsigned long long': 'toUInt64({arguments})', |
| +} |
| +V8_VALUE_TO_CPP_VALUE_AND_INCLUDES = { |
|
haraken
2013/09/20 15:21:35
You can merge V8_VALUE_TO_CPP_VALUE and V8_VALUE_T
Nils Barth (inactive)
2013/09/24 02:34:01
I actually did that at first!
It reduces us to 2 c
|
| + # idl_type -> (cpp_expression_format, includes) |
| + 'any': ('ScriptValue({v8_value}, {isolate})', |
| + set(['bindings/v8/ScriptValue.h'])), |
| + 'Dictionary': ('Dictionary({v8_value}, {isolate})', |
| + set(['bindings/v8/Dictionary.h'])), |
| + 'MediaQueryListListener': ('MediaQueryListListener::create({v8_value})', |
| + set(['core/css/MediaQueryListListener.h'])), |
| + 'SerializedScriptValue': ( |
| + 'SerializedScriptValue::create({v8_value}, {isolate})', |
| + set(['bindings/v8/SerializedScriptValue.h'])), |
| +} |
| + |
| + |
| +def v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, isolate): |
| + this_array_or_sequence_type = array_or_sequence_type(idl_type) |
| + if this_array_or_sequence_type: |
| + return v8_value_to_cpp_value_array_or_sequence(this_array_or_sequence_type, v8_value, isolate) |
| + |
| + if callback_function_type(idl_type): |
|
haraken
2013/09/20 15:21:35
Shall we implement preprocess_type_and_value for t
Nils Barth (inactive)
2013/09/24 02:34:01
I thought about it, but it's just two cases (this
|
| + idl_type = 'any' |
| + |
| + if 'EnforceRange' in extended_attributes: |
| + arguments = ', '.join([v8_value, 'EnforceRange', 'ok']) |
| + else: # NormalConversion |
| + arguments = v8_value |
| + |
| + if idl_type in V8_VALUE_TO_CPP_VALUE: |
| + cpp_expression_format = V8_VALUE_TO_CPP_VALUE[idl_type] |
| + includes = set() |
| + elif idl_type in V8_VALUE_TO_CPP_VALUE_AND_INCLUDES: |
| + cpp_expression_format, includes = V8_VALUE_TO_CPP_VALUE_AND_INCLUDES[idl_type] |
| + else: |
| + cpp_expression_format = ( |
| + 'V8{idl_type}::HasInstance({v8_value}, {isolate}, worldType({isolate})) ? ' |
| + 'V8{idl_type}::toNative(v8::Handle<v8::Object>::Cast({v8_value})) : 0') |
| + includes = includes_for_type(idl_type) |
| + includes.add('V8%s.h' % idl_type) |
| + |
| + cpp_expression = cpp_expression_format.format(arguments=arguments, idl_type=idl_type, isolate=isolate, v8_value=v8_value) |
| + return cpp_expression, includes |
| + |
| + |
| +def v8_value_to_cpp_value_array_or_sequence(this_array_or_sequence_type, v8_value, isolate): |
| + if ref_ptr_type(this_array_or_sequence_type): |
| + this_cpp_type = None |
| + expression_format = '(toRefPtrNativeArray<{array_or_sequence_type}, V8{array_or_sequence_type}>({v8_value}, {isolate}))' |
| + includes = set(['V8%s.h' % this_array_or_sequence_type]) |
| + else: |
| + this_cpp_type = cpp_type(this_array_or_sequence_type) |
| + expression_format = 'toNativeArray<{cpp_type}>({v8_value}, {isolate})' |
| + includes = set() |
| + expression = expression_format.format(array_or_sequence_type=this_array_or_sequence_type, cpp_type=this_cpp_type, isolate=isolate, v8_value=v8_value) |
| + return expression, includes |
| + |
| + |
| +def v8_value_to_cpp_value_statement(idl_type, extended_attributes, v8_value, variable_name, isolate): |
| + this_cpp_type = cpp_type(idl_type, extended_attributes=extended_attributes, used_as_argument=True) |
| + |
| + if idl_type == 'DOMString': |
| + format_string = 'V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID({cpp_type}, {variable_name}, {cpp_value});' |
| + elif 'EnforceRange' in extended_attributes: |
| + format_string = 'V8TRYCATCH_WITH_TYPECHECK_VOID({cpp_type}, {variable_name}, {cpp_value}, {isolate});' |
| + else: |
| + format_string = 'V8TRYCATCH_VOID({cpp_type}, {variable_name}, {cpp_value});' |
| + |
| + cpp_value, includes = v8_value_to_cpp_value(idl_type, extended_attributes, v8_value, isolate) |
| + statement = format_string.format(cpp_type=this_cpp_type, cpp_value=cpp_value, isolate=isolate, variable_name=variable_name) |
| + return statement, includes |
| + |
| + |
| +################################################################################ |
| +# C++ -> V8 |
| +################################################################################ |
| + |
| + |
| +def preprocess_type_and_value(idl_type, cpp_value, extended_attributes): |
| + """Returns type and value, with preliminary type conversions applied.""" |
| + if idl_type in ['long long', 'unsigned long long', 'DOMTimeStamp']: |
| + # long long and unsigned long long are not representable in ECMAScript; |
| + # we represent them as doubles. |
| + # Also, DOMTimeStamp is a typedef for unsigned long long: |
| + # http://dev.w3.org/2006/webapi/WebIDL/#common-DOMTimeStamp |
| + idl_type = 'double' |
| + cpp_value = 'static_cast<double>(%s)' % cpp_value |
| + # HTML5 says that unsigned reflected attributes should be in the range |
| + # [0, 2^31). When a value isn't in this range, a default value (or 0) |
| + # should be returned instead. |
| + extended_attributes = extended_attributes or {} |
| + if ('Reflect' in extended_attributes and |
| + idl_type in ['unsigned long', 'unsigned short']): |
| + cpp_value = cpp_value.replace('getUnsignedIntegralAttribute', |
| + 'getIntegralAttribute') |
| + cpp_value = 'std::max(0, %s)' % cpp_value |
| + return idl_type, cpp_value |
| + |
| + |
| +def v8_conversion_type_and_includes(idl_type): |
| + """Returns conversion type and any additional includes. |
| + |
| + The conversion type is used to select the C++ -> V8 conversion function |
| + or v8SetReturnValue* function; it can be an idl_type, a cpp_type, or a |
| + separate name for the type of conversion (e.g., 'primitive', |
| + 'for_main_world'). |
| + """ |
| + # Simple cases, without additional includes |
| + if idl_type in ['boolean', 'void', 'DOMString', 'Date']: |
| + # FIXME: support TreatReturnedNullStringAs |
| + return idl_type, set() |
| + if idl_type in CPP_INT_TYPES: |
| + return 'int', set() |
|
haraken
2013/09/20 15:21:35
int => signed
Nils Barth (inactive)
2013/09/24 02:34:01
See above (we use 'int' internally, like v8SetRetu
|
| + if idl_type in CPP_UNSIGNED_TYPES: |
| + return 'unsigned', set() |
| + if callback_function_type(idl_type): |
| + return 'ScriptValue', set() |
| + if idl_type in ['float', 'double']: |
| + return 'number', set() |
| + if primitive_type(idl_type): # primitive but not yet handled |
| + raise Exception('unexpected type %s' % idl_type) |
| + |
| + # Data type with potential additional includes |
| + this_array_or_sequence_type = array_or_sequence_type(idl_type) |
| + if this_array_or_sequence_type: |
| + if ref_ptr_type(this_array_or_sequence_type): |
| + includes = includes_for_type(this_array_or_sequence_type) |
| + else: |
| + includes = set() |
| + return 'array', includes |
| + |
| + includes = includes_for_type(idl_type) |
| + if idl_type == 'SerializedScriptValue': |
| + return 'SerializedScriptValue', includes |
| + |
| + # Pointer type |
| + # FIXME: are these necessary? |
|
haraken
2013/09/20 15:21:35
RefPtr.h is necessary, but I don't think GetPtr.h
Nils Barth (inactive)
2013/09/24 02:34:01
Got it, thanks!
Reworded and moved FIXME to GetPtr
|
| + includes.add('wtf/GetPtr.h') |
| + includes.add('wtf/RefPtr.h') |
| + return 'pointer', includes |
|
haraken
2013/09/20 15:21:35
pointer => DOMWrapper
Nils Barth (inactive)
2013/09/24 02:34:01
Done.
|
| + |
| + |
| +V8_SET_RETURN_VALUE = { |
| + 'boolean': 'v8SetReturnValueBool({callback_info}, {cpp_value});', |
| + 'void': '', |
| + 'DOMString': 'v8SetReturnValueString({callback_info}, {cpp_value}, {isolate});', |
| + 'int': 'v8SetReturnValueInt({callback_info}, {cpp_value});', |
| + 'unsigned': 'v8SetReturnValueUnsigned({callback_info}, {cpp_value});', |
| + # General |
| + 'fast': 'v8SetReturnValueFast({callback_info}, {cpp_value}, {script_wrappable});', |
| + 'number': 'v8SetReturnValue({callback_info}, {cpp_value});', |
| + 'converted': 'v8SetReturnValue({callback_info}, {cpp_value});', |
| + 'default': 'v8SetReturnValue({callback_info}, {cpp_value}, {creation_context})', |
| +} |
| + |
| + |
| +def v8_set_return_value(idl_type, cpp_value, callback_info, isolate, creation_context='', extended_attributes=None, script_wrappable=''): |
| + """Returns a statement that converts a C++ value to a V8 value and sets it as a return value.""" |
| + def pointer_conversion_type(): |
|
haraken
2013/09/20 15:21:35
pointer_conversion_type => dom_wrapper_conversion_
Nils Barth (inactive)
2013/09/24 02:34:01
Done.
|
| + if not script_wrappable: |
| + return 'default' |
|
haraken
2013/09/20 15:21:35
default => DOMWrapperDefault
Nils Barth (inactive)
2013/09/24 02:34:01
Done.
|
| + return 'fast' |
|
haraken
2013/09/20 15:21:35
fast => DOMWrapperFast
Nils Barth (inactive)
2013/09/24 02:34:01
Done.
|
| + |
| + idl_type, cpp_value = preprocess_type_and_value(idl_type, cpp_value, extended_attributes) |
| + conversion_type, includes = v8_conversion_type_and_includes(idl_type) |
|
haraken
2013/09/20 15:21:35
conversion_type => v8_conversion_type
Nils Barth (inactive)
2013/09/24 02:34:01
Done.
|
| + # SetReturn-specific overrides |
| + if conversion_type in ['array', 'Date', 'ScriptValue', 'SerializedScriptValue']: |
| + # No special v8SetReturnValue* function; instead convert value to V8 and |
| + # use general v8SetReturnValue, as for primitive types. |
| + cpp_value, _ = cpp_value_to_v8_value(idl_type, cpp_value, isolate, callback_info=callback_info) |
| + conversion_type = 'converted' |
|
haraken
2013/09/20 15:21:35
The presence of 'converted' looks strange.
The ke
Nils Barth (inactive)
2013/09/24 02:34:01
Got it; that makes the code clearer (less indirect
|
| + if conversion_type == 'pointer': |
| + conversion_type = pointer_conversion_type() |
| + |
| + format_string = V8_SET_RETURN_VALUE[conversion_type] |
| + statement = format_string.format(callback_info=callback_info, cpp_value=cpp_value, creation_context=creation_context, isolate=isolate, script_wrappable=script_wrappable) |
| + return statement, includes |
| + |
| + |
| +CPP_VALUE_TO_V8_VALUE = { |
| + 'Date': 'v8DateOrNull({cpp_value}, {isolate})', |
| + 'DOMString': 'v8String({cpp_value}, {isolate})', |
| + 'ScriptValue': '{cpp_value}.v8Value()', |
| + 'SerializedScriptValue': '{cpp_value} ? {cpp_value}->deserialize() : v8::Handle<v8::Value>(v8::Null({isolate}))', |
| + 'boolean': 'v8Boolean({cpp_value}, {isolate})', |
| + 'void': 'v8Undefined()', |
| + 'int': 'v8::Integer::New({cpp_value}, {isolate})', |
| + 'unsigned': 'v8::Integer::NewFromUnsigned({cpp_value}, {isolate})', |
| + # General |
| + 'array': 'v8Array({cpp_value}, {isolate})', |
| + 'number': 'v8::Number::New({cpp_value})', |
| + 'default': 'toV8({cpp_value}, {creation_context}, {isolate})', |
| +} |
| + |
| + |
| +def cpp_value_to_v8_value(idl_type, cpp_value, isolate, callback_info='', creation_context='', extended_attributes=None): |
| + """Returns an expression that converts a C++ value to a V8 value.""" |
| + idl_type, cpp_value = preprocess_type_and_value(idl_type, cpp_value, extended_attributes) |
| + conversion_type, includes = v8_conversion_type_and_includes(idl_type) |
|
haraken
2013/09/20 15:21:35
conversion_type => v8_conversion_type
Nils Barth (inactive)
2013/09/24 02:34:01
Done.
|
| + format_string = CPP_VALUE_TO_V8_VALUE[conversion_type] |
| + statement = format_string.format(callback_info=callback_info, cpp_value=cpp_value, creation_context=creation_context, isolate=isolate) |
| + return statement, includes |