fix: prevent global Promise overwrite for thread safety.
This PR ensures thread safety for Promises by preventing the global Promise object from being overwritten by user-space code or 3rd party libraries.
NativeScript relies on a custom Promise proxy implementation to ensure that callbacks are executed on the same thread where they were created. This is critical for iOS, where UI updates must happen on the main thread.
Some JavaScript libraries (e.g., Mocha) attempt to replace the global Promise with their own implementation or polyfill. If this happens, the runtime's thread marshalling logic is lost, leading to deadlocks, race conditions, or crashes when callbacks run on the wrong thread.
This change wraps globalThis in a Proxy during initialization to intercept and silently block any attempts to redefine or assign to the Promise property, strictly preserving the runtime's thread-safe implementation.
Note: This has been battle-tested since Nov 2020 in a project I work on.
I'm not sure that preventing overwrite is the best idea, because some other things (like zone.js) override some parts of promise to intercept calls. I believe this might take too much of user agency over our globals, even if it's something that can potentially break an app due to incorrect polyfills.
Edit: additionally, making a global proxy is probably way too overkill, considering that's intercepting every single global call from now on (which also slows down everything on the global scope)
When get chance @adrian-niculescu could you send quick email to [email protected]?