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

Test members installed by maplike/setlike declarations #33951

Merged
merged 1 commit into from
Jul 12, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions event-timing/idlharness.any.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ idl_test(
idl_array => {
idl_array.add_objects({
Performance: ['performance'],
EventCounts: ['performance.eventCounts'],
InteractionCounts: ['performance.interactionCounts'],
// PerformanceEventTiming: [ TODO ]
});
}
Expand Down
99 changes: 98 additions & 1 deletion resources/idlharness.js
Original file line number Diff line number Diff line change
Expand Up @@ -2458,7 +2458,7 @@ IdlInterface.prototype.test_member_iterable = function(member)
].forEach(([property, length]) => {
var desc = Object.getOwnPropertyDescriptor(proto, property);
assert_equals(typeof desc.value, "function", property + " property should be a function");
assert_equals(desc.value.length, length, property + " function object length should be " + length);
assert_equals(desc.value.length, length, property + " function object should have the right length");
assert_equals(desc.value.name, property, property + " function object should have the right name");
});
} else {
Expand All @@ -2471,6 +2471,97 @@ IdlInterface.prototype.test_member_iterable = function(member)
}.bind(this), this.name + " interface: iterable<" + member.idlType.map(function(t) { return t.idlType; }).join(", ") + ">");
};

IdlInterface.prototype.test_member_maplike = function(member) {
subsetTestByKey(this.name, test, () => {
const proto = this.get_interface_object().prototype;

const methods = [
["entries", 0],
["keys", 0],
["values", 0],
["forEach", 1],
["get", 1],
["has", 1]
];
if (!member.readonly) {
methods.push(
["set", 2],
["delete", 1],
["clear", 1]
);
}

for (const [name, length] of methods) {
const desc = Object.getOwnPropertyDescriptor(proto, name);
assert_equals(typeof desc.value, "function", `${name} should be a function`);
assert_equals(desc.enumerable, false, `${name} enumerable`);
assert_equals(desc.configurable, true, `${name} configurable`);
assert_equals(desc.writable, true, `${name} writable`);
assert_equals(desc.value.length, length, `${name} function object length should be ${length}`);
assert_equals(desc.value.name, name, `${name} function object should have the right name`);
}

const iteratorDesc = Object.getOwnPropertyDescriptor(proto, Symbol.iterator);
assert_equals(iteratorDesc.value, proto.entries, `@@iterator should equal entries`);
assert_equals(iteratorDesc.enumerable, false, `@@iterator enumerable`);
assert_equals(iteratorDesc.configurable, true, `@@iterator configurable`);
assert_equals(iteratorDesc.writable, true, `@@iterator writable`);

const sizeDesc = Object.getOwnPropertyDescriptor(proto, "size");
assert_equals(typeof sizeDesc.get, "function", `size getter should be a function`);
assert_equals(sizeDesc.set, undefined, `size should not have a setter`);
assert_equals(sizeDesc.enumerable, false, `size enumerable`);
assert_equals(sizeDesc.configurable, true, `size configurable`);
assert_equals(sizeDesc.get.length, 0, `size getter length should have the right length`);
assert_equals(sizeDesc.get.name, "get size", `size getter have the right name`);
}, `${this.name} interface: maplike<${member.idlType.map(t => t.idlType).join(", ")}>`);
};

IdlInterface.prototype.test_member_setlike = function(member) {
subsetTestByKey(this.name, test, () => {
const proto = this.get_interface_object().prototype;

const methods = [
["entries", 0],
["keys", 0],
["values", 0],
["forEach", 1],
["has", 1]
];
if (!member.readonly) {
methods.push(
["add", 1],
["delete", 1],
["clear", 1]
);
}

for (const [name, length] of methods) {
const desc = Object.getOwnPropertyDescriptor(proto, name);
assert_equals(typeof desc.value, "function", `${name} should be a function`);
assert_equals(desc.enumerable, false, `${name} enumerable`);
assert_equals(desc.configurable, true, `${name} configurable`);
assert_equals(desc.writable, true, `${name} writable`);
assert_equals(desc.value.length, length, `${name} function object length should be ${length}`);
assert_equals(desc.value.name, name, `${name} function object should have the right name`);
}

const iteratorDesc = Object.getOwnPropertyDescriptor(proto, Symbol.iterator);
assert_equals(iteratorDesc.value, proto.values, `@@iterator should equal values`);
assert_equals(iteratorDesc.enumerable, false, `@@iterator enumerable`);
assert_equals(iteratorDesc.configurable, true, `@@iterator configurable`);
assert_equals(iteratorDesc.writable, true, `@@iterator writable`);

const sizeDesc = Object.getOwnPropertyDescriptor(proto, "size");
assert_equals(typeof sizeDesc.get, "function", `size getter should be a function`);
assert_equals(sizeDesc.set, undefined, `size should not have a setter`);
assert_equals(sizeDesc.enumerable, false, `size enumerable`);
assert_equals(sizeDesc.configurable, true, `size configurable`);
assert_equals(sizeDesc.get.length, 0, `size getter length should have the right length`);
assert_equals(sizeDesc.get.name, "size", `size getter have the right name`);
}, `${this.name} interface: setlike<${member.idlType.map(t => t.idlType).join(", ")}>`);
};

IdlInterface.prototype.test_member_async_iterable = function(member)
{
subsetTestByKey(this.name, test, function()
Expand Down Expand Up @@ -2624,6 +2715,12 @@ IdlInterface.prototype.test_members = function()
this.test_member_iterable(member);
}
break;
case "maplike":
this.test_member_maplike(member);
break;
case "setlike":
this.test_member_setlike(member);
break;
default:
// TODO: check more member types.
break;
Expand Down