Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(21)

Unified Diff: sdk/lib/_internal/compiler/implementation/js_backend/native_emitter.dart

Issue 11299220: Add @JSName annotation for native fields and methods. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: sdk/lib/_internal/compiler/implementation/js_backend/native_emitter.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_backend/native_emitter.dart b/sdk/lib/_internal/compiler/implementation/js_backend/native_emitter.dart
index c2542ef768db514920b37b0537583c57d667b6bb..c2e6b0de6c53aec4e63794dc5b5cc5eab9600da6 100644
--- a/sdk/lib/_internal/compiler/implementation/js_backend/native_emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_backend/native_emitter.dart
@@ -31,9 +31,6 @@ class NativeEmitter {
// Caches the methods that have a native body.
Set<FunctionElement> nativeMethods;
- // Caches the methods that redirect to a JS method.
- Map<FunctionElement, String> redirectingMethods;
-
// Do we need the native emitter to take care of handling
// noSuchMethod for us? This flag is set to true in the emitter if
// it finds any native class that needs noSuchMethod handling.
@@ -46,16 +43,11 @@ class NativeEmitter {
directSubtypes = new Map<ClassElement, List<ClassElement>>(),
overriddenMethods = new Set<FunctionElement>(),
nativeMethods = new Set<FunctionElement>(),
- redirectingMethods = new Map<FunctionElement, String>(),
nativeBuffer = new CodeBuffer();
Compiler get compiler => emitter.compiler;
JavaScriptBackend get backend => compiler.backend;
- void addRedirectingMethod(FunctionElement element, String name) {
- redirectingMethods[element] = name;
- }
-
String get dynamicName {
Element element = compiler.findHelper(
const SourceString('dynamicFunction'));
@@ -115,7 +107,7 @@ function(cls, desc) {
}
void generateNativeLiteral(ClassElement classElement) {
- String quotedNative = classElement.nativeName.slowToString();
+ String quotedNative = classElement.nativeTagInfo.slowToString();
String nativeCode = quotedNative.substring(2, quotedNative.length - 1);
String className = backend.namer.getName(classElement);
nativeBuffer.add(className);
@@ -142,8 +134,8 @@ function(cls, desc) {
return identical(quotedName[1], '@');
}
- String toNativeName(ClassElement cls) {
- String quotedName = cls.nativeName.slowToString();
+ String toNativeTag(ClassElement cls) {
+ String quotedName = cls.nativeTagInfo.slowToString();
if (isNativeGlobal(quotedName)) {
// Global object, just be like the other types for now.
return quotedName.substring(3, quotedName.length - 1);
@@ -156,7 +148,7 @@ function(cls, desc) {
nativeClasses.add(classElement);
assert(classElement.backendMembers.isEmpty);
- String quotedName = classElement.nativeName.slowToString();
+ String quotedName = classElement.nativeTagInfo.slowToString();
if (isNativeLiteral(quotedName)) {
generateNativeLiteral(classElement);
// The native literal kind needs to be dealt with specially when
@@ -178,8 +170,8 @@ function(cls, desc) {
return;
}
- String nativeName = toNativeName(classElement);
- nativeBuffer.add("$defineNativeClassName('$nativeName', ");
+ String nativeTag = toNativeTag(classElement);
+ nativeBuffer.add("$defineNativeClassName('$nativeTag', ");
nativeBuffer.add('{');
bool firstInMap = true;
if (!fieldBuffer.isEmpty) {
@@ -247,7 +239,7 @@ function(cls, desc) {
0, indexOfLastOptionalArgumentInParameters + 1);
ClassElement classElement = member.enclosingElement;
- String nativeName = classElement.nativeName.slowToString();
+ String nativeTagInfo = classElement.nativeTagInfo.slowToString();
String nativeArguments = Strings.join(nativeArgumentsBuffer, ",");
CodeBuffer code = new CodeBuffer();
@@ -260,12 +252,11 @@ function(cls, desc) {
code.add(' return this.${backend.namer.getName(member)}($arguments)');
} else {
// When calling a JS method, we call it with the native name.
- String name = redirectingMethods[member];
- if (name == null) name = member.name.slowToString();
+ String name = member.nativeName();
code.add(' return this.$name($nativeArguments);');
}
- if (isNativeLiteral(nativeName) || !overriddenMethods.contains(member)) {
+ if (isNativeLiteral(nativeTagInfo) || !overriddenMethods.contains(member)) {
// Call the method directly.
buffer.add(code.toString());
} else {
@@ -327,14 +318,14 @@ function(cls, desc) {
// Expression fragments for this set of cls keys.
List<js.Expression> expressions = <js.Expression>[];
// TODO: Remove if cls is abstract.
- List<String> subtags = [toNativeName(classElement)];
+ List<String> subtags = [toNativeTag(classElement)];
void walk(ClassElement cls) {
for (final ClassElement subclass in getDirectSubclasses(cls)) {
ClassElement tag = subclass;
js.Expression existing = tagDefns[tag];
if (existing == null) {
// [subclass] is still within the subtree between dispatch classes.
- subtags.add(toNativeName(tag));
+ subtags.add(toNativeTag(tag));
walk(subclass);
} else {
// [subclass] is one of the preorderDispatchClasses, so CSE this
@@ -404,7 +395,7 @@ function(cls, desc) {
new js.ArrayInitializer.from(
preorderDispatchClasses.map((cls) =>
new js.ArrayInitializer.from([
- new js.LiteralString("'${toNativeName(cls)}'"),
+ new js.LiteralString("'${toNativeTag(cls)}'"),
tagDefns[cls]])));
// $.dynamicSetMetadata(table);

Powered by Google App Engine
This is Rietveld 408576698