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

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

Issue 11419119: Don't use 'new Function' for lazily initialized getter. (Closed) Base URL: http://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
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/js_backend/emitter_no_eval.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart
===================================================================
--- sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart (revision 15244)
+++ sdk/lib/_internal/compiler/implementation/js_backend/emitter.dart (working copy)
@@ -322,14 +322,21 @@
String get lazyInitializerFunction {
String isolate = namer.CURRENT_ISOLATE;
+ return """
+function(prototype, staticName, fieldName, getterName, lazyValue) {
+ var getter = new Function("{ return $isolate." + fieldName + ";}");
+$lazyInitializerLogic
+}""";
+ }
+
+ String get lazyInitializerLogic {
+ String isolate = namer.CURRENT_ISOLATE;
JavaScriptBackend backend = compiler.backend;
String cyclicThrow = namer.isolateAccess(backend.cyclicThrowHelper);
return """
-function(prototype, staticName, fieldName, getterName, lazyValue) {
var sentinelUndefined = {};
var sentinelInProgress = {};
prototype[fieldName] = sentinelUndefined;
- var getter = new Function("{ return $isolate." + fieldName + ";}");
prototype[getterName] = function() {
var result = $isolate[fieldName];
try {
@@ -350,8 +357,7 @@
} finally {
$isolate[getterName] = getter;
}
- };
-}""";
+ };""";
}
void addDefineClassAndFinishClassFunctionsIfNecessary(CodeBuffer buffer) {
@@ -1336,11 +1342,16 @@
buffer.add(namer.getLazyInitializerName(element));
buffer.add("', ");
buffer.add(code);
+ emitLazyInitializedGetter(element, buffer);
buffer.add(");\n");
}
}
}
+ void emitLazyInitializedGetter(VariableElement element, CodeBuffer buffer) {
+ // Nothing to do, the 'lazy' function will create the getter.
+ }
+
void emitCompileTimeConstants(CodeBuffer buffer) {
ConstantHandler handler = compiler.constantHandler;
List<Constant> constants = handler.getConstantsForEmission();
« no previous file with comments | « no previous file | sdk/lib/_internal/compiler/implementation/js_backend/emitter_no_eval.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698