mirror of
https://github.com/robertkrimen/otto
synced 2025-10-12 20:27:30 +08:00
RegExp(/xyzzy/) & RegExp(/xyzzy/, undefined) will return a reference to the exact same /xyzzy/ object...
...instead of creating a new copy
This commit is contained in:
parent
1628647e05
commit
de97589c43
|
@ -7,7 +7,14 @@ import (
|
|||
// RegExp
|
||||
|
||||
func builtinRegExp(call FunctionCall) Value {
|
||||
return toValue(call.runtime.newRegExp(call.Argument(0), call.Argument(1)))
|
||||
pattern := call.Argument(0)
|
||||
flags := call.Argument(1)
|
||||
if object := pattern._object(); object != nil {
|
||||
if object.class == "RegExp" && flags.IsUndefined() {
|
||||
return pattern
|
||||
}
|
||||
}
|
||||
return toValue(call.runtime.newRegExp(pattern, flags))
|
||||
}
|
||||
|
||||
func builtinNewRegExp(self *_object, _ Value, argumentList []Value) Value {
|
||||
|
|
|
@ -121,6 +121,18 @@ func TestRegExp_zaacbbbcac(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestRegExpCopying(t *testing.T) {
|
||||
Terst(t)
|
||||
|
||||
test := runTest()
|
||||
test(`
|
||||
abc = /xyzzy/i;
|
||||
def = RegExp(abc);
|
||||
abc.indicator = 1;
|
||||
[ abc.indicator, def.indicator ];
|
||||
`, "1,1")
|
||||
}
|
||||
|
||||
func TestRegExp_multiline(t *testing.T) {
|
||||
Terst(t)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user