Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2014 Google Inc. All rights reserved. | 2 * Copyright (C) 2014 Google Inc. All rights reserved. |
|
jsbell
2014/06/05 17:48:02
Use new (shorter) copyright header: http://dev.chr
gavinp
2014/06/06 16:43:14
Done.
| |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| 11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
| 12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
| 13 * distribution. | 13 * distribution. |
| 14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
| 15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
| 16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
| 17 * | 17 * |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #ifndef WebHeap_h | 31 // 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.
| |
| 32 #define WebHeap_h | 32 // to end serviceworker testing. |
| 33 | 33 |
| 34 #include "public/platform/WebCommon.h" | 34 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.
| |
| 35 function _castToRequest(item) { | |
| 36 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.
| |
| 37 item = new Request({ | |
| 38 url: item | |
| 39 }); | |
| 40 } | |
| 41 return item; | |
| 42 }; | |
| 35 | 43 |
| 36 namespace blink { | 44 request = _castToRequest(request); |
| 37 | 45 |
| 38 class WebHeap { | 46 return new Promise(function(resolve, reject) { |
| 39 public: | 47 var xhr = new XMLHttpRequest(); |
| 40 // Attach thread to the garbage collector managed heap. Thread can | 48 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.
| |
| 41 // allocate or use garbage collector managed objects only while it is | 49 xhr.send(null); |
| 42 // attached. | 50 xhr.onreadystatechange = function() { |
| 43 BLINK_EXPORT static void attachThread(); | 51 if (xhr.readyState !== 4) return; |
| 44 | 52 |
| 45 // Detach thread from the garbage collector managed heap. Thread can | 53 var response = new Response({ |
| 46 // no longer allocate or use garbage collector managed objects. | 54 status: xhr.status, |
| 47 BLINK_EXPORT static void detachThread(); | 55 statusText: xhr.statusText, |
| 56 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,
| |
| 57 // FIXME: Implement a hack for the response headers. | |
| 58 // 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.
| |
| 59 }); | |
| 48 | 60 |
| 49 // While this object is active on the stack current thread is marked as | 61 if (xhr.status === 200) { |
| 50 // being at safepoint. It can't manipulate garbage collector managed objects | 62 resolve(response); |
| 51 // until it leaves safepoint, but it can block indefinitely. | 63 } else { |
| 52 // When thread is not at safe-point it must not block indefinitely because | 64 reject(response); |
|
jsbell
2014/06/05 23:06:44
So far as I can tell from http://fetch.spec.whatwg
| |
| 53 // garbage collector might want to stop it. | 65 } |
| 54 class SafePointScope { | 66 }; |
| 55 public: | 67 }); |
| 56 BLINK_EXPORT SafePointScope(); | 68 } |
|
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.
| |
| 57 BLINK_EXPORT ~SafePointScope(); | |
| 58 }; | |
| 59 }; | |
| 60 | |
| 61 } // namespace blink | |
| 62 | |
| 63 #endif | |
| OLD | NEW |