Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Merge pull request #491 from arv/constructors
Browse files Browse the repository at this point in the history
Make sure we set the constructor for wrapper classes
  • Loading branch information
arv committed Aug 13, 2014
2 parents f104b0d + a8c525a commit 6386877
Show file tree
Hide file tree
Showing 42 changed files with 270 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/MutationObserver.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,8 @@
}

MutationObserver.prototype = {
constructor: MutationObserver,

// http://dom.spec.whatwg.org/#dom-mutationobserver-observe
observe: function(target, options) {
target = wrapIfNeeded(target);
Expand Down
1 change: 1 addition & 0 deletions src/wrappers/DOMTokenList.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
}

DOMTokenList.prototype = {
constructor: DOMTokenList,
get length() {
return unsafeUnwrap(this).length;
},
Expand Down
2 changes: 2 additions & 0 deletions src/wrappers/HTMLContentElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
}
HTMLContentElement.prototype = Object.create(HTMLElement.prototype);
mixin(HTMLContentElement.prototype, {
constructor: HTMLContentElement,

get select() {
return this.getAttribute('select');
},
Expand Down
1 change: 1 addition & 0 deletions src/wrappers/HTMLShadowElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
HTMLElement.call(this, node);
}
HTMLShadowElement.prototype = Object.create(HTMLElement.prototype);
HTMLShadowElement.prototype.constructor = HTMLShadowElement;

// getDistributedNodes is added in ShadowRenderer

Expand Down
1 change: 1 addition & 0 deletions src/wrappers/HTMLTableSectionElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}
HTMLTableSectionElement.prototype = Object.create(HTMLElement.prototype);
mixin(HTMLTableSectionElement.prototype, {
constructor: HTMLTableSectionElement,
get rows() {
return wrapHTMLCollection(unwrap(this).rows);
},
Expand Down
1 change: 1 addition & 0 deletions src/wrappers/HTMLTemplateElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
HTMLTemplateElement.prototype = Object.create(HTMLElement.prototype);

mixin(HTMLTemplateElement.prototype, {
constructor: HTMLTemplateElement,
get content() {
if (OriginalHTMLTemplateElement)
return wrap(unsafeUnwrap(this).content);
Expand Down
2 changes: 2 additions & 0 deletions src/wrappers/ShadowRoot.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
}
ShadowRoot.prototype = Object.create(DocumentFragment.prototype);
mixin(ShadowRoot.prototype, {
constructor: ShadowRoot,

get innerHTML() {
return getInnerHTML(this);
},
Expand Down
6 changes: 6 additions & 0 deletions test/js/Comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ suite('Comment', function() {
assert.instanceOf(div.firstChild, Comment);
});

test('instanceof', function() {
var div = document.createElement('div');
div.innerHTML = '<!-- comment -->';
assert.equal(Comment, div.firstChild.constructor);
});

});
5 changes: 5 additions & 0 deletions test/js/DOMTokenList.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ suite('DOMTokenList', function() {
assert.instanceOf(div.classList, DOMTokenList);
});

test('constructor', function() {
var div = document.createElement('div');
assert.equal(DOMTokenList, div.classList.constructor);
});

test('identity', function() {
var div = document.createElement('div');
assert.equal(div.classList, div.classList);
Expand Down
5 changes: 5 additions & 0 deletions test/js/FormData.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ suite('FormData', function() {
assert.instanceOf(fd, FormData);
});

test('constructor', function() {
var fd = new FormData();
assert.equal(FormData, fd.constructor);
});

test('form element', function() {
var formElement = document.createElement('form');
var fd = new FormData(formElement)
Expand Down
5 changes: 5 additions & 0 deletions test/js/HTMLAudioElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ suite('HTMLAudioElement', function() {
assert.instanceOf(audio, HTMLElement);
});

test('constructor', function() {
var audio = document.createElement('audio');
assert.equal(audio.constructor, HTMLAudioElement);
});

test('Audio', function() {
var audio = new Audio();
assert.instanceOf(audio, HTMLAudioElement);
Expand Down
8 changes: 8 additions & 0 deletions test/js/HTMLBodyElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,13 @@ htmlSuite('HTMLBodyElement', function() {
assert.isTrue(document.body.contains(document.body.firstChild));
});

test('instanceof', function() {
assert.instanceOf(document.createElement('body'), HTMLBodyElement);
});

test('constructor', function() {
assert.equal(HTMLBodyElement, document.createElement('body').constructor);
});

htmlTest('html/document-body-inner-html.html');
});
9 changes: 9 additions & 0 deletions test/js/HTMLButtonElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ suite('HTMLButtonElement', function() {
assert.equal(button.form, form);
});

test('instanceof', function() {
assert.instanceOf(document.createElement('button'), HTMLButtonElement);
});

test('constructor', function() {
assert.equal(HTMLButtonElement,
document.createElement('button').constructor);
});

});
9 changes: 9 additions & 0 deletions test/js/HTMLCanvasElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,13 @@ suite('HTMLCanvasElement', function() {
assert.isNumber(canvas.height);
});

test('instanceof', function() {
assert.instanceOf(document.createElement('canvas'), HTMLCanvasElement);
});

test('constructor', function() {
assert.equal(HTMLCanvasElement,
document.createElement('canvas').constructor);
});

});
9 changes: 9 additions & 0 deletions test/js/HTMLContentElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,4 +228,13 @@ suite('HTMLContentElement', function() {
var content = document.createElement('content');
assert.deepEqual(content.getDistributedNodes(), []);
});

test('instanceof', function() {
assert.instanceOf(document.createElement('content'), HTMLContentElement);
});

test('constructor', function() {
assert.equal(HTMLContentElement,
document.createElement('content').constructor);
});
});
9 changes: 9 additions & 0 deletions test/js/HTMLFieldSetElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ suite('HTMLFieldSetElement', function() {
assert.equal(fieldSet.form, form);
});

test('instanceof', function() {
assert.instanceOf(document.createElement('fieldset'), HTMLFieldSetElement);
});

test('constructor', function() {
assert.equal(HTMLFieldSetElement,
document.createElement('fieldset').constructor);
});

});
9 changes: 9 additions & 0 deletions test/js/HTMLFormElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@ suite('HTMLFormElement', function() {
assert.equal(form.elements.length, 1);
});

test('instanceof', function() {
assert.instanceOf(document.createElement('form'), HTMLFormElement);
});

test('constructor', function() {
assert.equal(HTMLFormElement,
document.createElement('form').constructor);
});

});
10 changes: 10 additions & 0 deletions test/js/HTMLHeadElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,14 @@ suite('HTMLHeadElement', function() {
assert.isTrue(document.head.contains(doc.head.firstChild));
assert.isTrue(document.head.contains(document.head.firstChild));
});

