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

Commit

Permalink
unwrap(FormData) fails
Browse files Browse the repository at this point in the history
  • Loading branch information
atotic authored and arv committed Aug 5, 2014
1 parent cdb189f commit c4da637
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/wrappers.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,13 +282,15 @@ window.ShadowDOMPolyfill = {};
var OriginalCanvasRenderingContext2D = window.CanvasRenderingContext2D;
var OriginalWebGLRenderingContext = window.WebGLRenderingContext;
var OriginalSVGElementInstance = window.SVGElementInstance;

var OriginalFormData = window.FormData;

function isWrapper(object) {
return object instanceof wrappers.EventTarget ||
object instanceof wrappers.Event ||
object instanceof wrappers.Range ||
object instanceof wrappers.DOMImplementation ||
object instanceof wrappers.CanvasRenderingContext2D ||
object instanceof wrappers.FormData ||
wrappers.WebGLRenderingContext &&
object instanceof wrappers.WebGLRenderingContext;
}
Expand All @@ -301,6 +303,7 @@ window.ShadowDOMPolyfill = {};
object instanceof OriginalRange ||
object instanceof OriginalDOMImplementation ||
object instanceof OriginalCanvasRenderingContext2D ||
object instanceof OriginalFormData ||
OriginalWebGLRenderingContext &&
object instanceof OriginalWebGLRenderingContext ||
OriginalSVGElementInstance &&
Expand Down
5 changes: 4 additions & 1 deletion src/wrappers/FormData.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
var OriginalFormData = window.FormData;

function FormData(formElement) {
this.impl = new OriginalFormData(formElement && unwrap(formElement));
if (formElement instanceof OriginalFormData)
this.impl = formElement;
else
this.impl = new OriginalFormData(formElement && unwrap(formElement));
}

registerWrapper(OriginalFormData, FormData, new OriginalFormData());
Expand Down
10 changes: 10 additions & 0 deletions test/js/FormData.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

suite('FormData', function() {

var wrap = ShadowDOMPolyfill.wrap;
var unwrap = ShadowDOMPolyfill.unwrap;

test('instanceof', function() {
var fd = new FormData();
assert.instanceOf(fd, FormData);
Expand All @@ -17,4 +20,11 @@ suite('FormData', function() {
assert.instanceOf(fd, FormData);
});

test('wrap/unwrap', function() {
var fd = new FormData();
var unwrapped = unwrap(fd);
var wrapped = wrap(unwrapped);
assert.equal(fd.impl, wrapped.impl);
});

});

0 comments on commit c4da637

Please sign in to comment.