react-native-reanimated 3.12.0 → 3.12.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module/reanimated2/platform-specific/jsVersion.js +1 -1
- package/lib/module/reanimated2/platform-specific/jsVersion.js.map +1 -1
- package/lib/module/reanimated2/shareables.js +4 -0
- package/lib/module/reanimated2/shareables.js.map +1 -1
- package/lib/typescript/reanimated2/platform-specific/jsVersion.d.ts +1 -1
- package/package.json +1 -1
- package/src/reanimated2/platform-specific/jsVersion.ts +1 -1
- package/src/reanimated2/shareables.ts +4 -0
|
@@ -5,5 +5,5 @@
|
|
|
5
5
|
* with the version used to build the native part of the library in runtime.
|
|
6
6
|
* Remember to keep this in sync with the version declared in `package.json`
|
|
7
7
|
*/
|
|
8
|
-
export const jsVersion = '3.12.
|
|
8
|
+
export const jsVersion = '3.12.1';
|
|
9
9
|
//# sourceMappingURL=jsVersion.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["jsVersion"],"sources":["jsVersion.ts"],"sourcesContent":["'use strict';\n/**\n * We hardcode the version of Reanimated here in order to compare it\n * with the version used to build the native part of the library in runtime.\n * Remember to keep this in sync with the version declared in `package.json`\n */\nexport const jsVersion = '3.12.
|
|
1
|
+
{"version":3,"names":["jsVersion"],"sources":["jsVersion.ts"],"sourcesContent":["'use strict';\n/**\n * We hardcode the version of Reanimated here in order to compare it\n * with the version used to build the native part of the library in runtime.\n * Remember to keep this in sync with the version declared in `package.json`\n */\nexport const jsVersion = '3.12.1';\n"],"mappings":"AAAA,YAAY;;AACZ;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMA,SAAS,GAAG,QAAQ","ignoreList":[]}
|
|
@@ -249,6 +249,10 @@ function freezeObjectIfDev(value) {
|
|
|
249
249
|
return;
|
|
250
250
|
}
|
|
251
251
|
Object.entries(value).forEach(([key, element]) => {
|
|
252
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key);
|
|
253
|
+
if (!descriptor.configurable) {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
252
256
|
Object.defineProperty(value, key, {
|
|
253
257
|
get() {
|
|
254
258
|
return element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["NativeReanimatedModule","isWorkletFunction","shouldBeUseWeb","registerWorkletStackDetails","jsVersion","shareableMappingCache","shareableMappingFlag","SHOULD_BE_USE_WEB","MAGIC_KEY","isHostObject","value","isPlainJSObject","object","Object","getPrototypeOf","prototype","INACCESSIBLE_OBJECT","__init","Proxy","get","_","prop","Error","String","set","VALID_ARRAY_VIEWS_NAMES","DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD","processedObjectAtThresholdDepth","makeShareableCloneRecursive","shouldPersistRemote","depth","undefined","type","isTypeObject","isTypeFunction","cached","toAdapt","Array","isArray","map","element","freezeObjectIfDev","__DEV__","babelVersion","__initData","version","getWorkletCode","__workletHash","__stackDetails","key","entries","RegExp","pattern","source","flags","handle","name","message","stack","error","ArrayBuffer","isView","buffer","typeName","constructor","includes","global","inaccessibleObject","adapted","makeShareableClone","WORKLET_CODE_THRESHOLD","_value$__initData","code","length","substring","isRemoteFunction","__remoteFunction","forEach","defineProperty","console","warn","preventExtensions","makeShareableCloneOnUIRecursive","cloneRecursive","_makeShareableClone","makeShareableJS","makeShareableNative","makeShareable"],"sources":["shareables.ts"],"sourcesContent":["'use strict';\nimport NativeReanimatedModule from './NativeReanimated';\nimport { isWorkletFunction } from './commonTypes';\nimport type {\n ShareableRef,\n FlatShareableRef,\n WorkletFunction,\n} from './commonTypes';\nimport { shouldBeUseWeb } from './PlatformChecker';\nimport { registerWorkletStackDetails } from './errors';\nimport { jsVersion } from './platform-specific/jsVersion';\nimport {\n shareableMappingCache,\n shareableMappingFlag,\n} from './shareableMappingCache';\n\n// for web/chrome debugger/jest environments this file provides a stub implementation\n// where no shareable references are used. Instead, the objects themselves are used\n// instead of shareable references, because of the fact that we don't have to deal with\n// runnning the code on separate VMs.\nconst SHOULD_BE_USE_WEB = shouldBeUseWeb();\n\nconst MAGIC_KEY = 'REANIMATED_MAGIC_KEY';\n\nfunction isHostObject(value: NonNullable<object>) {\n 'worklet';\n // We could use JSI to determine whether an object is a host object, however\n // the below workaround works well and is way faster than an additional JSI call.\n // We use the fact that host objects have broken implementation of `hasOwnProperty`\n // and hence return true for all `in` checks regardless of the key we ask for.\n return MAGIC_KEY in value;\n}\n\nfunction isPlainJSObject(object: object) {\n return Object.getPrototypeOf(object) === Object.prototype;\n}\n\n// The below object is used as a replacement for objects that cannot be transferred\n// as shareable values. In makeShareableCloneRecursive we detect if an object is of\n// a plain Object.prototype and only allow such objects to be transferred. This lets\n// us avoid all sorts of react internals from leaking into the UI runtime. To make it\n// possible to catch errors when someone actually tries to access such object on the UI\n// runtime, we use the below Proxy object which is instantiated on the UI runtime and\n// throws whenever someone tries to access its fields.\nconst INACCESSIBLE_OBJECT = {\n __init: () => {\n 'worklet';\n return new Proxy(\n {},\n {\n get: (_: unknown, prop: string | symbol) => {\n if (\n prop === '_isReanimatedSharedValue' ||\n prop === '__remoteFunction'\n ) {\n // not very happy about this check here, but we need to allow for\n // \"inaccessible\" objects to be tested with isSharedValue check\n // as it is being used in the mappers when extracting inputs recursively\n // as well as with isRemoteFunction when cloning objects recursively.\n // Apparently we can't check if a key exists there as HostObjects always\n // return true for such tests, so the only possibility for us is to\n // actually access that key and see if it is set to true. We therefore\n // need to allow for this key to be accessed here.\n return false;\n }\n throw new Error(\n `[Reanimated] Trying to access property \\`${String(\n prop\n )}\\` of an object which cannot be sent to the UI runtime.`\n );\n },\n set: () => {\n throw new Error(\n '[Reanimated] Trying to write to an object which cannot be sent to the UI runtime.'\n );\n },\n }\n );\n },\n};\n\nconst VALID_ARRAY_VIEWS_NAMES = [\n 'Int8Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Int16Array',\n 'Uint16Array',\n 'Int32Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'BigInt64Array',\n 'BigUint64Array',\n 'DataView',\n];\n\nconst DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;\n// Below variable stores object that we process in makeShareableCloneRecursive at the specified depth.\n// We use it to check if later on the function reenters with the same object\nlet processedObjectAtThresholdDepth: unknown;\n\nexport function makeShareableCloneRecursive<T>(\n value: any,\n shouldPersistRemote = false,\n depth = 0\n): ShareableRef<T> {\n if (SHOULD_BE_USE_WEB) {\n return value;\n }\n if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {\n // if we reach certain recursion depth we suspect that we are dealing with a cyclic object.\n // this type of objects are not supported and cannot be trasferred as shareable, so we\n // implement a simple detection mechanism that remembers the value at a given depth and\n // tests whether we try reenter this method later on with the same value. If that happens\n // we throw an appropriate error.\n if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {\n processedObjectAtThresholdDepth = value;\n } else if (value === processedObjectAtThresholdDepth) {\n throw new Error(\n '[Reanimated] Trying to convert a cyclic object to a shareable. This is not supported.'\n );\n }\n } else {\n processedObjectAtThresholdDepth = undefined;\n }\n // This one actually may be worth to be moved to c++, we also need similar logic to run on the UI thread\n const type = typeof value;\n const isTypeObject = type === 'object';\n const isTypeFunction = type === 'function';\n if ((isTypeObject || isTypeFunction) && value !== null) {\n const cached = shareableMappingCache.get(value);\n if (cached === shareableMappingFlag) {\n return value;\n } else if (cached !== undefined) {\n return cached as ShareableRef<T>;\n } else {\n let toAdapt: any;\n if (Array.isArray(value)) {\n toAdapt = value.map((element) =>\n makeShareableCloneRecursive(element, shouldPersistRemote, depth + 1)\n );\n freezeObjectIfDev(value);\n } else if (isTypeFunction && !isWorkletFunction(value)) {\n // this is a remote function\n toAdapt = value;\n freezeObjectIfDev(value);\n } else if (isHostObject(value)) {\n // for host objects we pass the reference to the object as shareable and\n // then recreate new host object wrapping the same instance on the UI thread.\n // there is no point of iterating over keys as we do for regular objects.\n toAdapt = value;\n } else if (isPlainJSObject(value) || isTypeFunction) {\n toAdapt = {};\n if (isWorkletFunction(value)) {\n if (__DEV__) {\n const babelVersion = value.__initData.version;\n if (babelVersion !== undefined && babelVersion !== jsVersion) {\n throw new Error(`[Reanimated] Mismatch between JavaScript code version and Reanimated Babel plugin version (${jsVersion} vs. ${babelVersion}). \nSee \\`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-reanimated-babel-plugin-version\\` for more details.\nOffending code was: \\`${getWorkletCode(value)}\\``);\n }\n registerWorkletStackDetails(\n value.__workletHash,\n value.__stackDetails!\n );\n }\n if (value.__stackDetails) {\n // `Error` type of value cannot be copied to the UI thread, so we\n // remove it after we handled it in dev mode or delete it to ignore it in production mode.\n // Not removing this would cause an infinite loop in production mode and it just\n // seems more elegant to handle it this way.\n delete value.__stackDetails;\n }\n // to save on transferring static __initData field of worklet structure\n // we request shareable value to persist its UI counterpart. This means\n // that the __initData field that contains long strings represeting the\n // worklet code, source map, and location, will always be\n // serialized/deserialized once.\n toAdapt.__initData = makeShareableCloneRecursive(\n value.__initData,\n true,\n depth + 1\n );\n }\n\n for (const [key, element] of Object.entries(value)) {\n if (key === '__initData' && toAdapt.__initData !== undefined) {\n continue;\n }\n toAdapt[key] = makeShareableCloneRecursive(\n element,\n shouldPersistRemote,\n depth + 1\n );\n }\n freezeObjectIfDev(value);\n } else if (value instanceof RegExp) {\n const pattern = value.source;\n const flags = value.flags;\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return new RegExp(pattern, flags);\n },\n });\n shareableMappingCache.set(value, handle);\n return handle as ShareableRef<T>;\n } else if (value instanceof Error) {\n const { name, message, stack } = value;\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n const error = new Error();\n error.name = name;\n error.message = message;\n error.stack = stack;\n return error;\n },\n });\n shareableMappingCache.set(value, handle);\n return handle as ShareableRef<T>;\n } else if (value instanceof ArrayBuffer) {\n toAdapt = value;\n } else if (ArrayBuffer.isView(value)) {\n // typed array (e.g. Int32Array, Uint8ClampedArray) or DataView\n const buffer = value.buffer;\n const typeName = value.constructor.name;\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n if (!VALID_ARRAY_VIEWS_NAMES.includes(typeName)) {\n throw new Error(\n `[Reanimated] Invalid array view name \\`${typeName}\\`.`\n );\n }\n const constructor = global[typeName as keyof typeof global];\n if (constructor === undefined) {\n throw new Error(\n `[Reanimated] Constructor for \\`${typeName}\\` not found.`\n );\n }\n return new constructor(buffer);\n },\n });\n shareableMappingCache.set(value, handle);\n return handle as ShareableRef<T>;\n } else {\n // This is reached for object types that are not of plain Object.prototype.\n // We don't support such objects from being transferred as shareables to\n // the UI runtime and hence we replace them with \"inaccessible object\"\n // which is implemented as a Proxy object that throws on any attempt\n // of accessing its fields. We argue that such objects can sometimes leak\n // as attributes of objects being captured by worklets but should never\n // be used on the UI runtime regardless. If they are being accessed, the user\n // will get an appropriate error message.\n const inaccessibleObject =\n makeShareableCloneRecursive<T>(INACCESSIBLE_OBJECT);\n shareableMappingCache.set(value, inaccessibleObject);\n return inaccessibleObject;\n }\n const adapted = NativeReanimatedModule.makeShareableClone(\n toAdapt,\n shouldPersistRemote,\n value\n );\n shareableMappingCache.set(value, adapted);\n shareableMappingCache.set(adapted);\n return adapted;\n }\n }\n return NativeReanimatedModule.makeShareableClone(\n value,\n shouldPersistRemote,\n undefined\n );\n}\n\nconst WORKLET_CODE_THRESHOLD = 255;\n\nfunction getWorkletCode(value: WorkletFunction) {\n // @ts-ignore this is fine\n const code = value?.__initData?.code;\n if (!code) {\n return 'unknown';\n }\n if (code.length > WORKLET_CODE_THRESHOLD) {\n return `${code.substring(0, WORKLET_CODE_THRESHOLD)}...`;\n }\n return code;\n}\n\ntype RemoteFunction<T> = {\n __remoteFunction: FlatShareableRef<T>;\n};\n\nfunction isRemoteFunction<T>(value: {\n __remoteFunction?: unknown;\n}): value is RemoteFunction<T> {\n 'worklet';\n return !!value.__remoteFunction;\n}\n\n/**\n * We freeze\n * - arrays,\n * - remote functions,\n * - plain JS objects,\n *\n * that are transformed to a shareable with a meaningful warning.\n * This should help detect issues when someone modifies data after it's been converted.\n * Meaning that they may be doing a faulty assumption in their\n * code expecting that the updates are going to automatically propagate to\n * the object sent to the UI thread. If the user really wants some objects\n * to be mutable they should use shared values instead.\n */\nfunction freezeObjectIfDev<T extends object>(value: T) {\n if (!__DEV__) {\n return;\n }\n Object.entries(value).forEach(([key, element]) => {\n Object.defineProperty(value, key, {\n get() {\n return element;\n },\n set() {\n console.warn(\n `[Reanimated] Tried to modify key \\`${key}\\` of an object which has been already passed to a worklet. See \nhttps://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-modify-key-of-an-object-which-has-been-converted-to-a-shareable \nfor more details.`\n );\n },\n });\n });\n Object.preventExtensions(value);\n}\n\nexport function makeShareableCloneOnUIRecursive<T>(\n value: T\n): FlatShareableRef<T> {\n 'worklet';\n if (SHOULD_BE_USE_WEB) {\n // @ts-ignore web is an interesting place where we don't run a secondary VM on the UI thread\n // see more details in the comment where USE_STUB_IMPLEMENTATION is defined.\n return value;\n }\n // eslint-disable-next-line @typescript-eslint/no-shadow\n function cloneRecursive(value: T): FlatShareableRef<T> {\n if (\n (typeof value === 'object' && value !== null) ||\n typeof value === 'function'\n ) {\n if (isHostObject(value)) {\n // We call `_makeShareableClone` to wrap the provided HostObject\n // inside ShareableJSRef.\n return global._makeShareableClone(\n value,\n undefined\n ) as FlatShareableRef<T>;\n }\n if (isRemoteFunction<T>(value)) {\n // RemoteFunctions are created by us therefore they are\n // a Shareable out of the box and there is no need to\n // call `_makeShareableClone`.\n return value.__remoteFunction;\n }\n if (Array.isArray(value)) {\n return global._makeShareableClone(\n value.map(cloneRecursive),\n undefined\n ) as FlatShareableRef<T>;\n }\n const toAdapt: Record<string, FlatShareableRef<T>> = {};\n for (const [key, element] of Object.entries(value)) {\n toAdapt[key] = cloneRecursive(element);\n }\n return global._makeShareableClone(toAdapt, value) as FlatShareableRef<T>;\n }\n return global._makeShareableClone(value, undefined);\n }\n return cloneRecursive(value);\n}\n\nfunction makeShareableJS<T extends object>(value: T): T {\n return value;\n}\n\nfunction makeShareableNative<T extends object>(value: T): T {\n if (shareableMappingCache.get(value)) {\n return value;\n }\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return value;\n },\n });\n shareableMappingCache.set(value, handle);\n return value;\n}\n\n/**\n * This function creates a value on UI with persistent state - changes to it on the UI\n * thread will be seen by all worklets. Use it when you want to create a value\n * that is read and written only on the UI thread.\n */\nexport const makeShareable = SHOULD_BE_USE_WEB\n ? makeShareableJS\n : makeShareableNative;\n"],"mappings":"AAAA,YAAY;;AACZ,OAAOA,sBAAsB,MAAM,oBAAoB;AACvD,SAASC,iBAAiB,QAAQ,eAAe;AAMjD,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,2BAA2B,QAAQ,UAAU;AACtD,SAASC,SAAS,QAAQ,+BAA+B;AACzD,SACEC,qBAAqB,EACrBC,oBAAoB,QACf,yBAAyB;;AAEhC;AACA;AACA;AACA;AACA,MAAMC,iBAAiB,GAAGL,cAAc,CAAC,CAAC;AAE1C,MAAMM,SAAS,GAAG,sBAAsB;AAExC,SAASC,YAAYA,CAACC,KAA0B,EAAE;EAChD,SAAS;;EACT;EACA;EACA;EACA;EACA,OAAOF,SAAS,IAAIE,KAAK;AAC3B;AAEA,SAASC,eAAeA,CAACC,MAAc,EAAE;EACvC,OAAOC,MAAM,CAACC,cAAc,CAACF,MAAM,CAAC,KAAKC,MAAM,CAACE,SAAS;AAC3D;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAG;EAC1BC,MAAM,EAAEA,CAAA,KAAM;IACZ,SAAS;;IACT,OAAO,IAAIC,KAAK,CACd,CAAC,CAAC,EACF;MACEC,GAAG,EAAEA,CAACC,CAAU,EAAEC,IAAqB,KAAK;QAC1C,IACEA,IAAI,KAAK,0BAA0B,IACnCA,IAAI,KAAK,kBAAk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AAK,CAAC;AAC9B;AAEA,SAAS2E,eAAeA,CAAmB3E,KAAQ,EAAK;EACtD,OAAOA,KAAK;AACd;AAEA,SAAS4E,mBAAmBA,CAAmB5E,KAAQ,EAAK;EAC1D,IAAIL,qBAAqB,CAACc,GAAG,CAACT,KAAK,CAAC,EAAE;IACpC,OAAOA,KAAK;EACd;EACA,MAAM6C,MAAM,GAAG3B,2BAA2B,CAAC;IACzCX,MAAM,EAAEA,CAAA,KAAM;MACZ,SAAS;;MACT,OAAOP,KAAK;IACd;EACF,CAAC,CAAC;EACFL,qBAAqB,CAACmB,GAAG,CAACd,KAAK,EAAE6C,MAAM,CAAC;EACxC,OAAO7C,KAAK;AACd;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAM6E,aAAa,GAAGhF,iBAAiB,GAC1C8E,eAAe,GACfC,mBAAmB","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["NativeReanimatedModule","isWorkletFunction","shouldBeUseWeb","registerWorkletStackDetails","jsVersion","shareableMappingCache","shareableMappingFlag","SHOULD_BE_USE_WEB","MAGIC_KEY","isHostObject","value","isPlainJSObject","object","Object","getPrototypeOf","prototype","INACCESSIBLE_OBJECT","__init","Proxy","get","_","prop","Error","String","set","VALID_ARRAY_VIEWS_NAMES","DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD","processedObjectAtThresholdDepth","makeShareableCloneRecursive","shouldPersistRemote","depth","undefined","type","isTypeObject","isTypeFunction","cached","toAdapt","Array","isArray","map","element","freezeObjectIfDev","__DEV__","babelVersion","__initData","version","getWorkletCode","__workletHash","__stackDetails","key","entries","RegExp","pattern","source","flags","handle","name","message","stack","error","ArrayBuffer","isView","buffer","typeName","constructor","includes","global","inaccessibleObject","adapted","makeShareableClone","WORKLET_CODE_THRESHOLD","_value$__initData","code","length","substring","isRemoteFunction","__remoteFunction","forEach","descriptor","getOwnPropertyDescriptor","configurable","defineProperty","console","warn","preventExtensions","makeShareableCloneOnUIRecursive","cloneRecursive","_makeShareableClone","makeShareableJS","makeShareableNative","makeShareable"],"sources":["shareables.ts"],"sourcesContent":["'use strict';\nimport NativeReanimatedModule from './NativeReanimated';\nimport { isWorkletFunction } from './commonTypes';\nimport type {\n ShareableRef,\n FlatShareableRef,\n WorkletFunction,\n} from './commonTypes';\nimport { shouldBeUseWeb } from './PlatformChecker';\nimport { registerWorkletStackDetails } from './errors';\nimport { jsVersion } from './platform-specific/jsVersion';\nimport {\n shareableMappingCache,\n shareableMappingFlag,\n} from './shareableMappingCache';\n\n// for web/chrome debugger/jest environments this file provides a stub implementation\n// where no shareable references are used. Instead, the objects themselves are used\n// instead of shareable references, because of the fact that we don't have to deal with\n// runnning the code on separate VMs.\nconst SHOULD_BE_USE_WEB = shouldBeUseWeb();\n\nconst MAGIC_KEY = 'REANIMATED_MAGIC_KEY';\n\nfunction isHostObject(value: NonNullable<object>) {\n 'worklet';\n // We could use JSI to determine whether an object is a host object, however\n // the below workaround works well and is way faster than an additional JSI call.\n // We use the fact that host objects have broken implementation of `hasOwnProperty`\n // and hence return true for all `in` checks regardless of the key we ask for.\n return MAGIC_KEY in value;\n}\n\nfunction isPlainJSObject(object: object) {\n return Object.getPrototypeOf(object) === Object.prototype;\n}\n\n// The below object is used as a replacement for objects that cannot be transferred\n// as shareable values. In makeShareableCloneRecursive we detect if an object is of\n// a plain Object.prototype and only allow such objects to be transferred. This lets\n// us avoid all sorts of react internals from leaking into the UI runtime. To make it\n// possible to catch errors when someone actually tries to access such object on the UI\n// runtime, we use the below Proxy object which is instantiated on the UI runtime and\n// throws whenever someone tries to access its fields.\nconst INACCESSIBLE_OBJECT = {\n __init: () => {\n 'worklet';\n return new Proxy(\n {},\n {\n get: (_: unknown, prop: string | symbol) => {\n if (\n prop === '_isReanimatedSharedValue' ||\n prop === '__remoteFunction'\n ) {\n // not very happy about this check here, but we need to allow for\n // \"inaccessible\" objects to be tested with isSharedValue check\n // as it is being used in the mappers when extracting inputs recursively\n // as well as with isRemoteFunction when cloning objects recursively.\n // Apparently we can't check if a key exists there as HostObjects always\n // return true for such tests, so the only possibility for us is to\n // actually access that key and see if it is set to true. We therefore\n // need to allow for this key to be accessed here.\n return false;\n }\n throw new Error(\n `[Reanimated] Trying to access property \\`${String(\n prop\n )}\\` of an object which cannot be sent to the UI runtime.`\n );\n },\n set: () => {\n throw new Error(\n '[Reanimated] Trying to write to an object which cannot be sent to the UI runtime.'\n );\n },\n }\n );\n },\n};\n\nconst VALID_ARRAY_VIEWS_NAMES = [\n 'Int8Array',\n 'Uint8Array',\n 'Uint8ClampedArray',\n 'Int16Array',\n 'Uint16Array',\n 'Int32Array',\n 'Uint32Array',\n 'Float32Array',\n 'Float64Array',\n 'BigInt64Array',\n 'BigUint64Array',\n 'DataView',\n];\n\nconst DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD = 30;\n// Below variable stores object that we process in makeShareableCloneRecursive at the specified depth.\n// We use it to check if later on the function reenters with the same object\nlet processedObjectAtThresholdDepth: unknown;\n\nexport function makeShareableCloneRecursive<T>(\n value: any,\n shouldPersistRemote = false,\n depth = 0\n): ShareableRef<T> {\n if (SHOULD_BE_USE_WEB) {\n return value;\n }\n if (depth >= DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {\n // if we reach certain recursion depth we suspect that we are dealing with a cyclic object.\n // this type of objects are not supported and cannot be trasferred as shareable, so we\n // implement a simple detection mechanism that remembers the value at a given depth and\n // tests whether we try reenter this method later on with the same value. If that happens\n // we throw an appropriate error.\n if (depth === DETECT_CYCLIC_OBJECT_DEPTH_THRESHOLD) {\n processedObjectAtThresholdDepth = value;\n } else if (value === processedObjectAtThresholdDepth) {\n throw new Error(\n '[Reanimated] Trying to convert a cyclic object to a shareable. This is not supported.'\n );\n }\n } else {\n processedObjectAtThresholdDepth = undefined;\n }\n // This one actually may be worth to be moved to c++, we also need similar logic to run on the UI thread\n const type = typeof value;\n const isTypeObject = type === 'object';\n const isTypeFunction = type === 'function';\n if ((isTypeObject || isTypeFunction) && value !== null) {\n const cached = shareableMappingCache.get(value);\n if (cached === shareableMappingFlag) {\n return value;\n } else if (cached !== undefined) {\n return cached as ShareableRef<T>;\n } else {\n let toAdapt: any;\n if (Array.isArray(value)) {\n toAdapt = value.map((element) =>\n makeShareableCloneRecursive(element, shouldPersistRemote, depth + 1)\n );\n freezeObjectIfDev(value);\n } else if (isTypeFunction && !isWorkletFunction(value)) {\n // this is a remote function\n toAdapt = value;\n freezeObjectIfDev(value);\n } else if (isHostObject(value)) {\n // for host objects we pass the reference to the object as shareable and\n // then recreate new host object wrapping the same instance on the UI thread.\n // there is no point of iterating over keys as we do for regular objects.\n toAdapt = value;\n } else if (isPlainJSObject(value) || isTypeFunction) {\n toAdapt = {};\n if (isWorkletFunction(value)) {\n if (__DEV__) {\n const babelVersion = value.__initData.version;\n if (babelVersion !== undefined && babelVersion !== jsVersion) {\n throw new Error(`[Reanimated] Mismatch between JavaScript code version and Reanimated Babel plugin version (${jsVersion} vs. ${babelVersion}). \nSee \\`https://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#mismatch-between-javascript-code-version-and-reanimated-babel-plugin-version\\` for more details.\nOffending code was: \\`${getWorkletCode(value)}\\``);\n }\n registerWorkletStackDetails(\n value.__workletHash,\n value.__stackDetails!\n );\n }\n if (value.__stackDetails) {\n // `Error` type of value cannot be copied to the UI thread, so we\n // remove it after we handled it in dev mode or delete it to ignore it in production mode.\n // Not removing this would cause an infinite loop in production mode and it just\n // seems more elegant to handle it this way.\n delete value.__stackDetails;\n }\n // to save on transferring static __initData field of worklet structure\n // we request shareable value to persist its UI counterpart. This means\n // that the __initData field that contains long strings represeting the\n // worklet code, source map, and location, will always be\n // serialized/deserialized once.\n toAdapt.__initData = makeShareableCloneRecursive(\n value.__initData,\n true,\n depth + 1\n );\n }\n\n for (const [key, element] of Object.entries(value)) {\n if (key === '__initData' && toAdapt.__initData !== undefined) {\n continue;\n }\n toAdapt[key] = makeShareableCloneRecursive(\n element,\n shouldPersistRemote,\n depth + 1\n );\n }\n freezeObjectIfDev(value);\n } else if (value instanceof RegExp) {\n const pattern = value.source;\n const flags = value.flags;\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return new RegExp(pattern, flags);\n },\n });\n shareableMappingCache.set(value, handle);\n return handle as ShareableRef<T>;\n } else if (value instanceof Error) {\n const { name, message, stack } = value;\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n const error = new Error();\n error.name = name;\n error.message = message;\n error.stack = stack;\n return error;\n },\n });\n shareableMappingCache.set(value, handle);\n return handle as ShareableRef<T>;\n } else if (value instanceof ArrayBuffer) {\n toAdapt = value;\n } else if (ArrayBuffer.isView(value)) {\n // typed array (e.g. Int32Array, Uint8ClampedArray) or DataView\n const buffer = value.buffer;\n const typeName = value.constructor.name;\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n if (!VALID_ARRAY_VIEWS_NAMES.includes(typeName)) {\n throw new Error(\n `[Reanimated] Invalid array view name \\`${typeName}\\`.`\n );\n }\n const constructor = global[typeName as keyof typeof global];\n if (constructor === undefined) {\n throw new Error(\n `[Reanimated] Constructor for \\`${typeName}\\` not found.`\n );\n }\n return new constructor(buffer);\n },\n });\n shareableMappingCache.set(value, handle);\n return handle as ShareableRef<T>;\n } else {\n // This is reached for object types that are not of plain Object.prototype.\n // We don't support such objects from being transferred as shareables to\n // the UI runtime and hence we replace them with \"inaccessible object\"\n // which is implemented as a Proxy object that throws on any attempt\n // of accessing its fields. We argue that such objects can sometimes leak\n // as attributes of objects being captured by worklets but should never\n // be used on the UI runtime regardless. If they are being accessed, the user\n // will get an appropriate error message.\n const inaccessibleObject =\n makeShareableCloneRecursive<T>(INACCESSIBLE_OBJECT);\n shareableMappingCache.set(value, inaccessibleObject);\n return inaccessibleObject;\n }\n const adapted = NativeReanimatedModule.makeShareableClone(\n toAdapt,\n shouldPersistRemote,\n value\n );\n shareableMappingCache.set(value, adapted);\n shareableMappingCache.set(adapted);\n return adapted;\n }\n }\n return NativeReanimatedModule.makeShareableClone(\n value,\n shouldPersistRemote,\n undefined\n );\n}\n\nconst WORKLET_CODE_THRESHOLD = 255;\n\nfunction getWorkletCode(value: WorkletFunction) {\n // @ts-ignore this is fine\n const code = value?.__initData?.code;\n if (!code) {\n return 'unknown';\n }\n if (code.length > WORKLET_CODE_THRESHOLD) {\n return `${code.substring(0, WORKLET_CODE_THRESHOLD)}...`;\n }\n return code;\n}\n\ntype RemoteFunction<T> = {\n __remoteFunction: FlatShareableRef<T>;\n};\n\nfunction isRemoteFunction<T>(value: {\n __remoteFunction?: unknown;\n}): value is RemoteFunction<T> {\n 'worklet';\n return !!value.__remoteFunction;\n}\n\n/**\n * We freeze\n * - arrays,\n * - remote functions,\n * - plain JS objects,\n *\n * that are transformed to a shareable with a meaningful warning.\n * This should help detect issues when someone modifies data after it's been converted.\n * Meaning that they may be doing a faulty assumption in their\n * code expecting that the updates are going to automatically propagate to\n * the object sent to the UI thread. If the user really wants some objects\n * to be mutable they should use shared values instead.\n */\nfunction freezeObjectIfDev<T extends object>(value: T) {\n if (!__DEV__) {\n return;\n }\n Object.entries(value).forEach(([key, element]) => {\n const descriptor = Object.getOwnPropertyDescriptor(value, key)!;\n if (!descriptor.configurable) {\n return;\n }\n Object.defineProperty(value, key, {\n get() {\n return element;\n },\n set() {\n console.warn(\n `[Reanimated] Tried to modify key \\`${key}\\` of an object which has been already passed to a worklet. See \nhttps://docs.swmansion.com/react-native-reanimated/docs/guides/troubleshooting#tried-to-modify-key-of-an-object-which-has-been-converted-to-a-shareable \nfor more details.`\n );\n },\n });\n });\n Object.preventExtensions(value);\n}\n\nexport function makeShareableCloneOnUIRecursive<T>(\n value: T\n): FlatShareableRef<T> {\n 'worklet';\n if (SHOULD_BE_USE_WEB) {\n // @ts-ignore web is an interesting place where we don't run a secondary VM on the UI thread\n // see more details in the comment where USE_STUB_IMPLEMENTATION is defined.\n return value;\n }\n // eslint-disable-next-line @typescript-eslint/no-shadow\n function cloneRecursive(value: T): FlatShareableRef<T> {\n if (\n (typeof value === 'object' && value !== null) ||\n typeof value === 'function'\n ) {\n if (isHostObject(value)) {\n // We call `_makeShareableClone` to wrap the provided HostObject\n // inside ShareableJSRef.\n return global._makeShareableClone(\n value,\n undefined\n ) as FlatShareableRef<T>;\n }\n if (isRemoteFunction<T>(value)) {\n // RemoteFunctions are created by us therefore they are\n // a Shareable out of the box and there is no need to\n // call `_makeShareableClone`.\n return value.__remoteFunction;\n }\n if (Array.isArray(value)) {\n return global._makeShareableClone(\n value.map(cloneRecursive),\n undefined\n ) as FlatShareableRef<T>;\n }\n const toAdapt: Record<string, FlatShareableRef<T>> = {};\n for (const [key, element] of Object.entries(value)) {\n toAdapt[key] = cloneRecursive(element);\n }\n return global._makeShareableClone(toAdapt, value) as FlatShareableRef<T>;\n }\n return global._makeShareableClone(value, undefined);\n }\n return cloneRecursive(value);\n}\n\nfunction makeShareableJS<T extends object>(value: T): T {\n return value;\n}\n\nfunction makeShareableNative<T extends object>(value: T): T {\n if (shareableMappingCache.get(value)) {\n return value;\n }\n const handle = makeShareableCloneRecursive({\n __init: () => {\n 'worklet';\n return value;\n },\n });\n shareableMappingCache.set(value, handle);\n return value;\n}\n\n/**\n * This function creates a value on UI with persistent state - changes to it on the UI\n * thread will be seen by all worklets. Use it when you want to create a value\n * that is read and written only on the UI thread.\n */\nexport const makeShareable = SHOULD_BE_USE_WEB\n ? makeShareableJS\n : makeShareableNative;\n"],"mappings":"AAAA,YAAY;;AACZ,OAAOA,sBAAsB,MAAM,oBAAoB;AACvD,SAASC,iBAAiB,QAAQ,eAAe;AAMjD,SAASC,cAAc,QAAQ,mBAAmB;AAClD,SAASC,2BAA2B,QAAQ,UAAU;AACtD,SAASC,SAAS,QAAQ,+BAA+B;AACzD,SACEC,qBAAqB,EACrBC,oBAAoB,QACf,yBAAyB;;AAEhC;AACA;AACA;AACA;AACA,MAAMC,iBAAiB,GAAGL,cAAc,CAAC,CAAC;AAE1C,MAAMM,SAAS,GAAG,sBAAsB;AA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T extends object>(value: T) {
|
|
|
318
318
|
return;
|
|
319
319
|
}
|
|
320
320
|
Object.entries(value).forEach(([key, element]) => {
|
|
321
|
+
const descriptor = Object.getOwnPropertyDescriptor(value, key)!;
|
|
322
|
+
if (!descriptor.configurable) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
321
325
|
Object.defineProperty(value, key, {
|
|
322
326
|
get() {
|
|
323
327
|
return element;
|