How to use defaultWriterLockException method in wpt

Best JavaScript code snippet using wpt

writable.js

Source:writable.js Github

copy

Full Screen

...372 if (IsWritableStreamDefaultWriter(this) === false) {373 throw defaultWriterBrandCheckException('desiredSize');374 }375 if (this[kOwnerWritableStream] === undefined) {376 throw defaultWriterLockException('desiredSize');377 }378 return WritableStreamDefaultWriterGetDesiredSize(this);379 }380 get ready() {381 if (IsWritableStreamDefaultWriter(this) === false) {382 return Promise.reject(defaultWriterBrandCheckException('ready'));383 }384 return this[kReadyPromise];385 }386 abort(reason) {387 if (IsWritableStreamDefaultWriter(this) === false) {388 return Promise.reject(defaultWriterBrandCheckException('abort'));389 }390 if (this[kOwnerWritableStream] === undefined) {391 return Promise.reject(defaultWriterLockException('abort'));392 }393 return WritableStreamDefaultWriterAbort(this, reason);394 }395 close() {396 if (IsWritableStreamDefaultWriter(this) === false) {397 return Promise.reject(defaultWriterBrandCheckException('close'));398 }399 const stream = this[kOwnerWritableStream];400 if (stream === undefined) {401 return Promise.reject(defaultWriterLockException('close'));402 }403 if (WritableStreamCloseQueuedOrInFlight(stream) === true) {404 return Promise.reject(new TypeError('cannot close an already-closing stream'));405 }406 return WritableStreamDefaultWriterClose(this);407 }408 releaseLock() {409 if (IsWritableStreamDefaultWriter(this) === false) {410 throw defaultWriterBrandCheckException('releaseLock');411 }412 const stream = this[kOwnerWritableStream];413 if (stream === undefined) {414 return;415 }416 assert(stream[kWriter] !== undefined);417 WritableStreamDefaultWriterRelease(this);418 }419 write(chunk) {420 if (IsWritableStreamDefaultWriter(this) === false) {421 return Promise.reject(defaultWriterBrandCheckException('write'));422 }423 if (this[kOwnerWritableStream] === undefined) {424 return Promise.reject(defaultWriterLockException('write to'));425 }426 return WritableStreamDefaultWriterWrite(this, chunk);427 }428 }429 // Abstract operations for the WritableStreamDefaultWriter.430 function IsWritableStreamDefaultWriter(x) {431 if (!typeIsObject(x)) {432 return false;433 }434 if (!Object.prototype.hasOwnProperty.call(x, kOwnerWritableStream)) {435 return false;436 }437 return true;438 }439 // A client of WritableStreamDefaultWriter may use these functions directly to bypass state check.440 function WritableStreamDefaultWriterAbort(writer, reason) {441 const stream = writer[kOwnerWritableStream];442 assert(stream !== undefined);443 return WritableStreamAbort(stream, reason);444 }445 function WritableStreamDefaultWriterClose(writer) {446 const stream = writer[kOwnerWritableStream];447 assert(stream !== undefined);448 const state = stream[kState];449 if (state === 'closed' || state === 'errored') {450 return Promise.reject(new TypeError(451 `The stream (in ${state} state) is not in the writable state and cannot be closed`,452 ));453 }454 assert(state === 'writable' || state === 'erroring');455 assert(WritableStreamCloseQueuedOrInFlight(stream) === false);456 const promise = new Promise((resolve, reject) => {457 const closeRequest = {458 _resolve: resolve,459 _reject: reject,460 };461 stream[kCloseRequest] = closeRequest;462 });463 if (stream[kBackpressure] === true && state === 'writable') {464 defaultWriterReadyPromiseResolve(writer);465 }466 WritableStreamDefaultControllerClose(stream[kWritableStreamController]);467 return promise;468 }469 function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) {470 const stream = writer[kOwnerWritableStream];471 assert(stream !== undefined);472 const state = stream[kState];473 if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') {474 return Promise.resolve();475 }476 if (state === 'errored') {477 return Promise.reject(stream[kStoredError]);478 }479 assert(state === 'writable' || state === 'erroring');480 return WritableStreamDefaultWriterClose(writer);481 }482 function WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, error) {483 if (writer[kClosedPromiseState] === 'pending') {484 defaultWriterClosedPromiseReject(writer, error);485 } else {486 defaultWriterClosedPromiseResetToRejected(writer, error);487 }488 writer[kClosedPromise].catch(() => {});489 }490 function WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, error) {491 if (writer[kReadyPromiseState] === 'pending') {492 defaultWriterReadyPromiseReject(writer, error);493 } else {494 defaultWriterReadyPromiseResetToRejected(writer, error);495 }496 writer[kReadyPromise].catch(() => {});497 }498 function WritableStreamDefaultWriterGetDesiredSize(writer) {499 const stream = writer[kOwnerWritableStream];500 const state = stream[kState];501 if (state === 'errored' || state === 'erroring') {502 return null;503 }504 if (state === 'closed') {505 return 0;506 }507 return WritableStreamDefaultControllerGetDesiredSize(stream[kWritableStreamController]);508 }509 function WritableStreamDefaultWriterRelease(writer) {510 const stream = writer[kOwnerWritableStream];511 assert(stream !== undefined);512 assert(stream[kWriter] === writer);513 const releasedError = new TypeError(514 'Writer was released and can no longer be used to monitor the stream\'s closedness',515 );516 WritableStreamDefaultWriterEnsureReadyPromiseRejected(writer, releasedError);517 // The state transitions to "errored" before the sink abort() method runs, but the writer.closed promise is not518 // rejected until afterwards. This means that simply testing state will not work.519 WritableStreamDefaultWriterEnsureClosedPromiseRejected(writer, releasedError);520 stream[kWriter] = undefined;521 writer[kOwnerWritableStream] = undefined;522 }523 function WritableStreamDefaultWriterWrite(writer, chunk) {524 const stream = writer[kOwnerWritableStream];525 assert(stream !== undefined);526 const controller = stream[kWritableStreamController];527 const chunkSize = WritableStreamDefaultControllerGetChunkSize(controller, chunk);528 if (stream !== writer[kOwnerWritableStream]) {529 return Promise.reject(defaultWriterLockException('write to'));530 }531 const state = stream[kState];532 if (state === 'errored') {533 return Promise.reject(stream[kStoredError]);534 }535 if (WritableStreamCloseQueuedOrInFlight(stream) === true || state === 'closed') {536 return Promise.reject(new TypeError('The stream is closing or closed and cannot be written to'));537 }538 if (state === 'erroring') {539 return Promise.reject(stream[kStoredError]);540 }541 assert(state === 'writable');542 const promise = WritableStreamAddWriteRequest(stream);543 WritableStreamDefaultControllerWrite(controller, chunk, chunkSize);544 return promise;545 }546 class WritableStreamDefaultController {547 constructor() {548 throw new TypeError('WritableStreamDefaultController cannot be constructed explicitly');549 }550 error(e) {551 if (IsWritableStreamDefaultController(this) === false) {552 throw new TypeError(553 'WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController',554 );555 }556 const state = this[kControlledWritableStream][kState];557 if (state !== 'writable') {558 // The stream is closed, errored or will be soon. The sink can't do anything useful if it gets an error here, so559 // just treat it as a no-op.560 return;561 }562 WritableStreamDefaultControllerError(this, e);563 }564 [AbortSteps](reason) {565 return this[kAbortAlgorithm](reason);566 }567 [ErrorSteps]() {568 ResetQueue(this);569 }570 }571 // Abstract operations implementing interface required by the WritableStream.572 function IsWritableStreamDefaultController(x) {573 if (!typeIsObject(x)) {574 return false;575 }576 if (!Object.prototype.hasOwnProperty.call(x, kControlledWritableStream)) {577 return false;578 }579 return true;580 }581 function SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm,582 abortAlgorithm, highWaterMark, sizeAlgorithm) {583 assert(IsWritableStream(stream) === true);584 assert(stream[kWritableStreamController] === undefined);585 controller[kControlledWritableStream] = stream;586 stream[kWritableStreamController] = controller;587 // Need to set the slots so that the assert doesn't fire. In the spec the slots already exist implicitly.588 controller[kQueue] = undefined;589 controller[kQueueTotalSize] = undefined;590 ResetQueue(controller);591 controller[kStarted] = false;592 controller[kStrategySizeAlgorithm] = sizeAlgorithm;593 controller[kStrategyHWM] = highWaterMark;594 controller[kWriteAlgorithm] = writeAlgorithm;595 controller[kCloseAlgorithm] = closeAlgorithm;596 controller[kAbortAlgorithm] = abortAlgorithm;597 const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);598 WritableStreamUpdateBackpressure(stream, backpressure);599 const startResult = startAlgorithm();600 const startPromise = Promise.resolve(startResult);601 startPromise.then(602 () => {603 assert(stream[kState] === 'writable' || stream[kState] === 'erroring');604 controller[kStarted] = true;605 WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);606 },607 (r) => {608 assert(stream[kState] === 'writable' || stream[kState] === 'erroring');609 controller[kStarted] = true;610 WritableStreamDealWithRejection(stream, r);611 },612 )613 .catch(rethrowAssertionErrorRejection);614 }615 function SetUpWritableStreamDefaultControllerFromUnderlyingSink(stream, underlyingSink, highWaterMark, sizeAlgorithm) {616 assert(underlyingSink !== undefined);617 const controller = Object.create(WritableStreamDefaultController.prototype);618 function startAlgorithm() {619 return InvokeOrNoop(underlyingSink, 'start', [controller]);620 }621 const writeAlgorithm = CreateAlgorithmFromUnderlyingMethod(underlyingSink, 'write', 1, [controller]);622 const closeAlgorithm = CreateAlgorithmFromUnderlyingMethod(underlyingSink, 'close', 0, []);623 const abortAlgorithm = CreateAlgorithmFromUnderlyingMethod(underlyingSink, 'abort', 1, []);624 SetUpWritableStreamDefaultController(stream, controller, startAlgorithm, writeAlgorithm, closeAlgorithm,625 abortAlgorithm, highWaterMark, sizeAlgorithm);626 }627 function WritableStreamDefaultControllerClose(controller) {628 EnqueueValueWithSize(controller, 'close', 0);629 WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);630 }631 function WritableStreamDefaultControllerGetChunkSize(controller, chunk) {632 try {633 return controller[kStrategySizeAlgorithm](chunk);634 } catch (chunkSizeE) {635 WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);636 return 1;637 }638 }639 function WritableStreamDefaultControllerGetDesiredSize(controller) {640 return controller[kStrategyHWM] - controller[kQueueTotalSize];641 }642 function WritableStreamDefaultControllerWrite(controller, chunk, chunkSize) {643 const writeRecord = { chunk };644 try {645 EnqueueValueWithSize(controller, writeRecord, chunkSize);646 } catch (enqueueE) {647 WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);648 return;649 }650 const stream = controller[kControlledWritableStream];651 if (WritableStreamCloseQueuedOrInFlight(stream) === false && stream[kState] === 'writable') {652 const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);653 WritableStreamUpdateBackpressure(stream, backpressure);654 }655 WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);656 }657 // Abstract operations for the WritableStreamDefaultController.658 function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {659 const stream = controller[kControlledWritableStream];660 if (controller[kStarted] === false) {661 return;662 }663 if (stream[kInFlightWriteRequest] !== undefined) {664 return;665 }666 const state = stream[kState];667 if (state === 'closed' || state === 'errored') {668 return;669 }670 if (state === 'erroring') {671 WritableStreamFinishErroring(stream);672 return;673 }674 if (controller[kQueue].length === 0) {675 return;676 }677 const writeRecord = PeekQueueValue(controller);678 if (writeRecord === 'close') {679 WritableStreamDefaultControllerProcessClose(controller);680 } else {681 WritableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk);682 }683 }684 function WritableStreamDefaultControllerErrorIfNeeded(controller, error) {685 if (controller[kControlledWritableStream][kState] === 'writable') {686 WritableStreamDefaultControllerError(controller, error);687 }688 }689 function WritableStreamDefaultControllerProcessClose(controller) {690 const stream = controller[kControlledWritableStream];691 WritableStreamMarkCloseRequestInFlight(stream);692 DequeueValue(controller);693 assert(controller[kQueue].length === 0);694 const sinkClosePromise = controller[kCloseAlgorithm]();695 sinkClosePromise.then(696 () => {697 WritableStreamFinishInFlightClose(stream);698 },699 (reason) => {700 WritableStreamFinishInFlightCloseWithError(stream, reason);701 },702 )703 .catch(rethrowAssertionErrorRejection);704 }705 function WritableStreamDefaultControllerProcessWrite(controller, chunk) {706 const stream = controller[kControlledWritableStream];707 WritableStreamMarkFirstWriteRequestInFlight(stream);708 const sinkWritePromise = controller[kWriteAlgorithm](chunk);709 sinkWritePromise.then(710 () => {711 WritableStreamFinishInFlightWrite(stream);712 const state = stream[kState];713 assert(state === 'writable' || state === 'erroring');714 DequeueValue(controller);715 if (WritableStreamCloseQueuedOrInFlight(stream) === false && state === 'writable') {716 const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);717 WritableStreamUpdateBackpressure(stream, backpressure);718 }719 WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);720 },721 (reason) => {722 WritableStreamFinishInFlightWriteWithError(stream, reason);723 },724 )725 .catch(rethrowAssertionErrorRejection);726 }727 function WritableStreamDefaultControllerGetBackpressure(controller) {728 const desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller);729 return desiredSize <= 0;730 }731 // A client of WritableStreamDefaultController may use these functions directly to bypass state check.732 function WritableStreamDefaultControllerError(controller, error) {733 const stream = controller[kControlledWritableStream];734 assert(stream[kState] === 'writable');735 WritableStreamStartErroring(stream, error);736 }737 // Helper functions for the WritableStream.738 function streamBrandCheckException(name) {739 return new TypeError(`WritableStream.prototype.${name} can only be used on a WritableStream`);740 }741 // Helper functions for the WritableStreamDefaultWriter.742 function defaultWriterBrandCheckException(name) {743 return new TypeError(744 `WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`,745 );746 }747 function defaultWriterLockException(name) {748 return new TypeError(`Cannot ${name} a stream using a released writer`);749 }750 function defaultWriterClosedPromiseInitialize(writer) {751 writer[kClosedPromise] = new Promise((resolve, reject) => {752 writer[kClosedPromiseResolve] = resolve;753 writer[kClosedPromiseReject] = reject;754 writer[kClosedPromiseState] = 'pending';755 });756 }757 function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) {758 writer[kClosedPromise] = Promise.reject(reason);759 writer[kClosedPromiseResolve] = undefined;760 writer[kClosedPromiseReject] = undefined;761 writer[kClosedPromiseState] = 'rejected';...

