Commit bde8f574 authored by rdevlin.cronin's avatar rdevlin.cronin Committed by Commit bot

[Extension API Extern Generation] Fix array specification

Instead of simply outputting "Array", we now output the type of the array
(e.g., Array<number> or Array<MyCustomType>). Additionally, arrays should not
be nullable.

Choices (e.g., (DOMString or number) in an .idl) are also now supported.

BUG=461039

Review URL: https://codereview.chromium.org/1034553003

Cr-Commit-Position: refs/heads/master@{#322110}
parent c4c495eb
......@@ -180,14 +180,19 @@ class _Generator(object):
elif js_type.property_type is PropertyType.OBJECT:
return 'Object'
elif js_type.property_type is PropertyType.ARRAY:
return 'Array'
return '!Array<%s>' % self._TypeToJsType(js_type.item_type)
elif js_type.property_type is PropertyType.REF:
ref_type = js_type.ref_type
# Enums are defined as chrome.fooAPI.MyEnum, but types are defined simply
# as MyType.
if self._namespace.types[ref_type].property_type is PropertyType.ENUM:
ref_type = 'chrome.%s.%s' % (self._namespace.name, ref_type)
ref_type = '!chrome.%s.%s' % (self._namespace.name, ref_type)
return ref_type
elif js_type.property_type is PropertyType.CHOICES:
return '(%s)' % '|'.join(
[self._TypeToJsType(choice) for choice in js_type.choices])
elif js_type.property_type is PropertyType.ANY:
return '*'
elif js_type.property_type.is_fundamental:
return js_type.property_type.name
else:
......
......@@ -34,9 +34,14 @@ namespace fakeApi {
long num;
boolean b;
Greek letter;
Greek? optionalLetter;
long[] arr;
Bar[]? optionalObjArr;
Greek[] enumArr;
any[] anythingGoes;
Bar obj;
long? maybe;
(DOMString or Greek or long[]) choice;
};
callback VoidCallback = void();
......@@ -83,10 +88,15 @@ var Bar;
* str: string,
* num: number,
* b: boolean,
* letter: chrome.fakeApi.Greek,
* arr: Array,
* letter: !chrome.fakeApi.Greek,
* optionalLetter: (!chrome.fakeApi.Greek|undefined),
* arr: !Array<number>,
* optionalObjArr: (!Array<Bar>|undefined),
* enumArr: !Array<!chrome.fakeApi.Greek>,
* anythingGoes: !Array<*>,
* obj: Bar,
* maybe: (number|undefined)
* maybe: (number|undefined),
* choice: (string|!chrome.fakeApi.Greek|!Array<number>)
* }}
*/
var Baz;
......@@ -102,12 +112,13 @@ chrome.fakeApi.doSomething = function(baz, callback) {};
class JsExternGeneratorTest(unittest.TestCase):
def testBasic(self):
self.maxDiff = None # Lets us see the full diff when inequal.
filename = 'fake_api.idl'
api_def = idl_schema.Process(fake_idl, filename)
m = model.Model()
namespace = m.AddNamespace(api_def[0], filename)
self.assertEquals(expected_output,
JsExternsGenerator().Generate(namespace).Render())
self.assertMultiLineEqual(expected_output,
JsExternsGenerator().Generate(namespace).Render())
if __name__ == '__main__':
......
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