Chromium Code Reviews| 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 values for V8PrivateScriptInterface. | |
| 6 | |
| 7 Design doc: http://www.chromium.org/developers/design-documents/idl-compiler | |
| 8 """ | |
| 9 | |
| 10 from idl_types import IdlType | |
| 11 from v8_globals import includes | |
| 12 import v8_types | |
| 13 import v8_utilities | |
| 14 | |
| 15 BLINK_IN_JS_INTERFACE_H_INCLUDES = frozenset([ | |
| 16 'bindings/v8/V8Binding.h', | |
| 17 ]) | |
| 18 | |
| 19 BLINK_IN_JS_INTERFACE_CPP_INCLUDES = frozenset([ | |
| 20 'bindings/core/v8/V8Window.h', | |
| 21 'bindings/v8/PrivateScriptController.h', | |
| 22 'core/dom/ScriptForbiddenScope.h', | |
| 23 'core/frame/LocalFrame.h', | |
| 24 ]) | |
| 25 | |
| 26 | |
| 27 def generate_private_script_interface(private_script_interface): | |
| 28 includes.clear() | |
| 29 includes.update(BLINK_IN_JS_INTERFACE_CPP_INCLUDES) | |
| 30 return { | |
| 31 'cpp_class': private_script_interface.name, | |
| 32 'v8_class': v8_utilities.v8_class_name(private_script_interface), | |
| 33 'header_includes': set(BLINK_IN_JS_INTERFACE_H_INCLUDES), | |
| 34 'forward_declarations': forward_declarations(private_script_interface), | |
|
Nils Barth (inactive)
2014/06/23 03:14:29
alpha
| |
| 35 'methods': [generate_method(operation) | |
| 36 for operation in private_script_interface.operations], | |
| 37 } | |
| 38 | |
| 39 | |
| 40 def forward_declarations(private_script_interface): | |
| 41 declarations = set(['LocalFrame']) | |
| 42 for operation in private_script_interface.operations: | |
| 43 if operation.idl_type.is_wrapper_type: | |
| 44 declarations.add(operation.idl_type.base_type) | |
| 45 for argument in operation.arguments: | |
| 46 if argument.idl_type.is_wrapper_type: | |
| 47 declarations.add(argument.idl_type.base_type) | |
| 48 return sorted(declarations) | |
| 49 | |
| 50 | |
| 51 def generate_method(operation): | |
| 52 extended_attributes = operation.extended_attributes | |
| 53 idl_type = operation.idl_type | |
| 54 idl_type_str = str(idl_type) | |
| 55 contents = { | |
| 56 'cpp_type': idl_type.cpp_type_args(used_as_primitive_type=True), | |
| 57 'name': operation.name, | |
| 58 'v8_value_to_cpp_value': v8_types.v8_value_to_cpp_value( | |
| 59 idl_type, extended_attributes, 'v8Value', 0, isolate='scriptState->i solate()') | |
|
Nils Barth (inactive)
2014/06/23 03:14:29
line break?
| |
| 60 if idl_type.name != 'void' else '', | |
|
Nils Barth (inactive)
2014/06/23 03:14:29
Could you just add a check to
v8_types.v8_value_t
| |
| 61 } | |
| 62 contents.update(generate_arguments_contents(operation.arguments, idl_type)) | |
| 63 return contents | |
| 64 | |
| 65 | |
| 66 def generate_arguments_contents(arguments, idl_type): | |
| 67 def generate_argument(argument): | |
| 68 return { | |
| 69 'handle': '%sHandle' % argument.name, | |
| 70 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value( | |
| 71 argument.name, isolate='scriptState->isolate()', | |
| 72 creation_context='scriptState->context()->Global()'), | |
| 73 } | |
| 74 | |
| 75 argument_declarations = ['LocalFrame* frame'] | |
| 76 argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args(use d_as_argument=True), argument.name) | |
|
Nils Barth (inactive)
2014/06/23 03:14:29
line break?
| |
| 77 for argument in arguments]) | |
| 78 if idl_type.name != 'void': | |
| 79 argument_declarations.append('%s* %s' % (idl_type.cpp_type, 'output')) | |
| 80 return { | |
| 81 'argument_declarations': argument_declarations, | |
| 82 'arguments': [generate_argument(argument) for argument in arguments], | |
| 83 } | |
| OLD | NEW |