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

Cannot supply flags when constructing one RegExp from another

This commit is contained in:
Robert Krimen 2013-05-02 20:23:06 +02:00
parent de97589c43
commit 74a8739188
3 changed files with 15 additions and 1 deletions

View File

@ -18,7 +18,10 @@ func builtinRegExp(call FunctionCall) Value {
}
func builtinNewRegExp(self *_object, _ Value, argumentList []Value) Value {
return toValue(self.runtime.newRegExp(valueOfArrayIndex(argumentList, 0), valueOfArrayIndex(argumentList, 1)))
return toValue(self.runtime.newRegExp(
valueOfArrayIndex(argumentList, 0),
valueOfArrayIndex(argumentList, 1),
))
}
func builtinRegExp_toString(call FunctionCall) Value {

View File

@ -774,6 +774,12 @@ func (runtime *_runtime) newNumber(value Value) *_object {
}
func (runtime *_runtime) newRegExp(patternValue Value, flagsValue Value) *_object {
if object := patternValue._object(); object != nil {
if object.class == "RegExp" && flagsValue.IsDefined() {
panic(newTypeError("Cannot supply flags when constructing one RegExp from another"))
}
}
pattern := ""
if patternValue.IsDefined() {
pattern = toString(patternValue)
@ -782,6 +788,7 @@ func (runtime *_runtime) newRegExp(patternValue Value, flagsValue Value) *_objec
if flagsValue.IsDefined() {
flags = toString(flagsValue)
}
return runtime._newRegExp(pattern, flags)
}

View File

@ -131,6 +131,10 @@ func TestRegExpCopying(t *testing.T) {
abc.indicator = 1;
[ abc.indicator, def.indicator ];
`, "1,1")
test(`raise:
RegExp(new RegExp("\d"), "1");
`, "TypeError: Cannot supply flags when constructing one RegExp from another")
}
func TestRegExp_multiline(t *testing.T) {