зеркало из https://github.com/mozilla/gecko-dev.git
Bug 757690 - Merge TokenStream::TokenStream() and TokenStream::init(). r=jorendorff.
--HG-- extra : rebase_source : a389e46e1c633a133a2f8b68b3cb5fa186c8c1fd
This commit is contained in:
Родитель
29d446ea56
Коммит
ff71f18d1e
|
@ -94,9 +94,9 @@ frontend::CompileScript(JSContext *cx, JSObject *scopeChain, StackFrame *callerF
|
|||
JS_ASSERT_IF(callerFrame, compileAndGo);
|
||||
JS_ASSERT_IF(staticLevel != 0, callerFrame);
|
||||
|
||||
bool foldConstants = true;
|
||||
Parser parser(cx, principals, originPrincipals, callerFrame, foldConstants, compileAndGo);
|
||||
if (!parser.init(chars, length, filename, lineno, version))
|
||||
Parser parser(cx, principals, originPrincipals, chars, length, filename, lineno, version,
|
||||
callerFrame, /* foldConstants = */ true, compileAndGo);
|
||||
if (!parser.init())
|
||||
return NULL;
|
||||
|
||||
SharedContext sc(cx, /* inFunction = */ false);
|
||||
|
@ -266,8 +266,9 @@ frontend::CompileFunctionBody(JSContext *cx, JSFunction *fun,
|
|||
Bindings *bindings, const jschar *chars, size_t length,
|
||||
const char *filename, unsigned lineno, JSVersion version)
|
||||
{
|
||||
Parser parser(cx, principals, originPrincipals);
|
||||
if (!parser.init(chars, length, filename, lineno, version))
|
||||
Parser parser(cx, principals, originPrincipals, chars, length, filename, lineno, version,
|
||||
/* cfp = */ NULL, /* foldConstants = */ true, /* compileAndGo = */ false);
|
||||
if (!parser.init())
|
||||
return false;
|
||||
|
||||
TokenStream &tokenStream = parser.tokenStream;
|
||||
|
|
|
@ -77,10 +77,12 @@ using namespace js::frontend;
|
|||
#define MUST_MATCH_TOKEN(tt, errno) MUST_MATCH_TOKEN_WITH_FLAGS(tt, errno, 0)
|
||||
|
||||
Parser::Parser(JSContext *cx, JSPrincipals *prin, JSPrincipals *originPrin,
|
||||
const jschar *chars, size_t length, const char *fn, unsigned ln, JSVersion v,
|
||||
StackFrame *cfp, bool foldConstants, bool compileAndGo)
|
||||
: AutoGCRooter(cx, PARSER),
|
||||
context(cx),
|
||||
tokenStream(cx, prin, originPrin),
|
||||
tokenStream(cx, prin, originPrin, chars, length, fn, ln, v),
|
||||
tempPoolMark(NULL),
|
||||
principals(NULL),
|
||||
originPrincipals(NULL),
|
||||
callerFrame(cfp),
|
||||
|
@ -97,19 +99,11 @@ Parser::Parser(JSContext *cx, JSPrincipals *prin, JSPrincipals *originPrin,
|
|||
}
|
||||
|
||||
bool
|
||||
Parser::init(const jschar *base, size_t length, const char *filename, unsigned lineno,
|
||||
JSVersion version)
|
||||
Parser::init()
|
||||
{
|
||||
JSContext *cx = context;
|
||||
if (!cx->ensureParseMapPool())
|
||||
if (!context->ensureParseMapPool())
|
||||
return false;
|
||||
tempPoolMark = cx->tempLifoAlloc().mark();
|
||||
if (!tokenStream.init(base, length, filename, lineno, version)) {
|
||||
cx->tempLifoAlloc().release(tempPoolMark);
|
||||
return false;
|
||||
}
|
||||
if (context->hasRunOption(JSOPTION_STRICT_MODE))
|
||||
tokenStream.setStrictMode();
|
||||
tempPoolMark = context->tempLifoAlloc().mark();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -54,22 +54,21 @@ struct Parser : private AutoGCRooter
|
|||
/* Script can optimize name references based on scope chain. */
|
||||
const bool compileAndGo:1;
|
||||
|
||||
Parser(JSContext *cx, JSPrincipals *prin = NULL, JSPrincipals *originPrin = NULL,
|
||||
StackFrame *cfp = NULL, bool fold = true, bool compileAndGo = false);
|
||||
Parser(JSContext *cx, JSPrincipals *prin, JSPrincipals *originPrin,
|
||||
const jschar *chars, size_t length, const char *fn, unsigned ln, JSVersion version,
|
||||
StackFrame *cfp, bool foldConstants, bool compileAndGo);
|
||||
~Parser();
|
||||
|
||||
friend void AutoGCRooter::trace(JSTracer *trc);
|
||||
friend struct TreeContext;
|
||||
|
||||
/*
|
||||
* Initialize a parser. Parameters are passed on to init tokenStream. The
|
||||
* compiler owns the arena pool "tops-of-stack" space above the current
|
||||
* JSContext.tempLifoAlloc mark. This means you cannot allocate from
|
||||
* tempLifoAlloc and save the pointer beyond the next Parser destructor
|
||||
* invocation.
|
||||
* Initialize a parser. The compiler owns the arena pool "tops-of-stack"
|
||||
* space above the current JSContext.tempLifoAlloc mark. This means you
|
||||
* cannot allocate from tempLifoAlloc and save the pointer beyond the next
|
||||
* Parser destructor invocation.
|
||||
*/
|
||||
bool init(const jschar *base, size_t length, const char *filename, unsigned lineno,
|
||||
JSVersion version);
|
||||
bool init();
|
||||
|
||||
void setPrincipals(JSPrincipals *prin, JSPrincipals *originPrin);
|
||||
|
||||
|
|
|
@ -119,32 +119,35 @@ js::IsIdentifier(JSLinearString *str)
|
|||
#endif
|
||||
|
||||
/* Initialize members that aren't initialized in |init|. */
|
||||
TokenStream::TokenStream(JSContext *cx, JSPrincipals *prin, JSPrincipals *originPrin)
|
||||
: tokens(), tokensRoot(cx, &tokens),
|
||||
cursor(), lookahead(), flags(),
|
||||
linebaseRoot(cx, &linebase), prevLinebaseRoot(cx, &prevLinebase), userbufRoot(cx, &userbuf),
|
||||
sourceMap(), listenerTSData(), tokenbuf(cx),
|
||||
cx(cx), originPrincipals(JSScript::normalizeOriginPrincipals(prin, originPrin))
|
||||
TokenStream::TokenStream(JSContext *cx, JSPrincipals *prin, JSPrincipals *originPrin,
|
||||
const jschar *base, size_t length, const char *fn, unsigned ln,
|
||||
JSVersion v)
|
||||
: tokens(),
|
||||
tokensRoot(cx, &tokens),
|
||||
cursor(),
|
||||
lookahead(),
|
||||
lineno(ln),
|
||||
flags(),
|
||||
linebase(base),
|
||||
prevLinebase(NULL),
|
||||
linebaseRoot(cx, &linebase),
|
||||
prevLinebaseRoot(cx, &prevLinebase),
|
||||
userbuf(base, length),
|
||||
userbufRoot(cx, &userbuf),
|
||||
filename(fn),
|
||||
sourceMap(NULL),
|
||||
listenerTSData(),
|
||||
tokenbuf(cx),
|
||||
version(v),
|
||||
xml(VersionHasXML(v)),
|
||||
cx(cx),
|
||||
originPrincipals(JSScript::normalizeOriginPrincipals(prin, originPrin))
|
||||
{
|
||||
if (originPrincipals)
|
||||
JS_HoldPrincipals(originPrincipals);
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
bool
|
||||
TokenStream::init(const jschar *base, size_t length, const char *fn, unsigned ln, JSVersion v)
|
||||
{
|
||||
filename = fn;
|
||||
lineno = ln;
|
||||
version = v;
|
||||
xml = VersionHasXML(v);
|
||||
|
||||
userbuf.init(base, length);
|
||||
linebase = base;
|
||||
prevLinebase = NULL;
|
||||
if (cx->hasRunOption(JSOPTION_STRICT_MODE))
|
||||
setStrictMode();
|
||||
|
||||
JSSourceHandler listener = cx->runtime->debugHooks.sourceHandler;
|
||||
void *listenerData = cx->runtime->debugHooks.sourceHandlerData;
|
||||
|
@ -206,9 +209,12 @@ TokenStream::init(const jschar *base, size_t length, const char *fn, unsigned ln
|
|||
* way to address the dependency from statements on the current token.
|
||||
*/
|
||||
tokens[0].pos.begin.lineno = tokens[0].pos.end.lineno = ln;
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
TokenStream::~TokenStream()
|
||||
{
|
||||
if (flags & TSF_OWNFILENAME)
|
||||
|
@ -263,8 +269,8 @@ TokenStream::getChar()
|
|||
* are by the far the most common) this gives false positives for '('
|
||||
* (0x0028) and ')' (0x0029). We could avoid those by incorporating
|
||||
* the 13th bit of d into the lookup, but that requires extra shifting
|
||||
* and masking and isn't worthwhile. See TokenStream::init() for the
|
||||
* initialization of the relevant entries in the table.
|
||||
* and masking and isn't worthwhile. See TokenStream::TokenStream()
|
||||
* for the initialization of the relevant entries in the table.
|
||||
*/
|
||||
if (JS_UNLIKELY(maybeEOL[c & 0xff])) {
|
||||
if (c == '\n')
|
||||
|
|
|
@ -427,24 +427,9 @@ class TokenStream
|
|||
public:
|
||||
typedef Vector<jschar, 32> CharBuffer;
|
||||
|
||||
/*
|
||||
* To construct a TokenStream, first call the constructor, which is
|
||||
* infallible, then call |init|, which can fail. To destroy a TokenStream,
|
||||
* first call |close| then call the destructor. If |init| fails, do not call
|
||||
* |close|.
|
||||
*
|
||||
* This class uses JSContext.tempLifoAlloc to allocate internal buffers. The
|
||||
* caller should JS_ARENA_MARK before calling |init| and JS_ARENA_RELEASE
|
||||
* after calling |close|.
|
||||
*/
|
||||
TokenStream(JSContext *, JSPrincipals *principals, JSPrincipals *originPrincipals);
|
||||
|
||||
/*
|
||||
* Create a new token stream from an input buffer.
|
||||
* Return false on memory-allocation failure.
|
||||
*/
|
||||
bool init(const jschar *base, size_t length, const char *filename, unsigned lineno,
|
||||
JSVersion version);
|
||||
TokenStream(JSContext *, JSPrincipals *principals, JSPrincipals *originPrincipals,
|
||||
const jschar *base, size_t length, const char *filename, unsigned lineno,
|
||||
JSVersion version);
|
||||
~TokenStream();
|
||||
|
||||
/* Accessors. */
|
||||
|
@ -652,12 +637,8 @@ class TokenStream
|
|||
*/
|
||||
class TokenBuf {
|
||||
public:
|
||||
TokenBuf() : base(NULL), limit(NULL), ptr(NULL) { }
|
||||
|
||||
void init(const jschar *buf, size_t length) {
|
||||
base = ptr = buf;
|
||||
limit = base + length;
|
||||
}
|
||||
TokenBuf(const jschar *buf, size_t length)
|
||||
: base(buf), limit(buf + length), ptr(buf), ptrWhenPoisoned(NULL) { }
|
||||
|
||||
bool hasRawChars() const {
|
||||
return ptr < limit;
|
||||
|
|
|
@ -4970,8 +4970,10 @@ JS_BufferIsCompilableUnit(JSContext *cx, JSBool bytes_are_utf8, JSObject *obj, c
|
|||
result = JS_TRUE;
|
||||
exnState = JS_SaveExceptionState(cx);
|
||||
{
|
||||
Parser parser(cx);
|
||||
if (parser.init(chars, length, NULL, 1, cx->findVersion())) {
|
||||
Parser parser(cx, /* prin = */ NULL, /* originPrin = */ NULL,
|
||||
chars, length, /* filename = */ NULL, /* lineno = */ 1, cx->findVersion(),
|
||||
/* cfp = */ NULL, /* foldConstants = */ true, /* compileAndGo = */ false);
|
||||
if (parser.init()) {
|
||||
older = JS_SetErrorReporter(cx, NULL);
|
||||
if (!parser.parse(obj) &&
|
||||
parser.tokenStream.isUnexpectedEOF()) {
|
||||
|
|
|
@ -1086,9 +1086,8 @@ Function(JSContext *cx, unsigned argc, Value *vp)
|
|||
}
|
||||
|
||||
/* Initialize a tokenstream that reads from the given string. */
|
||||
TokenStream ts(cx, principals, originPrincipals);
|
||||
if (!ts.init(collected_args, args_length, filename, lineno, cx->findVersion()))
|
||||
return false;
|
||||
TokenStream ts(cx, principals, originPrincipals,
|
||||
collected_args, args_length, filename, lineno, cx->findVersion());
|
||||
|
||||
/* The argument string may be empty or contain no tokens. */
|
||||
TokenKind tt = ts.getToken();
|
||||
|
|
|
@ -3164,9 +3164,10 @@ reflect_parse(JSContext *cx, uint32_t argc, jsval *vp)
|
|||
if (!chars)
|
||||
return JS_FALSE;
|
||||
|
||||
Parser parser(cx, NULL, NULL, NULL, false);
|
||||
|
||||
if (!parser.init(chars, length, filename, lineno, cx->findVersion()))
|
||||
Parser parser(cx, /* prin = */ NULL, /* originPrin = */ NULL,
|
||||
chars, length, filename, lineno, cx->findVersion(),
|
||||
/* cfp = */ NULL, /* foldConstants = */ false, /* compileAndGo = */ false);
|
||||
if (!parser.init())
|
||||
return JS_FALSE;
|
||||
|
||||
serialize.setParser(&parser);
|
||||
|
|
|
@ -1764,8 +1764,10 @@ ParseXMLSource(JSContext *cx, JSString *src)
|
|||
}
|
||||
|
||||
{
|
||||
Parser parser(cx);
|
||||
if (parser.init(chars, length, filename, lineno, cx->findVersion())) {
|
||||
Parser parser(cx, /* prin = */ NULL, /* originPrin = */ NULL,
|
||||
chars, length, filename, lineno, cx->findVersion(),
|
||||
/* cfp = */ NULL, /* foldConstants = */ true, /* compileAndGo = */ false);
|
||||
if (parser.init()) {
|
||||
JSObject *scopeChain = GetCurrentScopeChain(cx);
|
||||
if (!scopeChain) {
|
||||
cx->free_(chars);
|
||||
|
|
|
@ -3284,9 +3284,13 @@ Parse(JSContext *cx, unsigned argc, jsval *vp)
|
|||
}
|
||||
|
||||
JSString *scriptContents = JSVAL_TO_STRING(arg0);
|
||||
js::Parser parser(cx);
|
||||
parser.init(JS_GetStringCharsZ(cx, scriptContents), JS_GetStringLength(scriptContents),
|
||||
"<string>", 0, cx->findVersion());
|
||||
js::Parser parser(cx, /* prin = */ NULL, /* originPrin = */ NULL,
|
||||
JS_GetStringCharsZ(cx, scriptContents), JS_GetStringLength(scriptContents),
|
||||
"<string>", /* lineno = */ 0, cx->findVersion(),
|
||||
/* cfp = */ NULL, /* foldConstants = */ true, /* compileAndGo = */ false);
|
||||
if (!parser.init())
|
||||
return JS_FALSE;
|
||||
|
||||
ParseNode *pn = parser.parse(NULL);
|
||||
if (!pn)
|
||||
return JS_FALSE;
|
||||
|
|
Загрузка…
Ссылка в новой задаче