From 83e8b4f774383c87fbe5cfc5b9c076a6a5c7067e Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Sat, 24 Dec 2011 09:21:26 +0100 Subject: [PATCH] Bug 687134 - Get at the JSContext through IDL for pccount methods; r=bholley --- dom/base/nsDOMWindowUtils.cpp | 56 +++-------------------- dom/interfaces/base/nsIDOMWindowUtils.idl | 8 +++- 2 files changed, 13 insertions(+), 51 deletions(-) diff --git a/dom/base/nsDOMWindowUtils.cpp b/dom/base/nsDOMWindowUtils.cpp index 10818bb04075..28275f3b055a 100644 --- a/dom/base/nsDOMWindowUtils.cpp +++ b/dom/base/nsDOMWindowUtils.cpp @@ -1982,77 +1982,37 @@ nsDOMWindowUtils::GetFileReferences(const nsAString& aDatabaseName, return NS_OK; } -static inline JSContext * -GetJSContext() -{ - nsCOMPtr xpc = nsContentUtils::XPConnect(); - - // get the xpconnect native call context - nsAXPCNativeCallContext *cc = nsnull; - xpc->GetCurrentNativeCallContext(&cc); - if(!cc) - return NULL; - - // Get JSContext of current call - JSContext* cx; - nsresult rv = cc->GetJSContext(&cx); - if(NS_FAILED(rv) || !cx) - return NULL; - - return cx; -} - NS_IMETHODIMP -nsDOMWindowUtils::StartPCCountProfiling() +nsDOMWindowUtils::StartPCCountProfiling(JSContext* cx) { - JSContext *cx = GetJSContext(); - if (!cx) - return NS_ERROR_FAILURE; - js::StartPCCountProfiling(cx); return NS_OK; } NS_IMETHODIMP -nsDOMWindowUtils::StopPCCountProfiling() +nsDOMWindowUtils::StopPCCountProfiling(JSContext* cx) { - JSContext *cx = GetJSContext(); - if (!cx) - return NS_ERROR_FAILURE; - js::StopPCCountProfiling(cx); return NS_OK; } NS_IMETHODIMP -nsDOMWindowUtils::PurgePCCounts() +nsDOMWindowUtils::PurgePCCounts(JSContext* cx) { - JSContext *cx = GetJSContext(); - if (!cx) - return NS_ERROR_FAILURE; - js::PurgePCCounts(cx); return NS_OK; } NS_IMETHODIMP -nsDOMWindowUtils::GetPCCountScriptCount(PRInt32 *result) +nsDOMWindowUtils::GetPCCountScriptCount(JSContext* cx, PRInt32 *result) { - JSContext *cx = GetJSContext(); - if (!cx) - return NS_ERROR_FAILURE; - *result = js::GetPCCountScriptCount(cx); return NS_OK; } NS_IMETHODIMP -nsDOMWindowUtils::GetPCCountScriptSummary(PRInt32 script, nsAString& result) +nsDOMWindowUtils::GetPCCountScriptSummary(PRInt32 script, JSContext* cx, nsAString& result) { - JSContext *cx = GetJSContext(); - if (!cx) - return NS_ERROR_FAILURE; - JSString *text = js::GetPCCountScriptSummary(cx, script); if (!text) return NS_ERROR_FAILURE; @@ -2066,12 +2026,8 @@ nsDOMWindowUtils::GetPCCountScriptSummary(PRInt32 script, nsAString& result) } NS_IMETHODIMP -nsDOMWindowUtils::GetPCCountScriptContents(PRInt32 script, nsAString& result) +nsDOMWindowUtils::GetPCCountScriptContents(PRInt32 script, JSContext* cx, nsAString& result) { - JSContext *cx = GetJSContext(); - if (!cx) - return NS_ERROR_FAILURE; - JSString *text = js::GetPCCountScriptContents(cx, script); if (!text) return NS_ERROR_FAILURE; diff --git a/dom/interfaces/base/nsIDOMWindowUtils.idl b/dom/interfaces/base/nsIDOMWindowUtils.idl index 31724ec626ec..0ab427c52f0b 100644 --- a/dom/interfaces/base/nsIDOMWindowUtils.idl +++ b/dom/interfaces/base/nsIDOMWindowUtils.idl @@ -69,7 +69,7 @@ interface nsIDOMBlob; interface nsIDOMFile; interface nsIFile; -[scriptable, uuid(3af3c5ce-6f2a-47e7-acd0-555ed576fa82)] +[scriptable, uuid(9df58cf3-7094-4c8d-96f2-bebd765099fe)] interface nsIDOMWindowUtils : nsISupports { /** @@ -945,28 +945,33 @@ interface nsIDOMWindowUtils : nsISupports { * Begin opcode-level profiling of all JavaScript execution in the window's * runtime. */ + [implicit_jscontext] void startPCCountProfiling(); /** * Stop opcode-level profiling of JavaScript execution in the runtime, and * collect all counts for use by getPCCount methods. */ + [implicit_jscontext] void stopPCCountProfiling(); /** * Purge collected PC counters. */ + [implicit_jscontext] void purgePCCounts(); /** * Get the number of scripts with opcode-level profiling information. */ + [implicit_jscontext] long getPCCountScriptCount(); /** * Get a JSON string for a short summary of a script and the PC counts * accumulated for it. */ + [implicit_jscontext] AString getPCCountScriptSummary(in long script); /** @@ -974,5 +979,6 @@ interface nsIDOMWindowUtils : nsISupports { * including the decompilation of the script and placement of decompiled * operations within it, and PC counts for each operation. */ + [implicit_jscontext] AString getPCCountScriptContents(in long script); };