Beispiel #1
0
/*
 * 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);
}