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 | 9 import copy |
bashi
2014/08/15 15:08:25
nit: Could you remove this?
Jens Widell
2014/08/19 11:36:59
Done.
| |
10 import operator | 10 import operator |
11 from v8_globals import includes | 11 from v8_globals import includes |
12 import v8_types | 12 import v8_types |
13 import v8_utilities | 13 import v8_utilities |
14 | 14 |
15 | 15 |
16 DICTIONARY_H_INCLUDES = frozenset([ | 16 DICTIONARY_H_INCLUDES = frozenset([ |
17 'bindings/core/v8/V8Binding.h', | 17 'bindings/core/v8/V8Binding.h', |
18 'platform/heap/Handle.h', | 18 'platform/heap/Handle.h', |
19 ]) | 19 ]) |
(...skipping 25 matching lines...) Expand all Loading... | |
45 key=operator.attrgetter('name'))], | 45 key=operator.attrgetter('name'))], |
46 'v8_class': v8_utilities.v8_class_name(dictionary), | 46 'v8_class': v8_utilities.v8_class_name(dictionary), |
47 } | 47 } |
48 | 48 |
49 | 49 |
50 def member_context(member): | 50 def member_context(member): |
51 idl_type = member.idl_type | 51 idl_type = member.idl_type |
52 idl_type.add_includes_for_type() | 52 idl_type.add_includes_for_type() |
53 | 53 |
54 def idl_type_for_default_value(): | 54 def idl_type_for_default_value(): |
55 copied_type = copy.copy(idl_type) | 55 if idl_type.is_nullable: |
56 # IdlType for default values shouldn't be nullable. Otherwise, | 56 return idl_type.inner_type |
57 # it will generate meaningless expression like | 57 return idl_type |
58 # 'String("default value").isNull() ? ...'. | |
59 copied_type.is_nullable = False | |
60 return copied_type | |
61 | 58 |
62 def default_values(): | 59 def default_values(): |
63 if not member.default_value: | 60 if not member.default_value: |
64 return None, None | 61 return None, None |
65 if member.default_value.is_null: | 62 if member.default_value.is_null: |
66 return None, 'v8::Null(isolate)' | 63 return None, 'v8::Null(isolate)' |
67 cpp_default_value = str(member.default_value) | 64 cpp_default_value = str(member.default_value) |
68 v8_default_value = idl_type_for_default_value().cpp_value_to_v8_value( | 65 v8_default_value = idl_type_for_default_value().cpp_value_to_v8_value( |
69 cpp_value=cpp_default_value, isolate='isolate', | 66 cpp_value=cpp_default_value, isolate='isolate', |
70 creation_context='creationContext') | 67 creation_context='creationContext') |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
126 'getter_expression': getter_expression(), | 123 'getter_expression': getter_expression(), |
127 'has_method_expression': has_method_expression(), | 124 'has_method_expression': has_method_expression(), |
128 'has_method_name': has_method_name_for_dictionary_member(member), | 125 'has_method_name': has_method_name_for_dictionary_member(member), |
129 'is_traceable': (idl_type.is_garbage_collected or | 126 'is_traceable': (idl_type.is_garbage_collected or |
130 idl_type.is_will_be_garbage_collected), | 127 idl_type.is_will_be_garbage_collected), |
131 'member_cpp_type': member_cpp_type(), | 128 'member_cpp_type': member_cpp_type(), |
132 'name': member.name, | 129 'name': member.name, |
133 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), | 130 'rvalue_cpp_type': idl_type.cpp_type_args(used_as_rvalue_type=True), |
134 'setter_name': setter_name_for_dictionary_member(member), | 131 'setter_name': setter_name_for_dictionary_member(member), |
135 } | 132 } |
OLD | NEW |