Bug 1202048 - Root JSONParser explicitly; r=sfink

--HG--
extra : rebase_source : 6ed56523f0d4999762b89d8feb7ebb3738fb5be4
This commit is contained in:
Terrence Cole 2015-08-20 12:26:45 -07:00
Родитель 64db2267cf
Коммит c664099840
5 изменённых файлов: 39 добавлений и 13 удалений

Просмотреть файл

@ -183,7 +183,7 @@ ParseEvalStringAsJSON(JSContext* cx, const mozilla::Range<const CharT> chars, Mu
? chars
: mozilla::Range<const CharT>(chars.start().get() + 1U, len - 2);
JSONParser<CharT> parser(cx, jsonChars, JSONParserBase::NoError);
Rooted<JSONParser<CharT>> parser(cx, JSONParser<CharT>(cx, jsonChars, JSONParserBase::NoError));
if (!parser.parse(rval))
return EvalJSON_Failure;

Просмотреть файл

@ -146,10 +146,6 @@ AutoGCRooter::trace(JSTracer* trc)
return;
}
case JSONPARSER:
static_cast<js::JSONParserBase*>(this)->trace(trc);
return;
case CUSTOM:
static_cast<JS::CustomAutoRooter*>(this)->trace(trc);
return;

Просмотреть файл

@ -822,7 +822,7 @@ js::ParseJSONWithReviver(JSContext* cx, const mozilla::Range<const CharT> chars,
MutableHandleValue vp)
{
/* 15.12.2 steps 2-3. */
JSONParser<CharT> parser(cx, chars);
Rooted<JSONParser<CharT>> parser(cx, JSONParser<CharT>(cx, chars));
if (!parser.parse(vp))
return false;

Просмотреть файл

@ -224,7 +224,6 @@ class JS_PUBLIC_API(AutoGCRooter)
IONMASM = -19, /* js::jit::MacroAssembler */
WRAPVECTOR = -20, /* js::AutoWrapperVector */
WRAPPER = -21, /* js::AutoWrapperRooter */
JSONPARSER = -25, /* js::JSONParser */
CUSTOM = -26 /* js::CustomAutoRooter */
};

Просмотреть файл

@ -20,7 +20,7 @@ namespace js {
// JSONParser base class. JSONParser is templatized to work on either Latin1
// or TwoByte input strings, JSONParserBase holds all state and methods that
// can be shared between the two encodings.
class MOZ_STACK_CLASS JSONParserBase : private JS::AutoGCRooter
class MOZ_STACK_CLASS JSONParserBase
{
public:
enum ErrorHandling { RaiseError, NoError };
@ -108,8 +108,7 @@ class MOZ_STACK_CLASS JSONParserBase : private JS::AutoGCRooter
#endif
JSONParserBase(JSContext* cx, ErrorHandling errorHandling)
: JS::AutoGCRooter(cx, JSONPARSER),
cx(cx),
: cx(cx),
errorHandling(errorHandling),
stack(cx),
freeElements(cx),
@ -120,6 +119,20 @@ class MOZ_STACK_CLASS JSONParserBase : private JS::AutoGCRooter
{}
~JSONParserBase();
// Allow move construction for use with Rooted.
JSONParserBase(JSONParserBase&& other)
: v(other.v),
cx(other.cx),
errorHandling(other.errorHandling),
stack(mozilla::Move(other.stack)),
freeElements(mozilla::Move(other.freeElements)),
freeProperties(mozilla::Move(other.freeProperties))
#ifdef DEBUG
, lastToken(mozilla::Move(other.lastToken))
#endif
{}
Value numberValue() const {
MOZ_ASSERT(lastToken == Number);
MOZ_ASSERT(v.isNumber());
@ -169,16 +182,16 @@ class MOZ_STACK_CLASS JSONParserBase : private JS::AutoGCRooter
bool finishObject(MutableHandleValue vp, PropertyVector& properties);
bool finishArray(MutableHandleValue vp, ElementVector& elements);
private:
friend void AutoGCRooter::trace(JSTracer* trc);
void trace(JSTracer* trc);
private:
JSONParserBase(const JSONParserBase& other) = delete;
void operator=(const JSONParserBase& other) = delete;
};
template <typename CharT>
class MOZ_STACK_CLASS JSONParser : public JSONParserBase
class MOZ_STACK_CLASS JSONParser : public JSONParserBase,
public JS::Traceable
{
private:
typedef mozilla::RangedPtr<const CharT> CharPtr;
@ -200,6 +213,14 @@ class MOZ_STACK_CLASS JSONParser : public JSONParserBase
MOZ_ASSERT(current <= end);
}
/* Allow move construction for use with Rooted. */
JSONParser(JSONParser&& other)
: JSONParserBase(mozilla::Forward<JSONParser>(other)),
current(other.current),
begin(other.begin),
end(other.end)
{}
/*
* Parse the JSON data specified at construction time. If it parses
* successfully, store the prescribed value in *vp and return true. If an
@ -212,6 +233,9 @@ class MOZ_STACK_CLASS JSONParser : public JSONParserBase
*/
bool parse(MutableHandleValue vp);
static void trace(JSONParser<CharT>* parser, JSTracer* trc) { parser->trace(trc); }
void trace(JSTracer* trc) { JSONParserBase::trace(trc); }
private:
template<StringType ST> Token readString();
@ -233,6 +257,13 @@ class MOZ_STACK_CLASS JSONParser : public JSONParserBase
void operator=(const JSONParser& other) = delete;
};
template <typename CharT>
struct RootedBase<JSONParser<CharT>> {
bool parse(MutableHandleValue vp) {
return static_cast<Rooted<JSONParser<CharT>>*>(this)->get().parse(vp);
}
};
} /* namespace js */
#endif /* vm_JSONParser_h */