Index: tools/dom/scripts/htmldartgenerator.py |
diff --git a/tools/dom/scripts/htmldartgenerator.py b/tools/dom/scripts/htmldartgenerator.py |
index b4bccf95575221b3f0cfc7f56a7bc7a926ca2a41..33b8cfd5ea57e23ac5ca8201496a62e89a983018 100644 |
--- a/tools/dom/scripts/htmldartgenerator.py |
+++ b/tools/dom/scripts/htmldartgenerator.py |
@@ -10,7 +10,9 @@ import emitter |
from generator import AnalyzeOperation, ConstantOutputOrder, \ |
DartDomNameOfAttribute, FindMatchingAttribute, IsDartCollectionType, \ |
IsPureInterface, TypeOrNothing, ConvertToFuture, GetCallbackInfo |
+from copy import deepcopy |
from htmlrenamer import convert_to_future_members |
+import monitored |
# Types that are accessible cross-frame in a limited fashion. |
# In these cases, the base type (e.g., WindowBase) provides restricted access |
@@ -27,6 +29,74 @@ _custom_factories = [ |
'EventSource', |
] |
+# Members that have multiple definitions, but their types are vary, so we rename |
+# them to make them distinct. |
+_renamed_overloads = monitored.Dict('htmldartgenreator.renamed_overloads', { |
blois
2013/06/24 16:58:02
Could this go to htmlrenamer, just to keep our ren
Emily Fortuna
2013/06/25 03:53:31
Done.
|
+ 'AudioContext.createBuffer(unsigned long numberOfChannels, unsigned long ' |
+ 'numberOfFrames, float sampleRate)': 'createEmptyBuffer', |
+ 'AudioContext.createBuffer(ArrayBuffer buffer, boolean mixToMono)': |
+ 'createBufferFromBuffer', |
+ 'CSS.supports(DOMString conditionText)': 'supportsCondition', |
+ 'CSS.supports(DOMString property, DOMString value)': 'supportsProperty', |
+ 'CanvasRenderingContext2D.createPattern(HTMLCanvasElement canvas, ' |
+ 'DOMString repetitionType)': 'createPatternFromCanvas', |
+ 'CanvasRenderingContext2D.createPattern(HTMLImageElement image, ' |
+ 'DOMString repetitionType)': 'createPatternFromImage', |
+ 'DataTransferItemList.add(File file)': 'addFile', |
+ 'DataTransferItemList.add(DOMString data, DOMString type)': 'addData', |
+ 'FormData.append(DOMString name, DOMString value)': 'appendString', |
+ 'FormData.append(DOMString name, Blob value, DOMString filename)': |
+ 'appendBlob', |
+ 'IDBDatabase.transaction(DOMStringList storeNames, DOMString mode)': |
+ 'transactionStringList', |
+ 'IDBDatabase.transaction(sequence<DOMString> storeNames, DOMString mode)': |
+ 'transactionList', |
+ 'IDBDatabase.transaction(DOMString storeName, DOMString mode)': |
+ 'transactionString', |
+ 'RTCDataChannel.send(ArrayBuffer data)': 'sendByteBuffer', |
+ 'RTCDataChannel.send(ArrayBufferView data)': 'sendTypedData', |
+ 'RTCDataChannel.send(Blob data)': 'sendBlob', |
+ 'RTCDataChannel.send(DOMString data)': 'sendString', |
+ 'URL.createObjectURL(WebKitMediaSource source)': |
+ 'createObjectUrlFromSource', |
+ 'URL.createObjectURL(MediaStream stream)': 'createObjectUrlFromStream', |
+ 'URL.createObjectURL(Blob blob)': 'createObjectUrlFromBlob', |
+ 'WebGLRenderingContext.texImage2D(unsigned long target, long level, ' |
+ 'unsigned long internalformat, unsigned long format, unsigned long ' |
+ 'type, ImageData pixels)': 'texImage2DData', |
+ 'WebGLRenderingContext.texImage2D(unsigned long target, long level, ' |
+ 'unsigned long internalformat, unsigned long format, unsigned long ' |
+ 'type, HTMLImageElement image)': 'texImage2DImage', |
+ 'WebGLRenderingContext.texImage2D(unsigned long target, long level, ' |
+ 'unsigned long internalformat, unsigned long format, unsigned long ' |
+ 'type, HTMLCanvasElement canvas)': 'texImage2DCanvas', |
+ 'WebGLRenderingContext.texImage2D(unsigned long target, long level, ' |
+ 'unsigned long internalformat, unsigned long format, unsigned long ' |
+ 'type, HTMLVideoElement video)': 'texImage2DVideo', |
+ 'WebGLRenderingContext.texSubImage2D(unsigned long target, long level, ' |
+ 'long xoffset, long yoffset, unsigned long format, unsigned long type, ' |
+ 'ImageData pixels)': 'texSubImage2DData', |
+ 'WebGLRenderingContext.texSubImage2D(unsigned long target, long level, ' |
+ 'long xoffset, long yoffset, unsigned long format, unsigned long type, ' |
+ 'HTMLImageElement image)': 'texSubImage2DImage', |
+ 'WebGLRenderingContext.texSubImage2D(unsigned long target, long level, ' |
+ 'long xoffset, long yoffset, unsigned long format, unsigned long type, ' |
+ 'HTMLCanvasElement canvas)': 'texSubImage2DCanvas', |
+ 'WebGLRenderingContext.texSubImage2D(unsigned long target, long level, ' |
+ 'long xoffset, long yoffset, unsigned long format, unsigned long type, ' |
+ 'HTMLVideoElement video)': 'texSubImage2DVideo', |
+ 'WebGLRenderingContext.bufferData(unsigned long target, ' |
+ 'ArrayBufferView data, unsigned long usage)': 'bufferTypedData', |
+ 'WebGLRenderingContext.bufferData(unsigned long target, long long size, ' |
+ 'unsigned long usage)': 'bufferEmptyData', |
+ 'WebGLRenderingContext.bufferSubData(unsigned long target, ' |
+ 'long long offset, ArrayBufferView data)': 'bufferSubTypedData', |
+ 'WebSocket.send(ArrayBuffer data)': 'sendByteBuffer', |
+ 'WebSocket.send(ArrayBufferView data)': 'sendTypeData', |
+ 'WebSocket.send(DOMString data)': 'sendString', |
+ 'WebSocket.send(Blob data)': 'sendBlob' |
+}) |
+ |
class HtmlDartGenerator(object): |
def __init__(self, interface, options): |
self._database = options.database |
@@ -83,6 +153,7 @@ class HtmlDartGenerator(object): |
break |
# Group overloaded operations by name. |
+ self._AddRenamedOverloads(interface) |
operationsByName = self._OperationsByName(interface) |
# Generate operations. |
@@ -119,6 +190,35 @@ class HtmlDartGenerator(object): |
self.SecondaryContext(parent_interface) |
self.AddOperation(info) |
+ def _AddRenamedOverloads(self, interface): |
+ """The IDL has a number of functions with the same name but that accept |
+ different types. This is fine for JavaScript, but results in vague type |
+ signatures for Dart. We rename some of these (by adding a new identical |
+ operation with a different DartName), but leave the original version as |
+ well.""" |
+ # This function gets called twice per interface if we generate both dart2js |
blois
2013/06/24 16:58:02
Is there a more central place we can do this, so i
Emily Fortuna
2013/06/25 03:53:31
Not really if we do it in the python scripts, unle
|
+ # and dartium APIs, but we only want to rename the overloads once, so we |
+ # keep track of this via already_renamed. |
+ already_renamed = [operation.ext_attrs['DartName'] if 'DartName' in |
blois
2013/06/24 16:58:02
Doesn't have to be in this CL, but we should remov
|
+ operation.ext_attrs else '' for operation in interface.operations] |
+ added_operations = [] |
+ for operation in interface.operations: |
blois
2013/06/24 16:58:02
Are there any warnings when there are overloads th
Emily Fortuna
2013/06/25 03:53:31
added a warning output, but it's not super useful
|
+ if (self._GetStringRepresentation( |
+ interface, operation) in _renamed_overloads and _renamed_overloads[ |
+ self._GetStringRepresentation(interface, operation)] not in |
+ already_renamed): |
+ cloned_operation = deepcopy(operation) |
+ cloned_operation.ext_attrs['DartName'] = _renamed_overloads[ |
+ self._GetStringRepresentation(interface, operation)] |
+ added_operations.append(cloned_operation) |
+ interface.operations += added_operations |
+ |
+ def _GetStringRepresentation(self, interface, operation): |
+ """Given an IDLOperation, return a object-independent representation of the |
+ operations's signature.""" |
+ return '%s.%s(%s)' % (interface.id, operation.id, ', '.join( |
+ ['%s %s' % (arg.type.id, arg.id) for arg in operation.arguments])) |
+ |
def _OperationsByName(self, interface): |
operationsByName = {} |
for operation in interface.operations: |