test('instanceof', function() {
assert.instanceOf(document.createElement('head'), HTMLHeadElement);
});

test('constructor', function() {
assert.equal(HTMLHeadElement,
document.createElement('head').constructor);
});

});
5 changes: 5 additions & 0 deletions test/js/HTMLHtmlElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ suite('HTMLHtmlElement', function() {
assert.equal(wrap(document.documentElement), doc.documentElement);
});

test('constructor', function() {
assert.equal(HTMLHtmlElement,
document.createElement('html').constructor);
});

test('appendChild', function() {
var doc = wrap(document);

Expand Down
5 changes: 5 additions & 0 deletions test/js/HTMLImageElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ suite('HTMLImageElement', function() {
assert.instanceOf(img, HTMLElement);
});

test('constructor', function() {
assert.equal(HTMLImageElement, document.createElement('img').constructor);
assert.equal(HTMLImageElement, new Image().constructor);
});

test('Image', function() {
var img = new Image();
assert.instanceOf(img, HTMLImageElement);
Expand Down
9 changes: 9 additions & 0 deletions test/js/HTMLInputElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ suite('HTMLInputElement', function() {
assert.equal(input.form, form);
});

test('instanceof', function() {
assert.instanceOf(document.createElement('input'), HTMLInputElement);
});

test('constructor', function() {
assert.equal(HTMLInputElement,
document.createElement('input').constructor);
});

});
9 changes: 9 additions & 0 deletions test/js/HTMLKeygenElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ suite('HTMLKeygenElement', function() {
assert.equal(keygen.form, form);
});

test('instanceof', function() {
assert.instanceOf(document.createElement('keygen'), HTMLKeygenElement);
});

test('constructor', function() {
assert.equal(HTMLKeygenElement,
document.createElement('keygen').constructor);
});

});
9 changes: 9 additions & 0 deletions test/js/HTMLLabelElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ suite('HTMLLabelElement', function() {
assert.equal(label.form, form);
});

