Skip to content

Support [Global] #456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 27, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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