OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 """Generate template contexts of dictionaries for both v8 bindings and |
| 6 implementation classes that are used by blink's core/modules. |
| 7 """ |
| 8 |
| 9 import copy |
| 10 import operator |
| 11 from v8_globals import includes |
| 12 import v8_types |
| 13 import v8_utilities |
| 14 |
| 15 |
| 16 DICTIONARY_H_INCLUDES = frozenset([ |
| 17 'bindings/core/v8/V8Binding.h', |
| 18 'platform/heap/Handle.h', |
| 19 ]) |
| 20 |
| 21 DICTIONARY_CPP_INCLUDES = frozenset([ |
| 22 # FIXME: Remove this, http://crbug.com/321462 |
| 23 'bindings/core/v8/Dictionary.h', |
| 24 ]) |
| 25 |
| 26 |
| 27 def setter_name_for_dictionary_member(member): |
| 28 return 'set%s' % v8_utilities.capitalize(member.name) |
| 29 |
| 30 |
| 31 def has_name_for_dictionary_member(member): |
| 32 return 'has%s' % v8_utilities.capitalize(member.name) |
| 33 |
| 34 |
| 35 # Context for V8 bindings |
| 36 |
| 37 def dictionary_context(dictionary): |
| 38 includes.clear() |
| 39 includes.update(DICTIONARY_CPP_INCLUDES) |
| 40 return { |
| 41 'cpp_class': v8_utilities.cpp_name(dictionary), |
| 42 'header_includes': set(DICTIONARY_H_INCLUDES), |
| 43 'members': [member_context(member) |
| 44 for member in sorted(dictionary.members, |
| 45 key=operator.attrgetter('name'))], |
| 46 'v8_class': v8_utilities.v8_class_name(dictionary), |
| 47 } |
| 48 |
| 49 |
| 50 def member_context(member): |
| 51 idl_type = member.idl_type |
| 52 idl_type.add_includes_for_type() |
| 53 |
| 54 def idl_type_for_default_value(): |
| 55 copied_type = copy.copy(idl_type) |
| 56 # IdlType for default values shouldn't be nullable. Otherwise, |
| 57 # it will generate meaningless expression like |
| 58 # 'String("default value").isNull() ? ...'. |
| 59 copied_type.is_nullable = False |
| 60 return copied_type |
| 61 |
| 62 def default_values(): |
| 63 if not member.default_value: |
| 64 return None, None |
| 65 if member.default_value.is_null: |
| 66 return None, 'v8::Null(isolate)' |
| 67 cpp_default_value = str(member.default_value) |
| 68 v8_default_value = idl_type_for_default_value().cpp_value_to_v8_value( |
| 69 cpp_value=cpp_default_value, isolate='isolate', |
| 70 creation_context='creationContext') |
| 71 return cpp_default_value, v8_default_value |
| 72 |
| 73 cpp_default_value, v8_default_value = default_values() |
| 74 |
| 75 return { |
| 76 'cpp_default_value': cpp_default_value, |
| 77 'cpp_type': idl_type.cpp_type, |
| 78 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
| 79 cpp_value='impl->%s()' % member.name, isolate='isolate', |
| 80 creation_context='creationContext', |
| 81 extended_attributes=member.extended_attributes), |
| 82 'has_name': has_name_for_dictionary_member(member), |
| 83 'name': member.name, |
| 84 'setter_name': setter_name_for_dictionary_member(member), |
| 85 'v8_default_value': v8_default_value, |
| 86 'v8_type': v8_types.v8_type(idl_type.base_type), |
| 87 } |
| 88 |
| 89 # FIXME: Implement context for impl class. |
OLD | NEW |