| Index: Source/bindings/scripts/v8_union.py
|
| diff --git a/Source/bindings/scripts/v8_union.py b/Source/bindings/scripts/v8_union.py
|
| index 2c4d735d6edcf6b44cd8428b70a220ff17a7e436..531573e8c6cfc582addfa1b7c1a283f5b7a9de74 100644
|
| --- a/Source/bindings/scripts/v8_union.py
|
| +++ b/Source/bindings/scripts/v8_union.py
|
| @@ -16,12 +16,27 @@ header_forward_decls = set()
|
|
|
|
|
| def union_context(union_types, interfaces_info):
|
| + preprocessed_union_types = set()
|
| + nullable_union_types = set()
|
| + for union_type in union_types:
|
| + # Unwrap nullable if needed to avoid "OrNull" containers.
|
| + preprocessed_type = union_type.as_union_type
|
| + preprocessed_union_types.add(preprocessed_type)
|
| + if union_type.includes_nullable_type:
|
| + nullable_union_types.add(preprocessed_type)
|
| +
|
| + preprocessed_union_types = sorted(preprocessed_union_types,
|
| + key=lambda union_type: union_type.name)
|
| + nullable_union_types = sorted(nullable_union_types,
|
| + key=lambda union_type: union_type.name)
|
| return {
|
| 'containers': [container_context(union_type, interfaces_info)
|
| - for union_type in union_types],
|
| + for union_type in preprocessed_union_types],
|
| 'cpp_includes': sorted(cpp_includes),
|
| 'header_forward_decls': sorted(header_forward_decls),
|
| 'header_includes': sorted(UNION_H_INCLUDES),
|
| + 'nullable_containers': [nullable_container_context(union_type)
|
| + for union_type in nullable_union_types],
|
| }
|
|
|
|
|
| @@ -69,12 +84,20 @@ def container_context(union_type, interfaces_info):
|
| else:
|
| raise Exception('%s is not supported as an union member.' % member.name)
|
|
|
| + # Nullable restriction checks
|
| + nullable_members = union_type.number_of_nullable_member_types
|
| + if nullable_members > 1:
|
| + raise Exception('%s contains more than one nullable members' % union_type.name)
|
| + if dictionary_type and nullable_members == 1:
|
| + raise Exception('%s has a dictionary and a nullable member' % union_type.name)
|
| +
|
| return {
|
| 'array_buffer_type': array_buffer_type,
|
| 'array_buffer_view_type': array_buffer_view_type,
|
| 'boolean_type': boolean_type,
|
| - 'cpp_class': union_type.name,
|
| + 'cpp_class': union_type.cpp_type,
|
| 'dictionary_type': dictionary_type,
|
| + 'includes_nullable_type': union_type.includes_nullable_type,
|
| 'interface_types': interface_types,
|
| 'members': members,
|
| 'needs_trace': any(member['is_traceable'] for member in members),
|
| @@ -103,3 +126,9 @@ def member_context(member, interfaces_info):
|
| 'v8_value_to_local_cpp_value': member.v8_value_to_local_cpp_value(
|
| {}, 'v8Value', 'cppValue', needs_exception_state_for_string=True),
|
| }
|
| +
|
| +
|
| +def nullable_container_context(union_type):
|
| + return {
|
| + 'cpp_class': union_type.cpp_type,
|
| + }
|
|
|