From ac8a8762399f02d48bddab6cc712b3cf74ee8e60 Mon Sep 17 00:00:00 2001 From: Hannes Verschore Date: Fri, 1 Nov 2013 14:47:44 +0100 Subject: [PATCH] Bug 925949: Add fastpath to zeroLastIndex the normal RegExpObject, r=jwalden --- js/src/jsstr.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/js/src/jsstr.cpp b/js/src/jsstr.cpp index ccc86152a5a..b2e06a9863e 100644 --- a/js/src/jsstr.cpp +++ b/js/src/jsstr.cpp @@ -1788,8 +1788,14 @@ class MOZ_STACK_CLASS StringRegExpGuard if (!regExpIsObject()) return true; - // Don't use RegExpObject::setLastIndex, because that ignores the - // writability of "lastIndex" on this user-controlled RegExp object. + // Use a fast path for same-global RegExp objects with writable + // lastIndex. + if (obj_->is() && obj_->nativeLookup(cx, cx->names().lastIndex)->writable()) { + obj_->as().zeroLastIndex(); + return true; + } + + // Handle everything else generically (including throwing if .lastIndex is non-writable). RootedValue zero(cx, Int32Value(0)); return JSObject::setProperty(cx, obj_, obj_, cx->names().lastIndex, &zero, true); }