Commit 778ec014 authored by dpapad's avatar dpapad Committed by Commit Bot

js_externs_generator.py: Generate JS externs for top-level properties.

Previously top-level properties like chrome.runtime.id or
chrome.runtime.lastError where ignored by js_externs_generator.py
and were not reflected in the generated JS externs files.

Fixed: 1085641
Change-Id: I6a5719830f5c0945ca0b26c5c347bd3341b379c9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2213205
Commit-Queue: dpapad <dpapad@chromium.org>
Auto-Submit: dpapad <dpapad@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Reviewed-by: default avatarMike Frysinger <vapier@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772370}
parent 66c98769
......@@ -53,6 +53,9 @@ class _Generator(object):
for js_type in self._namespace.types.values():
self._AppendType(c, js_type)
for prop in self._namespace.properties.values():
self._AppendProperty(c, prop)
for function in self._namespace.functions.values():
self._AppendFunction(c, function)
......@@ -162,12 +165,24 @@ class _Generator(object):
c.Append('@typedef {')
if properties:
self._js_util.AppendObjectDefinition(
c, self._namespace.name, properties, new_line=False)
self._js_util.AppendObjectDefinition(c,
self._namespace.name,
properties,
new_line=False)
else:
c.Append('Object', new_line=False)
c.Append('Object', new_line=False)
c.Append('}', new_line=False)
def _AppendProperty(self, c, prop):
"""Appends the code representing a top-level property, including its
documentation. For example:
/** @type {string} */
chrome.runtime.id;
"""
self._AppendTypeJsDoc(c, prop.type_, prop.optional)
c.Append()
def _AppendFunction(self, c, function):
"""Appends the code representing a function, including its documentation.
For example:
......
......@@ -65,6 +65,10 @@ namespace fakeApi {
callback OptionalParamCallback = void(optional Qux qux);
interface Properties {
static DOMString lastError();
};
interface Functions {
// Does something exciting! And what's more, this is a multiline function
// comment! It goes onto multiple lines!
......@@ -193,6 +197,12 @@ chrome.fakeApi.Qux.prototype.go = function() {};
chrome.fakeApi.Qux.prototype.stop = function() {};
/**
* @type {string}
* @see https://developer.chrome.com/extensions/fakeApi#type-lastError
*/
chrome.fakeApi.lastError;
/**
* Does something exciting! And what's more, this is a multiline function
* comment! It goes onto multiple lines!
......@@ -336,6 +346,12 @@ fake_json = """// Copyright 2014 The Chromium Authors. All rights reserved.
"additionalProperties": {"type": "string"}
}
],
"properties": {
"lastError": {
"type": "string",
"description": "The lastError."
}
},
"functions": [ {
"name": "funcWithInlineObj",
"type": "function",
......@@ -429,6 +445,13 @@ chrome.fakeJson.CrazyEnum = {
*/
chrome.fakeJson.CrazyObject;
/**
* The lastError.
* @type {string}
* @see https://developer.chrome.com/extensions/fakeJson#type-lastError
*/
chrome.fakeJson.lastError;
/**
* @param {{
* foo: (boolean|undefined),
......
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