Skip to content
This repository has been archived by the owner on Aug 1, 2024. It is now read-only.

Commit

Permalink
Add another layer of abstraction to provide a native implementation o…
Browse files Browse the repository at this point in the history
…f the lite ponyfill.

RELNOTES: N/A

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=256067627
  • Loading branch information
John Plaisted committed Jul 3, 2019
1 parent 19c37f0 commit a01ad03
Show file tree
Hide file tree
Showing 15 changed files with 1,131 additions and 611 deletions.
4 changes: 3 additions & 1 deletion alltests.js
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,10 @@ var _allTests = [
'closure/goog/storage/mechanism/prefixedmechanism_test.html',
'closure/goog/storage/richstorage_test.html',
'closure/goog/storage/storage_test.html',
'closure/goog/streams/full_lite_test.html',
'closure/goog/streams/full_test.html',
'closure/goog/streams/lite_test.html',
'closure/goog/streams/lite_impl_test.html',
'closure/goog/streams/lite_native_impl_test.html',
'closure/goog/string/const_test.html',
'closure/goog/string/linkify_test.html',
'closure/goog/string/newlines_test.html',
Expand Down
13 changes: 10 additions & 3 deletions closure/goog/deps.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

29 changes: 29 additions & 0 deletions closure/goog/streams/defines.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2019 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

/**
* @fileoverview Defines used by streams.
*/
goog.module('goog.streams.defines');

/**
* 'false', 'true', or 'detect'. Detect does runtime feature detection.
* @define {string}
*/
const USE_NATIVE_IMPLEMENTATION =
goog.define('goog.streams.USE_NATIVE_IMPLEMENTATION', 'false');

exports = {
USE_NATIVE_IMPLEMENTATION,
};
31 changes: 16 additions & 15 deletions closure/goog/streams/full.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
goog.module('goog.streams.full');

const NativeResolver = goog.require('goog.promise.NativeResolver');
const lite = goog.require('goog.streams.lite');
const liteImpl = goog.require('goog.streams.liteImpl');
const liteTypes = goog.require('goog.streams.liteTypes');
const {assert, assertNumber} = goog.require('goog.asserts');

/**
* The underlying source for a ReadableStream.
* @template T
* @record
* @extends {lite.ReadableStreamUnderlyingSource}
* @extends {liteTypes.ReadableStreamUnderlyingSource}
*/
class ReadableStreamUnderlyingSource {
constructor() {
Expand Down Expand Up @@ -90,7 +91,7 @@ let PullAlgorithm;
* The implemenation of ReadableStream.
* @template T
*/
class ReadableStream extends lite.ReadableStream {
class ReadableStream extends liteImpl.ReadableStream {
/** @package */
constructor() {
super();
Expand Down Expand Up @@ -232,10 +233,10 @@ class ReadableStream extends lite.ReadableStream {
*/
cancelInternal(reason) {
this.disturbed = true;
if (this.state === lite.ReadableStream.State.CLOSED) {
if (this.state === liteImpl.ReadableStream.State.CLOSED) {
return Promise.resolve();
}
if (this.state === lite.ReadableStream.State.ERRORED) {
if (this.state === liteImpl.ReadableStream.State.ERRORED) {
return Promise.reject(this.storedError);
}
this.close();
Expand Down Expand Up @@ -263,11 +264,11 @@ function newReadableStream(underlyingSource = {}, strategy = {}) {
assert(
!(verifyObject.type),
`'type' property not allowed on an underlying source for a ` +
'lite ReadableStream');
'liteImpl ReadableStream');
assert(
!(verifyObject.autoAllocateChunkSize),
`'autoAllocateChunkSize' property not allowed on an underlying ` +
'source for a lite ReadableStream');
'source for a liteImpl ReadableStream');
const startAlgorithm = underlyingSource.start ?
(controller) => underlyingSource.start(controller) :
() => {};
Expand Down Expand Up @@ -299,11 +300,11 @@ function newReadableStream(underlyingSource = {}, strategy = {}) {
}

/**
* The DefaultReader for a ReadableStream. Adds cancellation onto the lite
* The DefaultReader for a ReadableStream. Adds cancellation onto the liteImpl
* DefaultReader.
* @template T
*/
class ReadableStreamDefaultReader extends lite.ReadableStreamDefaultReader {
class ReadableStreamDefaultReader extends liteImpl.ReadableStreamDefaultReader {
/**
* Cancels the ReadableStream with an optional reason.
* https://streams.spec.whatwg.org/#default-reader-cancel
Expand Down Expand Up @@ -383,11 +384,11 @@ class ReadableStreamAsyncIterator {

/**
* The controller for a ReadableStream. Adds cancellation and backpressure onto
* the lite DefaultController.
* the liteImpl DefaultController.
* @template T
*/
class ReadableStreamDefaultController extends
lite.ReadableStreamDefaultController {
liteImpl.ReadableStreamDefaultController {
/**
* @param {!ReadableStream} stream
* @param {!CancelAlgorithm|undefined} cancelAlgorithm
Expand Down Expand Up @@ -549,11 +550,11 @@ class ReadableStreamDefaultController extends
*/
getDesiredSize_() {
if (this.controlledReadableStream.state ===
lite.ReadableStream.State.ERRORED) {
liteImpl.ReadableStream.State.ERRORED) {
return null;
}
if (this.controlledReadableStream.state ===
lite.ReadableStream.State.CLOSED) {
liteImpl.ReadableStream.State.CLOSED) {
return 0;
}
return this.strategyHWM_ - this.queueTotalSize_;
Expand All @@ -568,11 +569,11 @@ class ReadableStreamDefaultController extends
*/
class QueueWithSizes {
/**
* @param {!lite.Queue} queue
* @param {!liteImpl.Queue} queue
*/
constructor(queue) {
/**
* @private @const {!lite.Queue}
* @private @const {!liteImpl.Queue}
*/
this.queue_ = queue;

Expand Down
11 changes: 11 additions & 0 deletions closure/goog/streams/full_lite_test.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html><!-- DO NOT EDIT. This file auto-generated by generate_closure_unit_tests.js --><!--
Copyright 2017 The Closure Library Authors. All Rights Reserved.
Use of this source code is governed by the Apache License, Version 2.0.
See the COPYING file for details.
--><html><head><meta charset="UTF-8">

<script src="../base.js"></script>

<script>goog.require('goog.streams.fullLiteTest');</script>
<title>Closure Unit Tests - goog.streams.fullLiteTest</title></head><body></body></html>
22 changes: 22 additions & 0 deletions closure/goog/streams/full_lite_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2019 The Closure Library Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS-IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

goog.module('goog.streams.fullLiteTest');
goog.setTestOnly();

const testSuite = goog.require('goog.testing.testSuite');
const {TestCases} = goog.require('goog.streams.liteTestCases');
const {newReadableStream} = goog.require('goog.streams.full');

testSuite(new TestCases(newReadableStream));
Loading

0 comments on commit a01ad03

Please sign in to comment.