| Index: dart/frog/leg/lib/regexp_helper.dart
|
| diff --git a/dart/frog/leg/lib/regexp_helper.dart b/dart/frog/leg/lib/regexp_helper.dart
|
| index df8858d831582d3effcc56c361afff5521acea71..ff9289b750e1d54bfcfdb86a0ee4438866e9b2d7 100644
|
| --- a/dart/frog/leg/lib/regexp_helper.dart
|
| +++ b/dart/frog/leg/lib/regexp_helper.dart
|
| @@ -3,22 +3,16 @@
|
| // BSD-style license that can be found in the LICENSE file.
|
|
|
| class RegExpWrapper {
|
| - final re;
|
| -
|
| - // TODO(ahe): This constructor is clearly not const. We need some
|
| - // better way to handle constant regular expressions. One might
|
| - // question if regular expressions are really constant as we have
|
| - // tests that expect an exception from the constructor.
|
| - const RegExpWrapper(pattern, multiLine, ignoreCase, global)
|
| - : re = makeRegExp(pattern, "${multiLine == true ? 'm' : ''}${
|
| - ignoreCase == true ? 'i' : ''}${
|
| - global == true ? 'g' : ''}");
|
| -
|
| - RegExpWrapper.fromRegExp(other, global)
|
| - // TODO(ahe): Use redirection.
|
| - : re = makeRegExp(other.pattern, "${other.multiLine == true ? 'm' : ''}${
|
| - other.ignoreCase == true ? 'i' : ''}${
|
| - global == true ? 'g' : ''}");
|
| + final String pattern;
|
| + final bool multiLine;
|
| + final bool ignoreCase;
|
| + final bool global;
|
| +
|
| + const RegExpWrapper(this.pattern,
|
| + this.multiLine, this.ignoreCase, this.global);
|
| +
|
| + const RegExpWrapper.fromRegExp(other, global)
|
| + : this(other.pattern, other.multiLine, other.ignoreCase, global);
|
|
|
| exec(str) {
|
| var result = JS('List', @'#.exec(#)', re, checkString(str));
|
| @@ -30,10 +24,22 @@ class RegExpWrapper {
|
|
|
| static matchStart(m) => JS('int', @'#.index', m);
|
|
|
| - static makeRegExp(pattern, flags) {
|
| + get re() {
|
| + var r = JS('var', @'#._re', this);
|
| + if (r === null) {
|
| + r = JS('var', @'#._re = #', this, makeRegExp());
|
| + }
|
| + return r;
|
| + }
|
| +
|
| + makeRegExp() {
|
| checkString(pattern);
|
| + StringBuffer sb = new StringBuffer();
|
| + if (multiLine) sb.add('m');
|
| + if (ignoreCase) sb.add('i');
|
| + if (global) sb.add('g');
|
| try {
|
| - return JS('Object', @'new RegExp(#, #)', pattern, flags);
|
| + return JS('Object', @'new RegExp(#, #)', pattern, sb.toString());
|
| } catch (var e) {
|
| throw new IllegalJSRegExpException(pattern,
|
| JS('String', @'String(#)', e));
|
|
|