bug #66562: r=harish, sr=brendan, a=blizzard. Make |document.write| work.

This commit is contained in:
scc%mozilla.org 2001-02-13 21:26:58 +00:00
parent 5cc33330bf
commit 94452f35f3
18 changed files with 142 additions and 100 deletions

View File

@ -1899,8 +1899,8 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk) {
// -- Ref: Bug# 22485 --
// Insert the unused input into the source buffer
// as if it was read from the input stream.
// Adding Insert() per vidur!!
mParserContext->mScanner->Insert(mUnusedInput);
// Adding UngetReadable() per vidur!!
mParserContext->mScanner->UngetReadable(mUnusedInput);
mUnusedInput.Truncate(0);
}
}

View File

@ -37,29 +37,6 @@ nsScannerString::nsScannerString(PRUnichar* aStorageStart,
{
}
void
nsScannerString::InsertData(const PRUnichar* aDataStart,
const PRUnichar* aDataEnd)
/*
* Warning: this routine manipulates the shared buffer list in an unexpected way.
* The original design did not really allow for insertions, but this call promises
* that if called for a point after then end of all extant token strings, that no token string
* nor the work string will be invalidated.
*/
{
BufferList()->SplitBuffer(StartPosition(), nsSharedBufferList::kSplitCopyRightData);
// splitting to the right keeps the work string and any extant token pointing to and
// holding a reference count on the same buffer
Buffer* new_buffer = nsSharedBufferList::NewSingleAllocationBuffer(aDataStart, aDataEnd-aDataStart, 0);
// make a new buffer with all the data to insert...
// BULLSHIT ALERT: we may have empty space to re-use in the split buffer, measure the cost
// of this and decide if we should do the work to fill it
Buffer* buffer_to_split = StartPosition().mBuffer;
BufferList()->LinkBuffer(buffer_to_split, new_buffer, buffer_to_split->mNext);
}
void
nsScannerString::ReplaceCharacter(nsReadingIterator<PRUnichar>& aPosition,
PRUnichar aChar)
@ -279,10 +256,13 @@ void nsScanner::Mark() {
* @update harishd 01/12/99
* @return error code
*/
PRBool nsScanner::Insert(const nsAReadableString& aBuffer) {
// XXX This is where insertion of a buffer at the head
// of the buffer list will take place pending checkins
// from scc.
PRBool nsScanner::UngetReadable(const nsAReadableString& aBuffer) {
mSlidingBuffer->UngetReadable(aBuffer,mCurrentPosition);
mSlidingBuffer->BeginReading(mCurrentPosition); // Insertion invalidated our iterators
mSlidingBuffer->EndReading(mEndPosition);
mTotalRead += aBuffer.Length();
return PR_TRUE;
}

View File

@ -48,8 +48,7 @@ class nsScannerString : public nsSlidingString {
nsScannerString(PRUnichar* aStorageStart,
PRUnichar* aDataEnd,
PRUnichar* aStorageEnd);
virtual void InsertData(const PRUnichar* aDataStart,
const PRUnichar* aDataEnd);
virtual void UngetReadable(const nsAReadableString& aReadable, const nsReadingIterator<PRUnichar>& aCurrentPosition) { InsertReadable(aReadable,aCurrentPosition); }
virtual void ReplaceCharacter(nsReadingIterator<PRUnichar>& aPosition,
PRUnichar aChar);
};
@ -260,7 +259,7 @@ class nsScanner {
* @param
* @return
*/
PRBool Insert(const nsAReadableString& aBuffer);
PRBool UngetReadable(const nsAReadableString& aBuffer);
/**
*

View File

@ -1899,8 +1899,8 @@ nsresult nsParser::ResumeParse(PRBool allowIteration, PRBool aIsFinalChunk) {
// -- Ref: Bug# 22485 --
// Insert the unused input into the source buffer
// as if it was read from the input stream.
// Adding Insert() per vidur!!
mParserContext->mScanner->Insert(mUnusedInput);
// Adding UngetReadable() per vidur!!
mParserContext->mScanner->UngetReadable(mUnusedInput);
mUnusedInput.Truncate(0);
}
}

View File

@ -37,29 +37,6 @@ nsScannerString::nsScannerString(PRUnichar* aStorageStart,
{
}
void
nsScannerString::InsertData(const PRUnichar* aDataStart,
const PRUnichar* aDataEnd)
/*
* Warning: this routine manipulates the shared buffer list in an unexpected way.
* The original design did not really allow for insertions, but this call promises
* that if called for a point after then end of all extant token strings, that no token string
* nor the work string will be invalidated.
*/
{
BufferList()->SplitBuffer(StartPosition(), nsSharedBufferList::kSplitCopyRightData);
// splitting to the right keeps the work string and any extant token pointing to and
// holding a reference count on the same buffer
Buffer* new_buffer = nsSharedBufferList::NewSingleAllocationBuffer(aDataStart, aDataEnd-aDataStart, 0);
// make a new buffer with all the data to insert...
// BULLSHIT ALERT: we may have empty space to re-use in the split buffer, measure the cost
// of this and decide if we should do the work to fill it
Buffer* buffer_to_split = StartPosition().mBuffer;
BufferList()->LinkBuffer(buffer_to_split, new_buffer, buffer_to_split->mNext);
}
void
nsScannerString::ReplaceCharacter(nsReadingIterator<PRUnichar>& aPosition,
PRUnichar aChar)
@ -279,10 +256,13 @@ void nsScanner::Mark() {
* @update harishd 01/12/99
* @return error code
*/
PRBool nsScanner::Insert(const nsAReadableString& aBuffer) {
// XXX This is where insertion of a buffer at the head
// of the buffer list will take place pending checkins
// from scc.
PRBool nsScanner::UngetReadable(const nsAReadableString& aBuffer) {
mSlidingBuffer->UngetReadable(aBuffer,mCurrentPosition);
mSlidingBuffer->BeginReading(mCurrentPosition); // Insertion invalidated our iterators
mSlidingBuffer->EndReading(mEndPosition);
mTotalRead += aBuffer.Length();
return PR_TRUE;
}

View File

@ -48,8 +48,7 @@ class nsScannerString : public nsSlidingString {
nsScannerString(PRUnichar* aStorageStart,
PRUnichar* aDataEnd,
PRUnichar* aStorageEnd);
virtual void InsertData(const PRUnichar* aDataStart,
const PRUnichar* aDataEnd);
virtual void UngetReadable(const nsAReadableString& aReadable, const nsReadingIterator<PRUnichar>& aCurrentPosition) { InsertReadable(aReadable,aCurrentPosition); }
virtual void ReplaceCharacter(nsReadingIterator<PRUnichar>& aPosition,
PRUnichar aChar);
};
@ -260,7 +259,7 @@ class nsScanner {
* @param
* @return
*/
PRBool Insert(const nsAReadableString& aBuffer);
PRBool UngetReadable(const nsAReadableString& aBuffer);
/**
*

View File

@ -183,6 +183,14 @@ class NS_COM nsSharedBufferList
return NS_AllocateContiguousHandleWithData(Buffer_ptr(0), NS_READABLE_CAST(PRUnichar, nsLiteralString(aData, aDataLength)), aAdditionalCapacity);
}
static
Buffer*
NewSingleAllocationBuffer( const nsAReadableString& aReadable, PRUint32 aAdditionalCapacity = 1 )
{
typedef Buffer* Buffer_ptr;
return NS_AllocateContiguousHandleWithData(Buffer_ptr(0), aReadable, aAdditionalCapacity);
}
static
Buffer*
NewWrappingBuffer( PRUnichar* aDataStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd )

View File

@ -160,9 +160,6 @@ class NS_COM nsSlidingString
friend class nsSlidingSubstring;
public:
typedef nsSlidingSharedBufferList::Buffer Buffer;
typedef nsSlidingSharedBufferList::Position Position;
nsSlidingString( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd );
// ...created by consuming ownership of a buffer ... |aStorageStart| must point to something
// that it will be OK for the slidking string to call |nsMemory::Free| on
@ -180,15 +177,7 @@ class NS_COM nsSlidingString
protected:
virtual const PRUnichar* GetReadableFragment( nsReadableFragment<PRUnichar>&, nsFragmentRequest, PRUint32 ) const;
// |using| doesn't work everywhere, so we have to provide accessors for derived classes
Position& StartPosition() { return mStart; }
const Position& StartPosition() const { return mStart; }
Position& EndPosition() { return mEnd; }
const Position& EndPosition() const { return mEnd; }
nsSlidingSharedBufferList* BufferList() { return mBufferList; }
const nsSlidingSharedBufferList* BufferList() const { return mBufferList; }
void InsertReadable( const nsAReadableString&, const nsReadingIterator<PRUnichar>& ); // ...to implement |nsScannerString::UngetReadable|
private:

View File

@ -104,6 +104,7 @@ nsSharedBufferList::SplitBuffer( const Position& aSplitPosition, SplitDispositio
// if the caller specifically asked to split off the right side of the buffer-to-be-split
// or else if they asked for the minimum amount of work, and that turned out to be the right side...
ptrdiff_t savedLength = mTotalDataLength;
if ( aSplitDirection==kSplitCopyRightData ||
( aSplitDirection==kSplitCopyLeastData && ((bufferToSplit->DataLength() >> 1) <= splitOffset) ) )
{
@ -119,6 +120,8 @@ nsSharedBufferList::SplitBuffer( const Position& aSplitPosition, SplitDispositio
LinkBuffer(bufferToSplit->mPrev, new_buffer, bufferToSplit);
bufferToSplit->DataStart(aSplitPosition.mPosInBuffer);
}
mTotalDataLength = savedLength;
// duh! splitting a buffer doesn't change the length.
}

View File

@ -290,6 +290,34 @@ nsSlidingString::AppendBuffer( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PR
mEnd.PointAfter(new_buffer);
}
void
nsSlidingString::InsertReadable( const nsAReadableString& aReadable, const nsReadingIterator<PRUnichar>& aInsertPoint )
/*
* Warning: this routine manipulates the shared buffer list in an unexpected way.
* The original design did not really allow for insertions, but this call promises
* that if called for a point after the end of all extant token strings, that no token string
* or the work string will be invalidated.
*
* This routine is protected because it is the responsibility of the derived class to keep those promises.
*/
{
Position insertPos(aInsertPoint);
mBufferList->SplitBuffer(insertPos, nsSharedBufferList::kSplitCopyRightData);
// splitting to the right keeps the work string and any extant token pointing to and
// holding a reference count on the same buffer
Buffer* new_buffer = nsSharedBufferList::NewSingleAllocationBuffer(aReadable, 0);
// make a new buffer with all the data to insert...
// BULLSHIT ALERT: we may have empty space to re-use in the split buffer, measure the cost
// of this and decide if we should do the work to fill it
Buffer* buffer_to_split = insertPos.mBuffer;
mBufferList->LinkBuffer(buffer_to_split, new_buffer, buffer_to_split->mNext);
mLength += aReadable.Length();
mEnd.PointAfter(mBufferList->GetLastBuffer());
}
void
nsSlidingString::DiscardPrefix( const nsReadingIterator<PRUnichar>& aIter )
{

View File

@ -104,6 +104,7 @@ nsSharedBufferList::SplitBuffer( const Position& aSplitPosition, SplitDispositio
// if the caller specifically asked to split off the right side of the buffer-to-be-split
// or else if they asked for the minimum amount of work, and that turned out to be the right side...
ptrdiff_t savedLength = mTotalDataLength;
if ( aSplitDirection==kSplitCopyRightData ||
( aSplitDirection==kSplitCopyLeastData && ((bufferToSplit->DataLength() >> 1) <= splitOffset) ) )
{
@ -119,6 +120,8 @@ nsSharedBufferList::SplitBuffer( const Position& aSplitPosition, SplitDispositio
LinkBuffer(bufferToSplit->mPrev, new_buffer, bufferToSplit);
bufferToSplit->DataStart(aSplitPosition.mPosInBuffer);
}
mTotalDataLength = savedLength;
// duh! splitting a buffer doesn't change the length.
}

View File

@ -183,6 +183,14 @@ class NS_COM nsSharedBufferList
return NS_AllocateContiguousHandleWithData(Buffer_ptr(0), NS_READABLE_CAST(PRUnichar, nsLiteralString(aData, aDataLength)), aAdditionalCapacity);
}
static
Buffer*
NewSingleAllocationBuffer( const nsAReadableString& aReadable, PRUint32 aAdditionalCapacity = 1 )
{
typedef Buffer* Buffer_ptr;
return NS_AllocateContiguousHandleWithData(Buffer_ptr(0), aReadable, aAdditionalCapacity);
}
static
Buffer*
NewWrappingBuffer( PRUnichar* aDataStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd )

View File

@ -290,6 +290,34 @@ nsSlidingString::AppendBuffer( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PR
mEnd.PointAfter(new_buffer);
}
void
nsSlidingString::InsertReadable( const nsAReadableString& aReadable, const nsReadingIterator<PRUnichar>& aInsertPoint )
/*
* Warning: this routine manipulates the shared buffer list in an unexpected way.
* The original design did not really allow for insertions, but this call promises
* that if called for a point after the end of all extant token strings, that no token string
* or the work string will be invalidated.
*
* This routine is protected because it is the responsibility of the derived class to keep those promises.
*/
{
Position insertPos(aInsertPoint);
mBufferList->SplitBuffer(insertPos, nsSharedBufferList::kSplitCopyRightData);
// splitting to the right keeps the work string and any extant token pointing to and
// holding a reference count on the same buffer
Buffer* new_buffer = nsSharedBufferList::NewSingleAllocationBuffer(aReadable, 0);
// make a new buffer with all the data to insert...
// BULLSHIT ALERT: we may have empty space to re-use in the split buffer, measure the cost
// of this and decide if we should do the work to fill it
Buffer* buffer_to_split = insertPos.mBuffer;
mBufferList->LinkBuffer(buffer_to_split, new_buffer, buffer_to_split->mNext);
mLength += aReadable.Length();
mEnd.PointAfter(mBufferList->GetLastBuffer());
}
void
nsSlidingString::DiscardPrefix( const nsReadingIterator<PRUnichar>& aIter )
{

View File

@ -160,9 +160,6 @@ class NS_COM nsSlidingString
friend class nsSlidingSubstring;
public:
typedef nsSlidingSharedBufferList::Buffer Buffer;
typedef nsSlidingSharedBufferList::Position Position;
nsSlidingString( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd );
// ...created by consuming ownership of a buffer ... |aStorageStart| must point to something
// that it will be OK for the slidking string to call |nsMemory::Free| on
@ -180,15 +177,7 @@ class NS_COM nsSlidingString
protected:
virtual const PRUnichar* GetReadableFragment( nsReadableFragment<PRUnichar>&, nsFragmentRequest, PRUint32 ) const;
// |using| doesn't work everywhere, so we have to provide accessors for derived classes
Position& StartPosition() { return mStart; }
const Position& StartPosition() const { return mStart; }
Position& EndPosition() { return mEnd; }
const Position& EndPosition() const { return mEnd; }
nsSlidingSharedBufferList* BufferList() { return mBufferList; }
const nsSlidingSharedBufferList* BufferList() const { return mBufferList; }
void InsertReadable( const nsAReadableString&, const nsReadingIterator<PRUnichar>& ); // ...to implement |nsScannerString::UngetReadable|
private:

View File

@ -183,6 +183,14 @@ class NS_COM nsSharedBufferList
return NS_AllocateContiguousHandleWithData(Buffer_ptr(0), NS_READABLE_CAST(PRUnichar, nsLiteralString(aData, aDataLength)), aAdditionalCapacity);
}
static
Buffer*
NewSingleAllocationBuffer( const nsAReadableString& aReadable, PRUint32 aAdditionalCapacity = 1 )
{
typedef Buffer* Buffer_ptr;
return NS_AllocateContiguousHandleWithData(Buffer_ptr(0), aReadable, aAdditionalCapacity);
}
static
Buffer*
NewWrappingBuffer( PRUnichar* aDataStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd )

View File

@ -160,9 +160,6 @@ class NS_COM nsSlidingString
friend class nsSlidingSubstring;
public:
typedef nsSlidingSharedBufferList::Buffer Buffer;
typedef nsSlidingSharedBufferList::Position Position;
nsSlidingString( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PRUnichar* aStorageEnd );
// ...created by consuming ownership of a buffer ... |aStorageStart| must point to something
// that it will be OK for the slidking string to call |nsMemory::Free| on
@ -180,15 +177,7 @@ class NS_COM nsSlidingString
protected:
virtual const PRUnichar* GetReadableFragment( nsReadableFragment<PRUnichar>&, nsFragmentRequest, PRUint32 ) const;
// |using| doesn't work everywhere, so we have to provide accessors for derived classes
Position& StartPosition() { return mStart; }
const Position& StartPosition() const { return mStart; }
Position& EndPosition() { return mEnd; }
const Position& EndPosition() const { return mEnd; }
nsSlidingSharedBufferList* BufferList() { return mBufferList; }
const nsSlidingSharedBufferList* BufferList() const { return mBufferList; }
void InsertReadable( const nsAReadableString&, const nsReadingIterator<PRUnichar>& ); // ...to implement |nsScannerString::UngetReadable|
private:

View File

@ -104,6 +104,7 @@ nsSharedBufferList::SplitBuffer( const Position& aSplitPosition, SplitDispositio
// if the caller specifically asked to split off the right side of the buffer-to-be-split
// or else if they asked for the minimum amount of work, and that turned out to be the right side...
ptrdiff_t savedLength = mTotalDataLength;
if ( aSplitDirection==kSplitCopyRightData ||
( aSplitDirection==kSplitCopyLeastData && ((bufferToSplit->DataLength() >> 1) <= splitOffset) ) )
{
@ -119,6 +120,8 @@ nsSharedBufferList::SplitBuffer( const Position& aSplitPosition, SplitDispositio
LinkBuffer(bufferToSplit->mPrev, new_buffer, bufferToSplit);
bufferToSplit->DataStart(aSplitPosition.mPosInBuffer);
}
mTotalDataLength = savedLength;
// duh! splitting a buffer doesn't change the length.
}

View File

@ -290,6 +290,34 @@ nsSlidingString::AppendBuffer( PRUnichar* aStorageStart, PRUnichar* aDataEnd, PR
mEnd.PointAfter(new_buffer);
}
void
nsSlidingString::InsertReadable( const nsAReadableString& aReadable, const nsReadingIterator<PRUnichar>& aInsertPoint )
/*
* Warning: this routine manipulates the shared buffer list in an unexpected way.
* The original design did not really allow for insertions, but this call promises
* that if called for a point after the end of all extant token strings, that no token string
* or the work string will be invalidated.
*
* This routine is protected because it is the responsibility of the derived class to keep those promises.
*/
{
Position insertPos(aInsertPoint);
mBufferList->SplitBuffer(insertPos, nsSharedBufferList::kSplitCopyRightData);
// splitting to the right keeps the work string and any extant token pointing to and
// holding a reference count on the same buffer
Buffer* new_buffer = nsSharedBufferList::NewSingleAllocationBuffer(aReadable, 0);
// make a new buffer with all the data to insert...
// BULLSHIT ALERT: we may have empty space to re-use in the split buffer, measure the cost
// of this and decide if we should do the work to fill it
Buffer* buffer_to_split = insertPos.mBuffer;
mBufferList->LinkBuffer(buffer_to_split, new_buffer, buffer_to_split->mNext);
mLength += aReadable.Length();
mEnd.PointAfter(mBufferList->GetLastBuffer());
}
void
nsSlidingString::DiscardPrefix( const nsReadingIterator<PRUnichar>& aIter )
{