Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 95f9179

Browse files
jbedardgkalpak
authored andcommitted
fixup! perf(copy): replace Map feature-test with native-test
1 parent 8f4eab4 commit 95f9179

File tree

2 files changed

+9
-54
lines changed

2 files changed

+9
-54
lines changed

src/Angular.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -749,7 +749,9 @@ function arrayRemove(array, value) {
749749
return index;
750750
}
751751

752-
752+
// A minimal ES6 Map implementation.
753+
// Should be bug/feature equivelent to the native implementations of supported browsers.
754+
// See https://kangax.github.io/compat-table/es6/#test-Map
753755
function ES6MapShim() {
754756
this._keys = [];
755757
this._values = [];
@@ -777,29 +779,15 @@ ES6MapShim.prototype = {
777779
}
778780
this._keys[idx] = key;
779781
this._values[idx] = value;
780-
return this;
782+
783+
// Support: IE11
784+
// Do not `return this` to simulate the partial IE11 implementation
781785
}
782786
};
783787

784-
function testES6Map(Map) {
785-
var m, o = {};
786-
return isFunction(Map) && (m = new Map())
787-
788-
// Required functions
789-
&& isFunction(m.get) && isFunction(m.set)
790-
791-
// Number keys, must not call toString
792-
&& m.get(1) === undefined
793-
&& m.set(1, o) === m
794-
&& m.get(1) === o
795-
&& m.get('1') === undefined
796-
797-
// Object keys, must use instance as key and not call toString
798-
&& m.set(o, 2) === m && m.get(o) === 2
799-
&& m.get({}) === undefined;
800-
}
801-
802-
var ES6Map = testES6Map(window.Map) ? window.Map : ES6MapShim;
788+
var ES6Map = isFunction(window.Map) && toString.call(window.Map.prototype) === '[object Map]'
789+
? window.Map
790+
: ES6MapShim;
803791

804792
/**
805793
* @ngdoc function

test/AngularSpec.js

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,39 +25,6 @@ describe('angular', function() {
2525
});
2626
});
2727

28-
describe('ES6Map', function() {
29-
it('should test for bad Map objects', function() {
30-
expect(testES6Map()).toBe(false);
31-
expect(testES6Map(null)).toBe(false);
32-
expect(testES6Map(3)).toBe(false);
33-
expect(testES6Map({})).toBe(false);
34-
});
35-
36-
it('should test for bad Map shims', function() {
37-
function NoMethods() {}
38-
39-
function ToStringOnKeys() {
40-
this._vals = {};
41-
}
42-
ToStringOnKeys.prototype = {
43-
get: function(key) {
44-
return this._vals[key];
45-
},
46-
set: function(key, val) {
47-
this._vals[key] = val;
48-
return this;
49-
}
50-
};
51-
52-
expect(testES6Map(NoMethods)).toBe(false);
53-
expect(testES6Map(ToStringOnKeys)).toBe(false);
54-
});
55-
56-
it('should pass the ES6Map test with ES6MapShim', function() {
57-
expect(testES6Map(ES6MapShim)).toBe(true);
58-
});
59-
});
60-
6128
describe('copy', function() {
6229
it('should return same object', function() {
6330
var obj = {};

0 commit comments

Comments
 (0)