Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / bindings / scripts / unstable / v8_types.py
index a46ab79..2137e9c 100644 (file)
@@ -88,6 +88,9 @@ def array_or_sequence_type(idl_type):
 
 
 def array_type(idl_type):
+    if is_union_type(idl_type):
+        # We do not support arrays of union types
+        return False
     matched = re.match(r'([\w\s]+)\[\]', idl_type)
     return matched and matched.group(1)
 
@@ -158,6 +161,9 @@ def is_interface_type(idl_type):
 
 
 def sequence_type(idl_type):
+    if is_union_type(idl_type):
+        # We do not support sequences of union types
+        return False
     matched = re.match(r'sequence<([\w\s]+)>', idl_type)
     return matched and matched.group(1)
 
@@ -269,7 +275,10 @@ def cpp_type(idl_type, extended_attributes=None, used_as_argument=False):
             return 'String'
         return 'V8StringResource<%s>' % string_mode()
     if is_union_type(idl_type):
-        raise Exception('UnionType is not supported')
+        # Attribute 'union_member_types' use is ok, but pylint can't infer this
+        # pylint: disable=E1103
+        return (cpp_type(union_member_type)
+                for union_member_type in idl_type.union_member_types)
     this_array_or_sequence_type = array_or_sequence_type(idl_type)
     if this_array_or_sequence_type:
         return cpp_template_type('Vector', cpp_type(this_array_or_sequence_type))
@@ -280,6 +289,8 @@ def cpp_type(idl_type, extended_attributes=None, used_as_argument=False):
         implemented_as_class = implemented_as(idl_type)
         if used_as_argument:
             return implemented_as_class + '*'
+        if is_will_be_garbage_collected(idl_type):
+            return cpp_template_type('RefPtrWillBeRawPtr', implemented_as_class)
         return cpp_template_type('RefPtr', implemented_as_class)
     # Default, assume native type is a pointer with same type name as idl type
     return idl_type + '*'
@@ -319,6 +330,18 @@ def set_implemented_as_interfaces(new_implemented_as_interfaces):
     implemented_as_interfaces.update(new_implemented_as_interfaces)
 
 
+# [WillBeGarbageCollected]
+will_be_garbage_collected_types = set()
+
+
+def is_will_be_garbage_collected(idl_type):
+    return idl_type in will_be_garbage_collected_types
+
+
+def set_will_be_garbage_collected_types(new_will_be_garbage_collected_types):
+    will_be_garbage_collected_types.update(new_will_be_garbage_collected_types)
+
+
 ################################################################################
 # Includes
 ################################################################################
@@ -329,6 +352,7 @@ def includes_for_cpp_class(class_name, relative_dir_posix):
 
 INCLUDES_FOR_TYPE = {
     'object': set(),
+    'CompareHow': set(),
     'Dictionary': set(['bindings/v8/Dictionary.h']),
     'EventHandler': set(['bindings/v8/V8AbstractEventListener.h',
                          'bindings/v8/V8EventListenerList.h']),
@@ -352,6 +376,18 @@ def includes_for_type(idl_type):
     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)
+    if is_union_type(idl_type):
+        # Attribute 'union_member_types' use is ok, but pylint can't infer this
+        # pylint: disable=E1103
+        return set.union(*[
+            includes_for_type(union_member_type)
+            for union_member_type in idl_type.union_member_types])
+    if idl_type.endswith('ConstructorConstructor'):
+        # FIXME: rename to NamedConstructor
+        # Ending with 'ConstructorConstructor' indicates a named constructor,
+        # and these do not have header files, as they are part of the generated
+        # bindings for the interface
+        return set()
     if idl_type.endswith('Constructor'):
         idl_type = constructor_type(idl_type)
     return set(['V8%s.h' % idl_type])
