Bug 1309147 - Part 3: Implement the support for CEReactions in Codegen.

Tag UXP Issue #1344
This commit is contained in:
Gaming4JC 2020-01-04 10:28:38 -05:00 committed by Roy Tam
commit 303037d0fc
8 changed files with 96 additions and 0 deletions

View file

@ -16,6 +16,7 @@
#include "mozilla/SizePrintfMacros.h"
#include "mozilla/Unused.h"
#include "mozilla/UseCounter.h"
#include "mozilla/dom/DocGroup.h"
#include "AccessCheck.h"
#include "jsfriendapi.h"
@ -3405,6 +3406,28 @@ GetDesiredProto(JSContext* aCx, const JS::CallArgs& aCallArgs,
return true;
}
CustomElementReactionsStack*
GetCustomElementReactionsStack(JS::Handle<JSObject*> aObj)
{
// This might not be the right object, if there are wrappers. Unwrap if we can.
JSObject* obj = js::CheckedUnwrap(aObj);
if (!obj) {
return nullptr;
}
nsGlobalWindow* window = xpc::WindowGlobalOrNull(obj);
if (!window) {
return nullptr;
}
DocGroup* docGroup = window->AsInner()->GetDocGroup();
if (!docGroup) {
return nullptr;
}
return docGroup->CustomElementReactionsStack();
}
// https://html.spec.whatwg.org/multipage/dom.html#htmlconstructor
already_AddRefed<nsGenericHTMLElement>
CreateHTMLElement(const GlobalObject& aGlobal, const JS::CallArgs& aCallArgs,

View file

@ -50,6 +50,7 @@ namespace mozilla {
enum UseCounter : int16_t;
namespace dom {
class CustomElementReactionsStack;
template<typename KeyType, typename ValueType> class Record;
nsresult
@ -3421,6 +3422,12 @@ bool
GetDesiredProto(JSContext* aCx, const JS::CallArgs& aCallArgs,
JS::MutableHandle<JSObject*> aDesiredProto);
// Get the CustomElementReactionsStack for the docgroup of the global
// of the underlying object of aObj. This can be null if aObj can't
// be CheckUnwrapped, or if the global of the result has no docgroup
// (e.g. because it's not a Window global).
CustomElementReactionsStack*
GetCustomElementReactionsStack(JS::Handle<JSObject*> aObj);
// This function is expected to be called from the constructor function for an
// HTML element interface; the global/callargs need to be whatever was passed to
// that constructor function.

View file

@ -1643,6 +1643,10 @@ DOMInterfaces = {
'register': False,
},
'TestCEReactionsInterface' : {
'headerFile': 'TestBindingHeader.h',
'register': False,
},
}
# These are temporary, until they've been converted to use new DOM bindings

View file

@ -7672,6 +7672,17 @@ class CGPerSignatureCall(CGThing):
CGIfWrapper(CGList(xraySteps),
"objIsXray"))
if (idlNode.getExtendedAttribute('CEReactions') is not None and
not getter):
cgThings.append(CGGeneric(fill(
"""
CustomElementReactionsStack* reactionsStack = GetCustomElementReactionsStack(${obj});
Maybe<AutoCEReaction> ceReaction;
if (reactionsStack) {
ceReaction.emplace(reactionsStack);
}
""", obj=objectName)))
# If this is a method that was generated by a maplike/setlike
# interface, use the maplike/setlike generator to fill in the body.
# Otherwise, use CGCallGenerator to call the native method.
@ -13840,12 +13851,18 @@ class CGBindingRoot(CGThing):
iface = desc.interface
return any(m.getExtendedAttribute("Deprecated") for m in iface.members + [iface])
def descriptorHasCEReactions(desc):
iface = desc.interface
return any(m.getExtendedAttribute("CEReactions") for m in iface.members + [iface])
bindingHeaders["nsIDocument.h"] = any(
descriptorDeprecated(d) for d in descriptors)
bindingHeaders["mozilla/Preferences.h"] = any(
descriptorRequiresPreferences(d) for d in descriptors)
bindingHeaders["mozilla/dom/DOMJSProxyHandler.h"] = any(
d.concrete and d.proxy for d in descriptors)
bindingHeaders["mozilla/dom/CustomElementRegistry.h"] = any(
descriptorHasCEReactions(d) for d in descriptors)
def descriptorHasChromeOnly(desc):
ctor = desc.interface.ctor()

View file

@ -939,6 +939,11 @@ public:
void NeedsCallerTypeMethod(CallerType);
bool NeedsCallerTypeAttr(CallerType);
void SetNeedsCallerTypeAttr(bool, CallerType);
void CeReactionsMethod();
void CeReactionsMethodOverload();
void CeReactionsMethodOverload(const nsAString&);
bool CeReactionsAttr() const;
void SetCeReactionsAttr(bool);
int16_t LegacyCall(const JS::Value&, uint32_t, TestInterface&);
void PassArgsWithDefaults(JSContext*, const Optional<int32_t>&,
TestInterface*, const Dict&, double,
@ -1431,6 +1436,25 @@ public:
virtual nsISupports* GetParentObject();
};
class TestCEReactionsInterface : public nsISupports,
public nsWrapperCache
{
public:
NS_DECL_ISUPPORTS
// We need a GetParentObject to make binding codegen happy
virtual nsISupports* GetParentObject();
int32_t Item(uint32_t);
uint32_t Length() const;
int32_t IndexedGetter(uint32_t, bool &);
void IndexedSetter(uint32_t, int32_t);
void NamedDeleter(const nsAString&, bool &);
void NamedGetter(const nsAString&, bool &, nsString&);
void NamedSetter(const nsAString&, const nsAString&);
void GetSupportedNames(nsTArray<nsString>&);
};
} // namespace dom
} // namespace mozilla

