Skip to content

Commit c89fa44

Browse files
committed
reuse is_plain_object helper
1 parent bc3e694 commit c89fa44

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

src/uneval.js

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
DevalueError,
33
escaped,
44
get_type,
5+
is_plain_object,
56
is_primitive,
67
stringify_string
78
} from './utils.js';
@@ -10,9 +11,6 @@ const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_$';
1011
const unsafe_chars = /[<>\b\f\n\r\t\0\u2028\u2029]/g;
1112
const reserved =
1213
/^(?:do|if|in|for|int|let|new|try|var|byte|case|char|else|enum|goto|long|this|void|with|await|break|catch|class|const|final|float|short|super|throw|while|yield|delete|double|export|import|native|return|switch|throws|typeof|boolean|default|extends|finally|package|private|abstract|continue|debugger|function|volatile|interface|protected|transient|implements|instanceof|synchronized)$/;
13-
const object_proto_names = Object.getOwnPropertyNames(Object.prototype)
14-
.sort()
15-
.join('\0');
1614

1715
/**
1816
* Turn a value into the JavaScript that creates an equivalent value
@@ -72,14 +70,7 @@ export function uneval(value) {
7270
break;
7371

7472
default:
75-
const proto = Object.getPrototypeOf(thing);
76-
77-
if (
78-
proto !== Object.prototype &&
79-
proto !== null &&
80-
Object.getOwnPropertyNames(proto).sort().join('\0') !==
81-
object_proto_names
82-
) {
73+
if (!is_plain_object(thing)) {
8374
throw new DevalueError(
8475
`Cannot stringify arbitrary non-POJOs`,
8576
keys

0 commit comments

Comments
 (0)