Bug 1083913: Make js::TokenStream::TokenBuf store the starting offset of its buffer explicitly, not implicitly as a bias on base_. r=shu

This commit is contained in:
Jim Blandy 2014-11-12 14:51:40 -08:00
parent e2487efe89
commit 29234315de
2 changed files with 16 additions and 7 deletions

View File

@ -295,7 +295,7 @@ TokenStream::TokenStream(ExclusiveContext *cx, const ReadOnlyCompileOptions &opt
flags(),
linebase(base - options.column),
prevLinebase(nullptr),
userbuf(cx, base - options.column, length + options.column), // See comment below
userbuf(cx, base, length, options.column),
filename(options.filename()),
displayURL_(nullptr),
sourceMapURL_(nullptr),
@ -308,7 +308,6 @@ TokenStream::TokenStream(ExclusiveContext *cx, const ReadOnlyCompileOptions &opt
// initial line's base must be included in the buffer. linebase and userbuf
// were adjusted above, and if we are starting tokenization part way through
// this line then adjust the next character.
userbuf.setAddressOfNextRawChar(base, /* allowPoisoned = */ true);
// Nb: the following tables could be static, but initializing them here is
// much easier. Don't worry, the time to initialize them for each

View File

@ -655,10 +655,18 @@ class MOZ_STACK_CLASS TokenStream
// and do some extra stuff like converting all EOL sequences to '\n',
// tracking the line number, and setting |flags.isEOF|. (The "raw" in "raw
// chars" refers to the lack of EOL sequence normalization.)
//
// buf[0..length-1] often represents a substring of some larger source,
// where we have only the substring in memory. The |startOffset| argument
// indicates the offset within this larger string at which our string
// begins, the offset of |buf[0]|.
class TokenBuf {
public:
TokenBuf(ExclusiveContext *cx, const char16_t *buf, size_t length)
: base_(buf), limit_(buf + length), ptr(buf)
TokenBuf(ExclusiveContext *cx, const char16_t *buf, size_t length, size_t startOffset)
: base_(buf),
startOffset(startOffset),
limit_(buf + length),
ptr(buf)
{ }
bool hasRawChars() const {
@ -670,12 +678,13 @@ class MOZ_STACK_CLASS TokenStream
}
size_t offset() const {
return mozilla::PointerRangeSize(base_, ptr);
return startOffset + mozilla::PointerRangeSize(base_, ptr);
}
const char16_t *rawCharPtrAt(size_t offset) const {
MOZ_ASSERT(base_ + offset <= limit_);
return base_ + offset;
MOZ_ASSERT(startOffset <= offset);
MOZ_ASSERT(offset - startOffset <= mozilla::PointerRangeSize(base_, limit_));
return base_ + (offset - startOffset);
}
const char16_t *limit() const {
@ -740,6 +749,7 @@ class MOZ_STACK_CLASS TokenStream
private:
const char16_t *base_; // base of buffer
uint32_t startOffset; // offset of base_[0]
const char16_t *limit_; // limit for quick bounds check
const char16_t *ptr; // next char to get
};