From f0af93a2925da40cc40eb8baee843dd3b9831e46 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 ccc86152a5a7..b2e06a9863e0 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); }