View file

@ -947,6 +947,10 @@ interface TestInterface {
[NeedsSubjectPrincipal] attribute boolean needsSubjectPrincipalAttr;
[NeedsCallerType] void needsCallerTypeMethod();
[NeedsCallerType] attribute boolean needsCallerTypeAttr;
[CEReactions] void ceReactionsMethod();
[CEReactions] void ceReactionsMethodOverload();
[CEReactions] void ceReactionsMethodOverload(DOMString bar);
[CEReactions] attribute boolean ceReactionsAttr;
legacycaller short(unsigned long arg1, TestInterface arg2);
void passArgsWithDefaults(optional long arg1,
optional TestInterface? arg2 = null,
@ -1266,3 +1270,12 @@ interface TestWorkerExposedInterface {
[HTMLConstructor]
interface TestHTMLConstructorInterface {
};
interface TestCEReactionsInterface {
[CEReactions] setter creator void (unsigned long index, long item);
[CEReactions] setter creator void (DOMString name, DOMString item);
[CEReactions] deleter void (DOMString name);
getter long item(unsigned long index);
getter DOMString (DOMString name);
readonly attribute unsigned long length;
};

View file

@ -777,6 +777,10 @@ interface TestExampleInterface {
[NeedsSubjectPrincipal] attribute boolean needsSubjectPrincipalAttr;
[NeedsCallerType] void needsCallerTypeMethod();
[NeedsCallerType] attribute boolean needsCallerTypeAttr;
[CEReactions] void ceReactionsMethod();
[CEReactions] void ceReactionsMethodOverload();
[CEReactions] void ceReactionsMethodOverload(DOMString bar);
[CEReactions] attribute boolean ceReactionsAttr;
legacycaller short(unsigned long arg1, TestInterface arg2);
void passArgsWithDefaults(optional long arg1,
optional TestInterface? arg2 = null,

View file

@ -794,6 +794,10 @@ interface TestJSImplInterface {
[Throws] attribute boolean throwingAttr;
[GetterThrows] attribute boolean throwingGetterAttr;
[SetterThrows] attribute boolean throwingSetterAttr;
[CEReactions] void ceReactionsMethod();
[CEReactions] void ceReactionsMethodOverload();
[CEReactions] void ceReactionsMethodOverload(DOMString bar);
[CEReactions] attribute boolean ceReactionsAttr;
// NeedsSubjectPrincipal not supported on JS-implemented things for
// now, because we always pass in the caller principal anyway.
// [NeedsSubjectPrincipal] void needsSubjectPrincipalMethod();