Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit 0b5b19f

Browse files
juliemrrkirov
authored andcommitted
chore(introspection): clean up workarounds for dart 1.4 and 1.5
1 parent 943d619 commit 0b5b19f

File tree

2 files changed

+63
-87
lines changed

2 files changed

+63
-87
lines changed

lib/introspection.dart

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -176,31 +176,10 @@ js.JsObject _jsScopeFromProbe(ElementProbe probe) =>
176176
// Proxies a Dart function that accepts up to 10 parameters.
177177
js.JsFunction _jsFunction(Function fn) {
178178
const Object X = __varargSentinel;
179-
Function fnCopy = fn; // workaround a bug.
180179
return new js.JsFunction.withThis(
181180
(thisArg, [o1=X, o2=X, o3=X, o4=X, o5=X, o6=X, o7=X, o8=X, o9=X, o10=X]) {
182-
// Work around a bug in dart 1.4.0 where the closurized variable, fn,
183-
// gets mysteriously replaced with our own closure function leading to a
184-
// stack overflow.
185-
fn = fnCopy;
186-
if (o10 == null && identical(o9, X)) {
187-
// Work around another bug in dart 1.4.0. This bug is not present in
188-
// dart 1.5.0-dev.2.0.
189-
// In dart 1.4.0, when running in Dartium (not dart2js), if you invoke
190-
// a JsFunction from Dart code (either by calling .apply([args]) on it
191-
// or by calling .callMethod(jsFuncName, [args]) on a JsObject
192-
// containing the JsFunction, regardless of whether you specified the
193-
// thisArg keyword parameter, the Dart function is called with the
194-
// first argument in the thisArg param causing all the arguments to be
195-
// shifted by one. We can detect this by the fact that o10 is null
196-
// but o9 is X (should only happen when o9 got a default value) and
197-
// work around it by using thisArg as the first parameter.
198-
return __invokeFn(fn, thisArg, o1, o2, o3, o4, o5, o6, o7, o8, o9);
199-
} else {
200-
return __invokeFn(fn, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10);
201-
}
202-
}
203-
);
181+
return __invokeFn(fn, o1, o2, o3, o4, o5, o6, o7, o8, o9, o10);
182+
});
204183
}
205184

206185

test/introspection_spec.dart

Lines changed: 61 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -125,80 +125,77 @@ void main() {
125125
expect(js.context['ngProbe'].apply([ngtop])).toBeDefined();
126126
});
127127

