OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Generate template contexts of dictionaries for both v8 bindings and | 5 """Generate template contexts of dictionaries for both v8 bindings and |
6 implementation classes that are used by blink's core/modules. | 6 implementation classes that are used by blink's core/modules. |
7 """ | 7 """ |
8 | 8 |
9 import copy | |
10 import operator | 9 import operator |
11 from v8_globals import includes | 10 from v8_globals import includes |
12 import v8_types | 11 import v8_types |
13 import v8_utilities | 12 import v8_utilities |
14 | 13 |
15 | 14 |
16 DICTIONARY_H_INCLUDES = frozenset([ | 15 DICTIONARY_H_INCLUDES = frozenset([ |
17 'bindings/core/v8/V8Binding.h', | 16 'bindings/core/v8/V8Binding.h', |
18 'platform/heap/Handle.h', | 17 'platform/heap/Handle.h', |
19 ]) | 18 ]) |
(...skipping 25 matching lines...) Expand all Loading... |
45 key=operator.attrgetter('name'))], | 44 key=operator.attrgetter('name'))], |
46 'v8_class': v8_utilities.v8_class_name(dictionary), | 45 'v8_class': v8_utilities.v8_class_name(dictionary), |
47 } | 46 } |
48 | 47 |
49 | 48 |
50 def member_context(member): | 49 def member_context(member): |
51 idl_type = member.idl_type | 50 idl_type = member.idl_type |
52 idl_type.add_includes_for_type() | 51 idl_type.add_includes_for_type() |
53 | 52 |
54 def idl_type_for_default_value(): | 53 def idl_type_for_default_value(): |
55 copied_type = copy.copy(idl_type) | 54 if idl_type.is_nullable: |
56 # IdlType for default values shouldn't be nullable. Otherwise, | 55 return idl_type.inner_type |
57 # it will generate meaningless expression like | 56 return idl_type |
58 # 'String("default value").isNull() ? ...'. | |
59 copied_type.is_nullable = False | |
60 return copied_type | |
61 | 57 |
62 def default_values(): | 58 def default_values(): |
63 if not member.default_value: | 59 if not member.default_value: |
64 return None, None | 60 return None, None |
65 if member.default_value.is_null: | 61 if member.default_value.is_null: |
66 return None, 'v8::Null(isolate)' | 62 return None, 'v8::Null(isolate)' |
67 cpp_default_value = str(member.default_value) | 63 cpp_default_value = str(member.default_value) |
68 v8_default_value = idl_type_for_default_value().cpp_value_to_v8_value( | 64 v8_default_value = idl_type_for_default_value().cpp_value_to_v8_value( |
69 cpp_value=cpp_default_value, isolate='isolate', | 65 cpp_value=cpp_default_value, isolate='isolate', |
70 creation_context='creationContext') | 66 creation_context='creationContext') |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 'getter_expression': getter_expression(), | 127 'getter_expression': getter_expression(), |
132 'has_method_expression': has_method_expression(), | 128 'has_method_expression': has_method_expression(), |
133 'has_method_name': has_method_name_for_dictionary_member(member), | 129 'has_method_name': has_method_name_for_dictionary_member(member), |
134 'is_traceable': (idl_type.is_garbage_collected or | 130 'is_traceable': (idl_type.is_garbage_collected or |
135 idl_type.is_will_be_garbage_collected), | 131 idl_type.is_will_be_garbage_collected), |
136 'member_cpp_type': member_cpp_type(), | 132 'member_cpp_type': member_cpp_type(), |
137 'name': member.name, | 133 'name': member.name, |
138 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 134 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
139 'setter_name': setter_name_for_dictionary_member(member), | 135 'setter_name': setter_name_for_dictionary_member(member), |
140 } | 136 } |
OLD | NEW |