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

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: Revised, fix Perl 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 | « Source/bindings/scripts/code_generator_v8.pm ('k') | 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 this_getter_name = getter_name(interface, attribute)
68 cpp_value = '%s()' % this_getter_name
67 this_is_keep_alive_for_gc = is_keep_alive_for_gc(attribute) 69 this_is_keep_alive_for_gc = is_keep_alive_for_gc(attribute)
68 contents = { 70 contents = {
69 'name': attribute.name,
70 'conditional_string': generate_conditional_string(attribute), 71 'conditional_string': generate_conditional_string(attribute),
71 'cpp_method_name': cpp_method_name(attribute), 72 'cpp_method_name': cpp_method_name(attribute),
haraken 2013/09/27 00:33:31 This is unused. If we have getter_name, setter_nam
Nils Barth (inactive) 2013/09/27 01:09:33 Good catch, removed! (Also some cleanup to v8_util
72 'cpp_type': v8_types.cpp_type(idl_type), 73 'cpp_type': v8_types.cpp_type(idl_type),
73 'is_keep_alive_for_gc': this_is_keep_alive_for_gc, 74 'is_keep_alive_for_gc': this_is_keep_alive_for_gc,
75 'cpp_value': cpp_value,
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),
haraken 2013/09/27 00:33:31 Reorder these keys. For example: conditional_strin
Nils Barth (inactive) 2013/09/27 01:09:33 Fixed by alphabetizing - is this ok? (General styl
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_name(interface, attribute):
haraken 2013/09/27 00:33:31 getter_name => cpp_getter_name ?
Nils Barth (inactive) 2013/09/27 01:09:33 That's a bit redundant: getter/setter is clearly C
90 getter_base_name = uncapitalize(attribute.name)
haraken 2013/09/27 00:33:31 getter_base_name => getter_method_name ?
Nils Barth (inactive) 2013/09/27 01:09:33 Good point, done!
91 if attribute.is_static:
92 return '%s::%s' % (interface.name, getter_base_name)
93 return 'imp->%s' % getter_base_name
94
95
86 def is_keep_alive_for_gc(attribute): 96 def is_keep_alive_for_gc(attribute):
87 idl_type = attribute.data_type 97 idl_type = attribute.data_type
88 extended_attributes = attribute.extended_attributes 98 extended_attributes = attribute.extended_attributes
89 return ( 99 return (
90 'KeepAttributeAliveForGC' in extended_attributes or 100 'KeepAttributeAliveForGC' in extended_attributes or
91 # For readonly attributes, for performance reasons we keep the attribute 101 # For readonly attributes, for performance reasons we keep the attribute
92 # wrapper alive while the owner wrapper is alive, because the attribute 102 # wrapper alive while the owner wrapper is alive, because the attribute
93 # never changes. 103 # never changes.
94 (attribute.is_read_only and 104 (attribute.is_read_only and
95 v8_types.wrapper_type(idl_type) and 105 v8_types.wrapper_type(idl_type) and
96 # There are some exceptions, however: 106 # There are some exceptions, however:
97 not( 107 not(
98 # Node lifetime is managed by object grouping. 108 # Node lifetime is managed by object grouping.
99 v8_types.dom_node_type(idl_type) or 109 v8_types.dom_node_type(idl_type) or
100 # A self-reference is unnecessary. 110 # A self-reference is unnecessary.
101 attribute.name == 'self' or 111 attribute.name == 'self' or
102 # FIXME: Remove these hard-coded hacks. 112 # FIXME: Remove these hard-coded hacks.
103 idl_type in ['SerializedScriptValue', 'Window'] or 113 idl_type in ['SerializedScriptValue', 'Window'] or
104 idl_type.startswith('HTML')))) 114 idl_type.startswith('HTML'))))
OLDNEW
« no previous file with comments | « Source/bindings/scripts/code_generator_v8.pm ('k') | Source/bindings/templates/attributes.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698