[Streams API] Shield streams against user replacing the Promise constructor
[WebKit-https.git] / Source / WebCore / Modules / streams / StreamInternals.js
index 63537f7daab7e742e0197ec37f63c583416b6b41..0475c510e7f0dd2e95088fb45c657ab8b5a06ec2 100644 (file)
@@ -24,7 +24,7 @@
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-// @optional=STREAMS_API
+// @conditional=ENABLE(STREAMS_API)
 // @internals
 
 function invokeOrNoop(object, key, args)
@@ -44,12 +44,12 @@ function promiseInvokeOrNoop(object, key, args)
     try {
         var method = object[key];
         if (typeof method === "undefined")
-            return Promise.resolve();
+            return @Promise.resolve();
         var result = method.@apply(object, args);
-        return Promise.resolve(result);
+        return @Promise.resolve(result);
     }
     catch(error) {
-        return Promise.reject(error);
+        return @Promise.reject(error);
     }
 
 }
@@ -63,10 +63,10 @@ function promiseInvokeOrFallbackOrNoop(object, key1, args1, key2, args2)
         if (typeof method === "undefined")
             return @promiseInvokeOrNoop(object, key2, args2);
         const result = method.@apply(object, args1);
-        return Promise.resolve(result);
+        return @Promise.resolve(result);
     }
     catch(error) {
-        return Promise.reject(error);
+        return @Promise.reject(error);
     }
 }
 
@@ -90,43 +90,6 @@ function validateAndNormalizeQueuingStrategy(size, highWaterMark)
     return normalizedStrategy;
 }
 
-function createNewStreamsPromise()
-{
-    "use strict";
-
-    var resolveFunction;
-    var rejectFunction;
-    var promise = new Promise(function(resolve, reject) {
-        resolveFunction = resolve;
-        rejectFunction = reject;
-    });
-    promise.@resolve = resolveFunction;
-    promise.@reject = rejectFunction;
-    return promise;
-}
-
-function resolveStreamsPromise(promise, value)
-{
-    "use strict";
-
-    if (promise && promise.@resolve) {
-        promise.@resolve(value);
-        promise.@resolve = undefined;
-        promise.@reject = undefined;
-    }
-}
-
-function rejectStreamsPromise(promise, value)
-{
-    "use strict";
-
-    if (promise && promise.@reject) {
-        promise.@reject(value);
-        promise.@resolve = undefined;
-        promise.@reject = undefined;
-    }
-}
-
 function newQueue()
 {
     return { content: [], size: 0 };
@@ -151,3 +114,11 @@ function enqueueValueWithSize(queue, value, size)
 
     return undefined;
 }
+
+function peekQueueValue(queue)
+{
+    // FIXME
+    // assert(queue.content.length > 0);
+
+    return queue.content[0].value;
+}