From 551b9d90cb8af57ca05ac36358f8052e0a133d74 Mon Sep 17 00:00:00 2001 From: Simon Pieters Date: Wed, 17 May 2017 15:05:22 +0200 Subject: [PATCH 1/3] [idlharness] Support testing of [LegacyWindowAlias] extended attribute Follows https://github.com/heycam/webidl/pull/364 --- resources/idlharness.js | 45 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/resources/idlharness.js b/resources/idlharness.js index f18d895b621ca2..b16e9818e917b2 100644 --- a/resources/idlharness.js +++ b/resources/idlharness.js @@ -972,6 +972,51 @@ IdlInterface.prototype.test_self = function() }.bind(this), this.name + " interface object name"); } + + if (this.has_extended_attribute("LegacyWindowAlias")) { + test(function() + { + var aliasAttrs = this.extAttrs.filter(function(o) { return o.name === "LegacyWindowAlias"; }); + if (aliasAttrs.length > 1) { + throw "Invalid IDL: multiple LegacyWindowAlias extended attributes on " + this.name; + } + if (this.is_callback()) { + throw "Invalid IDL: LegacyWindowAlias extended attribute on non-interface " + this.name; + } + if (this.exposureSet.indexOf("Window") === -1) { + throw "Invalid IDL: LegacyWindowAlias extended attribute on " + this.name + " but not exposed in Window"; + } + // TODO: when testing of [NoInterfaceObject] interfaces is supported, + // check that it's not specified together with LegacyWindowAlias. + + // TODO: maybe check that [LegacyWindowAlias] is not specified on a partial interface. + + var rhs = aliasAttrs[0].rhs; + if (!rhs) { + throw "Invalid IDL: LegacyWindowAlias extended attribute on " + this.name + " without identifier"; + } + var aliases; + if (rhs.type === "identifier-list") { + aliases = rhs.value; + } else { // rhs.type === identifier + aliases = [ rhs.value ]; + } + + // OK now actually check the aliases... + for (var alias of aliases) { + assert_true(alias in self, alias + " should exist"); + assert_equals(self[alias], self[this.name], "self." + alias + " should be the same value as self." + this.name); + var desc = Object.getOwnPropertyDescriptor(self, alias); + assert_equals(desc.value, self[this.name], "wrong value in " + alias + " property descriptor"); + assert_true(desc.writable, alias + " is not writable"); + assert_false(desc.enumerable, alias + " is enumerable"); + assert_true(desc.configurable, alias + " is not configurable"); + assert_false('get' in desc, alias + " has a getter"); + assert_false('set' in desc, alias + " has a setter"); + } + + }.bind(this), this.name + " interface: legacy window alias"); + } // TODO: Test named constructors if I find any interfaces that have them. test(function() From cbee70b37878c66da3d9f9fa99c41357820dab80 Mon Sep 17 00:00:00 2001 From: Simon Pieters Date: Thu, 18 May 2017 14:29:18 +0200 Subject: [PATCH 2/3] Address review comments --- resources/idlharness.js | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/resources/idlharness.js b/resources/idlharness.js index b16e9818e917b2..358bd374d8c28f 100644 --- a/resources/idlharness.js +++ b/resources/idlharness.js @@ -984,7 +984,7 @@ IdlInterface.prototype.test_self = function() throw "Invalid IDL: LegacyWindowAlias extended attribute on non-interface " + this.name; } if (this.exposureSet.indexOf("Window") === -1) { - throw "Invalid IDL: LegacyWindowAlias extended attribute on " + this.name + " but not exposed in Window"; + throw "Invalid IDL: LegacyWindowAlias extended attribute on " + this.name + " which is not exposed in Window"; } // TODO: when testing of [NoInterfaceObject] interfaces is supported, // check that it's not specified together with LegacyWindowAlias. @@ -1003,16 +1003,23 @@ IdlInterface.prototype.test_self = function() } // OK now actually check the aliases... - for (var alias of aliases) { - assert_true(alias in self, alias + " should exist"); - assert_equals(self[alias], self[this.name], "self." + alias + " should be the same value as self." + this.name); - var desc = Object.getOwnPropertyDescriptor(self, alias); - assert_equals(desc.value, self[this.name], "wrong value in " + alias + " property descriptor"); - assert_true(desc.writable, alias + " is not writable"); - assert_false(desc.enumerable, alias + " is enumerable"); - assert_true(desc.configurable, alias + " is not configurable"); - assert_false('get' in desc, alias + " has a getter"); - assert_false('set' in desc, alias + " has a setter"); + var alias; + if (exposed_in(exposure_set(this, ["Window"]))) { + for (alias of aliases) { + assert_true(alias in self, alias + " should exist"); + assert_equals(self[alias], self[this.name], "self." + alias + " should be the same value as self." + this.name); + var desc = Object.getOwnPropertyDescriptor(self, alias); + assert_equals(desc.value, self[this.name], "wrong value in " + alias + " property descriptor"); + assert_true(desc.writable, alias + " is not writable"); + assert_false(desc.enumerable, alias + " is enumerable"); + assert_true(desc.configurable, alias + " is not configurable"); + assert_false('get' in desc, alias + " has a getter"); + assert_false('set' in desc, alias + " has a setter"); + } + } else { + for (alias of aliases) { + assert_false(alias in self, alias + " should not exist"); + } } }.bind(this), this.name + " interface: legacy window alias"); From d1aad58b9bdc3a7a617f316688ec83c57890d54b Mon Sep 17 00:00:00 2001 From: Simon Pieters Date: Thu, 18 May 2017 16:46:01 +0200 Subject: [PATCH 3/3] Actually check if we're in a window --- resources/idlharness.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/idlharness.js b/resources/idlharness.js index 358bd374d8c28f..bf5999719d2faf 100644 --- a/resources/idlharness.js +++ b/resources/idlharness.js @@ -1004,7 +1004,7 @@ IdlInterface.prototype.test_self = function() // OK now actually check the aliases... var alias; - if (exposed_in(exposure_set(this, ["Window"]))) { + if (exposed_in(exposure_set(this, this.exposureSet)) && 'document' in self) { for (alias of aliases) { assert_true(alias in self, alias + " should exist"); assert_equals(self[alias], self[this.name], "self." + alias + " should be the same value as self." + this.name);