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 #507 from Polymer/xhr_formdata
Browse files Browse the repository at this point in the history
unwrap FormData in XMLHttpRequest.send if needed
  • Loading branch information
John Messerly committed Sep 10, 2014
2 parents 3c90686 + 383d9da commit b5abcf1
Show file tree
Hide file tree
Showing 5 changed files with 45 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
19 changes: 19 additions & 0 deletions src/wrappers/XMLHttpRequest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* 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 originalSend = XMLHttpRequest.prototype.send;

// Since we only need to adjust XHR.send, we just patch it instead of wrapping
// the entire object. This happens when FormData is passed.
XMLHttpRequest.prototype.send = function(obj) {
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 b5abcf1

Please sign in to comment.