From 99a2d372b53adf62a4ceed0b044bfbf0ffb5c230 Mon Sep 17 00:00:00 2001 From: Victor Berchet Date: Tue, 14 Oct 2014 19:56:22 +0200 Subject: [PATCH] fix(RootScope): set the scope on ScopeAware root context fixes #1554 --- lib/core/scope.dart | 1 + test/core/scope_spec.dart | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/core/scope.dart b/lib/core/scope.dart index e89966965..d12cda519 100644 --- a/lib/core/scope.dart +++ b/lib/core/scope.dart @@ -773,6 +773,7 @@ class RootScope extends Scope { _zone.onError = (e, s, ls) => _exceptionHandler(e, s); _zone.onScheduleMicrotask = runAsync; cacheRegister.registerCache("ScopeWatchASTs", astCache); + if (context is ScopeAware) context.scope = this; } RootScope get rootScope => this; diff --git a/test/core/scope_spec.dart b/test/core/scope_spec.dart index f7ae199b5..83f2d30d4 100644 --- a/test/core/scope_spec.dart +++ b/test/core/scope_spec.dart @@ -24,6 +24,18 @@ void main() { ..bind(ScopeStatsEmitter, toImplementation: MockScopeStatsEmitter); }); + describe('Root context', () { + beforeEachModule((Module module) { + module.bind(Object, toImplementation: _RootContext); + }); + + it('should set the scope when RootContext is ScopeAware', + (RootScope rootScope, Object rootContext) { + expect(rootContext).toBeAnInstanceOf(_RootContext); + expect((rootContext as _RootContext).scope).toBe(rootScope); + }); + }); + describe('AST Bridge', () { it('should watch field', (Logger logger, Map context, RootScope rootScope) { context['field'] = 'Worked!'; @@ -1751,3 +1763,7 @@ class UnstableList { class Foo { increment(x) => x+1; } + +class _RootContext implements ScopeAware { + var scope; +}