128-
// Issue #1219
129-
if (identical(1, 1.0) || !js.context['DART_VERSION'].toString().contains("version: 1.5.")) {
130-
describe(r'testability', () {
128+
describe(r'testability', () {
131129

132-
var testability;
130+
var testability;
133131

134-
beforeEach(() {
135-
testability = angular['getTestability'].apply([ngtop]);
136-
});
137-
138-
it('should be available from Javascript', () {
139-
expect(testability).toBeDefined();
140-
});
141-
142-
it('should expose allowAnimations', () {
143-
allowAnimations(allowed) => testability['allowAnimations'].apply([allowed]);
144-
expect(allowAnimations(false)).toEqual(true);
145-
expect(allowAnimations(false)).toEqual(false);
146-
expect(allowAnimations(true)).toEqual(false);
147-
expect(allowAnimations(true)).toEqual(true);
148-
});
132+
beforeEach(() {
133+
testability = angular['getTestability'].apply([ngtop]);
134+
});
149135

150-
describe('bindings', () {
151-
it('should find exact bindings', () {
152-
// exactMatch should fail.
153-
var bindingNodes = testability['findBindings'].apply(['introspection', true]);
154-
expect(bindingNodes.length).toEqual(0);
155-
156-
// substring search (default) should succeed.
157-
// exactMatch should default to false.
158-
bindingNodes = testability['findBindings'].apply(['introspection']);
159-
expect(bindingNodes.length).toEqual(1);
160-
bindingNodes = testability['findBindings'].apply(['introspection', false]);
161-
expect(bindingNodes.length).toEqual(1);
162-
163-
// and so should exact search with the correct query.
164-
bindingNodes = testability['findBindings'].apply(["'introspection FTW'", true]);
165-
expect(bindingNodes.length).toEqual(1);
166-
});
136+
it('should be available from Javascript', () {
137+
expect(testability).toBeDefined();
138+
});
167139

168-
_assertBinding(String query) {
169-
var bindingNodes = testability['findBindings'].apply([query]);
170-
expect(bindingNodes.length).toEqual(1);
171-
var node = bindingNodes[0];
172-
var probe = js.context['ngProbe'].apply([node]);
173-
expect(probe).toBeDefined();
174-
var bindings = probe['bindings'];
175-
expect(bindings['length']).toEqual(1);
176-
expect(bindings[0].contains(query)).toBe(true);
177-
}
178-
179-
it('should find ng-bind bindings', () => _assertBinding('introspection FTW'));
180-
it('should find attribute mustache bindings', () => _assertBinding('attrMustache'));
181-
it('should find text mustache bindings', () => _assertBinding('textMustache'));
182-
});
140+
it('should expose allowAnimations', () {
141+
allowAnimations(allowed) => testability['allowAnimations'].apply([allowed]);
142+
expect(allowAnimations(false)).toEqual(true);
143+
expect(allowAnimations(false)).toEqual(false);
144+
expect(allowAnimations(true)).toEqual(false);
145+
expect(allowAnimations(true)).toEqual(true);
146+
});
183147

184-
it('should find models', () {
148+
describe('bindings', () {
149+
it('should find exact bindings', () {
185150
// exactMatch should fail.
186-
var modelNodes = testability['findModels'].apply(['my', true]);
187-
expect(modelNodes.length).toEqual(0);
151+
var bindingNodes = testability['findBindings'].apply(['introspection', true]);
152+
expect(bindingNodes.length).toEqual(0);
188153

189154
// substring search (default) should succeed.
190-
modelNodes = testability['findModels'].apply(['my']);
191-
expect(modelNodes.length).toEqual(1);
192-
var divElement = modelNodes[0];
193-
expect(divElement is DivElement).toEqual(true);
194-
var probe = js.context['ngProbe'].apply([divElement]);
195-
expect(probe).toBeDefined();
196-
var models = probe['models'];
197-
expect(models['length']).toEqual(1);
198-
expect(models[0]).toEqual('myModel');
155+
// exactMatch should default to false.
156+
bindingNodes = testability['findBindings'].apply(['introspection']);
157+
expect(bindingNodes.length).toEqual(1);
158+
bindingNodes = testability['findBindings'].apply(['introspection', false]);
159+
expect(bindingNodes.length).toEqual(1);
160+
161+
// and so should exact search with the correct query.
162+
bindingNodes = testability['findBindings'].apply(["'introspection FTW'", true]);
163+
expect(bindingNodes.length).toEqual(1);
199164
});
165+
166+
_assertBinding(String query) {
167+
var bindingNodes = testability['findBindings'].apply([query]);
168+
expect(bindingNodes.length).toEqual(1);
169+
var node = bindingNodes[0];
170+
var probe = js.context['ngProbe'].apply([node]);
171+
expect(probe).toBeDefined();
172+
var bindings = probe['bindings'];
173+
expect(bindings['length']).toEqual(1);
174+
expect(bindings[0].contains(query)).toBe(true);
175+
}
176+
177+
it('should find ng-bind bindings', () => _assertBinding('introspection FTW'));
178+
it('should find attribute mustache bindings', () => _assertBinding('attrMustache'));
179+
it('should find text mustache bindings', () => _assertBinding('textMustache'));
200180
});
201-
}
181+
182+
it('should find models', () {
183+
// exactMatch should fail.
184+
var modelNodes = testability['findModels'].apply(['my', true]);
185+
expect(modelNodes.length).toEqual(0);
186+
187+
// substring search (default) should succeed.
188+
modelNodes = testability['findModels'].apply(['my']);
189+
expect(modelNodes.length).toEqual(1);
190+
var divElement = modelNodes[0];
191+
expect(divElement is DivElement).toEqual(true);
192+
var probe = js.context['ngProbe'].apply([divElement]);
193+
expect(probe).toBeDefined();
194+
var models = probe['models'];
195+
expect(models['length']).toEqual(1);
196+
expect(models[0]).toEqual('myModel');
197+
});
198+
});
202199
});
203200
});
204201
}

0 commit comments

Comments
 (0)