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

Throw proper SyntaxError if unable to parse a regular expression

This commit is contained in:
Robert Krimen 2012-11-15 16:10:24 -08:00
parent 30a04e1992
commit 8f9e999236
2 changed files with 13 additions and 4 deletions

View File

@ -18,7 +18,7 @@ otto: build
test-otto:
$(TEST) $(WITH_otto)
test.otto: otto
test.otto:
$(TEST) $(WITH_otto) | tee $@
test.otto-:
@ -36,9 +36,9 @@ test.v8-:
release: otto gauntlet
clean:
rm -f test.otto digest.json
rm -f test.otto digest.json .node.tmp.js
digest.json:
digest.json: test.otto
./digest < test.otto > $@
digest.json-:
@ -69,6 +69,10 @@ try-tmp: tmp.js
cat shim.js $< | $(otto)
@echo PASS
node-try-tmp: tmp.js
cat shim.js $< > .node.tmp.js
node ./.node.tmp.js
look: .fail
cat $<
@echo `readlink $<`

View File

@ -50,8 +50,13 @@ func (runtime *_runtime) newRegExpObject(pattern string, flags string) *_object
re2pattern = fmt.Sprintf("(?%s:%s)", re2flags, re2pattern)
}
regularExpression, err := regexp.Compile(re2pattern)
if err != nil {
panic(newSyntaxError("Invalid regular expression: %s", err.Error()[22:]))
}
self._RegExp = &_regExpObject{
RegularExpression: regexp.MustCompile(re2pattern),
RegularExpression: regularExpression,
Global: global,
IgnoreCase: ignoreCase,
Multiline: multiline,