Skip to content

use hasOwnProperty from Object.prototype #510

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,12 @@ function buildCode (location) {
schema.properties[key] = propertyLocation.schema
}

// Using obj['key'] !== undefined instead of obj.hasOwnProperty(prop) for perf reasons,
// see https://github.com/mcollina/fast-json-stringify/pull/3 for discussion.

const sanitized = JSON.stringify(key)
const asString = JSON.stringify(sanitized)

// Using obj['key'] !== undefined instead of obj.hasOwnProperty(prop) for perf reasons,
// see https://github.com/mcollina/fast-json-stringify/pull/3 for discussion.

code += `
if (obj[${sanitized}] !== undefined) {
${addComma}
Expand Down Expand Up @@ -901,7 +901,7 @@ function buildValue (location, input) {
switch (type) {
case 'string': {
code += `
${statement}(${input} === null || typeof ${input} === "${type}" || ${input} instanceof RegExp || (typeof ${input} === "object" && Object.hasOwnProperty.call(${input}, "toString")))
${statement}(${input} === null || typeof ${input} === "${type}" || ${input} instanceof RegExp || (typeof ${input} === "object" && Object.prototype.hasOwnProperty.call(${input}, "toString")))
${nestedResult}
`
break
Expand Down Expand Up @@ -987,7 +987,7 @@ function extendDateTimeType (schema) {
function isEmpty (schema) {
// eslint-disable-next-line
for (var key in schema) {
if (schema.hasOwnProperty(key) && schema[key] !== undefined) {
if (Object.prototype.hasOwnProperty.call(schema, key) && schema[key] !== undefined) {
return false
}
}
Expand Down