Full Screen

Full Screen

writable-stream.js

Source:writable-stream.js Github

copy

Full Screen

...185 if (IsWritableStreamDefaultWriter(this) === false) {186 throw defaultWriterBrandCheckException('desiredSize');187 }188 if (this._ownerWritableStream === undefined) {189 throw defaultWriterLockException('desiredSize');190 }191 return WritableStreamDefaultWriterGetDesiredSize(this);192 }193 get ready() {194 if (IsWritableStreamDefaultWriter(this) === false) {195 return Promise.reject(defaultWriterBrandCheckException('ready'));196 }197 return this._readyPromise;198 }199 abort(reason) {200 if (IsWritableStreamDefaultWriter(this) === false) {201 return Promise.reject(defaultWriterBrandCheckException('abort'));202 }203 if (this._ownerWritableStream === undefined) {204 return Promise.reject(defaultWriterLockException('abort'));205 }206 return WritableStreamDefaultWriterAbort(this, reason);207 }208 close() {209 if (IsWritableStreamDefaultWriter(this) === false) {210 return Promise.reject(defaultWriterBrandCheckException('close'));211 }212 const stream = this._ownerWritableStream;213 if (stream === undefined) {214 return Promise.reject(defaultWriterLockException('close'));215 }216 if (stream._state === 'closing') {217 return Promise.reject(new TypeError('cannot close an already-closing stream'));218 }219 return WritableStreamDefaultWriterClose(this);220 }221 releaseLock() {222 if (IsWritableStreamDefaultWriter(this) === false) {223 throw defaultWriterBrandCheckException('releaseLock');224 }225 const stream = this._ownerWritableStream;226 if (stream === undefined) {227 return;228 }229 assert(stream._writer !== undefined);230 WritableStreamDefaultWriterRelease(this);231 }232 write(chunk) {233 if (IsWritableStreamDefaultWriter(this) === false) {234 return Promise.reject(defaultWriterBrandCheckException('write'));235 }236 const stream = this._ownerWritableStream;237 if (stream === undefined) {238 return Promise.reject(defaultWriterLockException('write to'));239 }240 if (stream._state === 'closing') {241 return Promise.reject(new TypeError('Cannot write to an already-closed stream'));242 }243 return WritableStreamDefaultWriterWrite(this, chunk);244 }245}246// Abstract operations for the WritableStreamDefaultWriter.247function IsWritableStreamDefaultWriter(x) {248 if (!typeIsObject(x)) {249 return false;250 }251 if (!Object.prototype.hasOwnProperty.call(x, '_ownerWritableStream')) {252 return false;253 }254 return true;255}256// A client of WritableStreamDefaultWriter may use these functions directly to bypass state check.257function WritableStreamDefaultWriterAbort(writer, reason) {258 const stream = writer._ownerWritableStream;259 assert(stream !== undefined);260 return WritableStreamAbort(stream, reason);261}262function WritableStreamDefaultWriterClose(writer) {263 const stream = writer._ownerWritableStream;264 assert(stream !== undefined);265 const state = stream._state;266 if (state === 'closed' || state === 'errored') {267 return Promise.reject(new TypeError(268 `The stream (in ${state} state) is not in the writable state and cannot be closed`));269 }270 assert(state === 'writable');271 const promise = WritableStreamAddWriteRequest(stream);272 if (WritableStreamDefaultControllerGetBackpressure(stream._writableStreamController) === true) {273 defaultWriterReadyPromiseResolve(writer);274 }275 stream._state = 'closing';276 WritableStreamDefaultControllerClose(stream._writableStreamController);277 return promise;278}279function WritableStreamDefaultWriterCloseWithErrorPropagation(writer) {280 const stream = writer._ownerWritableStream;281 assert(stream !== undefined);282 const state = stream._state;283 if (state === 'closing' || state === 'closed') {284 return Promise.resolve();285 }286 if (state === 'errored') {287 return Promise.reject(stream._storedError);288 }289 assert(state === 'writable');290 return WritableStreamDefaultWriterClose(writer);291}292function WritableStreamDefaultWriterGetDesiredSize(writer) {293 const stream = writer._ownerWritableStream;294 const state = stream._state;295 if (state === 'errored') {296 return null;297 }298 if (state === 'closed') {299 return 0;300 }301 return WritableStreamDefaultControllerGetDesiredSize(stream._writableStreamController);302}303function WritableStreamDefaultWriterRelease(writer) {304 const stream = writer._ownerWritableStream;305 assert(stream !== undefined);306 assert(stream._writer === writer);307 const releasedError = new TypeError(308 'Writer was released and can no longer be used to monitor the stream\'s closedness');309 const state = stream._state;310 if (state === 'writable' || state === 'closing') {311 defaultWriterClosedPromiseReject(writer, releasedError);312 } else {313 defaultWriterClosedPromiseResetToRejected(writer, releasedError);314 }315 writer._closedPromise.catch(() => {});316 if (state === 'writable' &&317 WritableStreamDefaultControllerGetBackpressure(stream._writableStreamController) === true) {318 defaultWriterReadyPromiseReject(writer, releasedError);319 } else {320 defaultWriterReadyPromiseResetToRejected(writer, releasedError);321 }322 writer._readyPromise.catch(() => {});323 stream._writer = undefined;324 writer._ownerWritableStream = undefined;325}326function WritableStreamDefaultWriterWrite(writer, chunk) {327 const stream = writer._ownerWritableStream;328 assert(stream !== undefined);329 const state = stream._state;330 if (state === 'closed' || state === 'errored') {331 return Promise.reject(new TypeError(332 `The stream (in ${state} state) is not in the writable state and cannot be written to`));333 }334 assert(state === 'writable');335 const promise = WritableStreamAddWriteRequest(stream);336 WritableStreamDefaultControllerWrite(stream._writableStreamController, chunk);337 return promise;338}339class WritableStreamDefaultController {340 constructor(stream, underlyingSink, size, highWaterMark) {341 if (IsWritableStream(stream) === false) {342 throw new TypeError('WritableStreamDefaultController can only be constructed with a WritableStream instance');343 }344 if (stream._writableStreamController !== undefined) {345 throw new TypeError(346 'WritableStreamDefaultController instances can only be created by the WritableStream constructor');347 }348 this._controlledWritableStream = stream;349 this._underlyingSink = underlyingSink;350 this._queue = [];351 this._started = false;352 this._writing = false;353 const normalizedStrategy = ValidateAndNormalizeQueuingStrategy(size, highWaterMark);354 this._strategySize = normalizedStrategy.size;355 this._strategyHWM = normalizedStrategy.highWaterMark;356 const backpressure = WritableStreamDefaultControllerGetBackpressure(this);357 if (backpressure === true) {358 WritableStreamUpdateBackpressure(stream, backpressure);359 }360 const controller = this;361 const startResult = InvokeOrNoop(underlyingSink, 'start', [this]);362 Promise.resolve(startResult).then(363 () => {364 controller._started = true;365 WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);366 },367 r => {368 WritableStreamDefaultControllerErrorIfNeeded(controller, r);369 }370 )371 .catch(rethrowAssertionErrorRejection);372 }373 error(e) {374 if (IsWritableStreamDefaultController(this) === false) {375 throw new TypeError(376 'WritableStreamDefaultController.prototype.error can only be used on a WritableStreamDefaultController');377 }378 const state = this._controlledWritableStream._state;379 if (state === 'closed' || state === 'errored') {380 throw new TypeError(`The stream is ${state} and so cannot be errored`);381 }382 WritableStreamDefaultControllerError(this, e);383 }384}385// Abstract operations implementing interface required by the WritableStream.386function WritableStreamDefaultControllerAbort(controller, reason) {387 controller._queue = [];388 const sinkAbortPromise = PromiseInvokeOrFallbackOrNoop(controller._underlyingSink, 'abort', [reason],389 'close', [controller]);390 return sinkAbortPromise.then(() => undefined);391}392function WritableStreamDefaultControllerClose(controller) {393 EnqueueValueWithSize(controller._queue, 'close', 0);394 WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);395}396function WritableStreamDefaultControllerGetDesiredSize(controller) {397 const queueSize = GetTotalQueueSize(controller._queue);398 return controller._strategyHWM - queueSize;399}400function WritableStreamDefaultControllerWrite(controller, chunk) {401 const stream = controller._controlledWritableStream;402 assert(stream._state === 'writable');403 let chunkSize = 1;404 if (controller._strategySize !== undefined) {405 try {406 chunkSize = controller._strategySize(chunk);407 } catch (chunkSizeE) {408 // TODO: Should we notify the sink of this error?409 WritableStreamDefaultControllerErrorIfNeeded(controller, chunkSizeE);410 return;411 }412 }413 const writeRecord = { chunk };414 const lastBackpressure = WritableStreamDefaultControllerGetBackpressure(controller);415 try {416 EnqueueValueWithSize(controller._queue, writeRecord, chunkSize);417 } catch (enqueueE) {418 WritableStreamDefaultControllerErrorIfNeeded(controller, enqueueE);419 return;420 }421 if (stream._state === 'writable') {422 const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);423 if (lastBackpressure !== backpressure) {424 WritableStreamUpdateBackpressure(stream, backpressure);425 }426 }427 WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);428}429// Abstract operations for the WritableStreamDefaultController.430function IsWritableStreamDefaultController(x) {431 if (!typeIsObject(x)) {432 return false;433 }434 if (!Object.prototype.hasOwnProperty.call(x, '_underlyingSink')) {435 return false;436 }437 return true;438}439function WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller) {440 if (controller._controlledWritableStream._state === 'closed' ||441 controller._controlledWritableStream._state === 'errored') {442 return;443 }444 if (controller._started === false) {445 return;446 }447 if (controller._writing === true) {448 return;449 }450 if (controller._queue.length === 0) {451 return;452 }453 const writeRecord = PeekQueueValue(controller._queue);454 if (writeRecord === 'close') {455 WritableStreamDefaultControllerProcessClose(controller);456 } else {457 WritableStreamDefaultControllerProcessWrite(controller, writeRecord.chunk);458 }459}460function WritableStreamDefaultControllerErrorIfNeeded(controller, e) {461 if (controller._controlledWritableStream._state === 'writable' ||462 controller._controlledWritableStream._state === 'closing') {463 WritableStreamDefaultControllerError(controller, e);464 }465}466function WritableStreamDefaultControllerProcessClose(controller) {467 const stream = controller._controlledWritableStream;468 assert(stream._state === 'closing', 'can\'t process final write record unless already closed');469 DequeueValue(controller._queue);470 assert(controller._queue.length === 0, 'queue must be empty once the final write record is dequeued');471 const sinkClosePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'close', [controller]);472 sinkClosePromise.then(473 () => {474 if (stream._state !== 'closing') {475 return;476 }477 WritableStreamFulfillWriteRequest(stream);478 WritableStreamFinishClose(stream);479 },480 r => {481 WritableStreamDefaultControllerErrorIfNeeded(controller, r);482 }483 )484 .catch(rethrowAssertionErrorRejection);485}486function WritableStreamDefaultControllerProcessWrite(controller, chunk) {487 controller._writing = true;488 const sinkWritePromise = PromiseInvokeOrNoop(controller._underlyingSink, 'write', [chunk, controller]);489 sinkWritePromise.then(490 () => {491 const stream = controller._controlledWritableStream;492 const state = stream._state;493 if (state === 'errored' || state === 'closed') {494 return;495 }496 controller._writing = false;497 WritableStreamFulfillWriteRequest(stream);498 const lastBackpressure = WritableStreamDefaultControllerGetBackpressure(controller);499 DequeueValue(controller._queue);500 if (state !== 'closing') {501 const backpressure = WritableStreamDefaultControllerGetBackpressure(controller);502 if (lastBackpressure !== backpressure) {503 WritableStreamUpdateBackpressure(controller._controlledWritableStream, backpressure);504 }505 }506 WritableStreamDefaultControllerAdvanceQueueIfNeeded(controller);507 },508 r => {509 WritableStreamDefaultControllerErrorIfNeeded(controller, r);510 }511 )512 .catch(rethrowAssertionErrorRejection);513}514function WritableStreamDefaultControllerGetBackpressure(controller) {515 const desiredSize = WritableStreamDefaultControllerGetDesiredSize(controller);516 return desiredSize <= 0;517}518// A client of WritableStreamDefaultController may use these functions directly to bypass state check.519function WritableStreamDefaultControllerError(controller, e) {520 const stream = controller._controlledWritableStream;521 assert(stream._state === 'writable' || stream._state === 'closing');522 WritableStreamError(stream, e);523 controller._queue = [];524}525// Helper functions for the WritableStream.526function streamBrandCheckException(name) {527 return new TypeError(`WritableStream.prototype.${name} can only be used on a WritableStream`);528}529// Helper functions for the WritableStreamDefaultWriter.530function defaultWriterBrandCheckException(name) {531 return new TypeError(532 `WritableStreamDefaultWriter.prototype.${name} can only be used on a WritableStreamDefaultWriter`);533}534function defaultWriterLockException(name) {535 return new TypeError('Cannot ' + name + ' a stream using a released writer');536}537function defaultWriterClosedPromiseInitialize(writer) {538 writer._closedPromise = new Promise((resolve, reject) => {539 writer._closedPromise_resolve = resolve;540 writer._closedPromise_reject = reject;541 });542}543function defaultWriterClosedPromiseInitializeAsRejected(writer, reason) {544 writer._closedPromise = Promise.reject(reason);545 writer._closedPromise_resolve = undefined;546 writer._closedPromise_reject = undefined;547}548function defaultWriterClosedPromiseInitializeAsResolved(writer) {...

