From 28ec67ce73635184da6634ff21e257d37d58a93f Mon Sep 17 00:00:00 2001 From: Bobby Holley Date: Wed, 10 Oct 2012 11:01:26 +0200 Subject: [PATCH] Bug 797204 - Use JS_GetScriptedCaller instead of JSStackFrames in nsLocation. r=bz --- dom/base/nsLocation.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/dom/base/nsLocation.cpp b/dom/base/nsLocation.cpp index db9d99a01aa..587b91ec023 100644 --- a/dom/base/nsLocation.cpp +++ b/dom/base/nsLocation.cpp @@ -138,14 +138,14 @@ nsLocation::GetDocShell() return docshell; } -// Try to get the the document corresponding to the given JSStackFrame. +// Try to get the the document corresponding to the given JSScript. static already_AddRefed -GetFrameDocument(JSContext *cx, JSStackFrame *fp) +GetScriptDocument(JSContext *cx, JSScript *script) { - if (!cx || !fp) + if (!cx || !script) return nullptr; - JSObject* scope = JS_GetGlobalForFrame(fp); + JSObject* scope = JS_GetGlobalFromScript(script); if (!scope) return nullptr; @@ -206,12 +206,6 @@ nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo) rv = secMan->CheckLoadURIFromScript(cx, aURI); NS_ENSURE_SUCCESS(rv, rv); - // Now get the principal to use when loading the URI - // First, get the principal and frame. - JSStackFrame *fp; - nsIPrincipal* principal = secMan->GetCxSubjectPrincipalAndFrame(cx, &fp); - NS_ENSURE_TRUE(principal, NS_ERROR_FAILURE); - // Make the load's referrer reflect changes to the document's URI caused by // push/replaceState, if possible. First, get the document corresponding to // fp. If the document's original URI (i.e. its URI before @@ -219,7 +213,10 @@ nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo) // current URI as the referrer. If they don't match, use the principal's // URI. - nsCOMPtr doc = GetFrameDocument(cx, fp); + JSScript* script = nullptr; + if (!JS_DescribeScriptedCaller(cx, &script, nullptr)) + return NS_ERROR_FAILURE; + nsCOMPtr doc = GetScriptDocument(cx, script); nsCOMPtr docOriginalURI, docCurrentURI, principalURI; if (doc) { docOriginalURI = doc->GetOriginalURI();