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:
parent
4de35c1901
commit
2b5c4b6975
|
@ -1655,6 +1655,11 @@ func TestRegExp_exec(t *testing.T) {
|
||||||
}
|
}
|
||||||
[ ghi, lastIndex ];
|
[ ghi, lastIndex ];
|
||||||
`, "3,7")
|
`, "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) {
|
func TestNewFunction(t *testing.T) {
|
||||||
|
|
|
@ -68,6 +68,9 @@ func (runtime *_runtime) newRegExpObject(pattern string, flags string) *_object
|
||||||
}
|
}
|
||||||
|
|
||||||
func execRegExp(this *_object, target string) (match bool, result []int) {
|
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"))
|
lastIndex := toInteger(this.get("lastIndex"))
|
||||||
index := lastIndex
|
index := lastIndex
|
||||||
global := toBoolean(this.get("global"))
|
global := toBoolean(this.get("global"))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user