Skip to content
This repository was archived by the owner on Sep 19, 2018. It is now read-only.

Commit 65ae060

Browse files
bzbarskyMs2ger
authored andcommitted
Partially update idlharness to Promise-returning attributes now rejecting instead of throwing on invalid this and the like.
1 parent 77c9737 commit 65ae060

File tree

1 file changed

+49
-16
lines changed

1 file changed

+49
-16
lines changed

idlharness.js

Lines changed: 49 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,10 +1135,12 @@ IdlInterface.prototype.test_member_const = function(member)
11351135
//@}
11361136
IdlInterface.prototype.test_member_attribute = function(member)
11371137
//@{
1138-
{
1139-
test(function()
1138+
{
1139+
var a_test = async_test(this.name + " interface: attribute " + member.name);
1140+
a_test.step(function()
11401141
{
11411142
if (this.is_callback() && !this.has_constants()) {
1143+
a_test.done()
11421144
return;
11431145
}
11441146

@@ -1151,6 +1153,7 @@ IdlInterface.prototype.test_member_attribute = function(member)
11511153
assert_own_property(self[this.name], member.name,
11521154
"The interface object must have a property " +
11531155
format_value(member.name));
1156+
a_test.done();
11541157
} else if (this.is_global()) {
11551158
assert_own_property(self, member.name,
11561159
"The global object must have a property " +
@@ -1179,23 +1182,42 @@ IdlInterface.prototype.test_member_attribute = function(member)
11791182
"Gets on a global should not require an explicit this");
11801183
}
11811184

1182-
this.do_interface_attribute_asserts(self, member);
1185+
// do_interface_attribute_asserts must be the last thing we do,
1186+
// since it will call done() on a_test.
1187+
this.do_interface_attribute_asserts(self, member, a_test);
11831188
} else {
11841189
assert_true(member.name in self[this.name].prototype,
11851190
"The prototype object must have a property " +
11861191
format_value(member.name));
11871192

11881193
if (!member.has_extended_attribute("LenientThis")) {
1189-
assert_throws(new TypeError(), function() {
1190-
self[this.name].prototype[member.name];
1191-
}.bind(this), "getting property on prototype object must throw TypeError");
1194+
if (member.idlType.generic !== "Promise") {
1195+
assert_throws(new TypeError(), function() {
1196+
self[this.name].prototype[member.name];
1197+
}.bind(this), "getting property on prototype object must throw TypeError");
1198+
// do_interface_attribute_asserts must be the last thing we
1199+
// do, since it will call done() on a_test.
1200+
this.do_interface_attribute_asserts(self[this.name].prototype, member, a_test);
1201+
} else {
1202+
promise_rejects(a_test, new TypeError(),
1203+
self[this.name].prototype[member.name])
1204+
.then(function() {
1205+
// do_interface_attribute_asserts must be the last
1206+
// thing we do, since it will call done() on a_test.
1207+
this.do_interface_attribute_asserts(self[this.name].prototype,
1208+
member, a_test);
1209+
}.bind(this));
1210+
}
11921211
} else {
11931212
assert_equals(self[this.name].prototype[member.name], undefined,
11941213
"getting property on prototype object must return undefined");
1214+
// do_interface_attribute_asserts must be the last thing we do,
1215+
// since it will call done() on a_test.
1216+
this.do_interface_attribute_asserts(self[this.name].prototype, member, a_test);
11951217
}
1196-
this.do_interface_attribute_asserts(self[this.name].prototype, member);
1218+
11971219
}
1198-
}.bind(this), this.name + " interface: attribute " + member.name);
1220+
}.bind(this));
11991221
};
12001222

12011223
//@}
@@ -1596,12 +1618,13 @@ IdlInterface.prototype.test_interface_of = function(desc, obj, exception, expect
15961618
var member = this.members[i];
15971619
if (member.type == "attribute" && member.isUnforgeable)
15981620
{
1599-
test(function()
1600-
{
1621+
var a_test = async_test(this.name + " interface: " + desc + ' must have own property "' + member.name + '"');
1622+
a_test.step(function() {
16011623
assert_equals(exception, null, "Unexpected exception when evaluating object");
16021624
assert_equals(typeof obj, expected_typeof, "wrong typeof object");
1603-
this.do_interface_attribute_asserts(obj, member);
1604-
}.bind(this), this.name + " interface: " + desc + ' must have own property "' + member.name + '"');
1625+
// Call do_interface_attribute_asserts last, since it will call a_test.done()
1626+
this.do_interface_attribute_asserts(obj, member, a_test);
1627+
}.bind(this));
16051628
}
16061629
else if (member.type == "operation" &&
16071630
member.name &&
@@ -1720,7 +1743,7 @@ IdlInterface.prototype.has_stringifier = function()
17201743
};
17211744

17221745
//@}
1723-
IdlInterface.prototype.do_interface_attribute_asserts = function(obj, member)
1746+
IdlInterface.prototype.do_interface_attribute_asserts = function(obj, member, a_test)
17241747
//@{
17251748
{
17261749
// This function tests WebIDL as of 2015-01-27.
@@ -1730,6 +1753,8 @@ IdlInterface.prototype.do_interface_attribute_asserts = function(obj, member)
17301753
// it is not a global, and the global otherwise, and by test_interface_of()
17311754
// with the object as obj.
17321755

1756+
var pendingPromises = [];
1757+
17331758
// "For each exposed attribute of the interface, whether it was declared on
17341759
// the interface itself or one of its consequential interfaces, there MUST
17351760
// exist a corresponding property. The characteristics of this property are
@@ -1769,9 +1794,15 @@ IdlInterface.prototype.do_interface_attribute_asserts = function(obj, member)
17691794
// attribute, then return undefined.
17701795
// "Otherwise, throw a TypeError."
17711796
if (!member.has_extended_attribute("LenientThis")) {
1772-
assert_throws(new TypeError(), function() {
1773-
desc.get.call({});
1774-
}.bind(this), "calling getter on wrong object type must throw TypeError");
1797+
if (member.idlType.generic !== "Promise") {
1798+
assert_throws(new TypeError(), function() {
1799+
desc.get.call({});
1800+
}.bind(this), "calling getter on wrong object type must throw TypeError");
1801+
} else {
1802+
pendingPromises.push(
1803+
promise_rejects(a_test, new TypeError(), desc.get.call({}),
1804+
"calling getter on wrong object type must reject the return promise with TypeError"));
1805+
}
17751806
} else {
17761807
assert_equals(desc.get.call({}), undefined,
17771808
"calling getter on wrong object type must return undefined");
@@ -1822,6 +1853,8 @@ IdlInterface.prototype.do_interface_attribute_asserts = function(obj, member)
18221853
// value 1."
18231854
assert_equals(desc.set.length, 1, "setter length must be 1");
18241855
}
1856+
1857+
Promise.all(pendingPromises).then(a_test.done.bind(a_test));
18251858
}
18261859
//@}
18271860

0 commit comments

Comments
 (0)