mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-25 05:41:12 +00:00
Bug 1475228 - Allow construction of a SourceBufferHolder from a UniquePtr r=jandem r=kmag
This commit is contained in:
parent
cdfffa27fe
commit
3fb3cc8a1c
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user