Commit 3d48d10e authored by Asanka Herath's avatar Asanka Herath Committed by Commit Bot

[blink/bindings] Include more details in HighEntropy API list.

When generating the high entropy API list, instead of only showing the
high entropy ones, include all of them with proper annotations so we
know which ones are already marked as high entropy.

The output is also explicitly a CSV file that is now located at the root
of the build tree where it is easily accessible.

To generate the list of Blink JS APIs, use the following ninja
incantation:

    ninja -C out/Debug generate_high_entropy_list

Now look for the file named high_entropy_list.csv in the build
directory.

R=yukishiino@chromium.org

Bug: 973801
Change-Id: I1bf7ee7a48d0b8db0cf2dd284e3557a4fa73a7e2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2055685
Commit-Queue: Asanka Herath <asanka@chromium.org>
Reviewed-by: default avatarYuki Shiino <yukishiino@chromium.org>
Cr-Commit-Position: refs/heads/master@{#741760}
parent 80357c2a
...@@ -223,7 +223,7 @@ action_with_pydeps("generate_high_entropy_list") { ...@@ -223,7 +223,7 @@ action_with_pydeps("generate_high_entropy_list") {
web_idl_database = web_idl_database_outputs[0] web_idl_database = web_idl_database_outputs[0]
inputs = [ web_idl_database ] inputs = [ web_idl_database ]
output_data_file = "${bindings_output_dir}/high_entropy_list.txt" output_data_file = "${root_build_dir}/high_entropy_list.csv"
outputs = [ output_data_file ] outputs = [ output_data_file ]
args = [ args = [
......
# Copyright 2020 The Chromium Authors. All rights reserved. # Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
""" """
Given the Web IDL database as input, output a list of all high entropy entities. Generate of table of APIs and their attributes based on the WebIDL database.
Each row of the table contains the following:
High entropy entities (methods, attributes, constants) are annotated with * Interface or Namespace or Dictionary
the [HighEntropy] extended attribute. * Name : The name of a method or property.
* Entity type : One of 'interface', 'namespace', 'const', 'attribute',
'operation', 'constructor', 'stringifier', 'iterable',
'maplike', 'setlike', 'dictionary'
* IDL Type : Type of the object. For function-like entries, this is the
type of the return value. Note that the type is stripped
of nullable unions.
* UseCounter : If usage is being measured, this is the UseCounter.
* SecureContext? : 'SecureContext' or ''.
* HighEntropy? : 'HighEntropy' or ''.
""" """
import optparse import optparse
from io import BytesIO
from csv import DictWriter
from utilities import write_file from utilities import write_file
from v8_utilities import capitalize
import web_idl import web_idl
def parse_options(): def parse_options():
parser = optparse.OptionParser(usage="%prog [options]") parser = optparse.OptionParser(usage="%prog [options]")
parser.add_option("--web_idl_database", type="string", parser.add_option("--web_idl_database", type="string", help="filepath of the input database")
help="filepath of the input database") parser.add_option("--output", type="string", help="filepath of output file")
parser.add_option("--output", type="string",
help="filepath of output file")
options, args = parser.parse_args() options, args = parser.parse_args()
required_option_names = ("web_idl_database", "output") required_option_names = ("web_idl_database", "output")
...@@ -31,18 +42,79 @@ def parse_options(): ...@@ -31,18 +42,79 @@ def parse_options():
return options, args return options, args
def get_idl_type_name(idl_type):
assert isinstance(idl_type, web_idl.IdlType)
unwrapped_type = idl_type.unwrap()
return unwrapped_type.type_name, unwrapped_type.syntactic_form
def record(csv_writer, entity):
interface = ''
name = ''
entity_type = ''
use_counter = ''
secure_context = ''
high_entropy = ''
idl_type = ''
syntactic_form = ''
secure_context = ('SecureContext' in entity.extended_attributes)
high_entropy = ('HighEntropy' in entity.extended_attributes)
if 'Measure' in entity.extended_attributes:
use_counter = capitalize(entity.identifier)
if not isinstance(entity, web_idl.Interface):
use_counter = (capitalize(entity.owner.identifier) + '_' + use_counter)
elif 'MeasureAs' in entity.extended_attributes:
use_counter = entity.extended_attributes.value_of('MeasureAs')
if isinstance(entity, web_idl.Interface):
interface = entity.identifier
name = ''
entity_type = 'interface'
else:
interface = entity.owner.identifier
name = entity.identifier
if isinstance(entity, web_idl.Attribute):
entity_type = 'attribute'
idl_type, syntactic_form = get_idl_type_name(entity.idl_type)
elif isinstance(entity, web_idl.Operation):
entity_type = 'operation'
idl_type, syntactic_form = get_idl_type_name(entity.return_type)
elif isinstance(entity, web_idl.Constant):
entity_type = 'constant'
idl_type, syntactic_form = get_idl_type_name(entity.idl_type)
else:
assert False, "Unexpected IDL construct"
csv_writer.writerow({
'interface': interface,
'name': name,
'entity_type': entity_type,
'idl_type': idl_type,
'syntactic_form': syntactic_form,
'use_counter': use_counter,
'secure_context': secure_context,
'high_entropy': high_entropy
})
def main(): def main():
options, _ = parse_options() options, _ = parse_options()
with BytesIO() as out_buffer:
csv_writer = DictWriter(
out_buffer,
fieldnames=[
'interface', 'name', 'entity_type', 'idl_type', 'syntactic_form', 'use_counter', 'secure_context', 'high_entropy'
])
csv_writer.writeheader()
web_idl_database = web_idl.Database.read_from_file(options.web_idl_database) web_idl_database = web_idl.Database.read_from_file(options.web_idl_database)
high_entropy_list = [] for interface in web_idl_database.interfaces:
for interface in web_idl_database.interfaces: record(csv_writer, interface)
for entity in (interface.attributes + interface.operations + for entity in (interface.attributes + interface.operations + interface.constants):
interface.constants): record(csv_writer, entity)
if "HighEntropy" in entity.extended_attributes: write_file(out_buffer.getvalue(), options.output)
high_entropy_list.append('%s.%s' % (interface.identifier,
entity.identifier))
write_file('\n'.join(high_entropy_list) + '\n', options.output)
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -10,7 +10,11 @@ ...@@ -10,7 +10,11 @@
../../build/scripts/blinkbuild/__init__.py ../../build/scripts/blinkbuild/__init__.py
../../build/scripts/blinkbuild/name_style_converter.py ../../build/scripts/blinkbuild/name_style_converter.py
generate_high_entropy_list.py generate_high_entropy_list.py
idl_definitions.py
idl_types.py
utilities.py utilities.py
v8_globals.py
v8_utilities.py
web_idl/__init__.py web_idl/__init__.py
web_idl/argument.py web_idl/argument.py
web_idl/ast_group.py web_idl/ast_group.py
......
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