2015-04-07 84 views
2

爲Windows創建一個XulRunner應用程序我發現如果綁定B擴展綁定A。並且B正在被刪除,則僅調用B的析構函數,之後不會調用的A的析構函數。爲什麼在擴展綁定被刪除時不會調用擴展綁定的析構函數?

我的代碼有什麼問題,或者這是一個XulRunner錯誤(我在bugzilla中找不到匹配的錯誤)?

log after binding B is removed

這裏是我上的XULrunner 23和35檢測的一個例子:

main.xul:

<?xml version="1.0"?> 
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> 
<window id="main" title="My App" width="500" height="300" sizemode="normal" 
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 
     xmlns:html="http://www.w3.org/1999/xhtml"> 
    <script><![CDATA[ 
    function print(aString) { 
     document.getElementById("log_msg").value += aString + "\n"; 
    } 
    function removeElementById(aId) { 
     document.getElementById(aId).remove(); 
    }; 
    function callF(aId) { 
     document.getElementById(aId).f(); 
    } 
    ]]></script> 
    <vbox flex="1"> 
    <label onclick="removeElementById('A')">remove A</label> 
    <label onclick="removeElementById('B')">remove B</label> 
    <label onclick="callF('A')">Call A.f()</label> 
    <label onclick="callF('B')">Call B.f()</label> 
    <!--<binding-a id="A" style="-moz-binding: url('binding.xml#binding-a')"/>--> 
    <binding-b id="B" style="-moz-binding: url('binding.xml#binding-b')"/> 
    <textbox id="log_msg" label="Text" placeholder="placeholder" multiline="true" rows="6"/> 
    </vbox> 
</window> 

binding.xml:

<?xml version="1.0"?> 
<bindings xmlns="http://www.mozilla.org/xbl" 
    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 
    <binding id="binding-a"> 
    <content> 
     <xul:label anonid="label" value="Binding A"/> 
    </content> 
    <implementation> 
     <constructor><![CDATA[ 
     var label = document.getAnonymousElementByAttribute(this, "anonid", "label"); 
     label.value = label.value + " A.constructor"; 
     window.print("A.constructor"); 
     ]]></constructor> 
     <destructor><![CDATA[ 
     window.print("A.destructor"); 
     ]]></destructor> 
     <method name="f"> 
     <body><![CDATA[ 
      window.print("A.f"); 
     ]]></body> 
     </method> 
    </implementation> 
    </binding> 

    <binding id="binding-b" extends="#binding-a"> 
    <content> 
     <xul:label anonid="label" value="Binding B"/> 
    </content> 
    <implementation> 
     <constructor><![CDATA[ 
     window.print("B.constructor"); 
     ]]></constructor> 
     <destructor><![CDATA[ 
     window.print("B.destructor"); 
     ]]></destructor> 
    </implementation> 
    </binding> 
</bindings> 
+1

這是我和其他人都遇到的問題,這些都是討論的事情:https://ask.mozilla.org/question/297/apply-and-remove-xbl-binding-on-runtime/| https://ask.mozilla.org/question/271/my-xbl-is-not-working-on-findbar/ | https://stackoverflow.com/questions/24403667/dynamic-way-to-unbind-dynamically-binded-xbl |還有一些病人需要挖掘它 – Noitidart

回答

1

這裏是解決您的問題:

bindings.xml:

<?xml version="1.0"?> 
<bindings xmlns="http://www.mozilla.org/xbl" 
    xmlns:xbl="http://www.mozilla.org/xbl" 
    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 
    <binding id="binding-a"> 
    <content> 
     <xul:label anonid="label" value="Binding A"/> 
    </content> 
    <implementation> 
     <constructor><![CDATA[ 
     var label = document.getAnonymousElementByAttribute(this, "anonid", "label"); 
     label.value = label.value + " A.constructor"; 
     window.print("A.constructor"); 
     ]]></constructor> 
     <destructor><![CDATA[ 
     this.destruct(); 
     ]]></destructor> 
     <method name="f"> 
     <body><![CDATA[ 
      window.print("A.f"); 
     ]]></body> 
     </method> 
     <method name="destruct"> 
     <body><![CDATA[ 
      window.print("A.destructor"); 
     ]]></body> 
     </method> 
    </implementation> 
    </binding> 

    <binding id="binding-b" extends="#binding-a"> 
    <content> 
     <xul:label anonid="label" value="Binding B"/> 
    </content> 
    <implementation> 
     <constructor><![CDATA[ 
     window.print("B.constructor"); 
     ]]></constructor> 
     <destructor><![CDATA[ 
      this.destruct(); 
     ]]></destructor> 
     <method name="destruct"> 
     <body><![CDATA[ 
     this.__proto__.__proto__.destruct.call(this); 
      window.print("B.destructor"); 
     ]]></body> 
     </method> 
    </implementation> 
    </binding> 
</bindings> 

bindings.css:

@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); 

binding-a { -moz-binding: url("bindings.xml#binding-a"); } 
binding-b { -moz-binding: url("bindings.xml#binding-b"); } 

main.xul:

<?xml version="1.0"?> 
<?xml-stylesheet href="chrome://global/skin/" type="text/css"?> 
<?xml-stylesheet href="bindings.css" type="text/css"?> 
<window id="main" title="My App" width="500" height="300" sizemode="normal" 
     xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" 
     xmlns:html="http://www.w3.org/1999/xhtml"> 
    <script><![CDATA[ 
    function print(aString) { 
     document.getElementById("log_msg").value += aString + "\n"; 
    } 
    function removeElementById(aId) { 
     document.getElementById(aId).remove(); 
    }; 
    function callF(aId) { 
     document.getElementById(aId).f(); 
    } 
    ]]></script> 
    <vbox flex="1"> 
    <label onclick="removeElementById('A')">remove A</label> 
    <label onclick="removeElementById('B')">remove B</label> 
    <label onclick="callF('A')">Call A.f()</label> 
    <label onclick="callF('B')">Call B.f()</label> 
    <binding-a id="A"/> 
    <binding-b id="B"/> 
    <textbox id="log_msg" label="Text" placeholder="placeholder" multiline="true" rows="6"/> 
    </vbox> 
</window> 

我知道,它實際上是一個黑客,但它的工作原理。

+1

在FF 36上測試。 –

+0

我喜歡'this .__ proto __.__ proto __。destruct.call(this)'。 您能否確認在您的環境中實際存在此問題? 在你的解決方法中,我必須創建'destruct'方法嗎?我可以直接調用'binding-a'的''嗎? –

+1

當子綁定被破壞時,我可以確認不會自動調用擴展綁定中的''。這只是一個解決方法 - 如果你想要的話可​​以進行破解。 –