Bug 1475228 - Allow construction of a SourceBufferHolder from a UniquePtr r=jandem r=kmag

This commit is contained in:
Jon Coppeard 2018-07-17 14:30:23 +01:00
Родитель cdfffa27fe
Коммит 3fb3cc8a1c
2 изменённых файлов: 21 добавлений и 10 удалений

Просмотреть файл

@ -391,14 +391,15 @@ class SourceBufferHolder final
length_(dataLength),
ownsChars_(ownership == GiveOwnership)
{
// Ensure that null buffers properly return an unowned, empty,
// null-terminated string.
static const char16_t NullChar_ = 0;
if (!get()) {
data_ = &NullChar_;
length_ = 0;
ownsChars_ = false;
fixEmptyBuffer();
}
SourceBufferHolder(UniqueTwoByteChars&& data, size_t dataLength)
: data_(data.release()),
length_(dataLength),
ownsChars_(true)
{
fixEmptyBuffer();
}
SourceBufferHolder(SourceBufferHolder&& other)
@ -448,6 +449,17 @@ class SourceBufferHolder final
SourceBufferHolder(SourceBufferHolder&) = delete;
SourceBufferHolder& operator=(SourceBufferHolder&) = delete;
void fixEmptyBuffer() {
// Ensure that null buffers properly return an unowned, empty,
// null-terminated string.
static const char16_t NullChar_ = 0;
if (!get()) {
data_ = &NullChar_;
length_ = 0;
ownsChars_ = false;
}
}
const char16_t* data_;
size_t length_;
bool ownsChars_;

Просмотреть файл

@ -131,8 +131,7 @@ AsyncScriptCompiler::StartCompile(JSContext* aCx)
{
Rooted<JSObject*> global(aCx, mGlobalObject->GetGlobalJSObject());
JS::SourceBufferHolder srcBuf(mScriptText.get(), mScriptLength,
JS::SourceBufferHolder::NoOwnership);
JS::SourceBufferHolder srcBuf(std::move(mScriptText), mScriptLength);
if (JS::CanCompileOffThread(aCx, mOptions, mScriptLength)) {
if (!JS::CompileOffThread(aCx, mOptions, srcBuf,
OffThreadScriptLoaderCallback,