зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1046647 - Part 4: Replace nsCxPusher in nsDocShell::AddState. r=bholley
This commit is contained in:
Родитель
8de62d70df
Коммит
325adb5305
|
@ -172,11 +172,6 @@ class nsContentUtils
|
|||
public:
|
||||
static nsresult Init();
|
||||
|
||||
/**
|
||||
* Get a JSContext from the document's scope object.
|
||||
*/
|
||||
static JSContext* GetContextFromDocument(nsIDocument *aDocument);
|
||||
|
||||
static bool IsCallerChrome();
|
||||
static bool ThreadsafeIsCallerChrome();
|
||||
static bool IsCallerContentXBL();
|
||||
|
|
|
@ -1939,24 +1939,6 @@ nsContentUtils::InProlog(nsINode *aNode)
|
|||
return !root || doc->IndexOf(aNode) < doc->IndexOf(root);
|
||||
}
|
||||
|
||||
JSContext *
|
||||
nsContentUtils::GetContextFromDocument(nsIDocument *aDocument)
|
||||
{
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(aDocument->GetScopeObject());
|
||||
if (!sgo) {
|
||||
// No script global, no context.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
nsIScriptContext *scx = sgo->GetContext();
|
||||
if (!scx) {
|
||||
// No context left in the scope...
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return scx->GetNativeContext();
|
||||
}
|
||||
|
||||
//static
|
||||
void
|
||||
nsContentUtils::TraceSafeJSContext(JSTracer* aTrc)
|
||||
|
|
|
@ -10772,19 +10772,7 @@ nsDocShell::AddState(JS::Handle<JS::Value> aData, const nsAString& aTitle,
|
|||
nsCOMPtr<nsIPrincipal> origPrincipal = origDocument->NodePrincipal();
|
||||
|
||||
scContainer = new nsStructuredCloneContainer();
|
||||
JSContext *cx = aCx;
|
||||
nsCxPusher pusher;
|
||||
if (!cx) {
|
||||
cx = nsContentUtils::GetContextFromDocument(document);
|
||||
pusher.Push(cx);
|
||||
}
|
||||
rv = scContainer->InitFromJSVal(aData, cx);
|
||||
|
||||
// If we're running in the document's context and the structured clone
|
||||
// failed, clear the context's pending exception. See bug 637116.
|
||||
if (NS_FAILED(rv) && !aCx) {
|
||||
JS_ClearPendingException(aCx);
|
||||
}
|
||||
rv = scContainer->InitFromJSVal(aData);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIDocument> newDocument = GetDocument();
|
||||
|
|
|
@ -8,15 +8,18 @@
|
|||
#include "nsStructuredCloneContainer.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIScriptContext.h"
|
||||
#include "nsIGlobalObject.h"
|
||||
#include "nsIVariant.h"
|
||||
#include "nsIXPConnect.h"
|
||||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsContentUtils.h"
|
||||
#include "jsapi.h"
|
||||
#include "jsfriendapi.h"
|
||||
#include "js/StructuredClone.h"
|
||||
#include "xpcpublic.h"
|
||||
|
||||
#include "mozilla/Base64.h"
|
||||
#include "mozilla/dom/ScriptSettings.h"
|
||||
|
||||
using namespace mozilla;
|
||||
|
||||
|
@ -39,22 +42,31 @@ nsStructuredCloneContainer::~nsStructuredCloneContainer()
|
|||
}
|
||||
|
||||
nsresult
|
||||
nsStructuredCloneContainer::InitFromJSVal(JS::Handle<JS::Value> aData,
|
||||
JSContext* aCx)
|
||||
nsStructuredCloneContainer::InitFromJSVal(JS::Handle<JS::Value> aData)
|
||||
{
|
||||
NS_ENSURE_STATE(!mData);
|
||||
NS_ENSURE_ARG_POINTER(aCx);
|
||||
|
||||
// Make sure that we serialize in the right context.
|
||||
MOZ_ASSERT(aCx == nsContentUtils::GetCurrentJSContext());
|
||||
JS::Rooted<JS::Value> jsData(aCx, aData);
|
||||
bool success = JS_WrapValue(aCx, &jsData);
|
||||
NS_ENSURE_STATE(success);
|
||||
|
||||
uint64_t* jsBytes = nullptr;
|
||||
success = JS_WriteStructuredClone(aCx, jsData, &jsBytes, &mSize,
|
||||
nullptr, nullptr,
|
||||
JS::UndefinedHandleValue);
|
||||
bool success = false;
|
||||
if (aData.isPrimitive()) {
|
||||
// |aData| is a primitive, so the structured clone algorithm won't run
|
||||
// script and we can just use AutoJSAPI.
|
||||
dom::AutoJSAPI jsapi;
|
||||
jsapi.Init();
|
||||
success = JS_WriteStructuredClone(jsapi.cx(), aData, &jsBytes, &mSize,
|
||||
nullptr, nullptr,
|
||||
JS::UndefinedHandleValue);
|
||||
} else {
|
||||
// |aData| is an object and the structured clone algorithm can run script as
|
||||
// part of the "own" "deep clone" sub-steps, so we need an AutoEntryScript.
|
||||
// http://www.whatwg.org/specs/web-apps/current-work/#internal-structured-cloning-algorithm
|
||||
nsIGlobalObject* nativeGlobal =
|
||||
xpc::GetNativeForGlobal(js::GetGlobalForObjectCrossCompartment(&aData.toObject()));
|
||||
dom::AutoEntryScript aes(nativeGlobal);
|
||||
success = JS_WriteStructuredClone(aes.cx(), aData, &jsBytes, &mSize,
|
||||
nullptr, nullptr,
|
||||
JS::UndefinedHandleValue);
|
||||
}
|
||||
NS_ENSURE_STATE(success);
|
||||
NS_ENSURE_STATE(jsBytes);
|
||||
|
||||
|
|
|
@ -27,14 +27,14 @@ interface nsIDocument;
|
|||
* string containing a copy of the container's serialized data, using
|
||||
* getDataAsBase64.
|
||||
*/
|
||||
[scriptable, uuid(c8852f01-4c05-47c3-acca-253a958f39f6)]
|
||||
[scriptable, uuid(8144021a-7f8a-483a-a0f1-ca02b761403f)]
|
||||
interface nsIStructuredCloneContainer : nsISupports
|
||||
{
|
||||
/**
|
||||
* Initialize this structured clone container so it contains a clone of the
|
||||
* given jsval.
|
||||
*/
|
||||
[noscript, implicit_jscontext]
|
||||
[noscript]
|
||||
void initFromJSVal(in jsval aData);
|
||||
|
||||
/**
|
||||
|
|
Загрузка…
Ссылка в новой задаче