X Tutup
Skip to content

Commit 3a7b50f

Browse files
committed
fix(shims): function.name to return empty string when no name
1 parent e889ec8 commit 3a7b50f

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

modules/angular2/src/test_lib/shims_for_IE.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
if (!Object.hasOwnProperty('name')) {
44
Object.defineProperty(Function.prototype, 'name', {
55
get: function() {
6-
var name = this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1];
6+
var matches = this.toString().match(/^\s*function\s*(\S*)\s*\(/);
7+
var name = matches && matches.length > 1 ? matches[1] : "";
78
// For better performance only parse once, and then cache the
89
// result through a new accessor for repeated access.
910
Object.defineProperty(this, 'name', {value: name});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
library angular2.test.core.dom.shim_spec;
2+
3+
main() {
4+
// not relevant for dart.
5+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import {
2+
AsyncTestCompleter,
3+
beforeEach,
4+
ddescribe,
5+
describe,
6+
el,
7+
expect,
8+
iit,
9+
inject,
10+
it,
11+
xit
12+
} from 'angular2/test_lib';
13+
14+
export function main() {
15+
describe('Shim', () => {
16+
17+
it('should provide correct function.name ', () => {
18+
var functionWithoutName = function(_) {};
19+
function foo(_){};
20+
21+
expect((<any>functionWithoutName).name).toEqual('');
22+
expect((<any>foo).name).toEqual('foo');
23+
});
24+
25+
});
26+
}

0 commit comments

Comments
 (0)
X Tutup