зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1023778 part 2 - Parameterize JSONParser. r=Waldo
This commit is contained in:
Родитель
956d61eaf6
Коммит
e30254798a
|
@ -173,8 +173,9 @@ TryEvalJSON(JSContext *cx, JSScript *callerScript,
|
|||
|
||||
if (cp == end) {
|
||||
bool isArray = (chars[0] == '[');
|
||||
JSONParser parser(cx, isArray ? chars : chars + 1U, isArray ? length : length - 2,
|
||||
JSONParserBase::NoError);
|
||||
JSONParser<jschar> parser(cx, isArray ? chars : chars + 1U,
|
||||
isArray ? length : length - 2,
|
||||
JSONParserBase::NoError);
|
||||
RootedValue tmp(cx);
|
||||
if (!parser.parse(&tmp))
|
||||
return EvalJSON_Failure;
|
||||
|
|
|
@ -777,7 +777,7 @@ js::ParseJSONWithReviver(JSContext *cx, ConstTwoByteChars chars, size_t length,
|
|||
HandleValue reviver, MutableHandleValue vp)
|
||||
{
|
||||
/* 15.12.2 steps 2-3. */
|
||||
JSONParser parser(cx, chars, length);
|
||||
JSONParser<jschar> parser(cx, chars, length);
|
||||
if (!parser.parse(vp))
|
||||
return false;
|
||||
|
||||
|
|
|
@ -57,10 +57,11 @@ JSONParserBase::trace(JSTracer *trc)
|
|||
}
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
void
|
||||
JSONParser::getTextPosition(uint32_t *column, uint32_t *line)
|
||||
JSONParser<CharT>::getTextPosition(uint32_t *column, uint32_t *line)
|
||||
{
|
||||
ConstTwoByteChars ptr = begin;
|
||||
CharPtr ptr = begin;
|
||||
uint32_t col = 1;
|
||||
uint32_t row = 1;
|
||||
for (; ptr < current; ptr++) {
|
||||
|
@ -78,8 +79,9 @@ JSONParser::getTextPosition(uint32_t *column, uint32_t *line)
|
|||
*line = row;
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
void
|
||||
JSONParser::error(const char *msg)
|
||||
JSONParser<CharT>::error(const char *msg)
|
||||
{
|
||||
if (errorHandling == RaiseError) {
|
||||
uint32_t column = 1, line = 1;
|
||||
|
@ -102,9 +104,10 @@ JSONParserBase::errorReturn()
|
|||
return errorHandling == NoError;
|
||||
}
|
||||
|
||||
template<JSONParserBase::StringType ST>
|
||||
template <typename CharT>
|
||||
template <JSONParserBase::StringType ST>
|
||||
JSONParserBase::Token
|
||||
JSONParser::readString()
|
||||
JSONParser<CharT>::readString()
|
||||
{
|
||||
JS_ASSERT(current < end);
|
||||
JS_ASSERT(*current == '"');
|
||||
|
@ -236,8 +239,9 @@ JSONParser::readString()
|
|||
return token(Error);
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
JSONParserBase::Token
|
||||
JSONParser::readNumber()
|
||||
JSONParser<CharT>::readNumber()
|
||||
{
|
||||
JS_ASSERT(current < end);
|
||||
JS_ASSERT(JS7_ISDEC(*current) || *current == '-');
|
||||
|
@ -341,8 +345,9 @@ IsJSONWhitespace(jschar c)
|
|||
return c == '\t' || c == '\r' || c == '\n' || c == ' ';
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
JSONParserBase::Token
|
||||
JSONParser::advance()
|
||||
JSONParser<CharT>::advance()
|
||||
{
|
||||
while (current < end && IsJSONWhitespace(*current))
|
||||
current++;
|
||||
|
@ -422,8 +427,9 @@ JSONParser::advance()
|
|||
}
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
JSONParserBase::Token
|
||||
JSONParser::advanceAfterObjectOpen()
|
||||
JSONParser<CharT>::advanceAfterObjectOpen()
|
||||
{
|
||||
JS_ASSERT(current[-1] == '{');
|
||||
|
||||
|
@ -473,8 +479,9 @@ AssertPastValue(const RangedPtr<const jschar> current)
|
|||
JS7_ISDEC(current[-1]));
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
JSONParserBase::Token
|
||||
JSONParser::advanceAfterArrayElement()
|
||||
JSONParser<CharT>::advanceAfterArrayElement()
|
||||
{
|
||||
AssertPastValue(current);
|
||||
|
||||
|
@ -499,8 +506,9 @@ JSONParser::advanceAfterArrayElement()
|
|||
return token(Error);
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
JSONParserBase::Token
|
||||
JSONParser::advancePropertyName()
|
||||
JSONParser<CharT>::advancePropertyName()
|
||||
{
|
||||
JS_ASSERT(current[-1] == ',');
|
||||
|
||||
|
@ -518,8 +526,9 @@ JSONParser::advancePropertyName()
|
|||
return token(Error);
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
JSONParserBase::Token
|
||||
JSONParser::advancePropertyColon()
|
||||
JSONParser<CharT>::advancePropertyColon()
|
||||
{
|
||||
JS_ASSERT(current[-1] == '"');
|
||||
|
||||
|
@ -539,8 +548,9 @@ JSONParser::advancePropertyColon()
|
|||
return token(Error);
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
JSONParserBase::Token
|
||||
JSONParser::advanceAfterProperty()
|
||||
JSONParser<CharT>::advanceAfterProperty()
|
||||
{
|
||||
AssertPastValue(current);
|
||||
|
||||
|
@ -645,8 +655,9 @@ JSONParserBase::finishArray(MutableHandleValue vp, ElementVector &elements)
|
|||
return true;
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
bool
|
||||
JSONParser::parse(MutableHandleValue vp)
|
||||
JSONParser<CharT>::parse(MutableHandleValue vp)
|
||||
{
|
||||
RootedValue value(cx);
|
||||
JS_ASSERT(stack.empty());
|
||||
|
@ -815,3 +826,5 @@ JSONParser::parse(MutableHandleValue vp)
|
|||
vp.set(value);
|
||||
return true;
|
||||
}
|
||||
|
||||
template class js::JSONParser<jschar>;
|
||||
|
|
|
@ -178,17 +178,20 @@ class MOZ_STACK_CLASS JSONParserBase : private JS::AutoGCRooter
|
|||
void operator=(const JSONParserBase &other) MOZ_DELETE;
|
||||
};
|
||||
|
||||
template <typename CharT>
|
||||
class MOZ_STACK_CLASS JSONParser : public JSONParserBase
|
||||
{
|
||||
private:
|
||||
JS::ConstTwoByteChars current;
|
||||
const JS::ConstTwoByteChars begin, end;
|
||||
typedef mozilla::RangedPtr<const CharT> CharPtr;
|
||||
|
||||
CharPtr current;
|
||||
const CharPtr begin, end;
|
||||
|
||||
public:
|
||||
/* Public API */
|
||||
|
||||
/* Create a parser for the provided JSON data. */
|
||||
JSONParser(JSContext *cx, JS::ConstTwoByteChars data, size_t length,
|
||||
JSONParser(JSContext *cx, CharPtr data, size_t length,
|
||||
ErrorHandling errorHandling = RaiseError)
|
||||
: JSONParserBase(cx, errorHandling),
|
||||
current(data),
|
||||
|
|
Загрузка…
Ссылка в новой задаче