Skip to content

Commit cb227a4

Browse files
committed
Use Object.create(null) rather than {}
1 parent 108bc20 commit cb227a4

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/execution/values.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ function coerceVariableValues(
7878
inputs: { +[variable: string]: mixed, ... },
7979
onError: (GraphQLError) => void,
8080
): { [variable: string]: mixed, ... } {
81-
const coercedValues = {};
81+
const coercedValues = Object.create(null);
8282
for (const varDefNode of varDefNodes) {
8383
const varName = varDefNode.variable.name.value;
8484
const varType = typeFromAST(schema, varDefNode.type);
@@ -145,7 +145,7 @@ function coerceVariableValues(
145145
);
146146
}
147147

148-
return coercedValues;
148+
return { ...coercedValues };
149149
}
150150

151151
/**
@@ -163,7 +163,7 @@ export function getArgumentValues(
163163
node: FieldNode | DirectiveNode,
164164
variableValues?: ?ObjMap<mixed>,
165165
): { [argument: string]: mixed, ... } {
166-
const coercedValues = {};
166+
const coercedValues = Object.create(null);
167167

168168
// istanbul ignore next (See: 'https://github.com/graphql/graphql-js/issues/2203')
169169
const argumentNodes = node.arguments ?? [];
@@ -230,7 +230,7 @@ export function getArgumentValues(
230230
}
231231
coercedValues[name] = coercedValue;
232232
}
233-
return coercedValues;
233+
return { ...coercedValues };
234234
}
235235

236236
/**

src/utilities/coerceInputValue.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ function coerceInputValueImpl(
101101
return;
102102
}
103103

104-
const coercedValue = {};
104+
const coercedValue = Object.create(null);
105105
const fieldDefs = type.getFields();
106106

107107
for (const field of objectValues(fieldDefs)) {
@@ -148,7 +148,7 @@ function coerceInputValueImpl(
148148
);
149149
}
150150
}
151-
return coercedValue;
151+
return { ...coercedValue };
152152
}
153153

154154
// istanbul ignore else (See: 'https://github.com/graphql/graphql-js/issues/2618')

0 commit comments

Comments
 (0)