Index: third_party/WebKit/Source/bindings/scripts/v8_callback_function.py |
diff --git a/third_party/WebKit/Source/bindings/scripts/v8_callback_function.py b/third_party/WebKit/Source/bindings/scripts/v8_callback_function.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..9bacd79596918e7fe082638b163187477ce1e76b |
--- /dev/null |
+++ b/third_party/WebKit/Source/bindings/scripts/v8_callback_function.py |
@@ -0,0 +1,78 @@ |
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
Yuki
2016/09/08 10:45:25
The file header comment (of a new file) must be:
lkawai
2016/09/09 07:56:48
Done.
|
+ |
+"""Generate template values for a callback function. |
+ |
+ Extends IdlTypeBase with property |callback_cpp_type|. |
Yuki
2016/09/08 10:45:25
This line no longer applies.
lkawai
2016/09/09 07:56:48
Done.
|
+ |
+Design doc: http://www.chromium.org/developers/design-documents/idl-compiler |
+""" |
+ |
+from v8_globals import includes |
+import v8_types |
+import v8_utilities |
+ |
+CALLBACK_FUNCTION_H_INCLUDES = frozenset([ |
+ 'bindings/core/v8/ScopedPersistent.h', |
+ 'bindings/core/v8/ScriptValue.h', |
Yuki
2016/09/08 10:45:25
See a below comment. Let's stop using ScriptValue
lkawai
2016/09/09 07:56:48
Done.
|
+ 'platform/heap/Handle.h', |
+]) |
+CALLBACK_FUNCTION_CPP_INCLUDES = frozenset([ |
+ 'bindings/core/v8/ScriptState.h', |
+ 'bindings/core/v8/V8Binding.h', |
+ 'wtf/Assertions.h', |
+]) |
+ |
+ |
+def callback_function_context(callback_function): |
+ includes.clear() |
+ includes.update(CALLBACK_FUNCTION_CPP_INCLUDES) |
+ idl_type = callback_function.idl_type |
+ idl_type_str = str(idl_type) |
+ |
+ def member_cpp_type(): |
+ member_cpp_type = idl_type.cpp_type_args(used_in_cpp_sequence=True) |
+ if idl_type.impl_should_use_nullable_container: |
+ return v8_types.cpp_template_type('Nullable', member_cpp_type) |
+ return member_cpp_type |
+ context = { |
+ 'cpp_class': callback_function.name, |
+ 'v8_class': v8_utilities.v8_class_name(callback_function), |
+ 'header_includes': set(CALLBACK_FUNCTION_H_INCLUDES), |
+ 'cpp_includes': set(CALLBACK_FUNCTION_CPP_INCLUDES), |
+ 'rvalue_cpp_type': idl_type.callback_cpp_type, |
+ 'idl_type': idl_type_str, |
+ 'member_cpp_type': member_cpp_type(), |
+ 'v8_value_to_local_cpp_value_dict': idl_type.v8_value_to_local_cpp_value( |
+ callback_function.extended_attributes, 'currentValue', 'cppValue', bailout_return_value="false"), |
+ } |
+ context.update(arguments_context(callback_function.arguments)) |
+ return context |
+ |
+ |
+def arguments_context(arguments): |
+ def argument_context(argument): |
+ return { |
+ 'handle': '%sHandle' % argument.name, |
+ 'cpp_value_to_v8_value': argument.idl_type.cpp_value_to_v8_value( |
+ argument.name, isolate='m_scriptState->isolate()', |
+ creation_context='m_scriptState->context()->Global()'), |
+ } |
+ |
+ argument_declarations = ['ScriptValue thisValue'] |
Yuki
2016/09/08 10:45:25
I think we'd like to use ScriptWrappable* as |this
lkawai
2016/09/09 07:56:48
Done.
|
+ argument_declarations.extend( |
+ '%s %s' % (argument.idl_type.callback_cpp_type, argument.name) |
+ for argument in arguments) |
+ return { |
+ 'argument_declarations': argument_declarations, |
+ 'arguments': [argument_context(argument) for argument in arguments], |
+ } |