diff options
author | bors-servo <metajack+bors@gmail.com> | 2015-08-20 10:00:44 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2015-08-20 10:00:44 -0600 |
commit | d2a8c278eaa159ceacffee767523d4ad0cf83da2 (patch) | |
tree | 7ba0c00e054add7cdb07f6283abff7091439192f /tests | |
parent | 5bab439ab6c58a5b78a6c2f69d6e93ad80da560f (diff) | |
parent | b11be4d25392561d6a396a4f54588f719de5ebad (diff) | |
download | servo-d2a8c278eaa159ceacffee767523d4ad0cf83da2.tar.gz servo-d2a8c278eaa159ceacffee767523d4ad0cf83da2.zip |
Auto merge of #7254 - frewsxcv:own-property-keys, r=Ms2ger
Initial implementation of ownPropertyKeys proxy handler
Generates `SupportedPropertyNames` on DOM structs that should implement
it. Most of them are unimplemented now (which can be implemented in
later PRs), with the exception of `HTMLCollection`. Also added a couple
relevant WPT tests.
Closes #6390
Closes #2215
<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/7254)
<!-- Reviewable:end -->
Diffstat (limited to 'tests')
4 files changed, 118 insertions, 4 deletions
diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index 3e618095b54..10050f88235 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -13072,6 +13072,10 @@ "url": "/dom/collections/HTMLCollection-empty-name.html" }, { + "path": "dom/collections/HTMLCollection-supported-property-names.html", + "url": "/dom/collections/HTMLCollection-supported-property-names.html" + }, + { "path": "dom/events/Event-constants.html", "url": "/dom/events/Event-constants.html" }, @@ -18072,6 +18076,10 @@ "url": "/js/builtins/Object.prototype.freeze.html" }, { + "path": "js/builtins/Object.prototype.getOwnPropertyNames.html", + "url": "/js/builtins/Object.prototype.getOwnPropertyNames.html" + }, + { "path": "js/builtins/Object.prototype.hasOwnProperty-order.html", "url": "/js/builtins/Object.prototype.hasOwnProperty-order.html" }, diff --git a/tests/wpt/metadata/html/dom/documents/dom-tree-accessors/document.forms.html.ini b/tests/wpt/metadata/html/dom/documents/dom-tree-accessors/document.forms.html.ini index e91f95fe3df..3d14180ee0f 100644 --- a/tests/wpt/metadata/html/dom/documents/dom-tree-accessors/document.forms.html.ini +++ b/tests/wpt/metadata/html/dom/documents/dom-tree-accessors/document.forms.html.ini @@ -5,7 +5,3 @@ [document.forms iteration] expected: FAIL - - [document.forms getOwnPropertyNames] - expected: FAIL - diff --git a/tests/wpt/web-platform-tests/dom/collections/HTMLCollection-supported-property-names.html b/tests/wpt/web-platform-tests/dom/collections/HTMLCollection-supported-property-names.html new file mode 100644 index 00000000000..a37163b7d18 --- /dev/null +++ b/tests/wpt/web-platform-tests/dom/collections/HTMLCollection-supported-property-names.html @@ -0,0 +1,54 @@ +<!doctype html> +<meta charset=utf-8> +<link rel=help href=https://dom.spec.whatwg.org/#interface-htmlcollection> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> + +<div id=log></div> + +<!-- with no attribute --> +<span></span> + +<!-- with `id` attribute --> +<span id=''></span> +<span id='some-id'></span> +<span id='some-id'></span><!-- to ensure no duplicates --> + +<!-- with `name` attribute --> +<span name=''></span> +<span name='some-name'></span> +<span name='some-name'></span><!-- to ensure no duplicates --> + +<!-- with `name` and `id` attribute --> +<span id='another-id' name='another-name'></span> + +<script> +test(function () { + var elements = document.getElementsByTagName("span"); + assert_array_equals( + Object.getOwnPropertyNames(elements), + ['0', '1', '2', '3', '4', '5', '6', '7', 'some-id', 'some-name', 'another-id', 'another-name'] + ); +}, 'Object.getOwnPropertyNames on HTMLCollection'); + +test(function () { + var elem = document.createElementNS('some-random-namespace', 'foo'); + this.add_cleanup(function () {elem.remove();}); + elem.setAttribute("name", "some-name"); + document.body.appendChild(elem); + + var elements = document.getElementsByTagName("foo"); + assert_array_equals(Object.getOwnPropertyNames(elements), ['0']); +}, 'Object.getOwnPropertyNames on HTMLCollection with non-HTML namespace'); + +test(function () { + var elem = document.createElement('foo'); + this.add_cleanup(function () {elem.remove();}); + document.body.appendChild(elem); + + var elements = document.getElementsByTagName("foo"); + elements.someProperty = "some value"; + + assert_array_equals(Object.getOwnPropertyNames(elements), ['0', 'someProperty']); +}, 'Object.getOwnPropertyNames on HTMLCollection with expando object'); +</script> diff --git a/tests/wpt/web-platform-tests/js/builtins/Object.prototype.getOwnPropertyNames.html b/tests/wpt/web-platform-tests/js/builtins/Object.prototype.getOwnPropertyNames.html new file mode 100644 index 00000000000..582f41ba105 --- /dev/null +++ b/tests/wpt/web-platform-tests/js/builtins/Object.prototype.getOwnPropertyNames.html @@ -0,0 +1,56 @@ +<!doctype html> +<title>Object.prototype.getOwnPropertyNames</title> +<link rel=help href=http://es5.github.io/#x15.2.3.4> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> + +<div id=log></div> +<script> +test(function () { + var obj = {0: 'a', 1: 'b', 2: 'c'}; + assert_array_equals( + Object.getOwnPropertyNames(obj).sort(), + ['0', '1', '2'] + ); +}, "object"); + +test(function () { + var arr = ['a', 'b', 'c']; + assert_array_equals( + Object.getOwnPropertyNames(arr).sort(), + ['0', '1', '2', 'length'] + ); +}, "array-like"); + +test(function () { + var obj = Object.create({}, { + getFoo: { + value: function() { return this.foo; }, + enumerable: false + } + }); + obj.foo = 1; + assert_array_equals( + Object.getOwnPropertyNames(obj).sort(), + ['foo', 'getFoo'] + ); +}, "non-enumerable property"); + +test(function() { + function ParentClass() {} + ParentClass.prototype.inheritedMethod = function() {}; + + function ChildClass() { + this.prop = 5; + this.method = function() {}; + } + ChildClass.prototype = new ParentClass; + ChildClass.prototype.prototypeMethod = function() {}; + + var obj = new ChildClass; + assert_array_equals( + Object.getOwnPropertyNames(obj).sort(), + ['method', 'prop'] + ); +}, 'items on the prototype chain are not listed'); +</script> |