Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Side by Side Diff: Source/bindings/scripts/unstable/v8_attributes.py

Issue 24867002: Add static attributes to IDL compiler (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Reupload Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | Source/bindings/templates/attributes.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright (C) 2013 Google Inc. All rights reserved. 1 # Copyright (C) 2013 Google Inc. All rights reserved.
2 # 2 #
3 # Redistribution and use in source and binary forms, with or without 3 # Redistribution and use in source and binary forms, with or without
4 # modification, are permitted provided that the following conditions are 4 # modification, are permitted provided that the following conditions are
5 # met: 5 # met:
6 # 6 #
7 # * Redistributions of source code must retain the above copyright 7 # * Redistributions of source code must retain the above copyright
8 # notice, this list of conditions and the following disclaimer. 8 # notice, this list of conditions and the following disclaimer.
9 # * Redistributions in binary form must reproduce the above 9 # * Redistributions in binary form must reproduce the above
10 # copyright notice, this list of conditions and the following disclaimer 10 # copyright notice, this list of conditions and the following disclaimer
(...skipping 24 matching lines...) Expand all
35 For details, see bug http://crbug.com/239771 35 For details, see bug http://crbug.com/239771
36 """ 36 """
37 37
38 import v8_types 38 import v8_types
39 import v8_utilities 39 import v8_utilities
40 from v8_utilities import cpp_method_name, generate_conditional_string, uncapital ize 40 from v8_utilities import cpp_method_name, generate_conditional_string, uncapital ize
41 41
42 42
43 def generate_attributes(interface): 43 def generate_attributes(interface):
44 def generate_attribute(attribute): 44 def generate_attribute(attribute):
45 attribute_contents, attribute_includes = generate_attribute_and_includes (attribute) 45 attribute_contents, attribute_includes = generate_attribute_and_includes (interface, attribute)
46 includes.update(attribute_includes) 46 includes.update(attribute_includes)
47 return attribute_contents 47 return attribute_contents
48 48
49 includes = set() 49 includes = set()
50 contents = generate_attributes_common(interface) 50 contents = generate_attributes_common(interface)
51 contents['attributes'] = [generate_attribute(attribute) for attribute in int erface.attributes] 51 contents['attributes'] = [generate_attribute(attribute) for attribute in int erface.attributes]
52 return contents, includes 52 return contents, includes
53 53
54 54
55 def generate_attributes_common(interface): 55 def generate_attributes_common(interface):
56 attributes = interface.attributes 56 attributes = interface.attributes
57 v8_class_name = v8_utilities.v8_class_name(interface) 57 v8_class_name = v8_utilities.v8_class_name(interface)
58 return { 58 return {
59 # Size 0 constant array is not allowed in VC++ 59 # Size 0 constant array is not allowed in VC++
60 'number_of_attributes': 'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class_name if attributes else '0', 60 'number_of_attributes': 'WTF_ARRAY_LENGTH(%sAttributes)' % v8_class_name if attributes else '0',
61 'attribute_templates': '%sAttributes' % v8_class_name if attributes else '0', 61 'attribute_templates': '%sAttributes' % v8_class_name if attributes else '0',
62 } 62 }
63 63
64 64
65 def generate_attribute_and_includes(attribute): 65 def generate_attribute_and_includes(interface, attribute):
66 idl_type = attribute.data_type 66 idl_type = attribute.data_type
67 cpp_value = getter_expression(interface, attribute)
67 this_is_keep_alive_for_gc = is_keep_alive_for_gc(attribute) 68 this_is_keep_alive_for_gc = is_keep_alive_for_gc(attribute)
68 contents = { 69 contents = {
69 'name': attribute.name,
70 'conditional_string': generate_conditional_string(attribute), 70 'conditional_string': generate_conditional_string(attribute),
71 'cpp_method_name': cpp_method_name(attribute), 71 'cpp_method_name': cpp_method_name(attribute),
72 'cpp_type': v8_types.cpp_type(idl_type), 72 'cpp_type': v8_types.cpp_type(idl_type),
73 'is_keep_alive_for_gc': this_is_keep_alive_for_gc, 73 'is_keep_alive_for_gc': this_is_keep_alive_for_gc,
74 'cpp_value': cpp_value,
75 'is_normal': not attribute.is_static,
Nils Barth (inactive) 2013/09/26 22:30:34 In future there will be other exceptions (RunTimeE
76 'is_static': attribute.is_static,
77 'name': attribute.name,
74 'v8_type': v8_types.v8_type(idl_type), 78 'v8_type': v8_types.v8_type(idl_type),
75 } 79 }
76 if this_is_keep_alive_for_gc: 80 if this_is_keep_alive_for_gc:
77 includes = v8_types.includes_for_type(idl_type) 81 includes = v8_types.includes_for_type(idl_type)
78 includes.add('bindings/v8/V8HiddenPropertyName.h') 82 includes.add('bindings/v8/V8HiddenPropertyName.h')
79 else: 83 else:
80 cpp_value = 'imp->%s()' % uncapitalize(attribute.name)
81 return_v8_value_statement, includes = v8_types.v8_set_return_value(idl_t ype, cpp_value, callback_info='info', isolate='info.GetIsolate()', extended_attr ibutes=attribute.extended_attributes, script_wrappable='imp') 84 return_v8_value_statement, includes = v8_types.v8_set_return_value(idl_t ype, cpp_value, callback_info='info', isolate='info.GetIsolate()', extended_attr ibutes=attribute.extended_attributes, script_wrappable='imp')
82 contents['return_v8_value_statement'] = return_v8_value_statement 85 contents['return_v8_value_statement'] = return_v8_value_statement
83 return contents, includes 86 return contents, includes
84 87
85 88
89 def getter_expression(interface, attribute):
Nils Barth (inactive) 2013/09/26 22:30:34 This function will be more complicated in future,
90 getter_base_name = uncapitalize(attribute.name)
Nils Barth (inactive) 2013/09/26 22:30:34 This is more complicated in general: we'll need a
91 getter_name = scoped_name(interface, attribute, getter_base_name)
92 return '%s()' % getter_name
93
94
95 def scoped_name(interface, attribute, function_base_name):
Nils Barth (inactive) 2013/09/26 22:30:34 We need this for setters as well, and it will be m
96 if attribute.is_static:
97 return '%s::%s' % (interface.name, function_base_name)
98 return 'imp->%s' % function_base_name
99
100
86 def is_keep_alive_for_gc(attribute): 101 def is_keep_alive_for_gc(attribute):
87 idl_type = attribute.data_type 102 idl_type = attribute.data_type
88 extended_attributes = attribute.extended_attributes 103 extended_attributes = attribute.extended_attributes
89 return ( 104 return (
90 'KeepAttributeAliveForGC' in extended_attributes or 105 'KeepAttributeAliveForGC' in extended_attributes or
91 # For readonly attributes, for performance reasons we keep the attribute 106 # For readonly attributes, for performance reasons we keep the attribute
92 # wrapper alive while the owner wrapper is alive, because the attribute 107 # wrapper alive while the owner wrapper is alive, because the attribute
93 # never changes. 108 # never changes.
94 (attribute.is_read_only and 109 (attribute.is_read_only and
95 v8_types.wrapper_type(idl_type) and 110 v8_types.wrapper_type(idl_type) and
96 # There are some exceptions, however: 111 # There are some exceptions, however:
97 not( 112 not(
98 # Node lifetime is managed by object grouping. 113 # Node lifetime is managed by object grouping.
99 v8_types.dom_node_type(idl_type) or 114 v8_types.dom_node_type(idl_type) or
100 # A self-reference is unnecessary. 115 # A self-reference is unnecessary.
101 attribute.name == 'self' or 116 attribute.name == 'self' or
102 # FIXME: Remove these hard-coded hacks. 117 # FIXME: Remove these hard-coded hacks.
103 idl_type in ['SerializedScriptValue', 'Window'] or 118 idl_type in ['SerializedScriptValue', 'Window'] or
104 idl_type.startswith('HTML')))) 119 idl_type.startswith('HTML'))))
OLDNEW
« no previous file with comments | « no previous file | Source/bindings/templates/attributes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698