Skip to content

Commit

Permalink
fix(gatsby): fix proxy creation on read-only properties (#31346) (#31364
Browse files Browse the repository at this point in the history
)

(cherry picked from commit c210f1d)

Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
  • Loading branch information
GatsbyJS Bot and pieh committed May 11, 2021
1 parent 4eca6cc commit 63942db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
@@ -0,0 +1,7 @@
const fs = require(`../fs`)

describe(`tracking fs`, () => {
it(`doesn't crash on accessing fs.constants`, () => {
expect(() => fs.constants).not.toThrow()
})
})
Expand Up @@ -11,6 +11,18 @@ function createProxyHandler(prefix, options) {
return value
}

const fieldDescriptor = Object.getOwnPropertyDescriptor(target, key)
if (fieldDescriptor && !fieldDescriptor.writable) {
// this is to prevent errors like:
// ```
// TypeError: 'get' on proxy: property 'constants' is a read - only and
// non - configurable data property on the proxy target but the proxy
// did not return its actual value
// (expected '[object Object]' but got '[object Object]')
// ```
return value
}

if (typeof value === `function`) {
return function wrapper(...args) {
const myErrorHolder = {
Expand Down

0 comments on commit 63942db

Please sign in to comment.