Skip to content

Commit

Permalink
Prioritize Promise
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Oct 18, 2023
1 parent 059ad42 commit 24bf6c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 764 deletions.
14 changes: 7 additions & 7 deletions packages/seroval/src/core/base/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,13 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
break;
}
const currentFeatures = this.features;
// Promises
if (
(currentFeatures & Feature.Promise)
&& (currentClass === Promise || current instanceof Promise)
) {
return this.parsePromise(id, current as unknown as Promise<unknown>);
}
// Typed Arrays
if (currentFeatures & Feature.TypedArray) {
switch (currentClass) {
Expand Down Expand Up @@ -751,13 +758,6 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
) {
return this.parseAggregateError(id, current as unknown as AggregateError);
}
// Promises
if (
(currentFeatures & Feature.Promise)
&& (currentClass === Promise || current instanceof Promise)
) {
return this.parsePromise(id, current as unknown as Promise<unknown>);
}
// Slow path. We only need to handle Errors and Iterators
// since they have very broad implementations.
if (current instanceof Error) {
Expand Down
13 changes: 7 additions & 6 deletions packages/seroval/src/core/base/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,13 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont
break;
}
const currentFeatures = this.features;
// Promises
if (
(currentFeatures & Feature.Promise)
&& (currentClass === Promise || current instanceof Promise)
) {
return this.parsePromise(id, current as unknown as Promise<unknown>);
}
// Typed Arrays
if (currentFeatures & Feature.TypedArray) {
switch (currentClass) {
Expand Down Expand Up @@ -427,12 +434,6 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont
) {
return this.parseAggregateError(id, current as unknown as AggregateError);
}
if (
(currentFeatures & Feature.Promise)
&& (currentClass === Promise || current instanceof Promise)
) {
return this.parsePromise(id, current as unknown as Promise<unknown>);
}
// Slow path. We only need to handle Errors and Iterators
// since they have very broad implementations.
if (current instanceof Error) {
Expand Down
Loading

0 comments on commit 24bf6c6

Please sign in to comment.