From 9ea65c52298cc33c6bc229226004dc31e83d042f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcos=20C=C3=A1ceres?= formatting,
- // marked as an IDL definition, and returned. If no is found,
+ // marked as an IDL definition, and returned. If no is found,
// the function returns 'undefined'.
- function findDfn(parent, name, definitionMap) {
+ function findDfn(parent, name, definitionMap, type) {
var originalParent = parent;
var originalName = name;
parent = parent.toLowerCase();
- name = name.toLowerCase();
- if (unlinkable.has(name)){
+ switch (type) {
+ case "operation":
+ // ignore overloads
+ if (name.search("!overload") !== -1) {
+ break;
+ }
+ // Allow linking to both "method()" and "method" name.
+ const asMethodName = name.toLowerCase() + "()";
+
+ if (definitionMap[asMethodName]) {
+ const dfn = findDfn(parent, asMethodName, definitionMap);
+ if (!dfn) {
+ break; // try finding dfn using name, using normal search path...
+ }
+ const lt = (dfn[0].dataset.lt) ? dfn[0].dataset.lt.split("|") : [];
+ lt.push(asMethodName, name);
+ dfn[0].dataset.lt = lt.join("|");
+ if (!definitionMap[name]) {
+ definitionMap[name] = [];
+ }
+ definitionMap[name].push(dfn);
+ return dfn;
+ };
+ // no method alias, so let's find the dfn and add it
+ const dfn = findDfn(parent, name, definitionMap);
+ if (!dfn) {
+ break;
+ }
+ const lt = (dfn[0].dataset.lt) ? dfn[0].dataset.lt.split("|") : [];
+ lt.push(asMethodName, name);
+ dfn[0].dataset.lt = lt.join("|");
+ definitionMap[asMethodName] = [dfn];
+ return dfn;
+ case "enum":
+ if (name === "") {
+ name = "the-empty-string";
+ break;
+ }
+ default:
+ name = name.toLowerCase();
+ }
+ if (unlinkable.has(name)) {
return;
}
var dfnForArray = definitionMap[name];
@@ -882,9 +926,11 @@ define(
pubsubhub.pub("error", "Multiple s for " + originalName + (originalParent ? " in " + originalParent : ""));
}
if (dfns.length === 0) {
- const msg = "No for " + originalName + (originalParent ? " in " + originalParent : "") + ".";
- pubsubhub.pub("warn", msg);
- return undefined;
+ if (type) {
+ const msg = "No for " + originalName + (originalParent ? " in " + originalParent : "") + ".";
+ pubsubhub.pub("warn", msg);
+ }
+ return;
}
var dfn = dfns[0];
// Mark the definition as code.
diff --git a/tests/spec/core/webidl-contiguous-spec.js b/tests/spec/core/webidl-contiguous-spec.js
index 8c002ba4e3..78374c9b77 100644
--- a/tests/spec/core/webidl-contiguous-spec.js
+++ b/tests/spec/core/webidl-contiguous-spec.js
@@ -11,6 +11,46 @@ describe("Core - Contiguous WebIDL", function() {
doc = idlDoc;
}, "spec/core/webidl-contiguous.html").then(done);
});
+
+ it("links simple method names and types", done => {
+ const section = doc.querySelector("#sec-parenthesis-method");
+ [
+ "basic",
+ "ext",
+ "ull",
+ "paramed",
+ "withName",
+ "named",
+ ]
+ .map(
+ methodName => [methodName, methodName.toLowerCase()]
+ )
+ .map(
+ ([methodName, id]) => [id, methodName, doc.getElementById(`dom-parenthesistest-${id}()`)]
+ )
+ .forEach(([id, methodName, elem]) => {
+ expect(elem).toBeTruthy();
+ expect(elem.firstElementChild.localName).toEqual("code");
+ expect(elem.textContent).toEqual(`${methodName}()`);
+ expect(elem.id).toEqual(`dom-parenthesistest-${id}()`);
+ expect(elem.dataset.dfnType).toEqual("dfn");
+ expect(elem.dataset.dfnFor).toEqual("parenthesistest");
+ expect(elem.dataset.idl).toEqual("");
+ // corresponding link
+ const aElem = section.querySelector(`pre a[href="#dom-parenthesistest-${id}()"]`);
+ expect(aElem).toBeTruthy();
+ expect(aElem.textContent).toEqual(methodName);
+ });
+ const smokeTest = doc.getElementById("dom-parenthesistest-noparens");
+ expect(smokeTest).toBeTruthy();
+ expect(smokeTest.firstElementChild.localName).toEqual("code");
+ expect(smokeTest.textContent).toEqual("noParens");
+ // corresponding link
+ const aElem = section.querySelector(`pre a[href="#dom-parenthesistest-noparens"]`);
+ expect(aElem).toBeTruthy();
+ expect(aElem.textContent).toEqual("noParens");
+ done();
+ });
it("should handle interfaces", function(done) {
var $target = $("#if-basic", doc);
var text = "interface SuperStar {\n};";
@@ -530,7 +570,7 @@ describe("Core - Contiguous WebIDL", function() {
expect($target.find(".idlEnumItem").length)
.toEqual(4);
expect($target.find(".idlEnumItem").first().text())
- .toEqual("one");
+ .toEqual("\"one\"");
// Links and IDs.
expect($target.find(":contains('EnumBasic')").filter("a").attr("href"))
@@ -551,6 +591,16 @@ describe("Core - Contiguous WebIDL", function() {
done();
});
+ it("links empty-string enumeration value", done => {
+ const links = doc.querySelector(`#enum-empty-sec a[href="#dom-emptyenum-the-empty-string"]`);
+ const dfn = doc.querySelector("#dom-emptyenum-the-empty-string");
+ const smokeDfn = doc.querySelector(`#enum-empty-sec a[href="#dom-emptyenum-not empty"]`);
+ expect(links).toBeTruthy();
+ expect(dfn).toBeTruthy();
+ expect(smokeDfn).toBeTruthy();
+ done();
+ });
+
it("should handle callbacks", function(done) {
var $target = $("#cb-basic", doc);
var text = "callback SuperStar = void ();";
diff --git a/tests/spec/core/webidl-contiguous.html b/tests/spec/core/webidl-contiguous.html
index abeb618e49..ca740e9a70 100644
--- a/tests/spec/core/webidl-contiguous.html
+++ b/tests/spec/core/webidl-contiguous.html
@@ -37,6 +37,45 @@
CUSTOM PARAGRAPH
+ interface ParenthesisTest { + void basic(); + void noParens(); + [Something] void ext(); + unsigned long long ull(short s); + unsigned long long ull(long s); + SuperStar[][][][] paramed(SuperStar[][]?[] one, [ExtAttrs] ByteString? ext, optional short maybe, short[] shorts, short[][][][] hypercubes, optional short defaulted = 3.5, optional DOMString defaulted2 = "one", short... variable); + getter float withName (); + setter void named (); + void dataLtOverride(); + }; ++
+ ull is a method. Its overloaded form returns a SuperStar/
+
dataLtOverride()
+ParenthesisTest
+basic()...
+ext()...
+ull()...
+paramed()...
+withName()...
+named()...
+dfnDoesNotLinkToAnything()...
+noParens...
+1 basic
+2 basic()
+3 basic
+4 basic
+ + + + + + +@@ -410,6 +449,17 @@
one is first.
one is referenced with a [link-for]
attribute.
EnumBasic.one may also be referenced with fully-qualified name.
++ enum EmptyEnum { + "", + "not empty" + }; ++
EmptyEnum
+""
... +not empty...
+