зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1202048 - Root JSONParser explicitly; r=sfink
--HG-- extra : rebase_source : 432ac026a3bfb4498b1a88e645e0e7468d6ec64a
This commit is contained in:
Родитель
28e9bfed09
Коммит
3c4d6d3a3b
|
@ -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 */
|
||||
|
|
Загрузка…
Ссылка в новой задаче