diff --git a/content/base/public/nsContentUtils.h b/content/base/public/nsContentUtils.h index fe3f9e1e5385..4ec4428b4ffa 100644 --- a/content/base/public/nsContentUtils.h +++ b/content/base/public/nsContentUtils.h @@ -216,7 +216,8 @@ public: * When a document's scope changes (e.g., from document.open(), call this * function to move all content wrappers from the old scope to the new one. */ - static nsresult ReparentContentWrappersInScope(nsIScriptGlobalObject *aOldScope, + static nsresult ReparentContentWrappersInScope(JSContext *cx, + nsIScriptGlobalObject *aOldScope, nsIScriptGlobalObject *aNewScope); static PRBool IsCallerChrome(); diff --git a/content/base/src/nsContentUtils.cpp b/content/base/src/nsContentUtils.cpp index 7921bd14e8aa..77d7b103395e 100644 --- a/content/base/src/nsContentUtils.cpp +++ b/content/base/src/nsContentUtils.cpp @@ -1336,42 +1336,10 @@ nsContentUtils::GetContextAndScope(nsIDocument *aOldDocument, } nsresult -nsContentUtils::ReparentContentWrappersInScope(nsIScriptGlobalObject *aOldScope, +nsContentUtils::ReparentContentWrappersInScope(JSContext *cx, + nsIScriptGlobalObject *aOldScope, nsIScriptGlobalObject *aNewScope) { - JSContext *cx = nsnull; - - // Try really hard to find a context to work on. - nsIScriptContext *context = aOldScope->GetContext(); - if (context) { - cx = static_cast(context->GetNativeContext()); - } - - if (!cx) { - context = aNewScope->GetContext(); - if (context) { - cx = static_cast(context->GetNativeContext()); - } - - if (!cx) { - sThreadJSContextStack->Peek(&cx); - - if (!cx) { - sThreadJSContextStack->GetSafeJSContext(&cx); - - if (!cx) { - // Wow, this is really bad! - NS_WARNING("No context reachable in ReparentContentWrappers()!"); - - return NS_ERROR_NOT_AVAILABLE; - } - } - } - } - - // Now that we have a context, let's get the global objects from the two - // scopes and ask XPConnect to do the rest of the work. - JSObject *oldScopeObj = aOldScope->GetGlobalJSObject(); JSObject *newScopeObj = aNewScope->GetGlobalJSObject(); diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index 5e36675d9963..ac9db66f2a43 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -1518,7 +1518,8 @@ nsHTMLDocument::SetCookie(const nsAString& aCookie) // XXX TBI: accepting arguments to the open method. nsresult -nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace) +nsHTMLDocument::OpenCommon(JSContext *cx, const nsACString& aContentType, + PRBool aReplace) { if (!IsHTML() || mDisableDocWrite) { // No calling document.open() on XHTML @@ -1686,7 +1687,7 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace) nsCOMPtr newScope(do_QueryReferent(mScopeObject)); if (oldScope && newScope != oldScope) { - nsContentUtils::ReparentContentWrappersInScope(oldScope, newScope); + nsContentUtils::ReparentContentWrappersInScope(cx, oldScope, newScope); } } @@ -1767,9 +1768,9 @@ nsHTMLDocument::OpenCommon(const nsACString& aContentType, PRBool aReplace) NS_IMETHODIMP nsHTMLDocument::Open(const nsACString& aContentType, PRBool aReplace, - nsIDOMDocument** aReturn) + JSContext *cx, nsIDOMDocument** aReturn) { - nsresult rv = OpenCommon(aContentType, aReplace); + nsresult rv = OpenCommon(cx, aContentType, aReplace); NS_ENSURE_SUCCESS(rv, rv); return CallQueryInterface(this, aReturn); @@ -1843,7 +1844,8 @@ nsHTMLDocument::Close() } nsresult -nsHTMLDocument::WriteCommon(const nsAString& aText, +nsHTMLDocument::WriteCommon(JSContext *cx, + const nsAString& aText, PRBool aNewlineTerminate) { mTooDeepWriteRecursion = @@ -1892,7 +1894,7 @@ nsHTMLDocument::WriteCommon(const nsAString& aText, return NS_OK; } nsCOMPtr ignored; - rv = Open(NS_LITERAL_CSTRING("text/html"), PR_FALSE, + rv = Open(NS_LITERAL_CSTRING("text/html"), PR_FALSE, cx, getter_AddRefs(ignored)); // If Open() fails, or if it didn't create a parser (as it won't @@ -1940,15 +1942,15 @@ nsHTMLDocument::WriteCommon(const nsAString& aText, } NS_IMETHODIMP -nsHTMLDocument::Write(const nsAString& aText) +nsHTMLDocument::Write(const nsAString& aText, JSContext *cx) { - return WriteCommon(aText, PR_FALSE); + return WriteCommon(cx, aText, PR_FALSE); } NS_IMETHODIMP -nsHTMLDocument::Writeln(const nsAString& aText) +nsHTMLDocument::Writeln(const nsAString& aText, JSContext *cx) { - return WriteCommon(aText, PR_TRUE); + return WriteCommon(cx, aText, PR_TRUE); } PRBool diff --git a/content/html/document/src/nsHTMLDocument.h b/content/html/document/src/nsHTMLDocument.h index 85515231549b..cbb2ec48cee0 100644 --- a/content/html/document/src/nsHTMLDocument.h +++ b/content/html/document/src/nsHTMLDocument.h @@ -233,9 +233,10 @@ protected: void GetDomainURI(nsIURI **uri); - nsresult WriteCommon(const nsAString& aText, + nsresult WriteCommon(JSContext *cx, const nsAString& aText, PRBool aNewlineTerminate); - nsresult OpenCommon(const nsACString& aContentType, PRBool aReplace); + nsresult OpenCommon(JSContext *cx, const nsACString& aContentType, + PRBool aReplace); nsresult CreateAndAddWyciwygChannel(void); nsresult RemoveWyciwygChannel(void); diff --git a/dom/base/nsDOMClassInfo.cpp b/dom/base/nsDOMClassInfo.cpp index 956a0426966f..9e97b1726483 100644 --- a/dom/base/nsDOMClassInfo.cpp +++ b/dom/base/nsDOMClassInfo.cpp @@ -8986,7 +8986,7 @@ nsHTMLDocumentSH::DocumentOpen(JSContext *cx, uintN argc, jsval *vp) } nsCOMPtr retval; - nsresult rv = doc->Open(contentType, replace, getter_AddRefs(retval)); + nsresult rv = doc->Open(contentType, replace, cx, getter_AddRefs(retval)); if (NS_FAILED(rv)) { nsDOMClassInfo::ThrowJSException(cx, rv); diff --git a/dom/interfaces/html/nsIDOMHTMLDocument.idl b/dom/interfaces/html/nsIDOMHTMLDocument.idl index ef1f2c72ca94..15a6175f15a0 100644 --- a/dom/interfaces/html/nsIDOMHTMLDocument.idl +++ b/dom/interfaces/html/nsIDOMHTMLDocument.idl @@ -39,6 +39,10 @@ #include "nsIDOMDocument.idl" +%{C++ +#include "jspubtd.h" +%} + /** * The nsIDOMHTMLDocument interface is the interface to a [X]HTML * document object. @@ -46,7 +50,7 @@ * @see */ -[scriptable, uuid(6dd39b10-65ec-46f3-8c41-939300f6a7ce)] +[scriptable, uuid(3c0ca40f-72c5-4d15-935e-ccaff7953f2c)] interface nsIDOMHTMLDocument : nsIDOMDocument { readonly attribute DOMString URL; @@ -74,11 +78,14 @@ interface nsIDOMHTMLDocument : nsIDOMDocument // probably throw. // Pass aReplace = true to trigger a replacement of the previous // document in session history; pass false for normal history handling. + [implicit_jscontext] nsIDOMDocument open(in ACString aContentType, in boolean aReplace); void close(); + [implicit_jscontext] void write([optional, Null(Stringify)] in DOMString text); + [implicit_jscontext] void writeln([optional, Null(Stringify)] in DOMString text); /** diff --git a/js/src/xpconnect/src/dom_quickstubs.qsconf b/js/src/xpconnect/src/dom_quickstubs.qsconf index 392d00d52c88..d13c8d877de8 100644 --- a/js/src/xpconnect/src/dom_quickstubs.qsconf +++ b/js/src/xpconnect/src/dom_quickstubs.qsconf @@ -553,7 +553,7 @@ nsIDOMHTMLDocument_Write_customMethodCallCode = """ str.Append(next_arg); } - rv = self->%s(arg0); + rv = self->%s(arg0, cx); """ nsIDOMStorage_Clear_customMethodCallCode = """