зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1575077 - Cleanup ScriptSource::sourceMapURL/displayURL r=jandem
Add accessors to avoid direct access to fields so storage can be changed later. Differential Revision: https://phabricator.services.mozilla.com/D43185 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
cbdc34e90d
Коммит
bcd4f2a178
|
@ -3333,52 +3333,35 @@ XDRResult ScriptSource::XDR(XDRState<mode>* xdr,
|
||||||
MOZ_TRY(xdr->codeUint8(&haveSourceMap));
|
MOZ_TRY(xdr->codeUint8(&haveSourceMap));
|
||||||
|
|
||||||
if (haveSourceMap) {
|
if (haveSourceMap) {
|
||||||
UniqueTwoByteChars& sourceMapURL(ss->sourceMapURL_);
|
XDRTranscodeString<char16_t> chars;
|
||||||
uint32_t sourceMapURLLen =
|
|
||||||
(mode == XDR_DECODE) ? 0 : js_strlen(sourceMapURL.get());
|
|
||||||
MOZ_TRY(xdr->codeUint32(&sourceMapURLLen));
|
|
||||||
|
|
||||||
|
if (mode == XDR_ENCODE) {
|
||||||
|
chars.construct<const char16_t*>(ss->sourceMapURL());
|
||||||
|
}
|
||||||
|
MOZ_TRY(xdr->codeCharsZ(chars));
|
||||||
if (mode == XDR_DECODE) {
|
if (mode == XDR_DECODE) {
|
||||||
sourceMapURL =
|
if (!ss->setSourceMapURL(cx,
|
||||||
xdr->cx()->template make_pod_array<char16_t>(sourceMapURLLen + 1);
|
std::move(chars.ref<UniqueTwoByteChars>()))) {
|
||||||
if (!sourceMapURL) {
|
|
||||||
return xdr->fail(JS::TranscodeResult_Throw);
|
return xdr->fail(JS::TranscodeResult_Throw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto guard = mozilla::MakeScopeExit([&] {
|
|
||||||
if (mode == XDR_DECODE) {
|
|
||||||
sourceMapURL = nullptr;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
MOZ_TRY(xdr->codeChars(sourceMapURL.get(), sourceMapURLLen));
|
|
||||||
guard.release();
|
|
||||||
sourceMapURL[sourceMapURLLen] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t haveDisplayURL = ss->hasDisplayURL();
|
uint8_t haveDisplayURL = ss->hasDisplayURL();
|
||||||
MOZ_TRY(xdr->codeUint8(&haveDisplayURL));
|
MOZ_TRY(xdr->codeUint8(&haveDisplayURL));
|
||||||
|
|
||||||
if (haveDisplayURL) {
|
if (haveDisplayURL) {
|
||||||
UniqueTwoByteChars& displayURL(ss->displayURL_);
|
XDRTranscodeString<char16_t> chars;
|
||||||
uint32_t displayURLLen =
|
|
||||||
(mode == XDR_DECODE) ? 0 : js_strlen(displayURL.get());
|
|
||||||
MOZ_TRY(xdr->codeUint32(&displayURLLen));
|
|
||||||
|
|
||||||
|
if (mode == XDR_ENCODE) {
|
||||||
|
chars.construct<const char16_t*>(ss->displayURL());
|
||||||
|
}
|
||||||
|
MOZ_TRY(xdr->codeCharsZ(chars));
|
||||||
if (mode == XDR_DECODE) {
|
if (mode == XDR_DECODE) {
|
||||||
displayURL =
|
if (!ss->setDisplayURL(cx, std::move(chars.ref<UniqueTwoByteChars>()))) {
|
||||||
xdr->cx()->template make_pod_array<char16_t>(displayURLLen + 1);
|
|
||||||
if (!displayURL) {
|
|
||||||
return xdr->fail(JS::TranscodeResult_Throw);
|
return xdr->fail(JS::TranscodeResult_Throw);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
auto guard = mozilla::MakeScopeExit([&] {
|
|
||||||
if (mode == XDR_DECODE) {
|
|
||||||
displayURL = nullptr;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
MOZ_TRY(xdr->codeChars(displayURL.get(), displayURLLen));
|
|
||||||
guard.release();
|
|
||||||
displayURL[displayURLLen] = '\0';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t haveFilename = !!ss->filename_;
|
uint8_t haveFilename = !!ss->filename_;
|
||||||
|
@ -3512,37 +3495,50 @@ bool ScriptSource::setIntroducerFilename(JSContext* cx,
|
||||||
return true; // Subsequent patch will need this to be fallible.
|
return true; // Subsequent patch will need this to be fallible.
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptSource::setDisplayURL(JSContext* cx, const char16_t* displayURL) {
|
bool ScriptSource::setDisplayURL(JSContext* cx, const char16_t* url) {
|
||||||
MOZ_ASSERT(displayURL);
|
UniqueTwoByteChars owned = DuplicateString(cx, url);
|
||||||
|
if (!owned) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return setDisplayURL(cx, std::move(owned));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ScriptSource::setDisplayURL(JSContext* cx, UniqueTwoByteChars&& url) {
|
||||||
if (hasDisplayURL()) {
|
if (hasDisplayURL()) {
|
||||||
// FIXME: filename_.get() should be UTF-8 (bug 987069).
|
// FIXME: filename() should be UTF-8 (bug 987069).
|
||||||
if (!cx->isHelperThreadContext() &&
|
if (!cx->isHelperThreadContext() &&
|
||||||
!JS_ReportErrorFlagsAndNumberLatin1(
|
!JS_ReportErrorFlagsAndNumberLatin1(
|
||||||
cx, JSREPORT_WARNING, GetErrorMessage, nullptr,
|
cx, JSREPORT_WARNING, GetErrorMessage, nullptr,
|
||||||
JSMSG_ALREADY_HAS_PRAGMA, filename_.get(), "//# sourceURL")) {
|
JSMSG_ALREADY_HAS_PRAGMA, filename(), "//# sourceURL")) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
size_t len = js_strlen(displayURL) + 1;
|
|
||||||
if (len == 1) {
|
MOZ_ASSERT(url);
|
||||||
|
if (url[0] == '\0') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
displayURL_ = DuplicateString(cx, displayURL);
|
displayURL_ = std::move(url);
|
||||||
return displayURL_ != nullptr;
|
return true; // Subsequent patch will need this to be fallible.
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ScriptSource::setSourceMapURL(JSContext* cx,
|
bool ScriptSource::setSourceMapURL(JSContext* cx, const char16_t* url) {
|
||||||
const char16_t* sourceMapURL) {
|
UniqueTwoByteChars owned = DuplicateString(cx, url);
|
||||||
MOZ_ASSERT(sourceMapURL);
|
if (!owned) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return setSourceMapURL(cx, std::move(owned));
|
||||||
|
}
|
||||||
|
|
||||||
size_t len = js_strlen(sourceMapURL) + 1;
|
bool ScriptSource::setSourceMapURL(JSContext* cx, UniqueTwoByteChars&& url) {
|
||||||
if (len == 1) {
|
MOZ_ASSERT(url);
|
||||||
|
if (url[0] == '\0') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sourceMapURL_ = DuplicateString(cx, sourceMapURL);
|
sourceMapURL_ = std::move(url);
|
||||||
return sourceMapURL_ != nullptr;
|
return true; // Subsequent patch will need this to be fallible.
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ mozilla::Atomic<uint32_t, mozilla::SequentiallyConsistent,
|
/* static */ mozilla::Atomic<uint32_t, mozilla::SequentiallyConsistent,
|
||||||
|
|
|
@ -1121,7 +1121,8 @@ class ScriptSource {
|
||||||
uint32_t id() const { return id_; }
|
uint32_t id() const { return id_; }
|
||||||
|
|
||||||
// Display URLs
|
// Display URLs
|
||||||
MOZ_MUST_USE bool setDisplayURL(JSContext* cx, const char16_t* displayURL);
|
MOZ_MUST_USE bool setDisplayURL(JSContext* cx, const char16_t* url);
|
||||||
|
MOZ_MUST_USE bool setDisplayURL(JSContext* cx, UniqueTwoByteChars&& url);
|
||||||
bool hasDisplayURL() const { return displayURL_ != nullptr; }
|
bool hasDisplayURL() const { return displayURL_ != nullptr; }
|
||||||
const char16_t* displayURL() {
|
const char16_t* displayURL() {
|
||||||
MOZ_ASSERT(hasDisplayURL());
|
MOZ_ASSERT(hasDisplayURL());
|
||||||
|
@ -1129,8 +1130,8 @@ class ScriptSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Source maps
|
// Source maps
|
||||||
MOZ_MUST_USE bool setSourceMapURL(JSContext* cx,
|
MOZ_MUST_USE bool setSourceMapURL(JSContext* cx, const char16_t* url);
|
||||||
const char16_t* sourceMapURL);
|
MOZ_MUST_USE bool setSourceMapURL(JSContext* cx, UniqueTwoByteChars&& url);
|
||||||
bool hasSourceMapURL() const { return sourceMapURL_ != nullptr; }
|
bool hasSourceMapURL() const { return sourceMapURL_ != nullptr; }
|
||||||
const char16_t* sourceMapURL() {
|
const char16_t* sourceMapURL() {
|
||||||
MOZ_ASSERT(hasSourceMapURL());
|
MOZ_ASSERT(hasSourceMapURL());
|
||||||
|
|
Загрузка…
Ссылка в новой задаче