Chromium Code Reviews| Index: Source/bindings/scripts/v8_private_script_interface.py |
| diff --git a/Source/bindings/scripts/v8_private_script_interface.py b/Source/bindings/scripts/v8_private_script_interface.py |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..e48ecd2f624b449fcae71d6d76988ec55a4d2bd8 |
| --- /dev/null |
| +++ b/Source/bindings/scripts/v8_private_script_interface.py |
| @@ -0,0 +1,83 @@ |
| +# Copyright 2014 The Chromium Authors. All rights reserved. |
| +# Use of this source code is governed by a BSD-style license that can be |
| +# found in the LICENSE file. |
| + |
| +"""Generate template values for V8PrivateScriptInterface. |
| + |
| +Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
| +""" |
| + |
| +from idl_types import IdlType |
| +from v8_globals import includes |
| +import v8_types |
| +import v8_utilities |
| + |
| +BLINK_IN_JS_INTERFACE_H_INCLUDES = frozenset([ |
| + 'bindings/v8/V8Binding.h', |
| +]) |
| + |
| +BLINK_IN_JS_INTERFACE_CPP_INCLUDES = frozenset([ |
| + 'bindings/core/v8/V8Window.h', |
| + 'bindings/v8/PrivateScriptController.h', |
| + 'core/dom/ScriptForbiddenScope.h', |
| + 'core/frame/LocalFrame.h', |
| +]) |
| + |
| + |
| +def generate_private_script_interface(private_script_interface): |
| + includes.clear() |
| + includes.update(BLINK_IN_JS_INTERFACE_CPP_INCLUDES) |
| + return { |
| + 'cpp_class': private_script_interface.name, |
| + 'v8_class': v8_utilities.v8_class_name(private_script_interface), |
| + 'header_includes': set(BLINK_IN_JS_INTERFACE_H_INCLUDES), |
| + 'forward_declarations': forward_declarations(private_script_interface), |
|
Nils Barth (inactive)
2014/06/23 03:14:29
alpha
|
| + 'methods': [generate_method(operation) |
| + for operation in private_script_interface.operations], |
| + } |
| + |
| + |
| +def forward_declarations(private_script_interface): |
| + declarations = set(['LocalFrame']) |
| + for operation in private_script_interface.operations: |
| + if operation.idl_type.is_wrapper_type: |
| + declarations.add(operation.idl_type.base_type) |
| + for argument in operation.arguments: |
| + if argument.idl_type.is_wrapper_type: |
| + declarations.add(argument.idl_type.base_type) |
| + return sorted(declarations) |
| + |
| + |
| +def generate_method(operation): |
| + extended_attributes = operation.extended_attributes |
| + idl_type = operation.idl_type |
| + idl_type_str = str(idl_type) |
| + contents = { |
| + 'cpp_type': idl_type.cpp_type_args(used_as_primitive_type=True), |
| + 'name': operation.name, |
| + 'v8_value_to_cpp_value': v8_types.v8_value_to_cpp_value( |
| + idl_type, extended_attributes, 'v8Value', 0, isolate='scriptState->isolate()') |
|
Nils Barth (inactive)
2014/06/23 03:14:29
line break?
|
| + 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
|
| + } |
| + contents.update(generate_arguments_contents(operation.arguments, idl_type)) |
| + return contents |
| + |
| + |
| +def generate_arguments_contents(arguments, idl_type): |
| + def generate_argument(argument): |
| + return { |
| + 'handle': '%sHandle' % argument.name, |
| + 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value( |
| + argument.name, isolate='scriptState->isolate()', |
| + creation_context='scriptState->context()->Global()'), |
| + } |
| + |
| + argument_declarations = ['LocalFrame* frame'] |
| + argument_declarations.extend(['%s %s' % (argument.idl_type.cpp_type_args(used_as_argument=True), argument.name) |
|
Nils Barth (inactive)
2014/06/23 03:14:29
line break?
|
| + for argument in arguments]) |
| + if idl_type.name != 'void': |
| + argument_declarations.append('%s* %s' % (idl_type.cpp_type, 'output')) |
| + return { |
| + 'argument_declarations': argument_declarations, |
| + 'arguments': [generate_argument(argument) for argument in arguments], |
| + } |