Skip to content

Commit 9d28342

Browse files
committed
Expand iterable<> and async iterable<> checks
In particular, check the enumerable/configurable/writable-ness of all the methods. Related to whatwg/webidl#738.
1 parent 7d60342 commit 9d28342

File tree

1 file changed

+74
-62
lines changed

1 file changed

+74
-62
lines changed

resources/idlharness.js

+74-62
Original file line numberDiff line numberDiff line change
@@ -2433,44 +2433,6 @@ IdlInterface.prototype.test_to_json_operation = function(desc, memberHolderObjec
24332433
}
24342434
};
24352435

2436-
IdlInterface.prototype.test_member_iterable = function(member)
2437-
{
2438-
subsetTestByKey(this.name, test, function()
2439-
{
2440-
var isPairIterator = member.idlType.length === 2;
2441-
var proto = this.get_interface_object().prototype;
2442-
var iteratorDesc = Object.getOwnPropertyDescriptor(proto, Symbol.iterator);
2443-
2444-
assert_true(iteratorDesc.writable, "@@iterator property should be writable");
2445-
assert_true(iteratorDesc.configurable, "@@iterator property should be configurable");
2446-
assert_false(iteratorDesc.enumerable, "@@iterator property should not be enumerable");
2447-
assert_equals(typeof iteratorDesc.value, "function", "@@iterator property should be a function");
2448-
assert_equals(iteratorDesc.value.length, 0, "@@iterator function object length should be 0");
2449-
assert_equals(iteratorDesc.value.name, isPairIterator ? "entries" : "values", "@@iterator function object should have the right name");
2450-
2451-
if (isPairIterator) {
2452-
assert_equals(proto["entries"], proto[Symbol.iterator], "entries method should be the same as @@iterator method");
2453-
[
2454-
["entries", 0],
2455-
["keys", 0],
2456-
["values", 0],
2457-
["forEach", 1]
2458-
].forEach(([property, length]) => {
2459-
var desc = Object.getOwnPropertyDescriptor(proto, property);
2460-
assert_equals(typeof desc.value, "function", property + " property should be a function");
2461-
assert_equals(desc.value.length, length, property + " function object should have the right length");
2462-
assert_equals(desc.value.name, property, property + " function object should have the right name");
2463-
});
2464-
} else {
2465-
assert_equals(proto[Symbol.iterator], Array.prototype[Symbol.iterator], "@@iterator method should be the same as Array prototype's");
2466-
["entries", "keys", "values", "forEach", Symbol.iterator].forEach(property => {
2467-
var propertyName = property === Symbol.iterator ? "@@iterator" : property;
2468-
assert_equals(proto[property], Array.prototype[property], propertyName + " method should be the same as Array prototype's");
2469-
});
2470-
}
2471-
}.bind(this), this.name + " interface: iterable<" + member.idlType.map(function(t) { return t.idlType; }).join(", ") + ">");
2472-
};
2473-
24742436
IdlInterface.prototype.test_member_maplike = function(member) {
24752437
subsetTestByKey(this.name, test, () => {
24762438
const proto = this.get_interface_object().prototype;
@@ -2562,35 +2524,85 @@ IdlInterface.prototype.test_member_setlike = function(member) {
25622524
}, `${this.name} interface: setlike<${member.idlType.map(t => t.idlType).join(", ")}>`);
25632525
};
25642526

2565-
IdlInterface.prototype.test_member_async_iterable = function(member)
2566-
{
2567-
subsetTestByKey(this.name, test, function()
2568-
{
2569-
var isPairIterator = member.idlType.length === 2;
2570-
var proto = this.get_interface_object().prototype;
2571-
var iteratorDesc = Object.getOwnPropertyDescriptor(proto, Symbol.asyncIterator);
2527+
IdlInterface.prototype.test_member_iterable = function(member) {
2528+
subsetTestByKey(this.name, test, () => {
2529+
const isPairIterator = member.idlType.length === 2;
2530+
const proto = this.get_interface_object().prototype;
2531+
2532+
const methods = [
2533+
["entries", 0],
2534+
["keys", 0],
2535+
["values", 0],
2536+
["forEach", 1]
2537+
];
2538+
2539+
for (const [name, length] of methods) {
2540+
const desc = Object.getOwnPropertyDescriptor(proto, name);
2541+
assert_equals(typeof desc.value, "function", `${name} should be a function`);
2542+
assert_equals(desc.enumerable, true, `${name} enumerable`);
2543+
assert_equals(desc.configurable, true, `${name} configurable`);
2544+
assert_equals(desc.writable, true, `${name} writable`);
2545+
assert_equals(desc.value.length, length, `${name} function object length should be ${length}`);
2546+
assert_equals(desc.value.name, name, `${name} function object should have the right name`);
25722547

2573-
assert_true(iteratorDesc.writable, "@@asyncIterator property should be writable");
2574-
assert_true(iteratorDesc.configurable, "@@asyncIterator property should be configurable");
2575-
assert_false(iteratorDesc.enumerable, "@@asyncIterator property should not be enumerable");
2576-
assert_equals(typeof iteratorDesc.value, "function", "@@asyncIterator property should be a function");
2577-
assert_equals(iteratorDesc.value.length, 0, "@@asyncIterator function object length should be 0");
2578-
assert_equals(iteratorDesc.value.name, isPairIterator ? "entries" : "values", "@@asyncIterator function object should have the right name");
2548+
if (!isPairIterator) {
2549+
assert_equals(desc.value, Array.prototype[name], `${name} equality with Array.prototype version`);
2550+
}
2551+
}
2552+
2553+
const iteratorDesc = Object.getOwnPropertyDescriptor(proto, Symbol.iterator);
2554+
assert_equals(iteratorDesc.enumerable, false, `@@iterator enumerable`);
2555+
assert_equals(iteratorDesc.configurable, true, `@@iterator configurable`);
2556+
assert_equals(iteratorDesc.writable, true, `@@iterator writable`);
25792557

25802558
if (isPairIterator) {
2581-
assert_equals(proto["entries"], proto[Symbol.asyncIterator], "entries method should be the same as @@asyncIterator method");
2582-
["entries", "keys", "values"].forEach(property => {
2583-
var desc = Object.getOwnPropertyDescriptor(proto, property);
2584-
assert_equals(typeof desc.value, "function", property + " property should be a function");
2585-
assert_equals(desc.value.length, 0, property + " function object length should be 0");
2586-
assert_equals(desc.value.name, property, property + " function object should have the right name");
2587-
});
2559+
assert_equals(iteratorDesc.value, proto.entries, `@@iterator equality with entries`);
2560+
} else {
2561+
assert_equals(iteratorDesc.value, Array.prototype[Symbol.iterator], `@@iterator equality with Array.prototype version`);
2562+
}
2563+
}, `${this.name} interface: iterable<${member.idlType.map(t => t.idlType).join(", ")}>`);
2564+
};
2565+
2566+
IdlInterface.prototype.test_member_async_iterable = function(member) {
2567+
subsetTestByKey(this.name, test, () => {
2568+
const isPairIterator = member.idlType.length === 2;
2569+
const proto = this.get_interface_object().prototype;
2570+
2571+
// Note that although the spec allows arguments, which will be passed to the @@asyncIterator
2572+
// method (which is either values or entries), those arguments must always be optional. So
2573+
// length of 0 is still correct for values and entries.
2574+
const methods = [
2575+
["values", 0],
2576+
];
2577+
2578+
if (isPairIterator) {
2579+
methods.push(
2580+
["entries", 0],
2581+
["keys", 0]
2582+
);
2583+
}
2584+
2585+
for (const [name, length] of methods) {
2586+
const desc = Object.getOwnPropertyDescriptor(proto, name);
2587+
assert_equals(typeof desc.value, "function", `${name} should be a function`);
2588+
assert_equals(desc.enumerable, true, `${name} enumerable`);
2589+
assert_equals(desc.configurable, true, `${name} configurable`);
2590+
assert_equals(desc.writable, true, `${name} writable`);
2591+
assert_equals(desc.value.length, length, `${name} function object length should be ${length}`);
2592+
assert_equals(desc.value.name, name, `${name} function object should have the right name`);
2593+
}
2594+
2595+
const iteratorDesc = Object.getOwnPropertyDescriptor(proto, Symbol.asyncIterator);
2596+
assert_equals(iteratorDesc.enumerable, false, `@@iterator enumerable`);
2597+
assert_equals(iteratorDesc.configurable, true, `@@iterator configurable`);
2598+
assert_equals(iteratorDesc.writable, true, `@@iterator writable`);
2599+
2600+
if (isPairIterator) {
2601+
assert_equals(iteratorDesc.value, proto.entries, `@@iterator equality with entries`);
25882602
} else {
2589-
assert_equals(proto["values"], proto[Symbol.asyncIterator], "values method should be the same as @@asyncIterator method");
2590-
assert_false("entries" in proto, "should not have an entries method");
2591-
assert_false("keys" in proto, "should not have a keys method");
2603+
assert_equals(iteratorDesc.value, proto.values, `@@iterator equality with values`);
25922604
}
2593-
}.bind(this), this.name + " interface: async iterable<" + member.idlType.map(function(t) { return t.idlType; }).join(", ") + ">");
2605+
}, `${this.name} interface: async iterable<${member.idlType.map(t => t.idlType).join(", ")}>`);
25942606
};
25952607

25962608
IdlInterface.prototype.test_member_stringifier = function(member)

0 commit comments

Comments
 (0)