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

Unified Diff: pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart

Issue 1264283003: dart2js: Fix lazy statics in the startup-emitter. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Add check. Created 5 years, 4 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 | « no previous file | tests/language/lazy_static7_test.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/startup_emitter/fragment_emitter.dart
diff --git a/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart b/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
index 255c2feff21113f9b3b4087b0542384fa2ebad67..b9bd63b0a5676e3356c8c4a1cdb0c1e54acc202e 100644
--- a/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
+++ b/pkg/compiler/lib/src/js_emitter/startup_emitter/fragment_emitter.dart
@@ -134,14 +134,19 @@ function mixin(cls, mixin) {
// getter ([getterName]) to access the field. If the field wasn't set before
// the first access, it is initialized with the [initializer].
function lazy(holder, name, getterName, initializer) {
- holder[name] = null;
+ var uninitializedSentinel = holder;
+ holder[name] = uninitializedSentinel;
holder[getterName] = function() {
holder[getterName] = function() { #cyclicThrow(name) };
var result;
var sentinelInProgress = initializer;
try {
- result = holder[name] = sentinelInProgress;
- result = holder[name] = initializer();
+ if (holder[name] === uninitializedSentinel) {
+ result = holder[name] = sentinelInProgress;
+ result = holder[name] = initializer();
+ } else {
+ result = holder[name];
+ }
} finally {
// Use try-finally, not try-catch/throw as it destroys the stack
// trace.
« no previous file with comments | « no previous file | tests/language/lazy_static7_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698