Skip to content

Commit

Permalink
Bug 1475228 - Allow construction of a SourceBufferHolder from a Uniqu…
Browse files Browse the repository at this point in the history
…ePtr r=jandem r=kmag
  • Loading branch information
jonco3 committed Jul 17, 2018
1 parent cf5ef1c commit 173b4c6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
28 changes: 20 additions & 8 deletions js/src/jsapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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_;
Expand Down
3 changes: 1 addition & 2 deletions js/xpconnect/loader/ChromeScriptLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 173b4c6

Please sign in to comment.