Bug 1023969 - Part 3: Replace AutoPushJSContext in BluetoothManager GetAdapterTask::ParseSuccessfulReply. r=bholley

This commit is contained in:
Bob Owen 2014-06-19 20:17:59 +01:00
Родитель 872cb50d73
Коммит 480df31e2f
1 изменённых файлов: 7 добавлений и 12 удалений

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

@ -18,6 +18,7 @@
#include "nsThreadUtils.h"
#include "mozilla/dom/bluetooth/BluetoothTypes.h"
#include "mozilla/dom/BluetoothManagerBinding.h"
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/Services.h"
using namespace mozilla;
@ -67,20 +68,14 @@ public:
nsRefPtr<BluetoothAdapter> adapter =
BluetoothAdapter::Create(mManagerPtr->GetOwner(), values);
nsresult rv;
nsIScriptContext* sc = mManagerPtr->GetContextForEventHandlers(&rv);
if (!sc) {
BT_WARNING("Cannot create script context!");
SetError(NS_LITERAL_STRING("BluetoothScriptContextError"));
dom::AutoJSAPI jsapi;
if (!jsapi.InitUsingWin(mManagerPtr->GetOwner())) {
BT_WARNING("Failed to initialise AutoJSAPI!");
SetError(NS_LITERAL_STRING("BluetoothAutoJSAPIInitError"));
return false;
}
AutoPushJSContext cx(sc->GetNativeContext());
JS::Rooted<JSObject*> scope(cx, sc->GetWindowProxy());
JSAutoCompartment ac(cx, scope);
rv = nsContentUtils::WrapNative(cx, adapter, aValue);
if (NS_FAILED(rv)) {
JSContext* cx = jsapi.cx();
if (NS_FAILED(nsContentUtils::WrapNative(cx, adapter, aValue))) {
BT_WARNING("Cannot create native object!");
SetError(NS_LITERAL_STRING("BluetoothNativeObjectError"));
return false;