diff --git a/content/base/public/nsIDocument.h b/content/base/public/nsIDocument.h index af046e4b3b9a..eccb1bac5e0a 100644 --- a/content/base/public/nsIDocument.h +++ b/content/base/public/nsIDocument.h @@ -113,8 +113,8 @@ typedef CallbackObjectHolder NodeFilterHolder; } // namespace mozilla #define NS_IDOCUMENT_IID \ -{ 0x4be4a58d, 0x7fce, 0x4315, \ - { 0x9d, 0x6c, 0x8e, 0x9f, 0xc7, 0x2e, 0x51, 0xb } }; +{ 0x308f8444, 0x7679, 0x445a, \ + { 0xa6, 0xcc, 0xb9, 0x5c, 0x61, 0xff, 0xe2, 0x66 } } // Flag for AddStyleSheet(). #define NS_STYLESHEET_FROM_CATALOG (1 << 0) @@ -2098,6 +2098,9 @@ public: virtual nsHTMLDocument* AsHTMLDocument() { return nullptr; } + virtual JSObject* WrapObject(JSContext *aCx, + JS::Handle aScope) MOZ_OVERRIDE; + private: uint64_t mWarnedAbout; @@ -2139,10 +2142,6 @@ protected: return mContentType; } - // All document WrapNode implementations MUST call this method. A - // false return value means an exception was thrown. - bool PostCreateWrapper(JSContext* aCx, JS::Handle aNewObject); - nsCString mReferrer; nsString mLastModified; diff --git a/content/base/src/nsDocument.cpp b/content/base/src/nsDocument.cpp index a5a8f604b259..b56060438b4b 100644 --- a/content/base/src/nsDocument.cpp +++ b/content/base/src/nsDocument.cpp @@ -11230,43 +11230,53 @@ nsIDocument::Evaluate(const nsAString& aExpression, nsINode* aContextNode, // This is just a hack around the fact that window.document is not // [Unforgeable] yet. -bool -nsIDocument::PostCreateWrapper(JSContext* aCx, JS::Handle aNewObject) +JSObject* +nsIDocument::WrapObject(JSContext *aCx, JS::Handle aScope) { MOZ_ASSERT(IsDOMBinding()); + JS::Rooted obj(aCx, nsINode::WrapObject(aCx, aScope)); + if (!obj) { + return nullptr; + } + nsCOMPtr win = do_QueryInterface(GetScriptGlobalObject()); if (!win) { // No window, nothing else to do here - return true; + return obj; } if (this != win->GetExtantDoc()) { // We're not the current document; we're also done here - return true; + return obj; } - JSAutoCompartment ac(aCx, aNewObject); + JSAutoCompartment ac(aCx, obj); JS::Rooted winVal(aCx); nsCOMPtr holder; - nsresult rv = nsContentUtils::WrapNative(aCx, aNewObject, win, + nsresult rv = nsContentUtils::WrapNative(aCx, obj, win, &NS_GET_IID(nsIDOMWindow), winVal.address(), getter_AddRefs(holder), false); if (NS_FAILED(rv)) { - return Throw(aCx, rv); + Throw(aCx, rv); + return nullptr; } NS_NAMED_LITERAL_STRING(doc_str, "document"); - return JS_DefineUCProperty(aCx, JSVAL_TO_OBJECT(winVal), - reinterpret_cast - (doc_str.get()), - doc_str.Length(), JS::ObjectValue(*aNewObject), - JS_PropertyStub, JS_StrictPropertyStub, - JSPROP_READONLY | JSPROP_ENUMERATE); + if (!JS_DefineUCProperty(aCx, JSVAL_TO_OBJECT(winVal), + reinterpret_cast + (doc_str.get()), + doc_str.Length(), JS::ObjectValue(*obj), + JS_PropertyStub, JS_StrictPropertyStub, + JSPROP_READONLY | JSPROP_ENUMERATE)) { + return nullptr; + } + + return obj; } bool diff --git a/content/html/document/src/ImageDocument.cpp b/content/html/document/src/ImageDocument.cpp index 635bcab2b5a0..6f88d0dbc85c 100644 --- a/content/html/document/src/ImageDocument.cpp +++ b/content/html/document/src/ImageDocument.cpp @@ -175,11 +175,7 @@ ImageDocument::Init() JSObject* ImageDocument::WrapNode(JSContext* aCx, JS::Handle aScope) { - JS::Rooted obj(aCx, ImageDocumentBinding::Wrap(aCx, aScope, this)); - if (obj && !PostCreateWrapper(aCx, obj)) { - return nullptr; - } - return obj; + return ImageDocumentBinding::Wrap(aCx, aScope, this); } nsresult diff --git a/content/html/document/src/nsHTMLDocument.cpp b/content/html/document/src/nsHTMLDocument.cpp index e624b0cf169c..df98ae2d6bb5 100644 --- a/content/html/document/src/nsHTMLDocument.cpp +++ b/content/html/document/src/nsHTMLDocument.cpp @@ -258,11 +258,7 @@ NS_INTERFACE_MAP_END_INHERITING(nsDocument) JSObject* nsHTMLDocument::WrapNode(JSContext* aCx, JS::Handle aScope) { - JS::Rooted obj(aCx, HTMLDocumentBinding::Wrap(aCx, aScope, this)); - if (obj && !PostCreateWrapper(aCx, obj)) { - return nullptr; - } - return obj; + return HTMLDocumentBinding::Wrap(aCx, aScope, this); } nsresult diff --git a/content/svg/document/src/SVGDocument.cpp b/content/svg/document/src/SVGDocument.cpp index 9c90ae39aac2..d588a1577f5c 100644 --- a/content/svg/document/src/SVGDocument.cpp +++ b/content/svg/document/src/SVGDocument.cpp @@ -104,11 +104,7 @@ SVGDocument::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const JSObject* SVGDocument::WrapNode(JSContext *aCx, JS::Handle aScope) { - JS::Rooted obj(aCx, SVGDocumentBinding::Wrap(aCx, aScope, this)); - if (obj && !PostCreateWrapper(aCx, obj)) { - return nullptr; - } - return obj; + return SVGDocumentBinding::Wrap(aCx, aScope, this); } } // namespace dom diff --git a/content/xml/document/src/XMLDocument.cpp b/content/xml/document/src/XMLDocument.cpp index ed7eda4cfcb2..2319fea95031 100644 --- a/content/xml/document/src/XMLDocument.cpp +++ b/content/xml/document/src/XMLDocument.cpp @@ -629,11 +629,7 @@ XMLDocument::Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const JSObject* XMLDocument::WrapNode(JSContext *aCx, JS::Handle aScope) { - JS::Rooted obj(aCx, XMLDocumentBinding::Wrap(aCx, aScope, this)); - if (obj && !PostCreateWrapper(aCx, obj)) { - return nullptr; - } - return obj; + return XMLDocumentBinding::Wrap(aCx, aScope, this); } } // namespace dom diff --git a/content/xul/document/src/XULDocument.cpp b/content/xul/document/src/XULDocument.cpp index 9196a900ce02..11bff185d4fb 100644 --- a/content/xul/document/src/XULDocument.cpp +++ b/content/xul/document/src/XULDocument.cpp @@ -4762,11 +4762,7 @@ XULDocument::GetBoxObjectFor(nsIDOMElement* aElement, nsIBoxObject** aResult) JSObject* XULDocument::WrapNode(JSContext *aCx, JS::Handle aScope) { - JS::Rooted obj(aCx, XULDocumentBinding::Wrap(aCx, aScope, this)); - if (obj && !PostCreateWrapper(aCx, obj)) { - return nullptr; - } - return obj; + return XULDocumentBinding::Wrap(aCx, aScope, this); } } // namespace dom