1
0
mirror of https://github.com/robertkrimen/otto synced 2025-10-12 20:27:30 +08:00

Safeguard RegExp.exec against non-RegExp

This commit is contained in:
Robert Krimen 2012-11-21 18:19:15 -08:00
parent 4de35c1901
commit 2b5c4b6975
2 changed files with 8 additions and 0 deletions

View File

@ -1655,6 +1655,11 @@ func TestRegExp_exec(t *testing.T) {
}
[ ghi, lastIndex ];
`, "3,7")
test(`raise:
var exec = RegExp.prototype.exec;
exec("Xyzzy");
`, "TypeError: Calling RegExp.exec on a non-RegExp object")
}
func TestNewFunction(t *testing.T) {

View File

@ -68,6 +68,9 @@ func (runtime *_runtime) newRegExpObject(pattern string, flags string) *_object
}
func execRegExp(this *_object, target string) (match bool, result []int) {
if this.class != "RegExp" {
panic(newTypeError("Calling RegExp.exec on a non-RegExp object"))
}
lastIndex := toInteger(this.get("lastIndex"))
index := lastIndex
global := toBoolean(this.get("global"))