зеркало из https://github.com/mozilla/pjs.git
Bug 581305 - Expect nsIClassInfo of XPath extension functions in class, not in factory, r=peterv, a=jst
This commit is contained in:
Родитель
c6d05bf55a
Коммит
13662e0392
|
@ -191,10 +191,13 @@ private:
|
|||
|
||||
static nsresult
|
||||
LookupFunction(const char *aContractID, nsIAtom* aName, nsIID &aIID,
|
||||
PRUint16 &aMethodIndex)
|
||||
PRUint16 &aMethodIndex, nsISupports **aHelper)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIClassInfo> classInfo = do_GetClassObject(aContractID, &rv);
|
||||
nsCOMPtr<nsISupports> helper = do_GetService(aContractID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIClassInfo> classInfo = do_QueryInterface(helper, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsIInterfaceInfoManager> iim =
|
||||
|
@ -252,8 +255,7 @@ LookupFunction(const char *aContractID, nsIAtom* aName, nsIID &aIID,
|
|||
|
||||
aIID = *iid;
|
||||
aMethodIndex = methodIndex;
|
||||
|
||||
return NS_OK;
|
||||
return helper->QueryInterface(aIID, (void**)aHelper);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -268,11 +270,10 @@ TX_ResolveFunctionCallXPCOM(const nsCString &aContractID, PRInt32 aNamespaceID,
|
|||
{
|
||||
nsIID iid;
|
||||
PRUint16 methodIndex;
|
||||
nsresult rv = LookupFunction(aContractID.get(), aName, iid, methodIndex);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsISupports> helper;
|
||||
rv = CallGetService(aContractID.get(), iid, getter_AddRefs(helper));
|
||||
|
||||
nsresult rv = LookupFunction(aContractID.get(), aName, iid, methodIndex,
|
||||
getter_AddRefs(helper));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
if (!aFunction) {
|
||||
|
|
|
@ -50,22 +50,31 @@ function txEXSLTRegExFunctions()
|
|||
{
|
||||
}
|
||||
|
||||
var SingletonInstance = null;
|
||||
|
||||
txEXSLTRegExFunctions.prototype = {
|
||||
classID: Components.ID("{18a03189-067b-4978-b4f1-bafe35292ed6}"),
|
||||
classID: EXSLT_REGEXP_CID,
|
||||
|
||||
QueryInterface: function(iid) {
|
||||
if (iid.equals(Ci.nsISupports) ||
|
||||
iid.equals(Ci.txIEXSLTRegExFunctions))
|
||||
return this;
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.txIEXSLTRegExFunctions,
|
||||
Ci.nsIClassInfo]),
|
||||
|
||||
if (iid.equals(Ci.nsIClassInfo))
|
||||
return txEXSLTRegExModule.factory
|
||||
// nsIClassInfo
|
||||
getInterfaces: function(countRef) {
|
||||
var interfaces = [
|
||||
Ci.txIEXSLTRegExFunctions
|
||||
];
|
||||
countRef.value = interfaces.length;
|
||||
|
||||
throw Components.results.NS_ERROR_NO_INTERFACE;
|
||||
return interfaces;
|
||||
},
|
||||
|
||||
getHelperForLanguage: function(language) {
|
||||
return null;
|
||||
},
|
||||
|
||||
implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT,
|
||||
flags: 0,
|
||||
|
||||
|
||||
// txIEXSLTRegExFunctions
|
||||
match: function(context, str, regex, flags) {
|
||||
var nodeset = Components.classes[NODESET_CONTRACTID]
|
||||
.createInstance(Ci.txINodeSet);
|
||||
|
@ -101,38 +110,6 @@ txEXSLTRegExFunctions.prototype = {
|
|||
var re = new RegExp(regex, flags);
|
||||
|
||||
return re.test(str);
|
||||
},
|
||||
|
||||
_xpcom_factory: {
|
||||
QueryInterface: XPCOMUtils.generateQI([Ci.nsIFactory,
|
||||
Ci.nsIClassInfo]),
|
||||
|
||||
createInstance: function(outer, iid) {
|
||||
if (outer != null)
|
||||
throw Components.results.NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
if (SingletonInstance == null)
|
||||
SingletonInstance = new txEXSLTRegExFunctions();
|
||||
|
||||
return SingletonInstance.QueryInterface(iid);
|
||||
},
|
||||
|
||||
getInterfaces: function(countRef) {
|
||||
var interfaces = [
|
||||
Ci.txIEXSLTRegExFunctions
|
||||
];
|
||||
countRef.value = interfaces.length;
|
||||
|
||||
return interfaces;
|
||||
},
|
||||
|
||||
getHelperForLanguage: function(language) {
|
||||
return null;
|
||||
},
|
||||
|
||||
classID: EXSLT_REGEXP_CID,
|
||||
implementationLanguage: Ci.nsIProgrammingLanguage.JAVASCRIPT,
|
||||
flags: Ci.nsIClassInfo.SINGLETON
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ _TEST_FILES = test_bug319374.xhtml \
|
|||
test_bug511487.html \
|
||||
test_bug551412.html \
|
||||
test_bug551654.html \
|
||||
test_exslt_regex.html \
|
||||
$(NULL)
|
||||
|
||||
libs:: $(_TEST_FILES)
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
Test EXSLT Regular Expression Extension
|
||||
http://www.exslt.org/regexp/index.html
|
||||
-->
|
||||
<head>
|
||||
<title>Test for EXSLT Regular Expression Extensions</title>
|
||||
<script type="application/javascript" src="/MochiKit/packed.js"></script>
|
||||
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<p id="display"></p>
|
||||
<div id="content" style="display: none"></div>
|
||||
<pre id="test">
|
||||
<script type="application/javascript">
|
||||
var tests = [
|
||||
{ descr: "Testing regexp:test",
|
||||
expr: "regexp:test('XSLT is great', 'XSLT', '')",
|
||||
expResult: "true" },
|
||||
|
||||
{ descr: "Testing regexp:match",
|
||||
expr: "regexp:match('XSLT is great', 'XSL.', '')[1]",
|
||||
expResult: "XSLT" },
|
||||
|
||||
{ descr: "Testing regexp:replace",
|
||||
expr: "regexp:replace('Food is great', 'Fo.d', '', 'XSLT')",
|
||||
expResult: "XSLT is great" }
|
||||
];
|
||||
|
||||
for each(test in tests) {
|
||||
var style =
|
||||
'<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ' +
|
||||
'xmlns:regexp="http://exslt.org/regular-expressions" '+
|
||||
'version="1.0">' +
|
||||
'<xsl:output method="html"/>' +
|
||||
'<xsl:template match="/">' +
|
||||
'<xsl:value-of select="'+test.expr+'" /> ' +
|
||||
'</xsl:template>' +
|
||||
'</xsl:stylesheet>';
|
||||
var styleDoc = new DOMParser().parseFromString (style, "text/xml");
|
||||
|
||||
var data = '<root/>';
|
||||
var originalDoc = new DOMParser().parseFromString(data, "text/xml");
|
||||
|
||||
var processor = new XSLTProcessor();
|
||||
processor.importStylesheet(styleDoc);
|
||||
|
||||
var fragment = processor.transformToFragment(originalDoc, document);
|
||||
var content = document.getElementById("content");
|
||||
content.appendChild(fragment);
|
||||
is(content.innerHTML, test.expResult, test.descr);
|
||||
|
||||
content.innerHTML = '';
|
||||
}
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Загрузка…
Ссылка в новой задаче