зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1475228 - Allow construction of a SourceBufferHolder from a UniquePtr r=jandem r=kmag
This commit is contained in:
Родитель
4ff436874c
Коммит
827b83bae3
|
@ -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,
|
||||
|
|
Загрузка…
Ссылка в новой задаче