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

Side by Side Diff: third_party/WebKit/Source/bindings/scripts/v8_callback_interface.py

Issue 2837923003: Make NodeFilter a legacy callback interface. (Closed)
Patch Set: . Created 3 years, 7 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
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 17 matching lines...) Expand all
28 28
29 """Generate template values for a callback interface. 29 """Generate template values for a callback interface.
30 30
31 Extends IdlTypeBase with property |callback_cpp_type|. 31 Extends IdlTypeBase with property |callback_cpp_type|.
32 32
33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler 33 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler
34 """ 34 """
35 35
36 from idl_types import IdlTypeBase 36 from idl_types import IdlTypeBase
37 from v8_globals import includes 37 from v8_globals import includes
38 from v8_interface import constant_context
38 import v8_types 39 import v8_types
39 import v8_utilities 40 import v8_utilities
40 41
41 CALLBACK_INTERFACE_H_INCLUDES = frozenset([ 42 CALLBACK_INTERFACE_H_INCLUDES = frozenset([
42 'bindings/core/v8/DOMWrapperWorld.h', 43 'bindings/core/v8/DOMWrapperWorld.h',
43 'bindings/core/v8/ScopedPersistent.h', 44 'bindings/core/v8/ScopedPersistent.h',
44 ]) 45 ])
45 CALLBACK_INTERFACE_CPP_INCLUDES = frozenset([ 46 CALLBACK_INTERFACE_CPP_INCLUDES = frozenset([
46 'bindings/core/v8/ScriptController.h', 47 'bindings/core/v8/ScriptController.h',
47 'bindings/core/v8/V8BindingForCore.h', 48 'bindings/core/v8/V8BindingForCore.h',
49 'bindings/core/v8/V8DOMConfiguration.h',
48 'core/dom/ExecutionContext.h', 50 'core/dom/ExecutionContext.h',
49 'platform/wtf/Assertions.h', 51 'platform/wtf/Assertions.h',
50 'platform/wtf/GetPtr.h', 52 'platform/wtf/GetPtr.h',
51 'platform/wtf/RefPtr.h', 53 'platform/wtf/RefPtr.h',
52 ]) 54 ])
53 55
54 56
55 def cpp_type(idl_type): 57 def cpp_type(idl_type):
56 # FIXME: remove this function by making callback types consistent 58 # FIXME: remove this function by making callback types consistent
57 # (always use usual v8_types.cpp_type) 59 # (always use usual v8_types.cpp_type)
58 idl_type_name = idl_type.name 60 idl_type_name = idl_type.name
59 if idl_type_name == 'String': 61 if idl_type_name == 'String':
60 return 'const String&' 62 return 'const String&'
61 if idl_type_name == 'void': 63 if idl_type_name == 'void':
62 return 'void' 64 return 'void'
63 # Callbacks use raw pointers, so raw_type=True 65 # Callbacks use raw pointers, so raw_type=True
64 raw_cpp_type = idl_type.cpp_type_args(raw_type=True) 66 raw_cpp_type = idl_type.cpp_type_args(raw_type=True)
65 # Pass containers and dictionaries to callback method by const reference rat her than by value 67 # Pass containers and dictionaries to callback method by const reference rat her than by value
66 if raw_cpp_type.startswith(('Vector', 'HeapVector')) or idl_type.is_dictiona ry: 68 if raw_cpp_type.startswith(('Vector', 'HeapVector')) or idl_type.is_dictiona ry:
67 return 'const %s&' % raw_cpp_type 69 return 'const %s&' % raw_cpp_type
68 return raw_cpp_type 70 return raw_cpp_type
69 71
70 IdlTypeBase.callback_cpp_type = property(cpp_type) 72 IdlTypeBase.callback_cpp_type = property(cpp_type)
71 73
72 74
73 def callback_interface_context(callback_interface, _): 75 def callback_interface_context(callback_interface, _):
74 includes.clear() 76 includes.clear()
75 includes.update(CALLBACK_INTERFACE_CPP_INCLUDES) 77 includes.update(CALLBACK_INTERFACE_CPP_INCLUDES)
78 is_legacy = len(callback_interface.constants) > 0
76 return { 79 return {
77 'cpp_class': callback_interface.name, 80 'cpp_class': callback_interface.name,
78 'v8_class': v8_utilities.v8_class_name(callback_interface), 81 'v8_class': v8_utilities.v8_class_name(callback_interface),
79 'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES), 82 'header_includes': set(CALLBACK_INTERFACE_H_INCLUDES),
80 'methods': [method_context(operation) 83 'methods': [] if is_legacy else [method_context(operation)
bashi 2017/04/27 08:49:49 nit: We use alphabetical ordering in dicts.
bashi 2017/04/27 08:49:49 Why do we need to set an empty list when |is_legac
tkent 2017/04/27 09:15:12 Because method_context() crashes due to unsupporte
bashi 2017/04/27 23:12:32 Could you put the error log here? I'd prefer fixin
tkent 2017/04/28 00:09:43 Obviously, it's an intentional exception. def met
bashi 2017/04/28 00:59:09 I see. Thank you for the explanation. Given that w
81 for operation in callback_interface.operations], 84 for operation in callback_interface.ope rations],
85 'is_legacy': is_legacy,
86 # For legacy callback interface
87 'interface_name': callback_interface.name,
88 'constants': [constant_context(constant, callback_interface)
89 for constant in callback_interface.constants],
82 } 90 }
83 91
84 92
85 def add_includes_for_operation(operation): 93 def add_includes_for_operation(operation):
86 operation.idl_type.add_includes_for_type() 94 operation.idl_type.add_includes_for_type()
87 for argument in operation.arguments: 95 for argument in operation.arguments:
88 argument.idl_type.add_includes_for_type() 96 argument.idl_type.add_includes_for_type()
89 97
90 98
91 def method_context(operation): 99 def method_context(operation):
(...skipping 29 matching lines...) Expand all
121 } 129 }
122 130
123 argument_declarations = ['ScriptValue thisValue'] if call_with_this_handle e lse [] 131 argument_declarations = ['ScriptValue thisValue'] if call_with_this_handle e lse []
124 argument_declarations.extend( 132 argument_declarations.extend(
125 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name) 133 '%s %s' % (argument.idl_type.callback_cpp_type, argument.name)
126 for argument in arguments) 134 for argument in arguments)
127 return { 135 return {
128 'argument_declarations': argument_declarations, 136 'argument_declarations': argument_declarations,
129 'arguments': [argument_context(argument) for argument in arguments], 137 'arguments': [argument_context(argument) for argument in arguments],
130 } 138 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698