Chromium Code Reviews| Index: Source/modules/serviceworkers/polyfills/fetchPolyfill.js |
| diff --git a/public/web/WebHeap.h b/Source/modules/serviceworkers/polyfills/fetchPolyfill.js |
| similarity index 59% |
| copy from public/web/WebHeap.h |
| copy to Source/modules/serviceworkers/polyfills/fetchPolyfill.js |
| index 6f23c21fa6ccd2c0295675af185352924173a73b..3d40cd650a724c5c52a479b6fc5a4be5e5bb86ca 100644 |
| --- a/public/web/WebHeap.h |
| +++ b/Source/modules/serviceworkers/polyfills/fetchPolyfill.js |
| @@ -28,36 +28,41 @@ |
| * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| */ |
| -#ifndef WebHeap_h |
| -#define WebHeap_h |
| +// A simple, incomplete implementation of Fetch, intended to facilitate end |
|
jsbell
2014/06/05 17:48:03
Add link to spec in comment.
http://fetch.spec.wh
gavinp
2014/06/06 16:43:14
Done.
|
| +// to end serviceworker testing. |
| -#include "public/platform/WebCommon.h" |
| - |
| -namespace blink { |
| - |
| -class WebHeap { |
| -public: |
| - // Attach thread to the garbage collector managed heap. Thread can |
| - // allocate or use garbage collector managed objects only while it is |
| - // attached. |
| - BLINK_EXPORT static void attachThread(); |
| +function Fetch(request) { |
|
jsbell
2014/06/05 17:48:03
Function name is lower case in spec: "fetch"
Is m
jsbell
2014/06/05 23:06:44
FYI, the fetch spec's API has changed slightly - i
gavinp
2014/06/06 16:43:14
No. Fixed.
|
| + function _castToRequest(item) { |
| + if (typeof item == "string") { |
|
jsbell
2014/06/05 17:48:03
Nit: Be consistent with == vs. === (latter is pref
gavinp
2014/06/06 16:43:14
Done.
|
| + item = new Request({ |
| + url: item |
| + }); |
| + } |
| + return item; |
| + }; |
| - // Detach thread from the garbage collector managed heap. Thread can |
| - // no longer allocate or use garbage collector managed objects. |
| - BLINK_EXPORT static void detachThread(); |
| + request = _castToRequest(request); |
| - // While this object is active on the stack current thread is marked as |
| - // being at safepoint. It can't manipulate garbage collector managed objects |
| - // until it leaves safepoint, but it can block indefinitely. |
| - // When thread is not at safe-point it must not block indefinitely because |
| - // garbage collector might want to stop it. |
| - class SafePointScope { |
| - public: |
| - BLINK_EXPORT SafePointScope(); |
| - BLINK_EXPORT ~SafePointScope(); |
| - }; |
| -}; |
| + return new Promise(function(resolve, reject) { |
| + var xhr = new XMLHttpRequest(); |
| + xhr.open(request.method, request.url, true); |
|
jsbell
2014/06/05 17:48:02
Document the async flag, e.g. true /*async*/
jsbell
2014/06/05 17:48:02
Add extra request headers (or FIXME to do so) via
gavinp
2014/06/06 16:43:14
Done.
gavinp
2014/06/06 16:43:14
Done.
|
| + xhr.send(null); |
| + xhr.onreadystatechange = function() { |
| + if (xhr.readyState !== 4) return; |
| -} // namespace blink |
| + var response = new Response({ |
| + status: xhr.status, |
| + statusText: xhr.statusText, |
| + method: request.method, |
|
jsbell
2014/06/05 23:06:44
Looks like method is NYI in our Response impl.
gavinp
2014/06/06 16:43:14
Whoops. The cachePolyfill needs updating on this,
|
| + // FIXME: Implement a hack for the response headers. |
| + // FIXME: Implement body once Response has it. |
|
jsbell
2014/06/05 23:06:44
Add FIXME for url once Response has it.
gavinp
2014/06/06 16:43:14
Done.
|
| + }); |
| -#endif |
| + if (xhr.status === 200) { |
| + resolve(response); |
| + } else { |
| + reject(response); |
|
jsbell
2014/06/05 23:06:44
So far as I can tell from http://fetch.spec.whatwg
|
| + } |
| + }; |
| + }); |
| +} |
|
jsbell
2014/06/05 17:48:03
A good way to structure polyfills is to wrap every
gavinp
2014/06/06 16:43:14
Done.
|