Index: sdk/lib/html/scripts/systemhtml.py |
diff --git a/sdk/lib/html/scripts/systemhtml.py b/sdk/lib/html/scripts/systemhtml.py |
index c40d4b9fb962fb1540f40f6d010c7a2a80e9ec01..38ad58ca24f3460238cac30bceca0ab11fe19ae8 100644 |
--- a/sdk/lib/html/scripts/systemhtml.py |
+++ b/sdk/lib/html/scripts/systemhtml.py |
@@ -507,7 +507,11 @@ class Dart2JSBackend(HtmlDartGenerator): |
return |
if IsPureInterface(self._interface.id): |
- self._AddInterfaceAttribute(attribute, html_name) |
+ self._AddInterfaceAttribute(attribute) |
+ return |
+ |
+ if attribute.id != html_name: |
+ self._AddAttributeUsingProperties(attribute, html_name, read_only) |
return |
# If the attribute is shadowing, we can't generate a shadowing |
@@ -528,7 +532,7 @@ class Dart2JSBackend(HtmlDartGenerator): |
' // Use implementation from $SUPER.\n' |
' // final $TYPE $NAME;\n', |
SUPER=super_attribute_interface, |
- NAME=html_name, |
+ NAME=DartDomNameOfAttribute(attribute), |
TYPE=self.SecureOutputType(attribute.type.id)) |
return |
self._members_emitter.Emit('\n // Shadowing definition.') |
@@ -545,23 +549,20 @@ class Dart2JSBackend(HtmlDartGenerator): |
output_type = self.SecureOutputType(attribute.type.id) |
input_type = self._NarrowInputType(attribute.type.id) |
annotations = self._Annotations(attribute.type.id, attribute.id) |
- rename = self._RenamingAnnotation(attribute.id, html_name) |
self.EmitAttributeDocumentation(attribute) |
if not read_only: |
self._members_emitter.Emit( |
- '\n $RENAME$ANNOTATIONS$TYPE $NAME;' |
+ '\n $ANNOTATIONS$TYPE $NAME;' |
'\n', |
- RENAME=rename, |
ANNOTATIONS=annotations, |
- NAME=html_name, |
+ NAME=DartDomNameOfAttribute(attribute), |
TYPE=output_type) |
else: |
self._members_emitter.Emit( |
- '\n $RENAME$(ANNOTATIONS)final $TYPE $NAME;' |
+ '\n $(ANNOTATIONS)final $TYPE $NAME;' |
'\n', |
- RENAME=rename, |
ANNOTATIONS=annotations, |
- NAME=html_name, |
+ NAME=DartDomNameOfAttribute(attribute), |
TYPE=output_type) |
def _AddAttributeUsingProperties(self, attribute, html_name, read_only): |
@@ -569,11 +570,11 @@ class Dart2JSBackend(HtmlDartGenerator): |
if not read_only: |
self._AddRenamingSetter(attribute, html_name) |
- def _AddInterfaceAttribute(self, attribute, html_name): |
+ def _AddInterfaceAttribute(self, attribute): |
self._members_emitter.Emit( |
'\n $TYPE $NAME;' |
'\n', |
- NAME=html_name, |
+ NAME=DartDomNameOfAttribute(attribute), |
TYPE=self.SecureOutputType(attribute.type.id)) |
def _AddRenamingGetter(self, attr, html_name): |
@@ -611,11 +612,11 @@ class Dart2JSBackend(HtmlDartGenerator): |
def _AddConvertingGetter(self, attr, html_name, conversion): |
self._members_emitter.Emit( |
+ # TODO(sra): Use metadata to provide native name. |
'\n $RETURN_TYPE get $HTML_NAME => $CONVERT(this._$(HTML_NAME));' |
- "\n @JSName('$NAME')" |
- '\n $(ANNOTATIONS)final $NATIVE_TYPE _$HTML_NAME;' |
+ '\n $NATIVE_TYPE get _$HTML_NAME =>' |
+ ' JS("$NATIVE_TYPE", "#.$NAME", this);' |
'\n', |
- ANNOTATIONS=self._Annotations(attr.type.id, html_name), |
CONVERT=conversion.function_name, |
HTML_NAME=html_name, |
NAME=attr.id, |
@@ -660,15 +661,32 @@ class Dart2JSBackend(HtmlDartGenerator): |
self._AddDirectNativeOperation(info, html_name) |
def _AddDirectNativeOperation(self, info, html_name): |
- self._members_emitter.Emit( |
- '\n' |
- ' $RENAME$ANNOTATIONS$MODIFIERS$TYPE $NAME($PARAMS) native;\n', |
- RENAME=self._RenamingAnnotation(info.declared_name, html_name), |
- ANNOTATIONS=self._Annotations(info.type_name, info.declared_name), |
- MODIFIERS='static ' if info.IsStatic() else '', |
- TYPE=self.SecureOutputType(info.type_name), |
- NAME=html_name, |
- PARAMS=info.ParametersDeclaration(self._NarrowInputType)) |
+ # Do we need a native body? |
+ if html_name != info.declared_name: |
+ return_type = self.SecureOutputType(info.type_name) |
+ |
+ operation_emitter = self._members_emitter.Emit( |
+ '$!SCOPE', |
+ MODIFIERS='static ' if info.IsStatic() else '', |
+ ANNOTATIONS=self._Annotations(info.type_name, info.declared_name), |
+ TYPE=return_type, |
+ HTML_NAME=html_name, |
+ NAME=info.declared_name, |
+ PARAMS=info.ParametersDeclaration(self._NarrowInputType)) |
+ |
+ operation_emitter.Emit( |
+ '\n' |
+ ' $ANNOTATIONS' |
+ '$MODIFIERS$TYPE $(HTML_NAME)($PARAMS) native "$NAME";\n') |
+ else: |
+ self._members_emitter.Emit( |
+ '\n' |
+ ' $ANNOTATIONS$MODIFIERS$TYPE $NAME($PARAMS) native;\n', |
+ MODIFIERS='static ' if info.IsStatic() else '', |
+ ANNOTATIONS=self._Annotations(info.type_name, info.declared_name), |
+ TYPE=self.SecureOutputType(info.type_name), |
+ NAME=info.name, |
+ PARAMS=info.ParametersDeclaration(self._NarrowInputType)) |
def _AddOperationWithConversions(self, info, html_name): |
# Assert all operations have same return type. |
@@ -767,13 +785,13 @@ class Dart2JSBackend(HtmlDartGenerator): |
call_emitter.Emit('$(INDENT)return $CALL;\n', CALL=call) |
self._members_emitter.Emit( |
- ' $RENAME$ANNOTATIONS$MODIFIERS$TYPE$TARGET($PARAMS) native;\n', |
- RENAME=self._RenamingAnnotation(info.declared_name, target), |
- ANNOTATIONS=self._Annotations(info.type_name, info.declared_name), |
+ ' $MODIFIERS$ANNOTATIONS$TYPE$TARGET($PARAMS) native "$NATIVE";\n', |
MODIFIERS='static ' if info.IsStatic() else '', |
+ ANNOTATIONS=self._Annotations(info.type_name, info.declared_name), |
TYPE=TypeOrNothing(native_return_type), |
TARGET=target, |
- PARAMS=', '.join(target_parameters)) |
+ PARAMS=', '.join(target_parameters), |
+ NATIVE=info.declared_name) |
def GenerateChecksAndCall(operation, argument_count): |
checks = [] |
@@ -853,13 +871,8 @@ class Dart2JSBackend(HtmlDartGenerator): |
member_name) |
return member_name in _js_custom_members |
- def _RenamingAnnotation(self, idl_name, member_name): |
- if member_name != idl_name: |
- return "@JSName('%s')\n " % idl_name |
- return '' |
- |
- def _Annotations(self, idl_type, idl_member_name): |
- annotations = FindAnnotations(idl_type, self._interface.id, idl_member_name) |
+ def _Annotations(self, idl_type, member_name): |
+ annotations = FindAnnotations(idl_type, self._interface.id, member_name) |
if annotations: |
return '%s\n ' % annotations |
return_type = self.SecureOutputType(idl_type) |