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 operator |
| 10 from v8_globals import includes |
| 11 import v8_types |
| 12 import v8_utilities |
| 13 |
| 14 |
| 15 DICTIONARY_H_INCLUDES = frozenset([ |
| 16 'bindings/core/v8/V8Binding.h', |
| 17 'platform/heap/Handle.h', |
| 18 ]) |
| 19 |
| 20 DICTIONARY_CPP_INCLUDES = frozenset([ |
| 21 # FIXME: Remove this, http://crbug.com/321462 |
| 22 'bindings/core/v8/Dictionary.h', |
| 23 ]) |
| 24 |
| 25 |
| 26 def setter_name_for_dictionary_member(member): |
| 27 return 'set%s' % v8_utilities.capitalize(member.name) |
| 28 |
| 29 |
| 30 def has_name_for_dictionary_member(member): |
| 31 return 'has%s' % v8_utilities.capitalize(member.name) |
| 32 |
| 33 |
| 34 # Context for V8 bindings |
| 35 |
| 36 def dictionary_context(dictionary): |
| 37 includes.clear() |
| 38 includes.update(DICTIONARY_CPP_INCLUDES) |
| 39 return { |
| 40 'cpp_class': v8_utilities.cpp_name(dictionary), |
| 41 'header_includes': set(DICTIONARY_H_INCLUDES), |
| 42 'members': [member_context(member) |
| 43 for member in sorted(dictionary.members, |
| 44 key=operator.attrgetter('name'))], |
| 45 'v8_class': v8_utilities.v8_class_name(dictionary), |
| 46 } |
| 47 |
| 48 |
| 49 def member_context(member): |
| 50 idl_type = member.idl_type |
| 51 idl_type.add_includes_for_type() |
| 52 |
| 53 def default_values(): |
| 54 if not member.default_value: |
| 55 return None, None |
| 56 if member.default_value.is_null: |
| 57 return None, 'v8::Null(isolate)' |
| 58 cpp_default_value = str(member.default_value) |
| 59 v8_default_value = idl_type.cpp_value_to_v8_value( |
| 60 cpp_value=cpp_default_value, isolate='isolate', |
| 61 creation_context='creationContext', |
| 62 extended_attributes=member.extended_attributes) |
| 63 return cpp_default_value, v8_default_value |
| 64 |
| 65 cpp_default_value, v8_default_value = default_values() |
| 66 |
| 67 return { |
| 68 'cpp_default_value': cpp_default_value, |
| 69 'cpp_type': idl_type.cpp_type, |
| 70 'cpp_value_to_v8_value': idl_type.cpp_value_to_v8_value( |
| 71 cpp_value='impl->%s()' % member.name, isolate='isolate', |
| 72 creation_context='creationContext', |
| 73 extended_attributes=member.extended_attributes), |
| 74 'has_name': has_name_for_dictionary_member(member), |
| 75 'name': member.name, |
| 76 'setter_name': setter_name_for_dictionary_member(member), |
| 77 'v8_default_value': v8_default_value, |
| 78 'v8_type': v8_types.v8_type(idl_type.base_type), |
| 79 } |
| 80 |
| 81 # FIXME: Implement context for impl class. |
OLD | NEW |