Full Screen

Full Screen

WritableStreamDefaultWriter-impl.js

Source:WritableStreamDefaultWriter-impl.js Github

copy

Full Screen

...10 return this._closedPromise;11 }12 get desiredSize() {13 if (this._stream === undefined) {14 throw defaultWriterLockException('desiredSize');15 }16 return aos.WritableStreamDefaultWriterGetDesiredSize(this);17 }18 get ready() {19 return this._readyPromise;20 }21 abort(reason) {22 if (this._stream === undefined) {23 return promiseRejectedWith(defaultWriterLockException('abort'));24 }25 return aos.WritableStreamDefaultWriterAbort(this, reason);26 }27 close() {28 const stream = this._stream;29 if (stream === undefined) {30 return promiseRejectedWith(defaultWriterLockException('close'));31 }32 if (aos.WritableStreamCloseQueuedOrInFlight(stream) === true) {33 return promiseRejectedWith(new TypeError('Cannot close an already-closing stream'));34 }35 return aos.WritableStreamDefaultWriterClose(this);36 }37 releaseLock() {38 const stream = this._stream;39 if (stream === undefined) {40 return;41 }42 assert(stream._writer !== undefined);43 aos.WritableStreamDefaultWriterRelease(this);44 }45 write(chunk) {46 if (this._stream === undefined) {47 return promiseRejectedWith(defaultWriterLockException('write to'));48 }49 return aos.WritableStreamDefaultWriterWrite(this, chunk);50 }51};52function defaultWriterLockException(name) {53 return new TypeError('Cannot ' + name + ' a stream using a released writer');...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptLockException = require('wptLockException');2var wptLockExceptionObj = new wptLockException();3var defaultWriterLockExceptionObj = wptLockExceptionObj.defaultWriterLockException();4console.log(defaultWriterLockExceptionObj);5{ message: 'Writer lock exception', name: 'WriterLockException', code: 0 }6wptLockException.defaultReaderLockException()7wptLockException.defaultWriterLockException()

Full Screen

Using AI Code Generation

copy

Full Screen

1importClass(Packages.com.ibm.workplace.wcm.api.WCMException);2importClass(Packages.com.ibm.workplace.wcm.api.WCMContent);3importClass(Packages.com.ibm.workplace.wcm.api.WCMContentManager);4importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItem);5importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersion);6importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionCollection);7importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionList);8importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionManager);9importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadata);10importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataManager);11importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataList);12importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataManager);13importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataManager);14importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataList);15importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataManager);16importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataManager);17importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataList);18importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataManager);19importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataManager);20importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataList);21importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataManager);22importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataManager);23importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataList);24importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataManager);25importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataManager);26importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataList);27importClass(Packages.com.ibm.workplace.wcm.api.WCMContentItemVersionMetadataManager);28importClass(Packages

Full Screen

Using AI Code Generation

copy

Full Screen

1importClass(java.lang.System);2importClass(java.io.File);3importClass(java.io.FileOutputStream);4importClass(java.io.IOException);5importClass(java.io.FileNotFoundException);6importClass(java.io.RandomAccessFile);7importClass(java.nio.channels.FileChannel);8importClass(java.nio.channels.FileLock);9var file = new File("test.txt");10var fileOutStream = new FileOutputStream(file);11var fileChannel = fileOutStream.getChannel();12var fileLock = fileChannel.lock();13System.out.println(fileLock.toString());14fileLock.release();15fileChannel.close();16fileOutStream.close();17importClass(java.lang.System);18importClass(java.io.File);19importClass(java.io.FileOutputStream);20importClass(java.io.IOException);21importClass(java.io.FileNotFoundException);22importClass(java.io.RandomAccessFile);23importClass(java.nio.channels.FileChannel);24importClass(java.nio.channels.FileLock);25var file = new File("test.txt");26var fileOutStream = new FileOutputStream(file);27var fileChannel = fileOutStream.getChannel();28var fileLock = fileChannel.lock();29System.out.println(fileLock.toString());30fileLock.release();31fileChannel.close();32fileOutStream.close();33importClass(java.lang.System);34importClass(java.io.File);35importClass(java.io.FileOutputStream);36importClass(java.io.IOException);37importClass(java.io.FileNotFoundException);38importClass(java.io.RandomAccessFile);39importClass(java.nio.channels.FileChannel);40importClass(java.nio.channels.FileLock);41var file = new File("test.txt");42var fileOutStream = new FileOutputStream(file);43var fileChannel = fileOutStream.getChannel();44var fileLock = fileChannel.lock(0, 10, false);45System.out.println(fileLock.toString());46fileLock.release();47fileChannel.close();48fileOutStream.close();49importClass(java.lang.System);50importClass(java.io.File);51importClass(java.io.FileOutputStream);52importClass(java.io.IOException);53importClass(java.io.FileNotFoundException);54importClass(java.io.RandomAccessFile);55importClass(java.nio.channels.FileChannel);56importClass(java.nio.channels.FileLock);57var file = new File("test.txt");58var fileOutStream = new FileOutputStream(file);59var fileChannel = fileOutStream.getChannel();60var fileLock = fileChannel.lock(0, 10, false);61System.out.println(fileLock.toString());

Full Screen

Using AI Code Generation

copy

Full Screen

1function test() {2 var exception = wpt.defaultWriterLockException;3 if (exception instanceof Object) {4 testPassed('defaultWriterLockException is an Object');5 } else {6 testFailed('defaultWriterLockException is not an Object');7 }8}9test();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wpt = require('wpt');2var wptObj = new wpt();3var defaultWriterLockException = wptObj.defaultWriterLockException();4console.log(defaultWriterLockException);5Example 2: Using defaultWriterLockException() method6var wpt = require('wpt');7var wptObj = new wpt();8var defaultWriterLockException = wptObj.defaultWriterLockException();9console.log(defaultWriterLockException);

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require("fs");3var file = fs.createWriteStream("lock.txt");4var file2 = fs.createWriteStream("lock2.txt");5var lock = wptools.defaultWriterLockException(file);6var lock2 = wptools.defaultWriterLockException(file2);7lock.lock();8lock2.lock();9lock.unlock();10lock2.unlock();11lock.lock();12lock2.lock();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var wpt = new wptools();3wpt.defaultWriterLockException(function(err, data) {4 console.log(data);5});6{7}8var wptools = require('wptools');9var wpt = new wptools();10wpt.setDefaultWriterLockException(true, function(err, data) {11 console.log(data);12});13{14}15var wptools = require('wptools');16var wpt = new wptools();17wpt.getWriterLockException(function(err, data) {18 console.log(data);19});20{21}22var wptools = require('wptools');23var wpt = new wptools();24wpt.setWriterLockException(['

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var writerLockExceptionObj = wptools.defaultWriterLockException();3wptools.defaultWriterLockException(writerLockExceptionObj);4var getWriterLockExceptionObj = wptools.defaultWriterLockException();5console.log('getWriterLockExceptionObj = ' + getWriterLockExceptionObj);6var wptools = require('wptools');7var writerLockExceptionObj = wptools.defaultWriterLockException();8wptools.defaultWriterLockException(writerLockExceptionObj);

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful