Commit eca723d8 authored by Hitoshi Yoshida's avatar Hitoshi Yoshida Committed by Commit Bot

CodeGen: Define inline functions in IDL dictionary

Defines Create() and accessor functions in the class definition.



Bug: 839389
Change-Id: I9a2c0a8ec768fa219f95bdd73e8d923830b09545
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1983689Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Commit-Queue: Hitoshi Yoshida <peria@chromium.org>
Cr-Commit-Position: refs/heads/master@{#728465}
parent 80e62a0c
...@@ -96,11 +96,10 @@ def make_dict_member_get_def(cg_context): ...@@ -96,11 +96,10 @@ def make_dict_member_get_def(cg_context):
func_def = CxxFuncDefNode( func_def = CxxFuncDefNode(
name=blink_member_name.get_api, name=blink_member_name.get_api,
class_name=cg_context.class_name,
arg_decls=[], arg_decls=[],
return_type=blink_type_info(member.idl_type).ref_t, return_type=blink_type_info(member.idl_type).ref_t,
const=True) const=True)
func_def.add_template_vars(cg_context.template_bindings()) func_def.set_base_template_vars(cg_context.template_bindings())
body = func_def.body body = func_def.body
...@@ -121,11 +120,10 @@ def make_dict_member_has_def(cg_context): ...@@ -121,11 +120,10 @@ def make_dict_member_has_def(cg_context):
func_def = CxxFuncDefNode( func_def = CxxFuncDefNode(
name=_blink_member_name(member).has_api, name=_blink_member_name(member).has_api,
class_name=cg_context.class_name,
arg_decls=[], arg_decls=[],
return_type="bool", return_type="bool",
const=True) const=True)
func_def.add_template_vars(cg_context.template_bindings()) func_def.set_base_template_vars(cg_context.template_bindings())
body = func_def.body body = func_def.body
...@@ -145,13 +143,12 @@ def make_dict_member_set_def(cg_context): ...@@ -145,13 +143,12 @@ def make_dict_member_set_def(cg_context):
func_def = CxxFuncDefNode( func_def = CxxFuncDefNode(
name=blink_member_name.set_api, name=blink_member_name.set_api,
class_name=cg_context.class_name,
arg_decls=[ arg_decls=[
_format("{} value", _format("{} value",
blink_type_info(member.idl_type).ref_t) blink_type_info(member.idl_type).ref_t)
], ],
return_type="void") return_type="void")
func_def.add_template_vars(cg_context.template_bindings()) func_def.set_base_template_vars(cg_context.template_bindings())
body = func_def.body body = func_def.body
...@@ -262,7 +259,6 @@ const v8::Eternal<v8::Name>* member_names = GetV8MemberNames(isolate); ...@@ -262,7 +259,6 @@ const v8::Eternal<v8::Name>* member_names = GetV8MemberNames(isolate);
v8::Local<v8::Context> ${current_context} = isolate->GetCurrentContext();""" v8::Local<v8::Context> ${current_context} = isolate->GetCurrentContext();"""
body.append(T(text)) body.append(T(text))
# TODO(peria): Support runtime enabled / origin trial members.
for key_index, member in enumerate(own_members): for key_index, member in enumerate(own_members):
_1 = _blink_member_name(member).has_api _1 = _blink_member_name(member).has_api
_2 = key_index _2 = key_index
...@@ -427,7 +423,6 @@ if (${exception_state}.HadException()) { ...@@ -427,7 +423,6 @@ if (${exception_state}.HadException()) {
T("v8::Local<v8::Value> v8_value;"), T("v8::Local<v8::Value> v8_value;"),
]) ])
# TODO(peria): Support origin-trials and runtime enabled features.
for key_index, member in enumerate(own_members): for key_index, member in enumerate(own_members):
body.append(make_fill_own_dict_member(key_index, member)) body.append(make_fill_own_dict_member(key_index, member))
...@@ -527,7 +522,7 @@ def make_dict_class_def(cg_context): ...@@ -527,7 +522,7 @@ def make_dict_class_def(cg_context):
cg_context.class_name, cg_context.class_name,
base_class_names=[cg_context.base_class_name], base_class_names=[cg_context.base_class_name],
export=component_export(component)) export=component_export(component))
class_def.add_template_vars(cg_context.template_bindings()) class_def.set_base_template_vars(cg_context.template_bindings())
if dictionary.inherited: if dictionary.inherited:
class_def.top_section.append( class_def.top_section.append(
...@@ -536,7 +531,9 @@ def make_dict_class_def(cg_context): ...@@ -536,7 +531,9 @@ def make_dict_class_def(cg_context):
public_section = class_def.public_section public_section = class_def.public_section
public_section.append( public_section.append(
T("""\ T("""\
static ${class_name}* Create(); static ${class_name}* Create() {
return MakeGarbageCollected<${class_name}>();
}
static ${class_name}* Create( static ${class_name}* Create(
v8::Isolate* isolate, v8::Isolate* isolate,
v8::Local<v8::Object> v8_dictionary, v8::Local<v8::Object> v8_dictionary,
...@@ -547,27 +544,14 @@ ${class_name}() = default; ...@@ -547,27 +544,14 @@ ${class_name}() = default;
void Trace(Visitor* visitor); void Trace(Visitor* visitor);
""")) """))
# TODO(peria): Consider inlining these accessors.
for member in dictionary.own_members: for member in dictionary.own_members:
member_blink_type = blink_type_info(member.idl_type) member_cg_context = cg_context.make_copy(dict_member=member)
blink_member_name = _blink_member_name(member) public_section.extend([
public_section.append( T(""),
CxxFuncDeclNode( make_dict_member_get_def(member_cg_context),
name=blink_member_name.get_api, make_dict_member_has_def(member_cg_context),
return_type=member_blink_type.ref_t, make_dict_member_set_def(member_cg_context),
arg_decls=[], ])
const=True))
public_section.append(
CxxFuncDeclNode(
name=blink_member_name.set_api,
arg_decls=[_format("{} value", member_blink_type.ref_t)],
return_type="void"))
public_section.append(
CxxFuncDeclNode(
name=blink_member_name.has_api,
arg_decls=[],
return_type="bool",
const=True))
protected_section = class_def.protected_section protected_section = class_def.protected_section
protected_section.append( protected_section.append(
...@@ -723,16 +707,6 @@ def generate_dictionary(dictionary): ...@@ -723,16 +707,6 @@ def generate_dictionary(dictionary):
TextNode(""), TextNode(""),
make_dict_trace_def(cg_context), make_dict_trace_def(cg_context),
]) ])
for member in dictionary.own_members:
member_cg_context = cg_context.make_copy(dict_member=member)
source_blink_ns.body.extend([
TextNode(""),
make_dict_member_get_def(member_cg_context),
TextNode(""),
make_dict_member_has_def(member_cg_context),
TextNode(""),
make_dict_member_set_def(member_cg_context),
])
# Write down to the files. # Write down to the files.
write_code_node_to_file(header_node, path_manager.gen_path_to(header_path)) write_code_node_to_file(header_node, path_manager.gen_path_to(header_path))
......
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