Return <anonymous> for functions that have no actual words between keyword and (

- Also fixes a potential catastrophic backtracking if someone has
severely damaged their own `toString` during test execution.
This commit is contained in:
Gregg Van Hove
2018-02-15 12:31:10 -08:00
parent 11827572d3
commit 3b77f38188
2 changed files with 4 additions and 4 deletions

View File

@@ -255,8 +255,8 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
return func.name;
}
var matches = func.toString().match(/^\s*function\s*(\w*)\s*\(/) ||
func.toString().match(/^\s*\[object\s*(\w*)Constructor\]/);
var matches = func.toString().match(/^\s*function\s*(\w+)\s*\(/) ||
func.toString().match(/^\s*\[object\s*(\w+)Constructor\]/);
return matches ? matches[1] : '<anonymous>';
};

View File

@@ -121,8 +121,8 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
return func.name;
}
var matches = func.toString().match(/^\s*function\s*(\w*)\s*\(/) ||
func.toString().match(/^\s*\[object\s*(\w*)Constructor\]/);
var matches = func.toString().match(/^\s*function\s*(\w+)\s*\(/) ||
func.toString().match(/^\s*\[object\s*(\w+)Constructor\]/);
return matches ? matches[1] : '<anonymous>';
};