mirror of
https://github.com/robertkrimen/otto
synced 2025-10-19 19:55:30 +08:00
Cannot supply flags when constructing one RegExp from another
This commit is contained in:
parent
de97589c43
commit
74a8739188
|
|
@ -18,7 +18,10 @@ func builtinRegExp(call FunctionCall) Value {
|
||||||
}
|
}
|
||||||
|
|
||||||
func builtinNewRegExp(self *_object, _ Value, argumentList []Value) 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 {
|
func builtinRegExp_toString(call FunctionCall) Value {
|
||||||
|
|
|
||||||
|
|
@ -774,6 +774,12 @@ func (runtime *_runtime) newNumber(value Value) *_object {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (runtime *_runtime) newRegExp(patternValue Value, flagsValue 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 := ""
|
pattern := ""
|
||||||
if patternValue.IsDefined() {
|
if patternValue.IsDefined() {
|
||||||
pattern = toString(patternValue)
|
pattern = toString(patternValue)
|
||||||
|
|
@ -782,6 +788,7 @@ func (runtime *_runtime) newRegExp(patternValue Value, flagsValue Value) *_objec
|
||||||
if flagsValue.IsDefined() {
|
if flagsValue.IsDefined() {
|
||||||
flags = toString(flagsValue)
|
flags = toString(flagsValue)
|
||||||
}
|
}
|
||||||
|
|
||||||
return runtime._newRegExp(pattern, flags)
|
return runtime._newRegExp(pattern, flags)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -131,6 +131,10 @@ func TestRegExpCopying(t *testing.T) {
|
||||||
abc.indicator = 1;
|
abc.indicator = 1;
|
||||||
[ abc.indicator, def.indicator ];
|
[ abc.indicator, def.indicator ];
|
||||||
`, "1,1")
|
`, "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) {
|
func TestRegExp_multiline(t *testing.T) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user