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

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

Issue 237583014: JS templates (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: cleanup 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 cd8f703106ae89a78f856cefe57a7ccff4382b42..121195bf5bfcec803fff7ad9c0a5a70c9b9190f7 100644
--- a/sdk/lib/_internal/compiler/implementation/js_emitter/class_emitter.dart
+++ b/sdk/lib/_internal/compiler/implementation/js_emitter/class_emitter.dart
@@ -70,23 +70,37 @@ class ClassEmitter extends CodeEmitterHelper {
});
}
String constructorName = namer.getNameOfClass(classElement);
+
task.precompiledFunction.add(new jsAst.FunctionDeclaration(
new jsAst.VariableDeclaration(constructorName),
- js.fun(fields, fields.map(
- (name) => js('this.$name = $name')).toList())));
+ js('function(#) { #; }',
floitsch 2014/04/22 16:11:18 not correctly indented.
sra1 2014/04/23 02:33:50 Done.
+ [fields, fields.map((name) => js('this.# = #', [name, name]))])));
floitsch 2014/04/22 16:11:18 split arguments and body in separate lines.
sra1 2014/04/23 02:33:50 Done.
+ // TODO(sra): Implement placeholders in VariableDeclaration position:
floitsch 2014/04/22 16:11:18 Move TODO before the 'new'.
sra1 2014/04/23 02:33:50 Done.
+ // task.precompiledFunction.add(js.statement('function #(#) { #; }',
+ // [ constructorName, fields,
+ // fields.map(
+ // (name) => js('this.# = #', [name, name]))]));
if (runtimeName == null) {
runtimeName = 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));
+
+ task.precompiledFunction.add(
+ js.statement('''{
floitsch 2014/04/22 16:11:18 make raw string?
sra1 2014/04/23 02:33:50 Done.
+ #.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));
}
/// Returns `true` if fields added.
@@ -302,7 +316,7 @@ class ClassEmitter extends CodeEmitterHelper {
if (backend.isNeededForReflection(classElement)) {
Link typeVars = classElement.typeVariables;
Iterable typeVariableProperties = task.typeVariableHandler
- .typeVariablesOf(classElement).map(js.toExpression);
+ .typeVariablesOf(classElement).map(js.number);
ClassElement superclass = classElement.superclass;
bool hasSuper = superclass != null;
@@ -520,11 +534,12 @@ class ClassEmitter extends CodeEmitterHelper {
String receiver = backend.isInterceptorClass(cls) ? 'receiver' : 'this';
List<String> args = backend.isInterceptedMethod(member) ? ['receiver'] : [];
task.precompiledFunction.add(
- js('$className.prototype.$getterName = #',
- js.fun(args, js.return_(js('$receiver.$fieldName')))));
+ js('#.prototype.# = function(#) { return #.# }',
+ [className, getterName, args, receiver, fieldName]));
if (backend.isNeededForReflection(member)) {
task.precompiledFunction.add(
- js('$className.prototype.$getterName.${namer.reflectableField} = 1'));
+ js('#.prototype.#.${namer.reflectableField} = 1',
+ [className, getterName]));
}
}
@@ -534,14 +549,15 @@ 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', 'v'] : ['v'];
+ List<String> args = backend.isInterceptedMethod(member) ? ['receiver'] : [];
task.precompiledFunction.add(
- js('$className.prototype.$setterName = #',
- js.fun(args, js.return_(js('$receiver.$fieldName = v')))));
+ // TODO: remove 'return'?
+ js('#.prototype.# = function(#, v) { return #.# = v; }',
+ [className, setterName, args, receiver, fieldName]));
if (backend.isNeededForReflection(member)) {
task.precompiledFunction.add(
- js('$className.prototype.$setterName.${namer.reflectableField} = 1'));
+ js('#.prototype.#.${namer.reflectableField} = 1',
+ [className, setterName]));
}
}
@@ -578,7 +594,7 @@ class ClassEmitter extends CodeEmitterHelper {
TypeVariableElement element) {
String name = namer.readTypeVariableName(element);
jsAst.Expression index =
- js.toExpression(RuntimeTypes.getTypeVariableIndex(element));
+ js.number(RuntimeTypes.getTypeVariableIndex(element));
jsAst.Expression computeTypeVariable;
Substitution substitution =
@@ -586,9 +602,9 @@ class ClassEmitter extends CodeEmitterHelper {
cls, element.enclosingElement, alwaysGenerateFunction: true);
if (substitution != null) {
jsAst.Expression typeArguments =
- substitution.getCode(backend.rti, true)['apply'](
- ['null', r'this.$builtinTypeInfo']);
- computeTypeVariable = typeArguments[index];
+ js(r'#.apply(null, this.$builtinTypeInfo)',
+ substitution.getCode(backend.rti, true));
+ computeTypeVariable = js('#[#]', [typeArguments, index]);
} else {
// TODO(ahe): These can be generated dynamically.
computeTypeVariable =
@@ -596,8 +612,8 @@ class ClassEmitter extends CodeEmitterHelper {
}
jsAst.Expression convertRtiToRuntimeType =
namer.elementAccess(compiler.findHelper('convertRtiToRuntimeType'));
- builder.addProperty(
- name, js.fun(
- [], [js.return_(convertRtiToRuntimeType(computeTypeVariable))]));
+ builder.addProperty(name,
+ js('function () { return #(#) }',
+ [convertRtiToRuntimeType, computeTypeVariable]));
}
}

Powered by Google App Engine
This is Rietveld 408576698