Commit b7bd8cd4 authored by Yuki Shiino's avatar Yuki Shiino Committed by Commit Bot

bind-gen: Introduce v8_interface_bridge.h

Introduces v8_interface_bridge.h and makes generated v8_interface.h
compilable.

Bug: 839389
Change-Id: If5d75cb72eafa398f70dfa3667a562000df5d1fd
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1988092Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Reviewed-by: default avatarHitoshi Yoshida <peria@chromium.org>
Commit-Queue: Yuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728509}
parent 3843ac5c
......@@ -280,7 +280,7 @@ class CxxClassDefNode(CompositeNode):
"""
assert isinstance(final, bool)
template_format = ("{export}class {name}{final}{base_clause} {{\n"
template_format = ("class{export} {name}{final}{base_clause} {{\n"
" {top_section}\n"
" {public_section}\n"
" {protected_section}\n"
......@@ -291,7 +291,7 @@ class CxxClassDefNode(CompositeNode):
if export is None:
export = ""
else:
export = ListNode([_to_maybe_text_node(export)], tail=" ")
export = ListNode([_to_maybe_text_node(export)], head=" ")
final = " final" if final else ""
......
......@@ -64,6 +64,17 @@ def component_export(component):
return name_style.macro(component, "EXPORT")
def component_export_header(component):
assert isinstance(component, web_idl.Component)
if component == "core":
return "third_party/blink/renderer/core/core_export.h"
elif component == "modules":
return "third_party/blink/renderer/modules/modules_export.h"
else:
assert False
def enclose_with_header_guard(code_node, header_guard):
assert isinstance(code_node, CodeNode)
assert isinstance(header_guard, str)
......@@ -142,7 +153,10 @@ def collect_include_headers(idl_definition):
for type_def_obj in type_def_objs:
if isinstance(type_def_obj, web_idl.Enumeration):
continue
header_paths.add(PathManager(type_def_obj).blink_path(ext="h"))
if isinstance(type_def_obj, web_idl.Dictionary):
header_paths.add(PathManager(type_def_obj).dict_path(ext="h"))
continue
header_paths.add(PathManager(type_def_obj).api_path(ext="h"))
return header_paths
......
......@@ -37,6 +37,7 @@ from .codegen_expr import expr_or
from .codegen_format import format_template as _format
from .codegen_utils import collect_include_headers
from .codegen_utils import component_export
from .codegen_utils import component_export_header
from .codegen_utils import enclose_with_header_guard
from .codegen_utils import make_copyright_header
from .codegen_utils import make_forward_declarations
......@@ -1090,7 +1091,7 @@ def make_runtime_call_timer_scope(cg_context):
node = TextNode(
_format(
"{macro_name}(${isolate}, {counter_name})",
"{macro_name}(${isolate}, {counter_name});",
macro_name=macro_name,
counter_name=counter_name))
node.accumulate(
......@@ -2220,7 +2221,7 @@ def make_install_properties(cg_context, function_name, class_name,
if is_context_dependent:
arg_decls = [
"v8::Local<v8::Content> context",
"v8::Local<v8::Context> context",
"const DOMWrapperWorld& world",
"v8::Local<v8::Object> instance_object",
"v8::Local<v8::Object> prototype_object",
......@@ -2479,7 +2480,7 @@ def generate_interface(interface):
# Class names
api_class_name = v8_bridge_class_name(interface)
if is_cross_components:
impl_class_name = name_style.class_(api_class_name, "impl")
impl_class_name = "{}::Impl".format(api_class_name)
else:
impl_class_name = api_class_name
......@@ -2510,11 +2511,6 @@ def generate_interface(interface):
else:
impl_header_node = api_header_node
impl_source_node = api_source_node
api_header_node.add_template_var("impl_class_name", impl_class_name)
api_source_node.add_template_var("impl_class_name", impl_class_name)
if is_cross_components:
impl_header_node.add_template_var("impl_class_name", impl_class_name)
impl_source_node.add_template_var("impl_class_name", impl_class_name)
# Namespaces
api_header_blink_ns = CxxNamespaceNode(name_style.namespace("blink"))
......@@ -2529,20 +2525,24 @@ def generate_interface(interface):
# Class definitions
api_class_def = CxxClassDefNode(
cg_context.class_name,
base_class_names=[
_format("bindings::V8InterfaceBridge<${class_name}, {}>",
blink_class_name(interface)),
],
final=True,
export=component_export(api_component))
api_class_def.set_base_template_vars(cg_context.template_bindings())
api_class_def.top_section.append(TextNode("STATIC_ONLY(${class_name});"))
if is_cross_components:
api_class_def.bottom_section.append(
TextNode("friend class ${impl_class_name};"))
impl_class_def = CxxClassDefNode(
impl_class_name,
final=True,
export=component_export(impl_component))
impl_class_def.set_base_template_vars(cg_context.template_bindings())
impl_class_def.top_section.append(
TextNode("STATIC_ONLY(${impl_class_name});"))
api_class_def.public_section.extend([
TextNode("// Cross-component implementation class"),
TextNode("class Impl;"),
EmptyNode(),
])
else:
impl_class_def = api_class_def
......@@ -2717,10 +2717,21 @@ def generate_interface(interface):
make_forward_declarations(impl_source_node.accumulator),
EmptyNode(),
])
api_header_node.accumulator.add_include_headers([
component_export_header(api_component),
"third_party/blink/renderer/platform/bindings/v8_interface_bridge.h",
])
api_header_node.accumulator.add_class_decl(blink_class_name(interface))
if is_cross_components:
impl_header_node.accumulator.add_include_headers([
api_header_path,
component_export_header(impl_component),
])
impl_source_node.accumulator.add_include_headers([
path_manager.blink_path(ext="h"),
])
impl_source_node.accumulator.add_include_headers(
collect_include_headers(interface))
if is_cross_components:
impl_source_node.accumulator.add_include_header(api_header_path)
# Assemble the parts.
api_header_blink_ns.body.append(api_class_def)
......@@ -2730,11 +2741,8 @@ def generate_interface(interface):
if is_cross_components:
api_class_def.public_section.append(installer_function_trampolines)
api_class_def.private_section.append(trampoline_var_defs)
impl_class_def.public_section.extend([
cross_component_init_decl,
EmptyNode(),
installer_function_decls,
])
impl_class_def.public_section.append(cross_component_init_decl)
impl_class_def.private_section.append(installer_function_decls)
impl_source_blink_ns.body.extend([
cross_component_init_def,
EmptyNode(),
......
......@@ -449,6 +449,7 @@ jumbo_component("platform") {
"bindings/v8_dom_wrapper.cc",
"bindings/v8_dom_wrapper.h",
"bindings/v8_global_value_map.h",
"bindings/v8_interface_bridge.h",
"bindings/v8_object_constructor.cc",
"bindings/v8_object_constructor.h",
"bindings/v8_per_context_data.cc",
......
// Copyright 2020 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.
#ifndef THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_V8_INTERFACE_BRIDGE_H_
#define THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_V8_INTERFACE_BRIDGE_H_
#include "third_party/blink/renderer/platform/platform_export.h"
#include "third_party/blink/renderer/platform/wtf/allocator/allocator.h"
#include "v8/include/v8.h"
namespace blink {
class DOMWrapperWorld;
namespace bindings {
// The common base class of code-generated V8-Blink bridge class of IDL
// interfaces and namespaces.
class PLATFORM_EXPORT V8InterfaceBridgeBase {
STATIC_ONLY(V8InterfaceBridgeBase);
protected:
using InstallInterfaceTemplateFuncType =
void (*)(v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::FunctionTemplate> interface_template);
using InstallUnconditionalPropertiesFuncType =
void (*)(v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::ObjectTemplate> instance_template,
v8::Local<v8::ObjectTemplate> prototype_template,
v8::Local<v8::FunctionTemplate> interface_template);
using InstallContextIndependentPropertiesFuncType =
void (*)(v8::Isolate* isolate,
const DOMWrapperWorld& world,
v8::Local<v8::ObjectTemplate> instance_template,
v8::Local<v8::ObjectTemplate> prototype_template,
v8::Local<v8::FunctionTemplate> interface_template);
using InstallContextDependentPropertiesFuncType =
void (*)(v8::Local<v8::Context> context,
const DOMWrapperWorld& world,
v8::Local<v8::Object> instance_object,
v8::Local<v8::Object> prototype_object,
v8::Local<v8::Function> interface_object);
};
template <class V8T, class T>
class V8InterfaceBridge : public V8InterfaceBridgeBase {};
} // namespace bindings
} // namespace blink
#endif // THIRD_PARTY_BLINK_RENDERER_PLATFORM_BINDINGS_V8_INTERFACE_BRIDGE_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