Skip to content

Commit

Permalink
feat: prevent removing globalEvalWithSourceUrl in RELEASE builds (#34319
Browse files Browse the repository at this point in the history
)

Summary:
Expo Go was using `nativeInjectHMRUpdate` for [snack](https://snack.expo.io/) to provide stack traces to OTA errors. `nativeInjectHMRUpdate` was replaced with `globalEvalWithSourceUrl` [here](71c84cf). The issue with `globalEvalWithSourceUrl` is that it is stripped in RELEASE builds, and Expo Go is installed via the App Store, making it a release build.

I propose we keep the method, `eval` is still exposed in production so there's no increase in security risk, simply provides a better DX for multipurpose development clients.

## Changelog

<!-- Help reviewers and the release process by writing your own changelog entry. For an example, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[Android] [Added] - Expose `globalEvalWithSourceUrl` in production builds.
[iOS] [Added] - Expose `globalEvalWithSourceUrl` in production builds.

Pull Request resolved: #34319

Test Plan: - Function should be available as `global.globalEvalWithSourceUrl` in a production build.

Reviewed By: christophpurrer

Differential Revision: D38312111

Pulled By: motiz88

fbshipit-source-id: adcd83ad1103c8fd4c6d5d7aec765f27881e0432
  • Loading branch information
EvanBacon authored and facebook-github-bot committed Aug 4, 2022
1 parent 7fcdb9d commit 333583b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 6 deletions.
4 changes: 0 additions & 4 deletions ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ void JSIExecutor::initializeRuntime() {
const jsi::Value *args,
size_t count) { return nativeCallSyncHook(args, count); }));

#if DEBUG
runtime_->global().setProperty(
*runtime_,
"globalEvalWithSourceUrl",
Expand All @@ -134,7 +133,6 @@ void JSIExecutor::initializeRuntime() {
const jsi::Value &,
const jsi::Value *args,
size_t count) { return globalEvalWithSourceUrl(args, count); }));
#endif

if (runtimeInstaller_) {
runtimeInstaller_(*runtime_);
Expand Down Expand Up @@ -527,7 +525,6 @@ Value JSIExecutor::nativeCallSyncHook(const Value *args, size_t count) {
return returnValue;
}

#if DEBUG
Value JSIExecutor::globalEvalWithSourceUrl(const Value *args, size_t count) {
if (count != 1 && count != 2) {
throw std::invalid_argument(
Expand All @@ -543,7 +540,6 @@ Value JSIExecutor::globalEvalWithSourceUrl(const Value *args, size_t count) {
return runtime_->evaluateJavaScript(
std::make_unique<StringBuffer>(std::move(code)), url);
}
#endif

void bindNativeLogger(Runtime &runtime, Logger logger) {
runtime.global().setProperty(
Expand Down
2 changes: 0 additions & 2 deletions ReactCommon/jsiexecutor/jsireact/JSIExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,7 @@ class JSIExecutor : public JSExecutor {
void callNativeModules(const jsi::Value &queue, bool isEndOfBatch);
jsi::Value nativeCallSyncHook(const jsi::Value *args, size_t count);
jsi::Value nativeRequire(const jsi::Value *args, size_t count);
#ifdef DEBUG
jsi::Value globalEvalWithSourceUrl(const jsi::Value *args, size_t count);
#endif

std::shared_ptr<jsi::Runtime> runtime_;
std::shared_ptr<ExecutorDelegate> delegate_;
Expand Down

0 comments on commit 333583b

Please sign in to comment.