| 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 Blink-in-JS design doc: https://docs.google.com/a/google.com/document/d/13cT9Klg
vt_ciAR3ONGvzKvw6fz9-f6E0FrqYFqfoc8Y/edit | |
| 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/core/v8/V8Binding.h', | |
| 17 ]) | |
| 18 | |
| 19 BLINK_IN_JS_INTERFACE_CPP_INCLUDES = frozenset([ | |
| 20 'bindings/core/v8/PrivateScriptRunner.h', | |
| 21 'bindings/core/v8/V8Window.h', | |
| 22 'core/dom/ScriptForbiddenScope.h', | |
| 23 'core/frame/LocalFrame.h', | |
| 24 ]) | |
| 25 | |
| 26 | |
| 27 def private_script_interface_context(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 'forward_declarations': forward_declarations(private_script_interface), | |
| 33 'header_includes': set(BLINK_IN_JS_INTERFACE_H_INCLUDES), | |
| 34 'methods': [method_context(operation) | |
| 35 for operation in private_script_interface.operations], | |
| 36 'v8_class': v8_utilities.v8_class_name(private_script_interface), | |
| 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 method_context(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(raw_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, | |
| 60 isolate='scriptState->isolate()'), | |
| 61 } | |
| 62 contents.update(arguments_context(operation.arguments, idl_type)) | |
| 63 return contents | |
| 64 | |
| 65 | |
| 66 def arguments_context(arguments, idl_type): | |
| 67 def argument_context(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( | |
| 77 used_as_argument=True), argument.name) 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': [argument_context(argument) for argument in arguments], | |
| 83 } | |
| OLD | NEW |