Commit 0beaa36a authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Optimize IDL operations that take IDL callback functions

Optimizes the following two parts.
1. Faster conversion to the current execution context.
2. Avoid instantiation of ExceptionState if possible.

Bug: 839389, 1121730
Change-Id: Ia7c03a06def4e1d4a523ec5e699d6b5e7137a35e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2391425Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#804689}
parent d3552dbe
...@@ -484,7 +484,8 @@ def make_v8_to_blink_value(blink_var_name, ...@@ -484,7 +484,8 @@ def make_v8_to_blink_value(blink_var_name,
cg_context and cg_context.operation cg_context and cg_context.operation
and not (cg_context.is_return_type_promise_type or and not (cg_context.is_return_type_promise_type or
"RaisesException" in cg_context.operation.extended_attributes) "RaisesException" in cg_context.operation.extended_attributes)
and all(arg.idl_type.type_name == "String" and all((arg.idl_type.type_name == "String" or arg.idl_type.unwrap(
typedef=True).is_callback_function)
for arg in cg_context.operation.arguments)) for arg in cg_context.operation.arguments))
fast_path_cond = None fast_path_cond = None
fast_path_body_text = None fast_path_body_text = None
...@@ -496,6 +497,14 @@ def make_v8_to_blink_value(blink_var_name, ...@@ -496,6 +497,14 @@ def make_v8_to_blink_value(blink_var_name,
fast_path_cond = "LIKELY({}->IsString())".format(v8_value_expr) fast_path_cond = "LIKELY({}->IsString())".format(v8_value_expr)
fast_path_body_text = "{}.Init({}.As<v8::String>());".format( fast_path_body_text = "{}.Init({}.As<v8::String>());".format(
blink_var_name, v8_value_expr) blink_var_name, v8_value_expr)
elif idl_type.unwrap(typedef=True).is_callback_function:
# A key point of this fast path is that it doesn't require an
# ExceptionState.
fast_path_cond = "LIKELY({}->IsFunction())".format(v8_value_expr)
fast_path_body_text = "{} = {}::Create({}.As<v8::Function>());".format(
blink_var_name,
blink_class_name(idl_type.unwrap().type_definition_object),
v8_value_expr)
def create_definition(symbol_node): def create_definition(symbol_node):
if argument_index is None: if argument_index is None:
......
...@@ -325,7 +325,7 @@ def bind_callback_local_vars(code_node, cg_context): ...@@ -325,7 +325,7 @@ def bind_callback_local_vars(code_node, cg_context):
local_vars.append(S("execution_context", _format(pattern, _1=_1))) local_vars.append(S("execution_context", _format(pattern, _1=_1)))
node = S("current_execution_context", node = S("current_execution_context",
("ExecutionContext* ${current_execution_context} = " ("ExecutionContext* ${current_execution_context} = "
"ExecutionContext::From(${current_script_state});")) "ExecutionContext::From(${current_context});"))
node.accumulate( node.accumulate(
CodeGenAccumulator.require_include_headers([ CodeGenAccumulator.require_include_headers([
"third_party/blink/renderer/core/execution_context/execution_context.h" "third_party/blink/renderer/core/execution_context/execution_context.h"
...@@ -333,7 +333,7 @@ def bind_callback_local_vars(code_node, cg_context): ...@@ -333,7 +333,7 @@ def bind_callback_local_vars(code_node, cg_context):
local_vars.append(node) local_vars.append(node)
node = S("receiver_execution_context", node = S("receiver_execution_context",
("ExecutionContext* ${receiver_execution_context} = " ("ExecutionContext* ${receiver_execution_context} = "
"ExecutionContext::From(${receiver_script_state});")) "ExecutionContext::From(${receiver_context});"))
node.accumulate( node.accumulate(
CodeGenAccumulator.require_include_headers([ CodeGenAccumulator.require_include_headers([
"third_party/blink/renderer/core/execution_context/execution_context.h" "third_party/blink/renderer/core/execution_context/execution_context.h"
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment