Skip to content

Commit

Permalink
fix mp sdk defineProperty without descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
qkang07 committed Dec 4, 2024
1 parent a841840 commit dc9ebfc
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export default class MPWeixinRequestProxy extends MPNetworkProxyBase {
const mp = getMPSDK();
Object.defineProperty(mp, 'request', {
value: this.request,
configurable: true,
writable: true,
enumerable: true,
});
}
}
Expand Down Expand Up @@ -165,6 +168,9 @@ export default class MPWeixinRequestProxy extends MPNetworkProxyBase {
psLog.warn('The request object is not found on request event');
return null;
},
configurable: true,
writable: true,
enumerable: true,
});
}
}
15 changes: 15 additions & 0 deletions packages/page-spy-mp-base/src/plugins/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import socketStore from '../helpers/socket';
import { getMPSDK, utilAPI } from '../utils';
import type { MPStorageAPI } from '../types';

const descriptor = {
configurable: true,
writable: true,
enumerable: true,
};

export function mpDataStringify(data: any) {
const typeOfValue = typeof data;
let vStr: string = data;
Expand Down Expand Up @@ -57,6 +63,7 @@ export default class StoragePlugin implements PageSpyPlugin {
Object.entries(StoragePlugin.originFunctions).forEach(([key, fn]) => {
Object.defineProperty(mp, key, {
value: fn,
...descriptor,
});
});
StoragePlugin.hasInitd = false;
Expand Down Expand Up @@ -129,6 +136,7 @@ export default class StoragePlugin implements PageSpyPlugin {
},
});
},
...descriptor,
},
setStorageSync: {
value(keyOrObj: string | { key: string; data: any }, data: any) {
Expand Down Expand Up @@ -156,6 +164,7 @@ export default class StoragePlugin implements PageSpyPlugin {
throw e;
}
},
...descriptor,
},

removeStorage: {
Expand All @@ -168,6 +177,7 @@ export default class StoragePlugin implements PageSpyPlugin {
},
});
},
...descriptor,
},

removeStorageSync: {
Expand All @@ -185,6 +195,7 @@ export default class StoragePlugin implements PageSpyPlugin {
throw e;
}
},
...descriptor,
},

clearStorage: {
Expand All @@ -197,6 +208,7 @@ export default class StoragePlugin implements PageSpyPlugin {
},
});
},
...descriptor,
},

clearStorageSync: {
Expand All @@ -211,6 +223,7 @@ export default class StoragePlugin implements PageSpyPlugin {
throw e;
}
},
...descriptor,
},
});

Expand All @@ -235,6 +248,7 @@ export default class StoragePlugin implements PageSpyPlugin {
throw e;
}
},
...descriptor,
});
}
if (mp.canIUse('batchSetStorage')) {
Expand All @@ -250,6 +264,7 @@ export default class StoragePlugin implements PageSpyPlugin {
},
});
},
...descriptor,
});
}
}
Expand Down
14 changes: 14 additions & 0 deletions packages/page-spy-plugin-rn-async-storage/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ import type {
MultiCallback,
} from '@react-native-async-storage/async-storage/lib/typescript/types';

const descriptor = {
configurable: true,
writable: true,
enumerable: true,
};

export default class RNAsyncStoragePlugin implements PageSpyPlugin {
public name = 'RNAsyncStoragePlugin';

Expand Down Expand Up @@ -39,6 +45,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin {
([key, fn]) => {
Object.defineProperty(AsyncStorage, key, {
value: fn,
...descriptor,
});
},
);
Expand Down Expand Up @@ -108,6 +115,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin {
that.sendSetItem(key, value);
});
},
...descriptor,
},
mergeItem: {
value(key: string, value: string, callback?: Callback) {
Expand All @@ -126,6 +134,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin {
return res;
});
},
...descriptor,
},

multiSet: {
Expand All @@ -139,6 +148,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin {
});
});
},
...descriptor,
},
multiMerge: {
value(kvPairs: [string, string][], callback?: MultiCallback) {
Expand All @@ -158,6 +168,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin {
});
});
},
...descriptor,
},

removeItem: {
Expand All @@ -169,6 +180,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin {
that.sendRemoveItem(key);
});
},
...descriptor,
},

multiRemove: {
Expand All @@ -182,6 +194,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin {
});
});
},
...descriptor,
},

clear: {
Expand All @@ -192,6 +205,7 @@ export default class RNAsyncStoragePlugin implements PageSpyPlugin {
},
);
},
...descriptor,
},
});
}
Expand Down

0 comments on commit dc9ebfc

Please sign in to comment.