Bug 1253099 - Add some comments. r=arai, r=efaust

--HG--
extra : rebase_source : 7996749d247d3680285bbe25f61497b4394d8458
This commit is contained in:
Jeff Walden 2016-03-10 19:40:58 -08:00
parent 176f2f5a05
commit b99315effb
2 changed files with 20 additions and 3 deletions

View File

@ -24,8 +24,8 @@
using namespace js;
using namespace js::unicode;
using mozilla::CheckedInt;
using mozilla::ArrayLength;
using mozilla::CheckedInt;
using mozilla::Maybe;
/*
@ -187,8 +187,18 @@ enum RegExpSharedUse {
/*
* 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.
*
* Steps 14-15 set |obj|'s "lastIndex" property to zero. Some of
* RegExpInitialize's callers have a fresh RegExp not yet exposed to script:
* in these cases zeroing "lastIndex" is infallible. But others have a RegExp
* whose "lastIndex" property might have been made non-writable: here, zeroing
* "lastIndex" can fail. We efficiently solve this problem by completely
* removing "lastIndex" zeroing from the provided function.
*
* CALLERS MUST HANDLE "lastIndex" ZEROING THEMSELVES!
*
* Because this function only ever returns a user-provided |obj| in the spec,
* we omit it and just return the usual success/failure.
*/
static bool
RegExpInitializeIgnoringLastIndex(JSContext* cx, Handle<RegExpObject*> obj,
@ -347,6 +357,10 @@ regexp_compile_impl(JSContext* cx, const CallArgs& args)
return false;
}
// The final niggling bit of step 5.
//
// |regexp| is user-exposed, but if its "lastIndex" property hasn't been
// made non-writable, we can still use a fast path to zero it.
if (regexp->lookupPure(cx->names().lastIndex)->writable()) {
regexp->zeroLastIndex(cx);
} else {

View File

@ -485,6 +485,9 @@ class RegExpObject : public NativeObject
void initIgnoringLastIndex(HandleAtom source, RegExpFlag flags);
// NOTE: This method is *only* safe to call on RegExps that haven't been
// exposed to script, because it requires that the "lastIndex"
// property be writable.
void initAndZeroLastIndex(HandleAtom source, RegExpFlag flags, ExclusiveContext* cx);
private: