Backed out changeset c79e8bee853e (bug 851892)

This commit is contained in:
Sebastian Hengst 2017-01-20 19:29:38 +01:00
parent 696ece6386
commit d310ee3521
5 changed files with 85 additions and 0 deletions

View File

@ -69,6 +69,7 @@
#include "nsIDOMEventTarget.h"
// CSS related includes
#include "nsCSSRules.h"
#include "nsIDOMCSSRule.h"
#include "nsMemory.h"
@ -1892,6 +1893,32 @@ nsEventTargetSH::PreserveWrapper(nsISupports *aNative)
target->PreserveWrapper(aNative);
}
// CSS rule helper
NS_IMETHODIMP
nsCSSRuleSH::PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *aGlobalObj, JSObject **parentObj)
{
JS::Rooted<JSObject*> globalObj(cx, aGlobalObj);
nsCOMPtr<nsIDOMCSSRule> rule = do_QueryInterface(nativeObj);
if (!rule) {
return NS_ERROR_UNEXPECTED;
}
css::Rule* cssRule = rule->GetCSSRule();
MOZ_ASSERT(cssRule);
nsIDocument* doc = cssRule->GetDocument();
if (!doc) {
*parentObj = globalObj;
return NS_OK;
}
nsIGlobalObject* global = doc->GetScopeObject();
if (!global) {
return NS_ERROR_UNEXPECTED;
}
*parentObj = global->GetGlobalJSObject();
return *parentObj ? NS_OK : NS_ERROR_FAILURE;
}
// nsIDOMEventListener::HandleEvent() 'this' converter helper
NS_INTERFACE_MAP_BEGIN(nsEventListenerThisTranslator)

View File

@ -182,6 +182,28 @@ public:
virtual void PreserveWrapper(nsISupports *aNative) override;
};
// Makes sure that we always create our wrapper in the right global, so we won't
// cache one from the wrong global.
class nsCSSRuleSH : public nsDOMGenericSH
{
protected:
explicit nsCSSRuleSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData)
{
}
virtual ~nsCSSRuleSH()
{
}
public:
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
JSObject *globalObj, JSObject **parentObj) override;
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
{
return new nsCSSRuleSH(aData);
}
};
// A place to hang some static methods that we should really consider
// moving to be nsGlobalWindow member methods. See bug 1062418.
class nsWindowSH

View File

@ -264,6 +264,7 @@ DOMInterfaces = {
},
'CSSRule': {
'hasXPConnectImpls': True,
'concrete': False,
'nativeType': 'mozilla::css::Rule'
},

View File

@ -142,4 +142,18 @@ protected:
} // namespace css
} // namespace mozilla
// Specialization of the bindings UnwrapArg setup for css::Rule, so we can avoid
// adding an IID to css::Rule. This can go away once all css::Rule subclasses
// are on WebIDL bindings.
#include "js/TypeDecls.h"
namespace mozilla {
namespace dom {
template <>
nsresult
UnwrapArg(JS::Handle<JSObject*> src, css::Rule** ppArg);
} // namepace dom
} // namespace mozilla
#endif /* mozilla_css_Rule_h___ */

View File

@ -56,6 +56,27 @@ using namespace mozilla::dom;
// base class for all rule types in a CSS style sheet
// Temporary code that can go away once all css::Rules are on WebIDL bindings.
#include "xpcpublic.h"
namespace mozilla {
namespace dom {
template<>
nsresult
UnwrapArg(JS::Handle<JSObject*> src, css::Rule** ppArg)
{
MOZ_ASSERT(NS_IsMainThread());
nsCOMPtr<nsIDOMCSSRule> rule =
do_QueryInterface(xpc::UnwrapReflectorToISupports(src));
if (!rule) {
return NS_NOINTERFACE;
}
*ppArg = rule->GetCSSRule();
NS_ADDREF(*ppArg);
return NS_OK;
}
} // namespace dom
} // namespace mozilla
namespace mozilla {
namespace css {