@@ -367,7 +403,7 @@ def add_includes_for_type(idl_type):
 
 V8_VALUE_TO_CPP_VALUE = {
     # Basic
-    'Date': 'toWebCoreDate({v8_value})',
+    'Date': 'toCoreDate({v8_value})',
     'DOMString': '{v8_value}',
     'boolean': '{v8_value}->BooleanValue()',
     'float': 'static_cast<float>({v8_value}->NumberValue())',
@@ -383,12 +419,13 @@ V8_VALUE_TO_CPP_VALUE = {
     # Interface types
     'CompareHow': 'static_cast<Range::CompareHow>({v8_value}->Int32Value())',
     'Dictionary': 'Dictionary({v8_value}, info.GetIsolate())',
+    'EventTarget': 'V8DOMWrapper::isDOMWrapper({v8_value}) ? toWrapperTypeInfo(v8::Handle<v8::Object>::Cast({v8_value}))->toEventTarget(v8::Handle<v8::Object>::Cast({v8_value})) : 0',
     'MediaQueryListListener': 'MediaQueryListListener::create(ScriptValue({v8_value}, info.GetIsolate()))',
     'NodeFilter': 'toNodeFilter({v8_value}, info.GetIsolate())',
     'Promise': 'ScriptPromise({v8_value}, info.GetIsolate())',
     'SerializedScriptValue': 'SerializedScriptValue::create({v8_value}, info.GetIsolate())',
     'ScriptValue': 'ScriptValue({v8_value}, info.GetIsolate())',
-    'Window': 'toNativeDOMWindow({v8_value}, info.GetIsolate())',
+    'Window': 'toDOMWindow({v8_value}, info.GetIsolate())',
     'XPathNSResolver': 'toXPathNSResolver({v8_value}, info.GetIsolate())',
 }
 
@@ -529,8 +566,6 @@ def v8_conversion_type(idl_type, extended_attributes):
         return idl_type
 
     # Pointer type
-    includes.add('wtf/GetPtr.h')  # FIXME: remove if can eliminate WTF::getPtr
-    includes.add('wtf/RefPtr.h')
     return 'DOMWrapper'
 
 
@@ -554,18 +589,35 @@ V8_SET_RETURN_VALUE = {
     'ScriptValue': 'v8SetReturnValue(info, {cpp_value})',
     'SerializedScriptValue': 'v8SetReturnValue(info, {cpp_value})',
     # DOMWrapper
+    'DOMWrapperForMainWorld': 'v8SetReturnValueForMainWorld(info, {cpp_value})',
     'DOMWrapperFast': 'v8SetReturnValueFast(info, {cpp_value}, {script_wrappable})',
     'DOMWrapperDefault': 'v8SetReturnValue(info, {cpp_value})',
 }
 
 
-def v8_set_return_value(idl_type, cpp_value, 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 v8_set_return_value(idl_type, cpp_value, extended_attributes=None, script_wrappable='', release=False, for_main_world=False):
+    """Returns a statement that converts a C++ value to a V8 value and sets it as a return value.
+
+    release: for union types, can be either False (False for all member types)
+             or a sequence (list or tuple) of booleans (if specified
+             individually).
+    """
     def dom_wrapper_conversion_type():
         if not script_wrappable:
             return 'DOMWrapperDefault'
+        if for_main_world:
+            return 'DOMWrapperForMainWorld'
         return 'DOMWrapperFast'
 
+    if is_union_type(idl_type):
+        return [
+            v8_set_return_value(union_member_type,
+                                cpp_value + str(i),
+                                extended_attributes,
+                                script_wrappable,
+                                release and release[i])
+                for i, union_member_type in
+                enumerate(idl_type.union_member_types)]
     idl_type, cpp_value = preprocess_idl_type_and_value(idl_type, cpp_value, extended_attributes)
     this_v8_conversion_type = v8_conversion_type(idl_type, extended_attributes)
     # SetReturn-specific overrides
@@ -576,6 +628,8 @@ def v8_set_return_value(idl_type, cpp_value, extended_attributes=None, script_wr
         this_v8_conversion_type = dom_wrapper_conversion_type()
 
     format_string = V8_SET_RETURN_VALUE[this_v8_conversion_type]
+    if release:
+        cpp_value = '%s.release()' % cpp_value
     statement = format_string.format(cpp_value=cpp_value, script_wrappable=script_wrappable)
     return statement