Skip to content

Commit

Permalink
Merge pull request #456 from saschanaz/global
Browse files Browse the repository at this point in the history
Support [Global]
  • Loading branch information
mhegazy authored Apr 27, 2018
2 parents 4347577 + bd923b5 commit c6f87f1
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions src/widlprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,6 @@ export function convert(text: string) {
return { browser, partialInterfaces, partialDictionaries, includes };
}

function getExposure(extAttrs: webidl2.ExtendedAttributes[], inheritedExposure?: string) {
for (const extAttr of extAttrs) {
if (extAttr.name === "Exposed") {
if (Array.isArray(extAttr.rhs.value)) {
return extAttr.rhs.value.join(' ');
}
return extAttr.rhs.value;
}
}
return inheritedExposure;
}

function hasExtAttr(extAttrs: webidl2.ExtendedAttributes[], name: string) {
return extAttrs.some(extAttr => extAttr.name === name);
}
Expand All @@ -74,6 +62,13 @@ function getExtAttr(extAttrs: webidl2.ExtendedAttributes[], name: string) {
return attr.rhs.type === "identifier-list" ? attr.rhs.value : [attr.rhs.value];
}

function getExtAttrConcatenated(extAttrs: webidl2.ExtendedAttributes[], name: string) {
const extAttr = getExtAttr(extAttrs, name);
if (extAttr) {
return extAttr.join(" ");
}
}

function convertInterface(i: webidl2.InterfaceType) {
const result = convertInterfaceCommon(i);
if (i.inheritance) {
Expand All @@ -96,7 +91,8 @@ function convertInterfaceCommon(i: webidl2.InterfaceType | webidl2.InterfaceMixi
methods: { method: {} },
properties: { property: {} },
constructor: getConstructor(i.extAttrs, i.name),
exposed: getExposure(i.extAttrs),
exposed: getExtAttrConcatenated(i.extAttrs, "Exposed"),
global: getExtAttrConcatenated(i.extAttrs, "Global"),
"no-interface-object": hasExtAttr(i.extAttrs, "NoInterfaceObject") ? 1 : undefined,
"legacy-window-alias": getExtAttr(i.extAttrs, "LegacyWindowAlias")
};
Expand Down Expand Up @@ -162,7 +158,7 @@ function convertOperation(operation: webidl2.OperationMemberType, inheritedExpos
getter: operation.getter ? 1 : undefined,
static: operation.static ? 1 : undefined,
stringifier: operation.stringifier ? 1 : undefined,
exposed: getExposure(operation.extAttrs, inheritedExposure)
exposed: getExtAttrConcatenated(operation.extAttrs, "Exposed") || inheritedExposure
};
}

Expand Down Expand Up @@ -193,7 +189,7 @@ function convertAttribute(attribute: webidl2.AttributeMemberType, inheritedExpos
static: attribute.static ? 1 : undefined,
"read-only": attribute.readonly ? 1 : undefined,
"event-handler": attribute.idlType.idlType === "EventHandler" ? attribute.name.slice(2) : undefined,
exposed: getExposure(attribute.extAttrs, inheritedExposure)
exposed: getExtAttrConcatenated(attribute.extAttrs, "Exposed") || inheritedExposure
}
}

Expand Down

0 comments on commit c6f87f1

Please sign in to comment.