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

Unified Diff: pkg/compiler/lib/src/js_emitter/class_stub_generator.dart

Issue 1212613009: dart2js: Implement frequency based naming. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Reserve reserved names :) Created 5 years, 6 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
« no previous file with comments | « pkg/compiler/lib/src/js_backend/namer_names.dart ('k') | pkg/compiler/lib/src/js_emitter/js_emitter.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
diff --git a/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart b/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
index 366d76919df75b84e45a63eb96e20c824d9253ba..53e1130fd0538a2f4026607d3bd246d92f067f1a 100644
--- a/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
+++ b/pkg/compiler/lib/src/js_emitter/class_stub_generator.dart
@@ -220,52 +220,49 @@ List<jsAst.Statement> buildTearOffCode(JavaScriptBackend backend) {
Compiler compiler = backend.compiler;
Element closureFromTearOff = backend.findHelper('closureFromTearOff');
- String tearOffAccessText;
jsAst.Expression tearOffAccessExpression;
- String tearOffGlobalObjectName;
- String tearOffGlobalObject;
+ jsAst.Expression tearOffGlobalObjectString;
+ jsAst.Expression tearOffGlobalObject;
if (closureFromTearOff != null) {
- // We need both the AST that references [closureFromTearOff] and a string
- // for the NoCsp version that constructs a function.
tearOffAccessExpression =
backend.emitter.staticFunctionAccess(closureFromTearOff);
- tearOffAccessText =
- jsAst.prettyPrint(tearOffAccessExpression, compiler).getText();
- tearOffGlobalObjectName = tearOffGlobalObject =
- namer.globalObjectFor(closureFromTearOff);
+ tearOffGlobalObject =
+ js.stringPart(namer.globalObjectFor(closureFromTearOff));
+ tearOffGlobalObjectString =
+ js.string(namer.globalObjectFor(closureFromTearOff));
} else {
// Default values for mocked-up test libraries.
- tearOffAccessText =
- r'''function() { throw "Helper 'closureFromTearOff' missing." }''';
- tearOffAccessExpression = js(tearOffAccessText);
- tearOffGlobalObjectName = 'MissingHelperFunction';
- tearOffGlobalObject = '($tearOffAccessText())';
+ tearOffAccessExpression = js(
+ r'''function() { throw "Helper 'closureFromTearOff' missing." }''');
+ tearOffGlobalObjectString = js.string('MissingHelperFunction');
+ tearOffGlobalObject = js(
+ r'''(function() { throw "Helper 'closureFromTearOff' missing." })()''');
}
jsAst.Statement tearOffGetter;
if (!compiler.useContentSecurityPolicy) {
- // This template is uncached because it is constructed from code fragments
- // that can change from compilation to compilation. Some of these could be
- // avoided, except for the string literals that contain the compiled access
- // path to 'closureFromTearOff'.
- tearOffGetter = js.uncachedStatementTemplate('''
+ jsAst.Expression tearOffAccessText =
+ new jsAst.UnparsedNode(tearOffAccessExpression, compiler, false);
+ tearOffGetter = js.statement('''
function tearOffGetter(funcs, reflectionInfo, name, isIntercepted) {
return isIntercepted
? new Function("funcs", "reflectionInfo", "name",
- "$tearOffGlobalObjectName", "c",
+ #tearOffGlobalObjectString, "c",
"return function tearOff_" + name + (functionCounter++) + "(x) {" +
- "if (c === null) c = $tearOffAccessText(" +
+ "if (c === null) c = " + #tearOffAccessText + "(" +
"this, funcs, reflectionInfo, false, [x], name);" +
"return new c(this, funcs[0], x, name);" +
- "}")(funcs, reflectionInfo, name, $tearOffGlobalObject, null)
+ "}")(funcs, reflectionInfo, name, #tearOffGlobalObject, null)
: new Function("funcs", "reflectionInfo", "name",
- "$tearOffGlobalObjectName", "c",
+ #tearOffGlobalObjectString, "c",
"return function tearOff_" + name + (functionCounter++)+ "() {" +
- "if (c === null) c = $tearOffAccessText(" +
+ "if (c === null) c = " + #tearOffAccessText + "(" +
"this, funcs, reflectionInfo, false, [], name);" +
"return new c(this, funcs[0], null, name);" +
- "}")(funcs, reflectionInfo, name, $tearOffGlobalObject, null);
-}''').instantiate([]);
+ "}")(funcs, reflectionInfo, name, #tearOffGlobalObject, null);
+}''', {'tearOffAccessText': tearOffAccessText,
+ 'tearOffGlobalObject': tearOffGlobalObject,
+ 'tearOffGlobalObjectString': tearOffGlobalObjectString});
} else {
tearOffGetter = js.statement('''
function tearOffGetter(funcs, reflectionInfo, name, isIntercepted) {
« no previous file with comments | « pkg/compiler/lib/src/js_backend/namer_names.dart ('k') | pkg/compiler/lib/src/js_emitter/js_emitter.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698