From 333583bfbe7e3fbf6a6ebd0645019313ade86bea Mon Sep 17 00:00:00 2001 From: evanbacon Date: Thu, 4 Aug 2022 09:25:08 -0700 Subject: [PATCH] feat: prevent removing globalEvalWithSourceUrl in RELEASE builds (#34319) 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](https://github.com/facebook/react-native/commit/71c84cf6bebba701bb23b135e079aa68c05f4441). 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 [Android] [Added] - Expose `globalEvalWithSourceUrl` in production builds. [iOS] [Added] - Expose `globalEvalWithSourceUrl` in production builds. Pull Request resolved: https://github.com/facebook/react-native/pull/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 --- ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp | 4 ---- ReactCommon/jsiexecutor/jsireact/JSIExecutor.h | 2 -- 2 files changed, 6 deletions(-) diff --git a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp index b6f3f26ad13..7c957221400 100644 --- a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp +++ b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.cpp @@ -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", @@ -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_); @@ -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( @@ -543,7 +540,6 @@ Value JSIExecutor::globalEvalWithSourceUrl(const Value *args, size_t count) { return runtime_->evaluateJavaScript( std::make_unique(std::move(code)), url); } -#endif void bindNativeLogger(Runtime &runtime, Logger logger) { runtime.global().setProperty( diff --git a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.h b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.h index f06d0d32fd0..1a8d01f631f 100644 --- a/ReactCommon/jsiexecutor/jsireact/JSIExecutor.h +++ b/ReactCommon/jsiexecutor/jsireact/JSIExecutor.h @@ -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 runtime_; std::shared_ptr delegate_;