diff --git a/content/xbl/src/nsBindingManager.cpp b/content/xbl/src/nsBindingManager.cpp index 34acbdc0871..d7525689124 100644 --- a/content/xbl/src/nsBindingManager.cpp +++ b/content/xbl/src/nsBindingManager.cpp @@ -1407,8 +1407,14 @@ nsBindingManager::GetBindingImplementation(nsIContent* aContent, REFNSIID aIID, nsCOMPtr wrappedJS; GetWrappedJS(aContent, getter_AddRefs(wrappedJS)); - if (wrappedJS) - return wrappedJS->AggregatedQueryInterface(aIID, aResult); + if (wrappedJS) { + nsresult rv = wrappedJS->AggregatedQueryInterface(aIID, aResult); + if (*aResult) + return rv; + + // No result was found, so this must be another XBL interface. + // Fall through to create a new wrapper. + } // We have never made a wrapper for this implementation. // Create an XPC wrapper for the script object and hand it back. diff --git a/content/xbl/src/nsXBLBinding.cpp b/content/xbl/src/nsXBLBinding.cpp index c3561d98c81..81af9a741af 100644 --- a/content/xbl/src/nsXBLBinding.cpp +++ b/content/xbl/src/nsXBLBinding.cpp @@ -162,7 +162,6 @@ nsIAtom* nsXBLBinding::kActionAtom = nsnull; nsIAtom* nsXBLBinding::kMethodAtom = nsnull; nsIAtom* nsXBLBinding::kParameterAtom = nsnull; nsIAtom* nsXBLBinding::kBodyAtom = nsnull; -nsIAtom* nsXBLBinding::kPropertyAtom = nsnull; nsIAtom* nsXBLBinding::kOnSetAtom = nsnull; nsIAtom* nsXBLBinding::kOnGetAtom = nsnull; nsIAtom* nsXBLBinding::kGetterAtom = nsnull; @@ -270,7 +269,6 @@ nsXBLBinding::nsXBLBinding(nsIXBLPrototypeBinding* aBinding) kMethodAtom = NS_NewAtom("method"); kParameterAtom = NS_NewAtom("parameter"); kBodyAtom = NS_NewAtom("body"); - kPropertyAtom = NS_NewAtom("property"); kOnSetAtom = NS_NewAtom("onset"); kOnGetAtom = NS_NewAtom("onget"); kGetterAtom = NS_NewAtom("getter"); @@ -312,7 +310,6 @@ nsXBLBinding::~nsXBLBinding(void) NS_RELEASE(kMethodAtom); NS_RELEASE(kParameterAtom); NS_RELEASE(kBodyAtom); - NS_RELEASE(kPropertyAtom); NS_RELEASE(kOnSetAtom); NS_RELEASE(kOnGetAtom); NS_RELEASE(kGetterAtom); diff --git a/content/xbl/src/nsXBLBinding.h b/content/xbl/src/nsXBLBinding.h index ac59235609c..efd54ff7e38 100644 --- a/content/xbl/src/nsXBLBinding.h +++ b/content/xbl/src/nsXBLBinding.h @@ -136,7 +136,6 @@ public: static nsIAtom* kMethodAtom; static nsIAtom* kParameterAtom; static nsIAtom* kBodyAtom; - static nsIAtom* kPropertyAtom; static nsIAtom* kOnSetAtom; static nsIAtom* kOnGetAtom; static nsIAtom* kGetterAtom; diff --git a/content/xbl/src/nsXBLPrototypeBinding.cpp b/content/xbl/src/nsXBLPrototypeBinding.cpp index ee9deb8a999..8cd2ccaf867 100644 --- a/content/xbl/src/nsXBLPrototypeBinding.cpp +++ b/content/xbl/src/nsXBLPrototypeBinding.cpp @@ -1519,15 +1519,6 @@ nsXBLPrototypeBinding::ConstructInterfaceTable(nsIContent* aElement) nsMemory::Free(str); } - - // Recur into our children. - PRInt32 childCount; - aElement->ChildCount(childCount); - for (PRInt32 i = 0; i < childCount; i++) { - nsCOMPtr child; - aElement->ChildAt(i, *getter_AddRefs(child)); - ConstructAttributeTable(child); - } } void diff --git a/content/xbl/src/nsXBLPrototypeProperty.cpp b/content/xbl/src/nsXBLPrototypeProperty.cpp index 6527a07668f..443e69aa888 100644 --- a/content/xbl/src/nsXBLPrototypeProperty.cpp +++ b/content/xbl/src/nsXBLPrototypeProperty.cpp @@ -48,6 +48,7 @@ nsIAtom* nsXBLPrototypeProperty::kMethodAtom = nsnull; nsIAtom* nsXBLPrototypeProperty::kParameterAtom = nsnull; nsIAtom* nsXBLPrototypeProperty::kBodyAtom = nsnull; nsIAtom* nsXBLPrototypeProperty::kPropertyAtom = nsnull; +nsIAtom* nsXBLPrototypeProperty::kFieldAtom = nsnull; nsIAtom* nsXBLPrototypeProperty::kOnSetAtom = nsnull; nsIAtom* nsXBLPrototypeProperty::kOnGetAtom = nsnull; nsIAtom* nsXBLPrototypeProperty::kGetterAtom = nsnull; @@ -118,6 +119,7 @@ nsXBLPrototypeProperty::nsXBLPrototypeProperty(nsIXBLPrototypeBinding * aPrototy kParameterAtom = NS_NewAtom("parameter"); kBodyAtom = NS_NewAtom("body"); kPropertyAtom = NS_NewAtom("property"); + kFieldAtom = NS_NewAtom("field"); kOnSetAtom = NS_NewAtom("onset"); kOnGetAtom = NS_NewAtom("onget"); kGetterAtom = NS_NewAtom("getter"); @@ -146,6 +148,7 @@ nsXBLPrototypeProperty::~nsXBLPrototypeProperty() NS_RELEASE(kParameterAtom); NS_RELEASE(kBodyAtom); NS_RELEASE(kPropertyAtom); + NS_RELEASE(kFieldAtom); NS_RELEASE(kOnSetAtom); NS_RELEASE(kOnGetAtom); NS_RELEASE(kGetterAtom); @@ -266,12 +269,12 @@ nsXBLPrototypeProperty::InstallProperty(nsIScriptContext * aContext, nsIContent mName.Length(), JSVAL_VOID, (JSPropertyOp) getter, (JSPropertyOp) setter, mJSAttributes); } - else if (!mLiteralPropertyString.IsEmpty()) + else if (!mFieldString.IsEmpty()) { // compile the literal string jsval result = nsnull; PRBool undefined; - aContext->EvaluateStringWithValue(mLiteralPropertyString, + aContext->EvaluateStringWithValue(mFieldString, scriptObject, nsnull, nsnull, 0, nsnull, (void*) &result, &undefined); @@ -319,14 +322,12 @@ nsresult nsXBLPrototypeProperty::DelayedPropertyConstruction() binding->GetCompiledClassObject(mClassStr, context, (void *) scopeObject, &classObject); mClassObject = (JSObject *) classObject; - if (tagName.get() == kMethodAtom /* && mClassObject */) - { - ParseMethod(context, mPropertyElement, mClassStr); - } + if (tagName.get() == kMethodAtom) + ParseMethod(context); else if (tagName.get() == kPropertyAtom) - { - ParseProperty(context, mPropertyElement, mClassStr); - } + ParseProperty(context); + else if (tagName.get() == kFieldAtom) + ParseField(context); mPropertyIsCompiled = PR_TRUE; mInterfaceElement = nsnull; @@ -362,20 +363,19 @@ nsXBLPrototypeProperty::ConstructProperty(nsIContent * aInterfaceElement, nsICon const char* gPropertyArgs[] = { "val" }; -nsresult nsXBLPrototypeProperty::ParseProperty(nsIScriptContext * aContext, nsIContent* aPropertyElement, const char * aClassStr) +nsresult nsXBLPrototypeProperty::ParseProperty(nsIScriptContext * aContext) { // Obtain our name attribute. - nsAutoString name; nsresult rv = NS_OK; - aPropertyElement->GetAttr(kNameSpaceID_None, kNameAtom, mName); + mPropertyElement->GetAttr(kNameSpaceID_None, kNameAtom, mName); if (!mName.IsEmpty()) { // We have a property. nsAutoString getter, setter, readOnly; - aPropertyElement->GetAttr(kNameSpaceID_None, kOnGetAtom, getter); - aPropertyElement->GetAttr(kNameSpaceID_None, kOnSetAtom, setter); - aPropertyElement->GetAttr(kNameSpaceID_None, kReadOnlyAtom, readOnly); + mPropertyElement->GetAttr(kNameSpaceID_None, kOnGetAtom, getter); + mPropertyElement->GetAttr(kNameSpaceID_None, kOnSetAtom, setter); + mPropertyElement->GetAttr(kNameSpaceID_None, kReadOnlyAtom, readOnly); mJSAttributes = JSPROP_ENUMERATE; @@ -386,12 +386,12 @@ nsresult nsXBLPrototypeProperty::ParseProperty(nsIScriptContext * aContext, nsIC if (getter.IsEmpty()) { PRInt32 childCount; - aPropertyElement->ChildCount(childCount); + mPropertyElement->ChildCount(childCount); nsCOMPtr getterElement; for (PRInt32 j=0; jChildAt(j, *getter_AddRefs(getterElement)); + mPropertyElement->ChildAt(j, *getter_AddRefs(getterElement)); if (!getterElement) continue; @@ -410,7 +410,7 @@ nsresult nsXBLPrototypeProperty::ParseProperty(nsIScriptContext * aContext, nsIC if (!getter.IsEmpty() && mClassObject) { nsCAutoString functionUri; - functionUri.Assign(aClassStr); + functionUri.Assign(mClassStr); functionUri += "."; functionUri.AppendWithConversion(mName.get()); functionUri += " (getter)"; @@ -441,12 +441,12 @@ nsresult nsXBLPrototypeProperty::ParseProperty(nsIScriptContext * aContext, nsIC if (setter.IsEmpty()) { PRInt32 childCount; - aPropertyElement->ChildCount(childCount); + mPropertyElement->ChildCount(childCount); nsCOMPtr setterElement; for (PRInt32 j=0; jChildAt(j, *getter_AddRefs(setterElement)); + mPropertyElement->ChildAt(j, *getter_AddRefs(setterElement)); if (!setterElement) continue; @@ -462,7 +462,7 @@ nsresult nsXBLPrototypeProperty::ParseProperty(nsIScriptContext * aContext, nsIC if (!setter.IsEmpty() && mClassObject) { - nsCAutoString functionUri (aClassStr); + nsCAutoString functionUri (mClassStr); functionUri += "."; functionUri.AppendWithConversion(mName.get()); functionUri += " (setter)"; @@ -494,53 +494,64 @@ nsresult nsXBLPrototypeProperty::ParseProperty(nsIScriptContext * aContext, nsIC if (mJSSetterObject || mJSGetterObject) return NS_OK; - return ParseLiteral(aContext, aPropertyElement); + return ParseField(aContext); } // if name isn't empty return rv; } -nsresult nsXBLPrototypeProperty::ParseLiteral(nsIScriptContext * aContext, nsIContent* aPropertyElement) +nsresult nsXBLPrototypeProperty::ParseField(nsIScriptContext * aContext) { + nsresult rv = NS_OK; + mPropertyElement->GetAttr(kNameSpaceID_None, kNameAtom, mName); + if (mName.IsEmpty()) + return NS_OK; + + nsAutoString readOnly; + mPropertyElement->GetAttr(kNameSpaceID_None, kReadOnlyAtom, readOnly); + mJSAttributes = JSPROP_ENUMERATE; + if (readOnly == NS_LITERAL_STRING("true")) + mJSAttributes |= JSPROP_READONLY; // Fields can be read-only. + // Look for a normal value and just define that. nsCOMPtr textChild; PRInt32 textCount; - aPropertyElement->ChildCount(textCount); + mPropertyElement->ChildCount(textCount); for (PRInt32 j = 0; j < textCount; j++) { // Get the child. - aPropertyElement->ChildAt(j, *getter_AddRefs(textChild)); + mPropertyElement->ChildAt(j, *getter_AddRefs(textChild)); nsCOMPtr text(do_QueryInterface(textChild)); if (text) { nsAutoString data; text->GetData(data); - mLiteralPropertyString += data; + mFieldString += data; } } // for each element return NS_OK; } -nsresult nsXBLPrototypeProperty::ParseMethod(nsIScriptContext * aContext, nsIContent* aPropertyElement, const char * aClassStr) +nsresult nsXBLPrototypeProperty::ParseMethod(nsIScriptContext * aContext) { // TO DO: fix up class name and class object // Obtain our name attribute. nsAutoString body; nsresult rv = NS_OK; - aPropertyElement->GetAttr(kNameSpaceID_None, kNameAtom, mName); + mPropertyElement->GetAttr(kNameSpaceID_None, kNameAtom, mName); // Now walk all of our args. // XXX I'm lame. 32 max args allowed. char* args[32]; PRUint32 argCount = 0; PRInt32 kidCount; - aPropertyElement->ChildCount(kidCount); + mPropertyElement->ChildCount(kidCount); for (PRInt32 j = 0; j < kidCount; j++) { nsCOMPtr arg; - aPropertyElement->ChildAt(j, *getter_AddRefs(arg)); + mPropertyElement->ChildAt(j, *getter_AddRefs(arg)); nsCOMPtr kidTagName; arg->GetTag(*getter_AddRefs(kidTagName)); @@ -579,7 +590,7 @@ nsresult nsXBLPrototypeProperty::ParseMethod(nsIScriptContext * aContext, nsICon if (!body.IsEmpty()) { nsCAutoString cname; cname.AssignWithConversion(mName.get()); - nsCAutoString functionUri (aClassStr); + nsCAutoString functionUri (mClassStr); functionUri += "."; functionUri += cname; functionUri += "()"; diff --git a/content/xbl/src/nsXBLPrototypeProperty.h b/content/xbl/src/nsXBLPrototypeProperty.h index 11aee568c60..98cecce4b62 100644 --- a/content/xbl/src/nsXBLPrototypeProperty.h +++ b/content/xbl/src/nsXBLPrototypeProperty.h @@ -61,6 +61,7 @@ protected: static nsIAtom* kParameterAtom; static nsIAtom* kBodyAtom; static nsIAtom* kPropertyAtom; + static nsIAtom* kFieldAtom; static nsIAtom* kOnSetAtom; static nsIAtom* kOnGetAtom; static nsIAtom* kGetterAtom; @@ -71,11 +72,11 @@ protected: JSObject * mJSMethodObject; // precompiled JS for a method JSObject * mJSGetterObject; // precompiled JS for a getter property JSObject * mJSSetterObject; // precompiled JS for a setter property - nsString mLiteralPropertyString; // the property is just a literal string + nsString mFieldString; // a field's raw value. JSObject* mClassObject; - nsString mName; // name of the property + nsString mName; // name of the property or field uintN mJSAttributes; nsWeakPtr mPrototypeBinding; // weak reference back to the proto type binding which owns us. @@ -87,9 +88,9 @@ protected: protected: nsresult GetTextData(nsIContent *aParent, nsString& aResult); - nsresult ParseMethod(nsIScriptContext * aContext, nsIContent * aNode, const char * aClassStr); - nsresult ParseProperty(nsIScriptContext * aContext, nsIContent * aNode, const char * aClassStr); - nsresult ParseLiteral(nsIScriptContext * aContext, nsIContent* aPropertyElement); + nsresult ParseMethod(nsIScriptContext * aContext); + nsresult ParseProperty(nsIScriptContext * aContext); + nsresult ParseField(nsIScriptContext * aContext); nsresult DelayedPropertyConstruction(); };