mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-24 10:45:42 +00:00
Bug 891215 (part 16) - Slim down RegExpObject-inl.h. r=terrence.
--HG-- extra : rebase_source : b868181ba37ae1332589a08a7d9a97bd649ea115
This commit is contained in:
parent
b4e6f716de
commit
501472fdaf
@ -75,7 +75,17 @@ class MatchPairs
|
||||
void forgetArray() { pairs_ = NULL; }
|
||||
|
||||
void displace(size_t disp);
|
||||
inline void checkAgainst(size_t length);
|
||||
void checkAgainst(size_t inputLength) {
|
||||
#ifdef DEBUG
|
||||
for (size_t i = 0; i < pairCount_; i++) {
|
||||
const MatchPair &p = pair(i);
|
||||
JS_ASSERT(p.check());
|
||||
if (p.isUndefined())
|
||||
continue;
|
||||
JS_ASSERT(size_t(p.limit) <= inputLength);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public:
|
||||
/* Querying functions in the style of RegExpStatics. */
|
||||
|
@ -11,35 +11,8 @@
|
||||
|
||||
#include "vm/RegExpObject.h"
|
||||
|
||||
#include "jsstrinlines.h"
|
||||
|
||||
#include "vm/String-inl.h"
|
||||
|
||||
namespace js {
|
||||
|
||||
inline RegExpShared *
|
||||
RegExpObject::maybeShared() const
|
||||
{
|
||||
return static_cast<RegExpShared *>(JSObject::getPrivate());
|
||||
}
|
||||
|
||||
inline void
|
||||
RegExpObject::shared(RegExpGuard *g) const
|
||||
{
|
||||
JS_ASSERT(maybeShared() != NULL);
|
||||
g->init(*maybeShared());
|
||||
}
|
||||
|
||||
inline bool
|
||||
RegExpObject::getShared(ExclusiveContext *cx, RegExpGuard *g)
|
||||
{
|
||||
if (RegExpShared *shared = maybeShared()) {
|
||||
g->init(*shared);
|
||||
return true;
|
||||
}
|
||||
return createShared(cx, g);
|
||||
}
|
||||
|
||||
inline void
|
||||
RegExpObject::setShared(ExclusiveContext *cx, RegExpShared &shared)
|
||||
{
|
||||
@ -89,84 +62,6 @@ RegExpObject::setSticky(bool enabled)
|
||||
setSlot(STICKY_FLAG_SLOT, BooleanValue(enabled));
|
||||
}
|
||||
|
||||
/* This function should be deleted once bad Android platforms phase out. See bug 604774. */
|
||||
inline bool
|
||||
RegExpShared::isJITRuntimeEnabled(JSContext *cx)
|
||||
{
|
||||
#if ENABLE_YARR_JIT
|
||||
# if defined(ANDROID)
|
||||
return !cx->jitIsBroken;
|
||||
# else
|
||||
return true;
|
||||
# endif
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool
|
||||
RegExpToShared(JSContext *cx, HandleObject obj, RegExpGuard *g)
|
||||
{
|
||||
if (obj->is<RegExpObject>())
|
||||
return obj->as<RegExpObject>().getShared(cx, g);
|
||||
return Proxy::regexp_toShared(cx, obj, g);
|
||||
}
|
||||
|
||||
inline void
|
||||
RegExpShared::prepareForUse(ExclusiveContext *cx)
|
||||
{
|
||||
gcNumberWhenUsed = cx->gcNumber();
|
||||
}
|
||||
|
||||
RegExpGuard::RegExpGuard(ExclusiveContext *cx)
|
||||
: re_(NULL), source_(cx)
|
||||
{
|
||||
}
|
||||
|
||||
RegExpGuard::RegExpGuard(ExclusiveContext *cx, RegExpShared &re)
|
||||
: re_(&re), source_(cx, re.source)
|
||||
{
|
||||
re_->incRef();
|
||||
}
|
||||
|
||||
RegExpGuard::~RegExpGuard()
|
||||
{
|
||||
release();
|
||||
}
|
||||
|
||||
inline void
|
||||
RegExpGuard::init(RegExpShared &re)
|
||||
{
|
||||
JS_ASSERT(!initialized());
|
||||
re_ = &re;
|
||||
re_->incRef();
|
||||
source_ = re_->source;
|
||||
}
|
||||
|
||||
inline void
|
||||
RegExpGuard::release()
|
||||
{
|
||||
if (re_) {
|
||||
re_->decRef();
|
||||
re_ = NULL;
|
||||
source_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
inline void
|
||||
MatchPairs::checkAgainst(size_t inputLength)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
for (size_t i = 0; i < pairCount_; i++) {
|
||||
const MatchPair &p = pair(i);
|
||||
JS_ASSERT(p.check());
|
||||
if (p.isUndefined())
|
||||
continue;
|
||||
JS_ASSERT(size_t(p.limit) <= inputLength);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
} /* namespace js */
|
||||
|
||||
#endif /* vm_RegExpObject_inl_h */
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include <stddef.h>
|
||||
#include "jscntxt.h"
|
||||
#include "jsobj.h"
|
||||
#include "jsproxy.h"
|
||||
|
||||
#include "gc/Barrier.h"
|
||||
#include "gc/Marking.h"
|
||||
@ -159,12 +160,26 @@ class RegExpShared
|
||||
}
|
||||
|
||||
/* Static functions to expose some Yarr logic. */
|
||||
static inline bool isJITRuntimeEnabled(JSContext *cx);
|
||||
|
||||
// This function should be deleted once bad Android platforms phase out. See bug 604774.
|
||||
static bool isJITRuntimeEnabled(JSContext *cx) {
|
||||
#if ENABLE_YARR_JIT
|
||||
# if defined(ANDROID)
|
||||
return !cx->jitIsBroken;
|
||||
# else
|
||||
return true;
|
||||
# endif
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
static void reportYarrError(ExclusiveContext *cx, TokenStream *ts, ErrorCode error);
|
||||
static bool checkSyntax(ExclusiveContext *cx, TokenStream *tokenStream, JSLinearString *source);
|
||||
|
||||
/* Called when a RegExpShared is installed into a RegExpObject. */
|
||||
inline void prepareForUse(ExclusiveContext *cx);
|
||||
void prepareForUse(ExclusiveContext *cx) {
|
||||
gcNumberWhenUsed = cx->gcNumber();
|
||||
}
|
||||
|
||||
/* Primary interface: run this regular expression on the given string. */
|
||||
RegExpRunStatus execute(JSContext *cx, const jschar *chars, size_t length,
|
||||
@ -219,13 +234,35 @@ class RegExpGuard
|
||||
void operator=(const RegExpGuard &) MOZ_DELETE;
|
||||
|
||||
public:
|
||||
inline RegExpGuard(ExclusiveContext *cx);
|
||||
inline RegExpGuard(ExclusiveContext *cx, RegExpShared &re);
|
||||
inline ~RegExpGuard();
|
||||
RegExpGuard(ExclusiveContext *cx)
|
||||
: re_(NULL), source_(cx)
|
||||
{}
|
||||
|
||||
RegExpGuard(ExclusiveContext *cx, RegExpShared &re)
|
||||
: re_(&re), source_(cx, re.source)
|
||||
{
|
||||
re_->incRef();
|
||||
}
|
||||
|
||||
~RegExpGuard() {
|
||||
release();
|
||||
}
|
||||
|
||||
public:
|
||||
inline void init(RegExpShared &re);
|
||||
inline void release();
|
||||
void init(RegExpShared &re) {
|
||||
JS_ASSERT(!initialized());
|
||||
re_ = &re;
|
||||
re_->incRef();
|
||||
source_ = re_->source;
|
||||
}
|
||||
|
||||
void release() {
|
||||
if (re_) {
|
||||
re_->decRef();
|
||||
re_ = NULL;
|
||||
source_ = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool initialized() const { return !!re_; }
|
||||
RegExpShared *re() const { JS_ASSERT(initialized()); return re_; }
|
||||
@ -346,8 +383,18 @@ class RegExpObject : public JSObject
|
||||
bool multiline() const { return getSlot(MULTILINE_FLAG_SLOT).toBoolean(); }
|
||||
bool sticky() const { return getSlot(STICKY_FLAG_SLOT).toBoolean(); }
|
||||
|
||||
inline void shared(RegExpGuard *g) const;
|
||||
inline bool getShared(ExclusiveContext *cx, RegExpGuard *g);
|
||||
void shared(RegExpGuard *g) const {
|
||||
JS_ASSERT(maybeShared() != NULL);
|
||||
g->init(*maybeShared());
|
||||
}
|
||||
|
||||
bool getShared(ExclusiveContext *cx, RegExpGuard *g) {
|
||||
if (RegExpShared *shared = maybeShared()) {
|
||||
g->init(*shared);
|
||||
return true;
|
||||
}
|
||||
return createShared(cx, g);
|
||||
}
|
||||
inline void setShared(ExclusiveContext *cx, RegExpShared &shared);
|
||||
|
||||
private:
|
||||
@ -367,7 +414,9 @@ class RegExpObject : public JSObject
|
||||
* Side effect: sets the private field.
|
||||
*/
|
||||
bool createShared(ExclusiveContext *cx, RegExpGuard *g);
|
||||
RegExpShared *maybeShared() const;
|
||||
RegExpShared *maybeShared() const {
|
||||
return static_cast<RegExpShared *>(JSObject::getPrivate());
|
||||
}
|
||||
|
||||
/* Call setShared in preference to setPrivate. */
|
||||
void setPrivate(void *priv) MOZ_DELETE;
|
||||
@ -391,7 +440,12 @@ ParseRegExpFlags(JSContext *cx, JSString *flagStr, RegExpFlag *flagsOut);
|
||||
* to be the private of any RegExpObject.
|
||||
*/
|
||||
inline bool
|
||||
RegExpToShared(JSContext *cx, HandleObject obj, RegExpGuard *g);
|
||||
RegExpToShared(JSContext *cx, HandleObject obj, RegExpGuard *g)
|
||||
{
|
||||
if (obj->is<RegExpObject>())
|
||||
return obj->as<RegExpObject>().getShared(cx, g);
|
||||
return Proxy::regexp_toShared(cx, obj, g);
|
||||
}
|
||||
|
||||
template<XDRMode mode>
|
||||
bool
|
||||
|
Loading…
Reference in New Issue
Block a user