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

Commit 383d9da

Browse files
author
John Messerly
committed
fixes Polymer/polymer#725, unwrap FormData in XHR.send if needed
1 parent 740d3d3 commit 383d9da

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

build.json

+1
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,6 @@
4646
"src/wrappers/Window.js",
4747
"src/wrappers/DataTransfer.js",
4848
"src/wrappers/FormData.js",
49+
"src/wrappers/XMLHttpRequest.js",
4950
"src/wrappers/override-constructors.js"
5051
]

shadowdom.js

+1
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
'src/wrappers/Window.js',
6363
'src/wrappers/DataTransfer.js',
6464
'src/wrappers/FormData.js',
65+
'src/wrappers/XMLHttpRequest.js',
6566
'src/wrappers/override-constructors.js'
6667
].forEach(function(src) {
6768
document.write('<script src="' + base + src + '"></script>');

src/wrappers/XMLHttpRequest.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright 2014 The Polymer Authors. All rights reserved.
3+
* Use of this source code is goverened by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
(function(scope) {
8+
'use strict';
9+
10+
var unwrapIfNeeded = scope.unwrapIfNeeded;
11+
var originalSend = XMLHttpRequest.prototype.send;
12+
13+
// Since we only need to adjust XHR.send, we just patch it instead of wrapping
14+
// the entire object. This happens when FormData is passed.
15+
XMLHttpRequest.prototype.send = function(obj) {
16+
return originalSend.call(this, unwrapIfNeeded(obj));
17+
};
18+
19+
})(window.ShadowDOMPolyfill);

test/js/XMLHttpRequest.js

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/*
2+
* Copyright 2014 The Polymer Authors. All rights reserved.
3+
* Use of this source code is goverened by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
suite('XMLHttpRequest', function() {
8+
9+
var wrap = ShadowDOMPolyfill.wrap;
10+
var unwrap = ShadowDOMPolyfill.unwrap;
11+
12+
test('instanceof', function() {
13+
var xhr = new XMLHttpRequest();
14+
assert.instanceOf(xhr, XMLHttpRequest);
15+
});
16+
17+
test('send', function() {
18+
var xhr = new XMLHttpRequest();
19+
xhr.open('POST', location.href);
20+
xhr.send(new FormData());
21+
});
22+
23+
});

test/test.main.js

+1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ var modules = [
124124
'TouchEvent.js',
125125
'TreeScope.js',
126126
'Window.js',
127+
'XMLHttpRequest.js',
127128
'build-json.js',
128129
'createTable.js',
129130
'custom-element.js',

0 commit comments

Comments
 (0)