Bug 978042 - Part 6: AutoPushJSContext in nsNPAPIPlugin.cpp _evaluate. r=bholley

This commit is contained in:
Bob Owen 2014-03-09 18:35:52 +00:00
Родитель 7742334529
Коммит 8488284f48
1 изменённых файлов: 10 добавлений и 7 удалений

Просмотреть файл

@ -63,6 +63,7 @@
#endif
#endif
#include "nsJSUtils.h"
#include "nsJSNPRuntime.h"
#include "nsIHttpAuthManager.h"
#include "nsICookieService.h"
@ -1484,11 +1485,13 @@ _evaluate(NPP npp, NPObject* npobj, NPString *script, NPVariant *result)
nsIDocument *doc = GetDocumentFromNPP(npp);
NS_ENSURE_TRUE(doc, false);
AutoPushJSContext cx(GetJSContextFromDoc(doc));
NS_ENSURE_TRUE(cx, false);
nsGlobalWindow* win = static_cast<nsGlobalWindow*>(doc->GetInnerWindow());
if (NS_WARN_IF(!win || !win->FastGetGlobalJSObject())) {
return false;
}
nsCOMPtr<nsIScriptContext> scx = GetScriptContextFromJSContext(cx);
NS_ENSURE_TRUE(scx, false);
AutoSafeJSContext cx;
JSAutoCompartment ac(cx, win->FastGetGlobalJSObject());
JS::Rooted<JSObject*> obj(cx, nsNPObjWrapper::GetNewOrUsed(npp, cx, npobj));
@ -1553,9 +1556,9 @@ _evaluate(NPP npp, NPObject* npobj, NPString *script, NPVariant *result)
options.setFileAndLine(spec, 0)
.setVersion(JSVERSION_DEFAULT);
JS::Rooted<JS::Value> rval(cx);
nsresult rv = scx->EvaluateString(utf16script, obj, options,
/* aCoerceToString = */ false,
rval.address());
nsJSUtils::EvaluateOptions evalOptions;
nsresult rv = nsJSUtils::EvaluateString(cx, utf16script, obj, options,
evalOptions, rval.address());
return NS_SUCCEEDED(rv) &&
(!result || JSValToNPVariant(npp, cx, rval, result));