Skip to content

Commit

Permalink
Avoid Object.create(null)
Browse files Browse the repository at this point in the history
  • Loading branch information
demurgos committed Jan 30, 2018
1 parent 2cc8b82 commit 1969be8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# Next

- **[Fix]** Use `{}` instead of `Object.create(null)` when creating new objects in `DocumentType`.
Quickfix for [chaijs/deep-eql#51](https://github.com/chaijs/deep-eql/issues/51).

# 0.6.0 (2018-01-29)

- **[Breaking change]** Remove index module, you need to import specific modules with deep imports
Expand Down
6 changes: 3 additions & 3 deletions src/lib/bson/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DocumentType, name as typeName, PropertyDescriptor, renameKeys } from "

export function register(serializer: Serializer): void {
function write<T extends {}>(type: DocumentType<T>, val: T): any {
const result: any = Object.create(null);
const result: any = {}; // Object.create(null);
for (const [key, outKey] of renameKeys(type.properties, type.rename)) {
const descriptor: PropertyDescriptor<T[keyof T]> = type.properties[key];
const value: T[keyof T] = val[key];
Expand All @@ -22,7 +22,7 @@ export function register(serializer: Serializer): void {
const missing: Set<string> = new Set();
const invalid: Map<keyof T, Error> = new Map();

const result: Partial<T> = Object.create(null);
const result: Partial<T> = {}; // Object.create(null);

for (const [key, outKey] of renameKeys(type.properties, type.rename)) {
if (extra !== undefined) {
Expand Down Expand Up @@ -52,7 +52,7 @@ export function register(serializer: Serializer): void {
}

function readTrusted<T extends {}>(type: DocumentType<T>, input: any): T {
const result: Partial<T> = Object.create(null);
const result: Partial<T> = {}; // Object.create(null);
for (const [key, outKey] of renameKeys(type.properties, type.rename)) {
const descriptor: PropertyDescriptor<any> = type.properties[key];
const outValue: any = Reflect.get(input, outKey);
Expand Down
6 changes: 3 additions & 3 deletions src/lib/qs/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { DocumentType, name as typeName, PropertyDescriptor, renameKeys } from "

export function register(serializer: Serializer): void {
function write<T extends {}>(type: DocumentType<T>, val: T): any {
const result: any = Object.create(null);
const result: any = {}; // Object.create(null);
for (const [key, outKey] of renameKeys(type.properties, type.rename)) {
const descriptor: PropertyDescriptor<T[keyof T]> = type.properties[key];
const value: T[keyof T] = val[key];
Expand All @@ -22,7 +22,7 @@ export function register(serializer: Serializer): void {
const missing: Set<string> = new Set();
const invalid: Map<keyof T, Error> = new Map();

const result: Partial<T> = Object.create(null);
const result: Partial<T> = {}; // Object.create(null);

for (const [key, outKey] of renameKeys(type.properties, type.rename)) {
if (extra !== undefined) {
Expand Down Expand Up @@ -52,7 +52,7 @@ export function register(serializer: Serializer): void {
}

function readTrusted<T extends {}>(type: DocumentType<T>, input: any): T {
const result: Partial<T> = Object.create(null);
const result: Partial<T> = {}; // Object.create(null);
for (const [key, outKey] of renameKeys(type.properties, type.rename)) {
const descriptor: PropertyDescriptor<any> = type.properties[key];
const outValue: any = Reflect.get(input, outKey);
Expand Down
8 changes: 4 additions & 4 deletions src/lib/types/document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export const DocumentType: DocumentTypeConstructor = class<T extends {}> {
}

readTrustedJson(input: any): T {
const result: Partial<T> = Object.create(null);
const result: Partial<T> = {}; // Object.create(null);
for (const [key, outKey] of this.keys) {
const descriptor: PropertyDescriptor<any> = this.properties[key];
const jsonValue: any = Reflect.get(input, outKey);
Expand All @@ -123,7 +123,7 @@ export const DocumentType: DocumentTypeConstructor = class<T extends {}> {
const missing: Set<string> = new Set();
const invalid: Map<keyof T, Error> = new Map();

const result: Partial<T> = Object.create(null);
const result: Partial<T> = {}; // Object.create(null);

for (const [key, outKey] of this.keys) {
if (extra !== undefined) {
Expand Down Expand Up @@ -153,7 +153,7 @@ export const DocumentType: DocumentTypeConstructor = class<T extends {}> {
}

writeJson(val: T): any {
const result: any = Object.create(null);
const result: any = {}; // Object.create(null);
for (const [key, outKey] of this.keys) {
const descriptor: PropertyDescriptor<T[keyof T]> = this.properties[key];
const value: T[keyof T] = val[key];
Expand Down Expand Up @@ -244,7 +244,7 @@ export const DocumentType: DocumentTypeConstructor = class<T extends {}> {
}

clone(val: T): T {
const result: Partial<T> = Object.create(null);
const result: Partial<T> = {}; // Object.create(null);
for (const key in this.properties) {
result[key] = val[key] === undefined ? undefined : this.properties[key].type.clone(val[key]);
}
Expand Down

0 comments on commit 1969be8

Please sign in to comment.