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

Unified Diff: sdk/lib/_internal/compiler/implementation/js_emitter/class_emitter.dart

Issue 246633006: Revert "JS templates" (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months 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_emitter/class_emitter.dart
diff --git a/sdk/lib/_internal/compiler/implementation/js_emitter/class_emitter.dart b/sdk/lib/_internal/compiler/implementation/js_emitter/class_emitter.dart
index 6f19edbabfb30fca42b91aafa3009a93424c6f80..cd8f703106ae89a78f856cefe57a7ccff4382b42 100644
--- a/sdk/lib/_internal/compiler/implementation/js_emitter/class_emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_emitter/class_emitter.dart
@@ -70,39 +70,23 @@ class ClassEmitter extends CodeEmitterHelper {
});
}
String constructorName = namer.getNameOfClass(classElement);
-
- // TODO(sra): Implement placeholders in VariableDeclaration position:
- // task.precompiledFunction.add(js.statement('function #(#) { #; }',
- // [ constructorName, fields,
- // fields.map(
- // (name) => js('this.# = #', [name, name]))]));
- task.precompiledFunction.add(
- new jsAst.FunctionDeclaration(
- new jsAst.VariableDeclaration(constructorName),
- js('function(#) { #; }',
- [fields,
- fields.map((name) => js('this.# = #', [name, name]))])));
+ task.precompiledFunction.add(new jsAst.FunctionDeclaration(
+ new jsAst.VariableDeclaration(constructorName),
+ js.fun(fields, fields.map(
+ (name) => js('this.$name = $name')).toList())));
if (runtimeName == null) {
runtimeName = constructorName;
}
-
- task.precompiledFunction.add(
- js.statement(r'''{
- #.builtin$cls = #;
- if (!"name" in #)
- #.name = #;
- $desc=$collectedClasses.#;
- if ($desc instanceof Array) $desc = $desc[1];
- #.prototype = $desc;
- }''',
- [ constructorName, js.string(runtimeName),
- constructorName,
- constructorName, js.string(constructorName),
- constructorName,
- constructorName
- ]));
-
- task.precompiledConstructorNames.add(js('#', constructorName));
+ task.precompiledFunction.addAll([
+ js('$constructorName.builtin\$cls = "$runtimeName"'),
+ js.if_('!"name" in $constructorName',
+ js('$constructorName.name = "$constructorName"')),
+ js('\$desc=\$collectedClasses.$constructorName'),
+ js.if_('\$desc instanceof Array', js('\$desc = \$desc[1]')),
+ js('$constructorName.prototype = \$desc'),
+ ]);
+
+ task.precompiledConstructorNames.add(js(constructorName));
}
/// Returns `true` if fields added.
@@ -318,7 +302,7 @@ class ClassEmitter extends CodeEmitterHelper {
if (backend.isNeededForReflection(classElement)) {
Link typeVars = classElement.typeVariables;
Iterable typeVariableProperties = task.typeVariableHandler
- .typeVariablesOf(classElement).map(js.number);
+ .typeVariablesOf(classElement).map(js.toExpression);
ClassElement superclass = classElement.superclass;
bool hasSuper = superclass != null;
@@ -536,12 +520,11 @@ class ClassEmitter extends CodeEmitterHelper {
String receiver = backend.isInterceptorClass(cls) ? 'receiver' : 'this';
List<String> args = backend.isInterceptedMethod(member) ? ['receiver'] : [];
task.precompiledFunction.add(
- js('#.prototype.# = function(#) { return #.# }',
- [className, getterName, args, receiver, fieldName]));
+ js('$className.prototype.$getterName = #',
+ js.fun(args, js.return_(js('$receiver.$fieldName')))));
if (backend.isNeededForReflection(member)) {
task.precompiledFunction.add(
- js('#.prototype.#.${namer.reflectableField} = 1',
- [className, getterName]));
+ js('$className.prototype.$getterName.${namer.reflectableField} = 1'));
}
}
@@ -551,15 +534,14 @@ class ClassEmitter extends CodeEmitterHelper {
ClassElement cls = member.getEnclosingClass();
String className = namer.getNameOfClass(cls);
String receiver = backend.isInterceptorClass(cls) ? 'receiver' : 'this';
- List<String> args = backend.isInterceptedMethod(member) ? ['receiver'] : [];
+ List<String> args =
+ backend.isInterceptedMethod(member) ? ['receiver', 'v'] : ['v'];
task.precompiledFunction.add(
- // TODO: remove 'return'?
- js('#.prototype.# = function(#, v) { return #.# = v; }',
- [className, setterName, args, receiver, fieldName]));
+ js('$className.prototype.$setterName = #',
+ js.fun(args, js.return_(js('$receiver.$fieldName = v')))));
if (backend.isNeededForReflection(member)) {
task.precompiledFunction.add(
- js('#.prototype.#.${namer.reflectableField} = 1',
- [className, setterName]));
+ js('$className.prototype.$setterName.${namer.reflectableField} = 1'));
}
}
@@ -596,7 +578,7 @@ class ClassEmitter extends CodeEmitterHelper {
TypeVariableElement element) {
String name = namer.readTypeVariableName(element);
jsAst.Expression index =
- js.number(RuntimeTypes.getTypeVariableIndex(element));
+ js.toExpression(RuntimeTypes.getTypeVariableIndex(element));
jsAst.Expression computeTypeVariable;
Substitution substitution =
@@ -604,9 +586,9 @@ class ClassEmitter extends CodeEmitterHelper {
cls, element.enclosingElement, alwaysGenerateFunction: true);
if (substitution != null) {
jsAst.Expression typeArguments =
- js(r'#.apply(null, this.$builtinTypeInfo)',
- substitution.getCode(backend.rti, true));
- computeTypeVariable = js('#[#]', [typeArguments, index]);
+ substitution.getCode(backend.rti, true)['apply'](
+ ['null', r'this.$builtinTypeInfo']);
+ computeTypeVariable = typeArguments[index];
} else {
// TODO(ahe): These can be generated dynamically.
computeTypeVariable =
@@ -614,8 +596,8 @@ class ClassEmitter extends CodeEmitterHelper {
}
jsAst.Expression convertRtiToRuntimeType =
namer.elementAccess(compiler.findHelper('convertRtiToRuntimeType'));
- builder.addProperty(name,
- js('function () { return #(#) }',
- [convertRtiToRuntimeType, computeTypeVariable]));
+ builder.addProperty(
+ name, js.fun(
+ [], [js.return_(convertRtiToRuntimeType(computeTypeVariable))]));
}
}

Powered by Google App Engine
This is Rietveld 408576698