Skip to content

Commit 13f130d

Browse files
authored
Use Object.create(null) over {} to avoid prototype issues - v16 (#4631)
1 parent 6ca59e1 commit 13f130d

File tree

3 files changed

+6
-17
lines changed

3 files changed

+6
-17
lines changed

src/execution/values.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function coerceVariableValues(
7575
inputs: { readonly [variable: string]: unknown },
7676
onError: (error: GraphQLError) => void,
7777
): { [variable: string]: unknown } {
78-
const coercedValues: { [variable: string]: unknown } = {};
78+
const coercedValues: { [variable: string]: unknown } = Object.create(null);
7979
for (const varDefNode of varDefNodes) {
8080
const varName = varDefNode.variable.name.value;
8181
const varType = typeFromAST(schema, varDefNode.type);
@@ -138,7 +138,7 @@ function coerceVariableValues(
138138
);
139139
}
140140

141-
return coercedValues;
141+
return { ...coercedValues };
142142
}
143143

144144
/**
@@ -154,7 +154,7 @@ export function getArgumentValues(
154154
node: FieldNode | DirectiveNode,
155155
variableValues?: Maybe<ObjMap<unknown>>,
156156
): { [argument: string]: unknown } {
157-
const coercedValues: { [argument: string]: unknown } = {};
157+
const coercedValues: { [argument: string]: unknown } = Object.create(null);
158158

159159
// FIXME: https://github.com/graphql/graphql-js/issues/2203
160160
/* c8 ignore next */
@@ -222,7 +222,7 @@ export function getArgumentValues(
222222
}
223223
coercedValues[name] = coercedValue;
224224
}
225-
return coercedValues;
225+
return { ...coercedValues };
226226
}
227227

228228
/**

src/utilities/coerceInputValue.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function coerceInputValueImpl(
9595
return;
9696
}
9797

98-
const coercedValue: any = {};
98+
const coercedValue: any = Object.create(null);
9999
const fieldDefs = type.getFields();
100100

101101
for (const field of Object.values(fieldDefs)) {
@@ -166,7 +166,7 @@ function coerceInputValueImpl(
166166
}
167167
}
168168

169-
return coercedValue;
169+
return { ...coercedValue };
170170
}
171171

172172
if (isLeafType(type)) {

src/validation/rules/ValuesOfCorrectTypeRule.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import type {
1010
ObjectFieldNode,
1111
ObjectValueNode,
1212
ValueNode,
13-
VariableDefinitionNode,
1413
} from '../../language/ast';
1514
import { Kind } from '../../language/kinds';
1615
import { print } from '../../language/printer';
@@ -40,17 +39,7 @@ import type { ValidationContext } from '../ValidationContext';
4039
export function ValuesOfCorrectTypeRule(
4140
context: ValidationContext,
4241
): ASTVisitor {
43-
let variableDefinitions: { [key: string]: VariableDefinitionNode } = {};
44-
4542
return {
46-
OperationDefinition: {
47-
enter() {
48-
variableDefinitions = {};
49-
},
50-
},
51-
VariableDefinition(definition) {
52-
variableDefinitions[definition.variable.name.value] = definition;
53-
},
5443
ListValue(node) {
5544
// Note: TypeInfo will traverse into a list's item type, so look to the
5645
// parent input type to check if it is a list.

0 commit comments

Comments
 (0)