Commit bdc79fdd authored by dpapad's avatar dpapad Committed by Chromium LUCI CQ

syncfs-intenals: Add JS type checking.

This is in preparation of migrating to JS modules.

Bug: 1154192
Change-Id: I9e1494d2c6880b1ea525db4548035501ca2c9e1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2566032
Commit-Queue: John Lee <johntlee@chromium.org>
Auto-Submit: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarJohn Lee <johntlee@chromium.org>
Cr-Commit-Position: refs/heads/master@{#833033}
parent 1659b968
...@@ -53,6 +53,7 @@ if (enable_js_type_check) { ...@@ -53,6 +53,7 @@ if (enable_js_type_check) {
"settings:closure_compile", "settings:closure_compile",
"settings:closure_compile_module", "settings:closure_compile_module",
"signin:closure_compile", "signin:closure_compile",
"sync_file_system_internals:closure_compile",
"tab_search:closure_compile", "tab_search:closure_compile",
"usb_internals:closure_compile", "usb_internals:closure_compile",
"user_manager:closure_compile", "user_manager:closure_compile",
......
# 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.
import("//third_party/closure_compiler/compile_js.gni")
js_type_check("closure_compile") {
deps = [
":dump_database",
":extension_statuses",
":file_metadata",
":sync_service",
":task_log",
":utils",
]
}
js_library("dump_database") {
deps = [
":utils",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:util",
]
}
js_library("extension_statuses") {
deps = [
":utils",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:util",
]
}
js_library("file_metadata") {
deps = [
":utils",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:icon",
"//ui/webui/resources/js:util",
]
}
js_library("sync_service") {
deps = [
":utils",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:util",
"//ui/webui/resources/js/cr:ui",
"//ui/webui/resources/js/cr/ui:tabs",
]
}
js_library("task_log") {
deps = [
":utils",
"//ui/webui/resources/js:cr",
"//ui/webui/resources/js:util",
]
}
js_library("utils") {
}
...@@ -17,24 +17,13 @@ const DumpDatabase = (function() { ...@@ -17,24 +17,13 @@ const DumpDatabase = (function() {
cr.sendWithPromise('getDatabaseDump').then(DumpDatabase.onGetDatabaseDump); cr.sendWithPromise('getDatabaseDump').then(DumpDatabase.onGetDatabaseDump);
} }
/**
* Creates an element named |elementName| containing the content |text|.
* @param {string} elementName Name of the new element to be created.
* @param {string} text Text to be contained in the new element.
* @return {HTMLElement} The newly created HTML element.
*/
function createElementFromText(elementName, text) {
const element = document.createElement(elementName);
element.appendChild(document.createTextNode(text));
return element;
}
/** /**
* Creates a table by filling |header| and |body|. * Creates a table by filling |header| and |body|.
* @param {HTMLElement} div The outer container of the table to be renderered. * @param {!HTMLElement} div The outer container of the table to be
* @param {HTMLElement} header The table header element to be fillied by * renderered.
* @param {!HTMLElement} header The table header element to be fillied by
* this function. * this function.
* @param {HTMLElement} body The table body element to be filled by this * @param {!HTMLElement} body The table body element to be filled by this
* function. * function.
* @param {Array} databaseDump List of dictionaries for the database dump. * @param {Array} databaseDump List of dictionaries for the database dump.
* The first element must have metadata of the entry. * The first element must have metadata of the entry.
...@@ -70,10 +59,12 @@ const DumpDatabase = (function() { ...@@ -70,10 +59,12 @@ const DumpDatabase = (function() {
const placeholder = $('dump-database-placeholder'); const placeholder = $('dump-database-placeholder');
placeholder.innerHTML = trustedTypes.emptyHTML; placeholder.innerHTML = trustedTypes.emptyHTML;
for (let i = 0; i < databaseDump.length; ++i) { for (let i = 0; i < databaseDump.length; ++i) {
const div = document.createElement('div'); const div = /** @type {!HTMLElement} */ (document.createElement('div'));
const table = document.createElement('table'); const table = document.createElement('table');
const header = document.createElement('thead'); const header =
const body = document.createElement('tbody'); /** @type {!HTMLElement} */ (document.createElement('thead'));
const body =
/** @type {!HTMLElement} */ (document.createElement('tbody'));
createDatabaseDumpTable(div, header, body, databaseDump[i]); createDatabaseDumpTable(div, header, body, databaseDump[i]);
table.appendChild(header); table.appendChild(header);
table.appendChild(body); table.appendChild(body);
......
...@@ -19,23 +19,13 @@ const ExtensionStatuses = (function() { ...@@ -19,23 +19,13 @@ const ExtensionStatuses = (function() {
.then(ExtensionStatuses.onGetExtensionStatuses); .then(ExtensionStatuses.onGetExtensionStatuses);
} }
// TODO(calvinlo): Move to helper file so it doesn't need to be duplicated.
/**
* Creates an element named |elementName| containing the content |text|.
* @param {string} elementName Name of the new element to be created.
* @param {string} text Text to be contained in the new element.
* @return {HTMLElement} The newly created HTML element.
*/
function createElementFromText(elementName, text) {
const element = document.createElement(elementName);
element.appendChild(document.createTextNode(text));
return element;
}
/** /**
* Handles callback from onGetExtensionStatuses. * Handles callback from onGetExtensionStatuses.
* @param {Array} list of dictionaries containing 'extensionName', * @param {!Array<!{
* 'extensionID, 'status'. * extensionName: string,
* extensionID: string,
* status: string,
* }>} extensionStatuses
*/ */
ExtensionStatuses.onGetExtensionStatuses = function(extensionStatuses) { ExtensionStatuses.onGetExtensionStatuses = function(extensionStatuses) {
const itemContainer = $('extension-entries'); const itemContainer = $('extension-entries');
......
...@@ -19,7 +19,11 @@ const FileMetadata = (function() { ...@@ -19,7 +19,11 @@ const FileMetadata = (function() {
/** /**
* Renders result of getFileMetadata as a table. * Renders result of getFileMetadata as a table.
* @param {Array} list of dictionaries containing 'extensionName', * @param {!Array<!{
* extensionName: string,
* extensionID: string,
* status: string,
* }>} extensionStatuses of dictionaries containing 'extensionName',
* 'extensionID', 'status'. * 'extensionID', 'status'.
*/ */
FileMetadata.onGetExtensions = function(extensionStatuses) { FileMetadata.onGetExtensions = function(extensionStatuses) {
...@@ -48,7 +52,7 @@ const FileMetadata = (function() { ...@@ -48,7 +52,7 @@ const FileMetadata = (function() {
}; };
/** /**
* @return {string} extension ID that's currently selected in drop down box. * @return {?string} extension ID that's currently selected in drop down box.
*/ */
function getSelectedExtensionId() { function getSelectedExtensionId() {
const dropDown = $('extensions-select').options; const dropDown = $('extensions-select').options;
...@@ -106,8 +110,8 @@ const FileMetadata = (function() { ...@@ -106,8 +110,8 @@ const FileMetadata = (function() {
}; };
/** /**
* @param {string} file type string. * @param {string} type file type string.
* @return {HTMLElement} TD with file or folder icon depending on type. * @return {!HTMLElement} TD with file or folder icon depending on type.
*/ */
function createFileIconCell(type) { function createFileIconCell(type) {
const img = document.createElement('div'); const img = document.createElement('div');
...@@ -123,7 +127,7 @@ const FileMetadata = (function() { ...@@ -123,7 +127,7 @@ const FileMetadata = (function() {
const imgWrapper = document.createElement('div'); const imgWrapper = document.createElement('div');
imgWrapper.appendChild(img); imgWrapper.appendChild(img);
const td = document.createElement('td'); const td = /** @type {!HTMLElement} */ (document.createElement('td'));
td.className = 'file-icon-cell'; td.className = 'file-icon-cell';
td.appendChild(imgWrapper); td.appendChild(imgWrapper);
td.appendChild(document.createTextNode(type)); td.appendChild(document.createTextNode(type));
......
...@@ -19,7 +19,7 @@ const SyncService = (function() { ...@@ -19,7 +19,7 @@ const SyncService = (function() {
/** /**
* Called when service status is initially retrieved or updated via events. * Called when service status is initially retrieved or updated via events.
* @param {string} Service status enum as a string. * @param {string} statusString Service status enum as a string.
*/ */
SyncService.onGetServiceStatus = function(statusString) { SyncService.onGetServiceStatus = function(statusString) {
$('service-status').textContent = statusString; $('service-status').textContent = statusString;
...@@ -35,7 +35,7 @@ const SyncService = (function() { ...@@ -35,7 +35,7 @@ const SyncService = (function() {
/** /**
* Handles callback from getNotificationSource. * Handles callback from getNotificationSource.
* @param {string} Notification source as a string. * @param {string} sourceString Notification source as a string.
*/ */
SyncService.onGetNotificationSource = function(sourceString) { SyncService.onGetNotificationSource = function(sourceString) {
$('notification-source').textContent = sourceString; $('notification-source').textContent = sourceString;
...@@ -61,7 +61,11 @@ const SyncService = (function() { ...@@ -61,7 +61,11 @@ const SyncService = (function() {
/** /**
* Handles callback from getUpdateLog. * Handles callback from getUpdateLog.
* @param {Array} list List of dictionaries containing 'id', 'time', 'logEvent'. * @param {!Array<!{
* id: number,
* logEvent: string,
* time: string,
* }>} logEntries List of dictionaries containing 'id', 'time', 'logEvent'.
*/ */
SyncService.onGetLog = function(logEntries) { SyncService.onGetLog = function(logEntries) {
const itemContainer = $('log-entries'); const itemContainer = $('log-entries');
......
...@@ -14,8 +14,12 @@ const TaskLog = (function() { ...@@ -14,8 +14,12 @@ const TaskLog = (function() {
/** /**
* Handles per-task log event. * Handles per-task log event.
* @param {Object} taskLog a dictionary containing 'duration', * @param {!{
* 'task_description', 'result_description' and 'details'. * duration: number,
* task_description: string,
* result_description: string,
* details: !Array,
* }} taskLog
*/ */
TaskLog.onTaskLogRecorded = function(taskLog) { TaskLog.onTaskLogRecorded = function(taskLog) {
const details = document.createElement('td'); const details = document.createElement('td');
...@@ -37,7 +41,7 @@ const TaskLog = (function() { ...@@ -37,7 +41,7 @@ const TaskLog = (function() {
const tr = document.createElement('tr'); const tr = document.createElement('tr');
tr.appendChild(createElementFromText( tr.appendChild(createElementFromText(
'td', taskLog.duration, {'class': 'task-log-duration'})); 'td', taskLog.duration.toString(), {'class': 'task-log-duration'}));
tr.appendChild(createElementFromText( tr.appendChild(createElementFromText(
'td', taskLog.task_description, {'class': 'task-log-description'})); 'td', taskLog.task_description, {'class': 'task-log-description'}));
tr.appendChild(createElementFromText( tr.appendChild(createElementFromText(
......
...@@ -6,11 +6,13 @@ ...@@ -6,11 +6,13 @@
* Creates an element named |elementName| containing the content |text|. * Creates an element named |elementName| containing the content |text|.
* @param {string} elementName Name of the new element to be created. * @param {string} elementName Name of the new element to be created.
* @param {string} text Text to be contained in the new element. * @param {string} text Text to be contained in the new element.
* @param {Object} opt_attributes Optional attribute dictionary for the element. * @param {Object=} opt_attributes Optional attribute dictionary for the
* @return {HTMLElement} The newly created HTML element. * element.
* @return {!HTMLElement} The newly created HTML element.
*/ */
function createElementFromText(elementName, text, opt_attributes) { function createElementFromText(elementName, text, opt_attributes) {
const element = document.createElement(elementName); const element =
/** @type {!HTMLElement} */ (document.createElement(elementName));
element.appendChild(document.createTextNode(text)); element.appendChild(document.createTextNode(text));
if (opt_attributes) { if (opt_attributes) {
for (const key in opt_attributes) { for (const key in opt_attributes) {
...@@ -25,10 +27,11 @@ function createElementFromText(elementName, text, opt_attributes) { ...@@ -25,10 +27,11 @@ function createElementFromText(elementName, text, opt_attributes) {
* @param {string} elementName Name of the new element to be created. * @param {string} elementName Name of the new element to be created.
* @param {Object<string>} dict Dictionary to be contained in the new * @param {Object<string>} dict Dictionary to be contained in the new
* element. * element.
* @return {HTMLElement} The newly created HTML element. * @return {!HTMLElement} The newly created HTML element.
*/ */
function createElementFromDictionary(elementName, dict) { function createElementFromDictionary(elementName, dict) {
const element = document.createElement(elementName); const element =
/** @type {!HTMLElement} */ (document.createElement(elementName));
for (const key in dict) { for (const key in dict) {
element.appendChild(document.createTextNode(key + ': ' + dict[key])); element.appendChild(document.createTextNode(key + ': ' + dict[key]));
element.appendChild(document.createElement('br')); element.appendChild(document.createElement('br'));
......
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