From 5103f080e9f60330c5b259e06a4375d4df3b4d81 Mon Sep 17 00:00:00 2001 From: Marc Laval Date: Thu, 21 May 2015 11:30:56 +0200 Subject: [PATCH] fix(test): function.name is not available (IE11) --- karma-js.conf.js | 3 ++- modules/angular2/src/test_lib/shims_for_IE.es6 | 13 +++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 modules/angular2/src/test_lib/shims_for_IE.es6 diff --git a/karma-js.conf.js b/karma-js.conf.js index 8549550b83..e8b1bf51bd 100644 --- a/karma-js.conf.js +++ b/karma-js.conf.js @@ -24,7 +24,8 @@ module.exports = function(config) { 'node_modules/reflect-metadata/Reflect.js', 'tools/build/file2modulename.js', 'test-main.js', - {pattern: 'modules/**/test/**/static_assets/**', included: false, watched: false} + {pattern: 'modules/**/test/**/static_assets/**', included: false, watched: false}, + 'modules/angular2/src/test_lib/shims_for_IE.es6' ], exclude: [ diff --git a/modules/angular2/src/test_lib/shims_for_IE.es6 b/modules/angular2/src/test_lib/shims_for_IE.es6 new file mode 100644 index 0000000000..94117011ff --- /dev/null +++ b/modules/angular2/src/test_lib/shims_for_IE.es6 @@ -0,0 +1,13 @@ +//function.name +/*! @source http://stackoverflow.com/questions/6903762/function-name-not-supported-in-ie*/ +if (!(function f() {}).name) { + Object.defineProperty(Function.prototype, 'name', { + get: function() { + var name = this.toString().match(/^\s*function\s*(\S*)\s*\(/)[1]; + // For better performance only parse once, and then cache the + // result through a new accessor for repeated access. + Object.defineProperty(this, 'name', { value: name }); + return name; + } + }); +}