static JSBool setStepMode(JSContext *cx, unsigned argc, jsval *vp) { JSScript *script; JS_DescribeScriptedCaller(cx, &script, NULL); JS_ASSERT(script); if (!JS_SetSingleStepMode(cx, script, true)) return false; JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; }
static bool setStepMode(JSContext *cx, unsigned argc, jsval *vp) { JS::RootedScript script(cx); JS_DescribeScriptedCaller(cx, &script, nullptr); JS_ASSERT(script); if (!JS_SetSingleStepMode(cx, script, true)) return false; JS_SET_RVAL(cx, vp, JSVAL_VOID); return true; }
bool nsJSUtils::GetCallingLocation(JSContext* aContext, const char* *aFilename, uint32_t* aLineno) { JSScript* script = nullptr; unsigned lineno = 0; if (!JS_DescribeScriptedCaller(aContext, &script, &lineno)) { return false; } *aFilename = ::JS_GetScriptFilename(aContext, script); *aLineno = lineno; return true; }
nsresult nsLocation::CheckURL(nsIURI* aURI, nsIDocShellLoadInfo** aLoadInfo) { *aLoadInfo = nullptr; nsCOMPtr<nsIDocShell> docShell(do_QueryReferent(mDocShell)); NS_ENSURE_TRUE(docShell, NS_ERROR_NOT_AVAILABLE); nsCOMPtr<nsISupports> owner; nsCOMPtr<nsIURI> sourceURI; if (JSContext *cx = nsContentUtils::GetCurrentJSContext()) { // No cx means that there's no JS running, or at least no JS that // was run through code that properly pushed a context onto the // context stack (as all code that runs JS off of web pages // does). We won't bother with security checks in this case, but // we need to create the loadinfo etc. // Get security manager. nsIScriptSecurityManager* ssm = nsContentUtils::GetSecurityManager(); NS_ENSURE_STATE(ssm); // Check to see if URI is allowed. nsresult rv = ssm->CheckLoadURIFromScript(cx, aURI); NS_ENSURE_SUCCESS(rv, rv); // 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 // push/replaceState) matches the principal's URI, use the document's // current URI as the referrer. If they don't match, use the principal's // URI. JSScript* script = nullptr; nsCOMPtr<nsIDocument> doc; nsCOMPtr<nsIURI> docOriginalURI, docCurrentURI, principalURI; // NB: A false return value from JS_DescribeScriptedCaller means no caller // was found. It does not signal that an exception was thrown. if (JS_DescribeScriptedCaller(cx, &script, nullptr)) { doc = GetScriptDocument(cx, script); } if (doc) { docOriginalURI = doc->GetOriginalURI(); docCurrentURI = doc->GetDocumentURI(); rv = doc->NodePrincipal()->GetURI(getter_AddRefs(principalURI)); NS_ENSURE_SUCCESS(rv, rv); } bool urisEqual = false; if (docOriginalURI && docCurrentURI && principalURI) { principalURI->Equals(docOriginalURI, &urisEqual); } if (urisEqual) { sourceURI = docCurrentURI; } else { sourceURI = principalURI; } owner = do_QueryInterface(ssm->GetCxSubjectPrincipal(cx)); } // Create load info nsCOMPtr<nsIDocShellLoadInfo> loadInfo; docShell->CreateLoadInfo(getter_AddRefs(loadInfo)); NS_ENSURE_TRUE(loadInfo, NS_ERROR_FAILURE); loadInfo->SetOwner(owner); if (sourceURI) { loadInfo->SetReferrer(sourceURI); } loadInfo.swap(*aLoadInfo); return NS_OK; }