Skip to content
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

Avoid Object.create(null) #47

Merged
merged 1 commit into from
Jan 30, 2018
Merged
Show file tree
Hide file tree
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
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