Commit f0457f04 authored by David Tseng's avatar David Tseng Committed by Commit Bot

Support instanceof with declared types in js externs generation

Test: tools/json_schema_compiler/compiler.py -g externs extensions/common/api/automation.idl > third_party/closure_compiler/externs/automation.js
results in no diffs. automation.js was hand edited previously.
Run
tools/json_schema_compiler/js_externs_generator_test.py

Change-Id: I949530eecb24e5a26bc2f5bff13c831bdad3dbbf
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2314016
Commit-Queue: David Tseng <dtseng@chromium.org>
Reviewed-by: default avatarDevlin <rdevlin.cronin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#791533}
parent 6ec89db7
...@@ -84,6 +84,8 @@ namespace fakeApi { ...@@ -84,6 +84,8 @@ namespace fakeApi {
static void instanceOfObjectParam([instanceOf=SomeType] object obj); static void instanceOfObjectParam([instanceOf=SomeType] object obj);
static void instanceOfBarObjectParam([instanceOf=Bar] object barObj);
static void optionalParam(optional OptionalParamCallback callback); static void optionalParam(optional OptionalParamCallback callback);
static void nonFinalOptionalParams( static void nonFinalOptionalParams(
...@@ -241,6 +243,12 @@ chrome.fakeApi.returnString = function() {}; ...@@ -241,6 +243,12 @@ chrome.fakeApi.returnString = function() {};
*/ */
chrome.fakeApi.instanceOfObjectParam = function(obj) {}; chrome.fakeApi.instanceOfObjectParam = function(obj) {};
/**
* @param {chrome.fakeApi.Bar} barObj
* @see https://developer.chrome.com/extensions/fakeApi#method-instanceOfBarObjectParam
*/
chrome.fakeApi.instanceOfBarObjectParam = function(barObj) {};
/** /**
* @param {function((!chrome.fakeApi.Qux|undefined)): void=} callback * @param {function((!chrome.fakeApi.Qux|undefined)): void=} callback
* @see https://developer.chrome.com/extensions/fakeApi#method-optionalParam * @see https://developer.chrome.com/extensions/fakeApi#method-optionalParam
......
...@@ -163,7 +163,14 @@ class JsUtil(object): ...@@ -163,7 +163,14 @@ class JsUtil(object):
c = Code() c = Code()
self.AppendObjectDefinition(c, namespace_name, js_type.properties) self.AppendObjectDefinition(c, namespace_name, js_type.properties)
return c return c
# Support instanceof for types in the same namespace and built-in
# types. This doesn't support types in another namespace e.g. if
# js_type.instanceof is 'tabs.Tab'.
if js_type.instance_of: if js_type.instance_of:
if js_type.instance_of in js_type.namespace.types:
return Code().Append('chrome.%s.%s' %
(namespace_name, js_type.instance_of))
return Code().Append(js_type.instance_of) return Code().Append(js_type.instance_of)
return Code().Append('Object') return Code().Append('Object')
if js_type.property_type is PropertyType.ARRAY: if js_type.property_type is PropertyType.ARRAY:
......
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