Skip to content

Commit

Permalink
Revert "Fix constructor name"
Browse files Browse the repository at this point in the history
This reverts commit 065ffd3.
  • Loading branch information
lxsmnsyc committed Oct 16, 2023
1 parent 065ffd3 commit def657e
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 25 deletions.
7 changes: 3 additions & 4 deletions packages/seroval/src/core/base/async.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
FALSE_NODE,
UNDEFINED_NODE,
} from '../literals';
import { getConstructor } from '../object';
import { BaseParserContext } from '../parser-context';
import promiseToResult from '../promise-to-result';
import { hasReferenceID } from '../reference';
Expand Down Expand Up @@ -153,7 +152,7 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
i: id,
s: undefined,
l: current.length,
c: getConstructor(current).name,
c: current.constructor.name,
m: undefined,
p: undefined,
e: undefined,
Expand All @@ -173,7 +172,7 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
i: id,
s: undefined,
l: current.length,
c: getConstructor(current).name,
c: current.constructor.name,
m: undefined,
p: undefined,
e: undefined,
Expand Down Expand Up @@ -642,7 +641,7 @@ export default abstract class BaseAsyncParserContext extends BaseParserContext {
if (Array.isArray(current)) {
return this.parseArray(id, current);
}
const currentClass = getConstructor(current);
const currentClass = current.constructor;
switch (currentClass) {
case Object:
return this.parsePlainObject(
Expand Down
3 changes: 1 addition & 2 deletions packages/seroval/src/core/base/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import type {
SerovalResponseNode,
} from '../types';
import { createDOMExceptionNode, createURLNode, createURLSearchParamsNode } from '../web-api';
import { getConstructor } from '../object';

export interface BaseStreamParserContextOptions extends BaseSyncParserContextOptions {
onParse: (node: SerovalNode, initial: boolean) => void;
Expand Down Expand Up @@ -297,7 +296,7 @@ export default abstract class BaseStreamParserContext extends BaseSyncParserCont
if (Array.isArray(current)) {
return this.parseArray(id, current);
}
const currentClass = getConstructor(current);
const currentClass = current.constructor;
switch (currentClass) {
case Object:
return this.parsePlainObject(
Expand Down
7 changes: 3 additions & 4 deletions packages/seroval/src/core/base/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
TRUE_NODE,
UNDEFINED_NODE,
} from '../literals';
import { getConstructor } from '../object';
import type { BaseParserContextOptions } from '../parser-context';
import { BaseParserContext } from '../parser-context';
import { hasReferenceID } from '../reference';
Expand Down Expand Up @@ -209,7 +208,7 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
i: id,
s: undefined,
l: current.length,
c: getConstructor(current).name,
c: current.constructor.name,
m: undefined,
p: undefined,
e: undefined,
Expand All @@ -229,7 +228,7 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
i: id,
s: undefined,
l: current.length,
c: getConstructor(current).name,
c: current.constructor.name,
m: undefined,
p: undefined,
e: undefined,
Expand Down Expand Up @@ -528,7 +527,7 @@ export default abstract class BaseSyncParserContext extends BaseParserContext {
if (Array.isArray(current)) {
return this.parseArray(id, current);
}
const currentClass = getConstructor(current);
const currentClass = current.constructor;
switch (currentClass) {
case Object:
return this.parsePlainObject(
Expand Down
6 changes: 0 additions & 6 deletions packages/seroval/src/core/object.ts

This file was deleted.

14 changes: 5 additions & 9 deletions packages/seroval/src/core/parser-context.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ALL_ENABLED, BIGINT_FLAG, Feature } from './compat';
import { ERROR_CONSTRUCTOR_STRING } from './constants';
import { getConstructor } from './object';
import type { Plugin, PluginAccessOptions, SerovalMode } from './plugin';
import { getErrorConstructor } from './shared';

Expand Down Expand Up @@ -36,13 +35,10 @@ export abstract class BaseParserContext implements PluginAccessOptions {
// Name has been modified
if (error.name !== constructor) {
options = { name: error.name };
} else {
const currentName = getConstructor(error).name;
if (currentName !== constructor) {
// Otherwise, name is overriden because
// the Error class is extended
options = { name: currentName };
}
} else if (error.constructor.name !== constructor) {
// Otherwise, name is overriden because
// the Error class is extended
options = { name: error.constructor.name };
}
const names = Object.getOwnPropertyNames(error);
for (let i = 0, len = names.length, name: string; i < len; i++) {
Expand Down Expand Up @@ -74,7 +70,7 @@ export abstract class BaseParserContext implements PluginAccessOptions {
if (Array.isArray(value)) {
return false;
}
const currentClass = getConstructor(value);
const currentClass = value.constructor;
if (this.features & Feature.TypedArray) {
switch (currentClass) {
case Int8Array:
Expand Down

0 comments on commit def657e

Please sign in to comment.