fix(shims): function.name to return empty string when no name
This commit is contained in:
parent
e889ec8335
commit
3a7b50f244
|
@ -3,7 +3,8 @@
|
||||||
if (!Object.hasOwnProperty('name')) {
|
if (!Object.hasOwnProperty('name')) {
|
||||||
Object.defineProperty(Function.prototype, 'name', {
|
Object.defineProperty(Function.prototype, 'name', {
|
||||||
get: function() {
|
get: function() {
|
||||||
var name = this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1];
|
var matches = this.toString().match(/^\s*function\s*(\S*)\s*\(/);
|
||||||
|
var name = matches && matches.length > 1 ? matches[1] : "";
|
||||||
// For better performance only parse once, and then cache the
|
// For better performance only parse once, and then cache the
|
||||||
// result through a new accessor for repeated access.
|
// result through a new accessor for repeated access.
|
||||||
Object.defineProperty(this, 'name', {value: name});
|
Object.defineProperty(this, 'name', {value: name});
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
library angular2.test.core.dom.shim_spec;
|
||||||
|
|
||||||
|
main() {
|
||||||
|
// not relevant for dart.
|
||||||
|
}
|
|
@ -0,0 +1,26 @@
|
||||||
|
import {
|
||||||
|
AsyncTestCompleter,
|
||||||
|
beforeEach,
|
||||||
|
ddescribe,
|
||||||
|
describe,
|
||||||
|
el,
|
||||||
|
expect,
|
||||||
|
iit,
|
||||||
|
inject,
|
||||||
|
it,
|
||||||
|
xit
|
||||||
|
} from 'angular2/test_lib';
|
||||||
|
|
||||||
|
export function main() {
|
||||||
|
describe('Shim', () => {
|
||||||
|
|
||||||
|
it('should provide correct function.name ', () => {
|
||||||
|
var functionWithoutName = function(_) {};
|
||||||
|
function foo(_){};
|
||||||
|
|
||||||
|
expect((<any>functionWithoutName).name).toEqual('');
|
||||||
|
expect((<any>foo).name).toEqual('foo');
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
Loading…
Reference in New Issue