bool RegExpMatcher::resetWithTestOptimized(RegExpObject *reobj) { JS_ASSERT(reobj->startsWithAtomizedGreedyStar()); JSAtom *source = &reobj->getSource()->asAtom(); AlreadyIncRefed<RegExpPrivate> priv = RegExpPrivate::createTestOptimized(cx, source, reobj->getFlags()); if (!priv) return false; /* * Create a dummy RegExpObject to persist this RegExpPrivate until the next GC. * Note that we give the ref we have to this new object. */ RegExpObjectBuilder builder(cx); RegExpObject *dummy = builder.build(priv); if (!dummy) { priv->decref(cx); return false; } arc.reset(NeedsIncRef<RegExpPrivate>(priv.get())); return true; }
RegExpPrivate * RegExpObject::makePrivate(JSContext *cx) { JS_ASSERT(!getPrivate()); AlreadyIncRefed<RegExpPrivate> rep = RegExpPrivate::create(cx, getSource(), getFlags(), NULL); if (!rep) return NULL; setPrivate(rep.get()); return rep.get(); }
JSObject * JS_FASTCALL js_CloneRegExpObject(JSContext *cx, JSObject *obj, JSObject *proto) { JS_ASSERT(obj->getClass() == &js_RegExpClass); JS_ASSERT(proto); JS_ASSERT(proto->getClass() == &js_RegExpClass); JSObject *clone = NewNativeClassInstance(cx, &js_RegExpClass, proto, proto->getParent()); if (!clone) return NULL; /* * This clone functionality does not duplicate the JITted code blob, which is necessary for * cross-compartment cloning functionality. */ assertSameCompartment(cx, obj, clone); RegExpStatics *res = cx->regExpStatics(); RegExp *re = RegExp::extractFrom(obj); { uint32 origFlags = re->getFlags(); uint32 staticsFlags = res->getFlags(); if ((origFlags & staticsFlags) != staticsFlags) { /* * This regex is lacking flags from the statics, so we must recompile with the new * flags instead of increffing. */ AlreadyIncRefed<RegExp> clone = RegExp::create(cx, re->getSource(), origFlags | staticsFlags, NULL); if (!clone) return NULL; re = clone.get(); } else { re->incref(cx); } } JS_ASSERT(re); if (!clone->initRegExp(cx, re)) return NULL; return clone; }
/* * Replace the regexp internals of |obj| with |newRegExp|. * Decref the replaced regexp internals. * Note that the refcount of |newRegExp| is unchanged. */ static void SwapObjectRegExp(JSContext *cx, JSObject *obj, AlreadyIncRefed<RegExp> newRegExp) { RegExp *oldRegExp = RegExp::extractFrom(obj); #ifdef DEBUG if (oldRegExp) assertSameCompartment(cx, obj, oldRegExp->compartment); assertSameCompartment(cx, obj, newRegExp->compartment); #endif /* * |obj| isn't a new regular expression, so it won't fail due to failing to * define the initial set of properties. */ JS_ALWAYS_TRUE(obj->initRegExp(cx, newRegExp.get())); if (oldRegExp) oldRegExp->decref(cx); }