Bug 987556 Part 7 Use JS::SourceBufferHolder in nsFrameMessageManager. r=bz

This commit is contained in:
Ben Kelly 2014-04-25 10:11:56 -04:00
parent 18f3111ceb
commit 85d7ef06d3

View File

@ -1493,6 +1493,8 @@ nsFrameScriptExecutor::TryCacheLoadAndCompileScript(const nsAString& aURL,
nsCOMPtr<nsIInputStream> input; nsCOMPtr<nsIInputStream> input;
channel->Open(getter_AddRefs(input)); channel->Open(getter_AddRefs(input));
nsString dataString; nsString dataString;
jschar* dataStringBuf = nullptr;
size_t dataStringLength = 0;
uint64_t avail64 = 0; uint64_t avail64 = 0;
if (input && NS_SUCCEEDED(input->Available(&avail64)) && avail64) { if (input && NS_SUCCEEDED(input->Available(&avail64)) && avail64) {
if (avail64 > UINT32_MAX) { if (avail64 > UINT32_MAX) {
@ -1504,10 +1506,14 @@ nsFrameScriptExecutor::TryCacheLoadAndCompileScript(const nsAString& aURL,
return; return;
} }
nsScriptLoader::ConvertToUTF16(channel, (uint8_t*)buffer.get(), avail, nsScriptLoader::ConvertToUTF16(channel, (uint8_t*)buffer.get(), avail,
EmptyString(), nullptr, dataString); EmptyString(), nullptr,
dataStringBuf, dataStringLength);
} }
if (!dataString.IsEmpty()) { JS::SourceBufferHolder srcBuf(dataStringBuf, dataStringLength,
JS::SourceBufferHolder::GiveOwnership);
if (dataStringBuf && dataStringLength > 0) {
AutoSafeJSContext cx; AutoSafeJSContext cx;
JS::Rooted<JSObject*> global(cx, mGlobal->GetJSObject()); JS::Rooted<JSObject*> global(cx, mGlobal->GetJSObject());
if (global) { if (global) {
@ -1518,14 +1524,12 @@ nsFrameScriptExecutor::TryCacheLoadAndCompileScript(const nsAString& aURL,
JS::Rooted<JSObject*> funobj(cx); JS::Rooted<JSObject*> funobj(cx);
if (aRunInGlobalScope) { if (aRunInGlobalScope) {
options.setNoScriptRval(true); options.setNoScriptRval(true);
script = JS::Compile(cx, JS::NullPtr(), options, dataString.get(), script = JS::Compile(cx, JS::NullPtr(), options, srcBuf);
dataString.Length());
} else { } else {
JS::Rooted<JSFunction *> fun(cx); JS::Rooted<JSFunction *> fun(cx);
fun = JS::CompileFunction(cx, JS::NullPtr(), options, fun = JS::CompileFunction(cx, JS::NullPtr(), options,
nullptr, 0, nullptr, /* name, nargs, args */ nullptr, 0, nullptr, /* name, nargs, args */
dataString.get(), srcBuf);
dataString.Length());
if (!fun) { if (!fun) {
return; return;
} }