-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid polluting the original object in case of Object.create (#1799)
Co-authored-by: Laurin Quast <[email protected]>
- Loading branch information
Showing
8 changed files
with
161 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@whatwg-node/server': patch | ||
--- | ||
|
||
Avoid polluting the original object in case of \`Object.create\` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { isolateObject } from '../src/utils'; | ||
|
||
describe('isolateObject', () => { | ||
describe('Object.create', () => { | ||
test('property assignments', () => { | ||
const origin = isolateObject({}); | ||
const a = Object.create(origin); | ||
const b = Object.create(origin); | ||
a.a = 1; | ||
expect(b.a).toEqual(undefined); | ||
}); | ||
test('property assignments with defineProperty', () => { | ||
const origin = isolateObject({}); | ||
const a = Object.create(origin); | ||
const b = Object.create(origin); | ||
Object.defineProperty(a, 'a', { value: 1 }); | ||
expect(b.a).toEqual(undefined); | ||
}); | ||
test('property deletions', () => { | ||
const origin = isolateObject({}); | ||
const a = Object.create(origin); | ||
const b = Object.create(origin); | ||
b.a = 2; | ||
a.a = 1; | ||
delete a.a; | ||
expect(b.a).toEqual(2); | ||
}); | ||
test('ownKeys', () => { | ||
const origin = isolateObject({}); | ||
const a = Object.create(origin); | ||
const b = Object.create(origin); | ||
a.a = 1; | ||
expect(Object.keys(a)).toEqual(['a']); | ||
expect(Object.keys(b)).toEqual([]); | ||
}); | ||
test('hasOwnProperty', () => { | ||
const origin = isolateObject({}); | ||
const a = Object.create(origin); | ||
const b = Object.create(origin); | ||
a.a = 1; | ||
expect(a.hasOwnProperty('a')).toEqual(true); | ||
expect(b.hasOwnProperty('a')).toEqual(false); | ||
}); | ||
test('getOwnPropertyDescriptor', () => { | ||
const origin = isolateObject({}); | ||
const a = Object.create(origin); | ||
const b = Object.create(origin); | ||
a.a = 1; | ||
const desc = Object.getOwnPropertyDescriptor(a, 'a'); | ||
expect(desc?.value).toEqual(1); | ||
expect(Object.getOwnPropertyDescriptor(b, 'a')).toEqual(undefined); | ||
}); | ||
}); | ||
}); |