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

Commit

Permalink
fixes Polymer/polymer#725, unwrap FormData in XHR.send if needed
Browse files Browse the repository at this point in the history
  • Loading branch information
John Messerly committed Sep 9, 2014
1 parent 740d3d3 commit 467a422
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions build.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@
"src/wrappers/Window.js",
"src/wrappers/DataTransfer.js",
"src/wrappers/FormData.js",
"src/wrappers/XMLHttpRequest.js",
"src/wrappers/override-constructors.js"
]
1 change: 1 addition & 0 deletions shadowdom.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'src/wrappers/Window.js',
'src/wrappers/DataTransfer.js',
'src/wrappers/FormData.js',
'src/wrappers/XMLHttpRequest.js',
'src/wrappers/override-constructors.js'
].forEach(function(src) {
document.write('<script src="' + base + src + '"></script>');
Expand Down
23 changes: 23 additions & 0 deletions src/wrappers/XMLHttpRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2014 The Polymer Authors. All rights reserved.
* Use of this source code is goverened by a BSD-style
* license that can be found in the LICENSE file.
*/

(function(scope) {
'use strict';

var unwrapIfNeeded = scope.unwrapIfNeeded;
var XMLHttpRequest = window.XMLHttpRequest;

var originalSend = XMLHttpRequest && XMLHttpRequest.prototype.send;
if (!originalSend) return;

// Note: since we only need to adjust XHR.send, we just patch it instead of
// wrapping the entire object.
XMLHttpRequest.prototype.send = function(obj) {
// Unwrap FormData if needed
return originalSend.call(this, unwrapIfNeeded(obj));
};

})(window.ShadowDOMPolyfill);
23 changes: 23 additions & 0 deletions test/js/XMLHttpRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright 2014 The Polymer Authors. All rights reserved.
* Use of this source code is goverened by a BSD-style
* license that can be found in the LICENSE file.
*/

suite('XMLHttpRequest', function() {

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

test('instanceof', function() {
var xhr = new XMLHttpRequest();
assert.instanceOf(xhr, XMLHttpRequest);
});

test('send', function() {
var xhr = new XMLHttpRequest();
xhr.open('POST', location.href);
xhr.send(new FormData());
});

});
1 change: 1 addition & 0 deletions test/test.main.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ var modules = [
'TouchEvent.js',
'TreeScope.js',
'Window.js',
'XMLHttpRequest.js',
'build-json.js',
'createTable.js',
'custom-element.js',
Expand Down

0 comments on commit 467a422

Please sign in to comment.