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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

evade override mistake #6264

Open
turadg opened this issue Feb 27, 2024 · 0 comments 路 May be fixed by #6265
Open

evade override mistake #6264

turadg opened this issue Feb 27, 2024 · 0 comments 路 May be fixed by #6265

Comments

@turadg
Copy link

turadg commented Feb 27, 2024

Hi! 馃憢

Firstly, thanks for your work on this project! 馃檪

Today I used patch-package to patch axios@1.6.7 for the project I'm working on.

The original code used assignment to override the constructor property. However, if the prototype is frozen, as it is under Hardened JS (aka SES) or under the Node frozen intrinsics flag, then this assignment fails due to the JavaScript override mistake.

Here is the diff that solved my problem:

diff --git a/node_modules/axios/dist/node/axios.cjs b/node_modules/axios/dist/node/axios.cjs
index 9099d87..7104f6e 100644
--- a/node_modules/axios/dist/node/axios.cjs
+++ b/node_modules/axios/dist/node/axios.cjs
@@ -370,9 +370,9 @@ function merge(/* obj1, obj2, obj3, ... */) {
 const extend = (a, b, thisArg, {allOwnKeys}= {}) => {
   forEach(b, (val, key) => {
     if (thisArg && isFunction(val)) {
-      a[key] = bind(val, thisArg);
+      Object.defineProperty(a, key, {value: bind(val, thisArg)});
     } else {
-      a[key] = val;
+      Object.defineProperty(a, key, {value: val});
     }
   }, {allOwnKeys});
   return a;
@@ -403,7 +403,9 @@ const stripBOM = (content) => {
  */
 const inherits = (constructor, superConstructor, props, descriptors) => {
   constructor.prototype = Object.create(superConstructor.prototype, descriptors);
-  constructor.prototype.constructor = constructor;
+  Object.defineProperty(constructor, 'constructor', {
+    value: constructor
+  });
   Object.defineProperty(constructor, 'super', {
     value: superConstructor.prototype
   });
@@ -565,12 +567,14 @@ const isRegExp = kindOfTest('RegExp');
 
 const reduceDescriptors = (obj, reducer) => {
   const descriptors = Object.getOwnPropertyDescriptors(obj);
-  const reducedDescriptors = {};
+  let reducedDescriptors = {};
 
   forEach(descriptors, (descriptor, name) => {
     let ret;
     if ((ret = reducer(descriptor, name, obj)) !== false) {
-      reducedDescriptors[name] = ret || descriptor;
+      reducedDescriptors = {...reducedDescriptors, 
+        [name]: ret || descriptor
+      };
     }
   });
 

This issue body was partially generated by patch-package.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant