mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-06 14:44:26 +00:00
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:
parent
e2487efe89
commit
29234315de
@ -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
|
||||
|
@ -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
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user