test('instanceof', function() {
assert.instanceOf(document.createElement('label'), HTMLLabelElement);
});

test('constructor', function() {
assert.equal(HTMLLabelElement,
document.createElement('label').constructor);
});

});
10 changes: 10 additions & 0 deletions test/js/HTMLLegendElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@ suite('HTMLLegendElement', function() {
assert.equal(legend.form, form);
});

test('instanceof', function() {
assert.instanceOf(document.createElement('legend'), HTMLLegendElement);
});

test('constructor', function() {
assert.equal(HTMLLegendElement,
document.createElement('legend').constructor);
});


});
9 changes: 9 additions & 0 deletions test/js/HTMLObjectElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,13 @@ suite('HTMLObjectElement', function() {
assert.equal(object.form, form);
});

test('instanceof', function() {
assert.instanceOf(document.createElement('object'), HTMLObjectElement);
});

test('constructor', function() {
assert.equal(HTMLObjectElement,
document.createElement('object').constructor);
});

});
6 changes: 6 additions & 0 deletions test/js/HTMLOptionElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ suite('HTMLOptionElement', function() {
assert.instanceOf(option, HTMLElement);
});

test('constructor', function() {
assert.equal(HTMLOptionElement,
document.createElement('option').constructor);
assert.equal(HTMLOptionElement, new Option().constructor);
});

test('Option', function() {
var option = new Option();
assert.instanceOf(option, HTMLOptionElement);
Expand Down
9 changes: 9 additions & 0 deletions test/js/HTMLOutputElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,13 @@ suite('HTMLOutputElement', function() {
assert.equal(output.form, form);
});

test('instanceof', function() {
assert.instanceOf(document.createElement('output'), HTMLOutputElement);
});

test('constructor', function() {
assert.equal(HTMLOutputElement,
document.createElement('output').constructor);
});

});
9 changes: 9 additions & 0 deletions test/js/HTMLSelectElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,13 @@ suite('HTMLSelectElement', function() {
assert.equal(div.firstChild, null);
});

test('instanceof', function() {
assert.instanceOf(document.createElement('select'), HTMLSelectElement);
});

test('constructor', function() {
assert.equal(HTMLSelectElement,
document.createElement('select').constructor);
});

});
5 changes: 5 additions & 0 deletions test/js/HTMLShadowElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ suite('HTMLShadowElement', function() {
assert.equal(unwrap(host).innerHTML, 'da<a>a</a><b>b</b>cf');
});

test('constructor', function() {
assert.equal(HTMLShadowElement,
document.createElement('shadow').constructor);
});

test('adding a new shadow element to a shadow tree', function() {
var host = document.createElement('div');
host.innerHTML = '<a></a>';
Expand Down
5 changes: 5 additions & 0 deletions test/js/HTMLTableElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ suite('HTMLTableElement', function() {
assert.instanceOf(table, HTMLTableElement);
});

test('constructor', function() {
assert.equal(HTMLTableElement,
document.createElement('table').constructor);
});

test('caption', function() {
var table = createTable();
assert.equal(table.caption.localName, 'caption');
Expand Down
6 changes: 6 additions & 0 deletions test/js/HTMLTableRowElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ suite('HTMLTableRowElement', function() {
assert.instanceOf(row, HTMLTableRowElement);
});

test('constructor', function() {
var table = createTable();
var row = table.querySelector('tr');
assert.equal(HTMLTableRowElement, row.constructor);
});

test('cells', function() {
var table = createTable();
var row = table.querySelector('tr');
Expand Down
8 changes: 8 additions & 0 deletions test/js/HTMLTableSectionElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ suite('HTMLTableSectionElement', function() {
assert.instanceOf(tfoot, HTMLTableSectionElement);
});

test('constructor', function() {
var table = createTable();
var thead = table.querySelector('thead');
assert.equal(HTMLTableSectionElement, thead.constructor);
var tfoot = table.querySelector('tfoot');
assert.equal(HTMLTableSectionElement, tfoot.constructor);
});

test('rows', function() {
var table = createTable();
var thead = table.querySelector('thead');
Expand Down
Loading

0 comments on commit 6386877

Please sign in to comment.