Skip to content

Commit

Permalink
cherry-pick
Browse files Browse the repository at this point in the history
  • Loading branch information
tjzel committed Jun 19, 2024
1 parent 3188d92 commit 54495af
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
27 changes: 23 additions & 4 deletions app/src/examples/ShareableFreezingExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ export default function FreezingShareables() {
onPress={tryModifyConvertedInt32Array}
/>
</View>
<View style={styles.textAndButton}>
<Text style={styles.text}>🤫</Text>
<Button
title="Modify unconfigurable object"
onPress={tryModifyUnconfigurableObject}
/>
</View>
</View>
);
}
Expand All @@ -92,7 +99,7 @@ function tryModifyConvertedHostObject() {
return;
}
makeShareableCloneRecursive(obj);
// @ts-expect-error
// @ts-expect-error It's ok
obj.prop = 2; // shouldn't warn because it's not frozen
}

Expand All @@ -107,21 +114,22 @@ function tryModifyConvertedPlainObject() {
function tryModifyConvertedRegExpLiteral() {
const obj = /a/;
makeShareableCloneRecursive(obj);
// @ts-expect-error
// @ts-expect-error It's ok
obj.prop = 2; // shouldn't warn because it's not frozen
}

function tryModifyConvertedRegExpInstance() {
// eslint-disable-next-line prefer-regex-literals
const obj = new RegExp('a');
makeShareableCloneRecursive(obj);
// @ts-expect-error
// @ts-expect-error It's ok
obj.prop = 2; // shouldn't warn because it's not frozen
}

function tryModifyConvertedArrayBuffer() {
const obj = new ArrayBuffer(8);
makeShareableCloneRecursive(obj);
// @ts-expect-error
// @ts-expect-error It's ok
obj.prop = 2; // shouldn't warn because it's not frozen
}

Expand All @@ -131,6 +139,17 @@ function tryModifyConvertedInt32Array() {
obj[1] = 2; // shouldn't warn because it's not frozen
}

function tryModifyUnconfigurableObject() {
const obj = {};
Object.defineProperty(obj, 'prop', {
value: 1,
writable: false,
enumerable: true,
configurable: false,
});
makeShareableCloneRecursive(obj);
}

const styles = StyleSheet.create({
container: {
flex: 1,
Expand Down
4 changes: 4 additions & 0 deletions src/reanimated2/shareables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ function freezeObjectIfDev<T extends object>(value: T) {
return;
}
Object.entries(value).forEach(([key, element]) => {
const descriptor = Object.getOwnPropertyDescriptor(value, key)!;
if (!descriptor.configurable) {
return;
}
Object.defineProperty(value, key, {
get() {
return element;
Expand Down

0 comments on commit 54495af

Please sign in to comment.