Bug 935283, Keep document as a data property on window for now. r=bz

--HG--
extra : rebase_source : cca1ee4bf96315526e953235a76522cb71f44bfa
This commit is contained in:
Peter Van der Beken 2013-11-06 10:21:36 +01:00
parent bf93b8ef19
commit 949acf3eb9
2 changed files with 54 additions and 0 deletions

View File

@ -2171,6 +2171,9 @@ public:
virtual nsHTMLDocument* AsHTMLDocument() { return nullptr; }
virtual JSObject* WrapObject(JSContext *aCx,
JS::Handle<JSObject*> aScope) MOZ_OVERRIDE;
private:
uint64_t mWarnedAbout;
SelectorCache mSelectorCache;

View File

@ -11329,6 +11329,57 @@ nsDocument::Evaluate(const nsAString& aExpression, nsIDOMNode* aContextNode,
aInResult, aResult);
}
// This is just a hack around the fact that window.document is not
// [Unforgeable] yet.
JSObject*
nsIDocument::WrapObject(JSContext *aCx, JS::Handle<JSObject*> aScope)
{
MOZ_ASSERT(IsDOMBinding());
JS::Rooted<JSObject*> obj(aCx, nsINode::WrapObject(aCx, aScope));
if (!obj) {
return nullptr;
}
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(GetInnerWindow());
if (!win) {
// No window, nothing else to do here
return obj;
}
if (this != win->GetExtantDoc()) {
// We're not the current document; we're also done here
return obj;
}
JSAutoCompartment ac(aCx, obj);
JS::Rooted<JS::Value> winVal(aCx);
nsCOMPtr<nsIXPConnectJSObjectHolder> holder;
nsresult rv = nsContentUtils::WrapNative(aCx, obj, win,
&NS_GET_IID(nsIDOMWindow),
&winVal,
getter_AddRefs(holder),
false);
if (NS_FAILED(rv)) {
Throw(aCx, rv);
return nullptr;
}
NS_NAMED_LITERAL_STRING(doc_str, "document");
if (!JS_DefineUCProperty(aCx, JSVAL_TO_OBJECT(winVal),
reinterpret_cast<const jschar *>
(doc_str.get()),
doc_str.Length(), JS::ObjectValue(*obj),
JS_PropertyStub, JS_StrictPropertyStub,
JSPROP_READONLY | JSPROP_ENUMERATE)) {
return nullptr;
}
return obj;
}
XPathEvaluator*
nsIDocument::XPathEvaluator()
{