author | Tooru Fujisawa <arai_a@mac.com> |
Sat, 05 Sep 2015 21:55:01 +0900 | |
changeset 292167 | 59426007bb575d8e46a3322b14117bb716bd51f4 |
parent 292166 | 28226109634e0589f8ce078ee4985033bc64b08a |
child 292168 | e88d83bf05bd4f3269286d4de9f15ad5c631748d |
push id | 74764 |
push user | arai_a@mac.com |
push date | Thu, 07 Apr 2016 10:49:15 +0000 |
treeherder | mozilla-inbound@4d0f975a2311 [default view] [failures only] |
perfherder | [talos] [build metrics] [platform microbench] (compared to previous push) |
reviewers | h4writer |
bugs | 887016 |
milestone | 48.0a1 |
first release with | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
last release without | nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
|
js/src/builtin/RegExp.cpp | file | annotate | diff | comparison | revisions | |
js/src/builtin/RegExp.h | file | annotate | diff | comparison | revisions |
--- a/js/src/builtin/RegExp.cpp +++ b/js/src/builtin/RegExp.cpp @@ -147,59 +147,98 @@ js::ExecuteRegExpLegacy(JSContext* cx, R /* Forbid an array, as an optimization. */ rval.setBoolean(true); return true; } return CreateRegExpMatchResult(cx, input, matches, rval); } +enum RegExpSharedUse { + UseRegExpShared, + DontUseRegExpShared +}; + /* - * ES6 21.2.3.2.2. Because this function only ever returns |obj| in the spec, - * provided by the user, we omit it and just return the usual success/failure. + * ES 2016 draft Mar 25, 2016 21.2.3.2.2. + * Because this function only ever returns |obj| in the spec, provided by the + * user, we omit it and just return the usual success/failure. */ static bool RegExpInitializeIgnoringLastIndex(JSContext* cx, Handle<RegExpObject*> obj, - HandleValue patternValue, HandleValue flagsValue) + HandleValue patternValue, HandleValue flagsValue, + RegExpSharedUse sharedUse = DontUseRegExpShared) { RootedAtom pattern(cx); if (patternValue.isUndefined()) { /* Step 1. */ pattern = cx->names().empty; } else { - /* Steps 2-3. */ + /* Step 2. */ pattern = ToAtom<CanGC>(cx, patternValue); if (!pattern) return false; } - /* Step 4. */ + /* Step 3. */ RegExpFlag flags = RegExpFlag(0); if (!flagsValue.isUndefined()) { - /* Steps 5-6. */ + /* Step 4. */ RootedString flagStr(cx, ToString<CanGC>(cx, flagsValue)); if (!flagStr) return false; - /* Step 7. */ + /* Step 5. */ if (!ParseRegExpFlags(cx, flagStr, &flags)) return false; } - /* Steps 8-10. */ - CompileOptions options(cx); - frontend::TokenStream dummyTokenStream(cx, options, nullptr, 0, nullptr); - if (!irregexp::ParsePatternSyntax(dummyTokenStream, cx->tempLifoAlloc(), pattern, - flags & UnicodeFlag)) - { - return false; + if (sharedUse == UseRegExpShared) { + /* Steps 7-8. */ + RegExpGuard re(cx); + if (!cx->compartment()->regExps.get(cx, pattern, flags, &re)) + return false; + + /* Steps 9-12. */ + obj->initIgnoringLastIndex(pattern, flags); + + obj->setShared(*re); + } else { + /* Steps 7-8. */ + CompileOptions options(cx); + frontend::TokenStream dummyTokenStream(cx, options, nullptr, 0, nullptr); + if (!irregexp::ParsePatternSyntax(dummyTokenStream, cx->tempLifoAlloc(), pattern, + flags & UnicodeFlag)) + { + return false; + } + + /* Steps 9-12. */ + obj->initIgnoringLastIndex(pattern, flags); } - /* Steps 11-13. */ - obj->initIgnoringLastIndex(pattern, flags); + return true; +} + +/* ES 2016 draft Mar 25, 2016 21.2.3.2.3. */ +bool +js::RegExpCreate(JSContext* cx, HandleValue patternValue, HandleValue flagsValue, + MutableHandleValue rval) +{ + /* Step 1. */ + Rooted<RegExpObject*> regexp(cx, RegExpAlloc(cx, nullptr)); + if (!regexp) + return false; + + /* Step 2. */ + if (!RegExpInitializeIgnoringLastIndex(cx, regexp, patternValue, flagsValue, UseRegExpShared)) + return false; + regexp->zeroLastIndex(cx); + + rval.setObject(*regexp); return true; } MOZ_ALWAYS_INLINE bool IsRegExpObject(HandleValue v) { return v.isObject() && v.toObject().is<RegExpObject>(); }
--- a/js/src/builtin/RegExp.h +++ b/js/src/builtin/RegExp.h @@ -83,16 +83,19 @@ regexp_test_no_statics(JSContext* cx, un * re = regexp_construct(pattern, flags) */ extern bool regexp_construct_self_hosting(JSContext* cx, unsigned argc, Value* vp); extern bool IsRegExp(JSContext* cx, HandleValue value, bool* result); +extern bool +RegExpCreate(JSContext* cx, HandleValue pattern, HandleValue flags, MutableHandleValue rval); + // RegExp ClassSpec members used in RegExpObject.cpp. extern bool regexp_construct(JSContext* cx, unsigned argc, Value* vp); extern const JSPropertySpec regexp_static_props[]; extern const JSPropertySpec regexp_properties[]; extern const JSFunctionSpec regexp_methods[]; // Used in RegExpObject::isOriginalFlagGetter.