Skip to content
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

Tweak test cases for dictionary defaults #225

Merged
merged 2 commits into from
May 20, 2020
Merged
Show file tree
Hide file tree
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
9 changes: 8 additions & 1 deletion lib/parameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ function generateVarConversion(ctx, overload, i, parent, errPrefix, targetIdx =
const requires = new utils.RequiresMap(ctx);
const idlType = overload.typeList[i];
// Always (try to) force-convert dictionaries
const optional = overload.optionalityList[i] === "optional" && !ctx.dictionaries.has(idlType.idlType);
const isDefaultedDictionary = overload.operation.arguments[i].default &&
overload.operation.arguments[i].default.type === "dictionary";
if (isDefaultedDictionary && !ctx.dictionaries.has(idlType.idlType)) {
throw new Error(
`The parameter ${overload.operation.arguments[i].name} was defaulted to {}, but no dictionary named ` +
`${idlType.idlType} exists`);
}
const optional = overload.optionalityList[i] === "optional" && !isDefaultedDictionary;
let str = `{ let curArg = arguments[${targetIdx}];`;
if (optional) {
str += `
Expand Down
10 changes: 4 additions & 6 deletions test/__snapshots__/test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,7 @@ exports[`with processors DOMRect.webidl 1`] = `
const conversions = require(\\"webidl-conversions\\");
const utils = require(\\"./utils.js\\");

const Dictionary = require(\\"./Dictionary.js\\");
const implSymbol = utils.implSymbol;
const ctorRegistrySymbol = utils.ctorRegistrySymbol;

Expand Down Expand Up @@ -1412,9 +1413,7 @@ exports.install = (globalObject, globalNames) => {
const args = [];
{
let curArg = arguments[0];
if (curArg !== undefined) {
curArg = utils.tryImplForWrapper(curArg);
}
curArg = Dictionary.convert(curArg, { context: \\"Failed to execute 'fromRect' on 'DOMRect': parameter 1\\" });
args.push(curArg);
}
return utils.tryWrapperForImpl(Impl.implementation.fromRect(globalObject, ...args));
Expand Down Expand Up @@ -10243,6 +10242,7 @@ exports[`without processors DOMRect.webidl 1`] = `
const conversions = require(\\"webidl-conversions\\");
const utils = require(\\"./utils.js\\");

const Dictionary = require(\\"./Dictionary.js\\");
const implSymbol = utils.implSymbol;
const ctorRegistrySymbol = utils.ctorRegistrySymbol;

Expand Down Expand Up @@ -10474,9 +10474,7 @@ exports.install = (globalObject, globalNames) => {
const args = [];
{
let curArg = arguments[0];
if (curArg !== undefined) {
curArg = utils.tryImplForWrapper(curArg);
}
curArg = Dictionary.convert(curArg, { context: \\"Failed to execute 'fromRect' on 'DOMRect': parameter 1\\" });
args.push(curArg);
}
return utils.tryWrapperForImpl(Impl.implementation.fromRect(globalObject, ...args));
Expand Down
2 changes: 1 addition & 1 deletion test/cases/DOMRect.webidl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface DOMRect /* : DOMRectReadOnly */ {
constructor(optional unrestricted double x = 0, optional unrestricted double y = 0,
optional unrestricted double width = 0, optional unrestricted double height = 0);

[NewObject, WebIDL2JSCallWithGlobal] static DOMRect fromRect(optional DOMRectInit other);
[NewObject, WebIDL2JSCallWithGlobal] static DOMRect fromRect(optional Dictionary other = {});

attribute unrestricted double x;
attribute unrestricted double y;
Expand Down
2 changes: 1 addition & 1 deletion test/cases/DictionaryConvert.webidl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[Exposed=Window]
interface DictionaryConvert {
// Test force-conversion of dictionary types.
DOMString op(optional DOMString arg1, optional Dictionary arg2);
DOMString op(optional DOMString arg1, optional Dictionary arg2 = {});
};