Skip to content

Commit

Permalink
Remove callFunctionSync experimental APIs
Browse files Browse the repository at this point in the history
Reviewed By: michalgr

Differential Revision: D6124038

fbshipit-source-id: 219afe30783da92cf10f800dc35e64823b61cf4b
  • Loading branch information
Dan Zimmerman authored and facebook-github-bot committed Mar 5, 2018
1 parent 860fcd4 commit 19a4a7d
Show file tree
Hide file tree
Showing 7 changed files with 0 additions and 144 deletions.
16 changes: 0 additions & 16 deletions React/Base/RCTBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,6 @@ RCT_EXTERN NSString *RCTBridgeModuleNameForClass(Class bridgeModuleClass);
- (void)enqueueJSCall:(NSString *)moduleDotMethod args:(NSArray *)args;
- (void)enqueueJSCall:(NSString *)module method:(NSString *)method args:(NSArray *)args completion:(dispatch_block_t)completion;

/**
* This method is used to call functions in the JavaScript application context
* synchronously. This is intended for use by applications which do their own
* thread management and are careful to manage multi-threaded access to the JSVM.
* See also -[RCTBridgeDelgate shouldBridgeLoadJavaScriptSynchronously], which
* may be needed to ensure that any requires JS code is loaded before this method
* is called. If the underlying executor is not JSC, this will return nil. Safe
* to call from any thread.
*
* @experimental
*/
- (JSValue *)callFunctionOnModule:(NSString *)module
method:(NSString *)method
arguments:(NSArray *)arguments
error:(NSError **)error;

/**
* This method registers the file path of an additional JS segment by its ID.
*
Expand Down
8 changes: 0 additions & 8 deletions React/Base/RCTBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,6 @@ - (void)enqueueCallback:(NSNumber *)cbID args:(NSArray *)args
[self.batchedBridge enqueueCallback:cbID args:args];
}

- (JSValue *)callFunctionOnModule:(NSString *)module
method:(NSString *)method
arguments:(NSArray *)arguments
error:(NSError **)error
{
return [self.batchedBridge callFunctionOnModule:module method:method arguments:arguments error:error];
}

- (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path
{
[self.batchedBridge registerSegmentWithId:segmentId path:path];
Expand Down
47 changes: 0 additions & 47 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1183,53 +1183,6 @@ - (void)executeApplicationScript:(NSData *)script
}];
}

- (JSValue *)callFunctionOnModule:(NSString *)module
method:(NSString *)method
arguments:(NSArray *)arguments
error:(NSError **)error
{
if (!_reactInstance) {
if (error) {
*error = RCTErrorWithMessage(
@"callFunctionOnModule was called on uninitialized bridge");
}
return nil;
} else if (self.executorClass) {
if (error) {
*error = RCTErrorWithMessage(
@"callFunctionOnModule can only be used with JSC executor");
}
return nil;
} else if (!self.valid) {
if (error) {
*error = RCTErrorWithMessage(
@"Bridge is no longer valid");
}
return nil;
} else if (self.loading) {
if (error) {
*error = RCTErrorWithMessage(
@"Bridge is still loading");
}
return nil;
}

RCT_PROFILE_BEGIN_EVENT(0, @"callFunctionOnModule", (@{ @"module": module, @"method": method }));
__block JSValue *ret = nil;
NSError *errorObj = tryAndReturnError(^{
Value result = self->_reactInstance->callFunctionSync([module UTF8String], [method UTF8String], (id)arguments);
JSContext *context = contextForGlobalContextRef(JSC_JSContextGetGlobalContext(result.context()));
ret = [JSC_JSValue(result.context()) valueWithJSValueRef:result inContext:context];
});
RCT_PROFILE_END_EVENT(RCTProfileTagAlways, @"js_call");

if (error) {
*error = errorObj;
}

return ret;
}

- (void)registerSegmentWithId:(NSUInteger)segmentId path:(NSString *)path
{
if (_reactInstance) {
Expand Down
9 changes: 0 additions & 9 deletions ReactCommon/cxxreact/Instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ class RN_EXPORT Instance {
// This method is experimental, and may be modified or removed.
void registerBundle(uint32_t bundleId, const std::string& bundlePath);

// This method is experimental, and may be modified or removed.
template <typename T>
Value callFunctionSync(const std::string &module, const std::string &method,
T &&args) {
CHECK(nativeToJsBridge_);
return nativeToJsBridge_->callFunctionSync(module, method,
std::forward<T>(args));
}

const ModuleRegistry &getModuleRegistry() const;
ModuleRegistry &getModuleRegistry();

Expand Down
24 changes: 0 additions & 24 deletions ReactCommon/cxxreact/JSCExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,30 +581,6 @@ namespace facebook {
callNativeModules(std::move(result));
}

Value JSCExecutor::callFunctionSyncWithValue(
const std::string& module, const std::string& method, Value args) {
SystraceSection s("JSCExecutor::callFunction");
Object result = [&] {
JSContextLock lock(m_context);
if (!m_callFunctionReturnResultAndFlushedQueueJS) {
bindBridge();
}
return m_callFunctionReturnResultAndFlushedQueueJS->callAsFunction({
Value(m_context, String::createExpectingAscii(m_context, module)),
Value(m_context, String::createExpectingAscii(m_context, method)),
std::move(args),
}).asObject();
}();

Value length = result.getProperty("length");

if (!length.isNumber() || length.asInteger() != 2) {
std::runtime_error("Return value of a callFunction must be an array of size 2");
}
callNativeModules(result.getPropertyAtIndex(1));
return result.getPropertyAtIndex(0);
}

void JSCExecutor::setGlobalVariable(std::string propName, std::unique_ptr<const JSBigString> jsonValue) {
try {
SystraceSection s("JSCExecutor::setGlobalVariable", "propName", propName);
Expand Down
11 changes: 0 additions & 11 deletions ReactCommon/cxxreact/JSCExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,6 @@ class RN_EXPORT JSCExecutor : public JSExecutor, public PrivateDataBase {
const double callbackId,
const folly::dynamic& arguments) override;

template <typename T>
Value callFunctionSync(
const std::string& module, const std::string& method, T&& args) {
return callFunctionSyncWithValue(
module, method, JSCValueEncoder<typename std::decay<T>::type>::toJSCValue(
m_context, std::forward<T>(args)));
}

virtual void setGlobalVariable(
std::string propName,
std::unique_ptr<const JSBigString> jsonValue) override;
Expand Down Expand Up @@ -123,9 +115,6 @@ class RN_EXPORT JSCExecutor : public JSExecutor, public PrivateDataBase {

void initOnJSVMThread() throw(JSException);
static bool isNetworkInspected(const std::string &owner, const std::string &app, const std::string &device);
// This method is experimental, and may be modified or removed.
Value callFunctionSyncWithValue(
const std::string& module, const std::string& method, Value value);
void terminateOnJSVMThread();
void bindBridge() throw(JSException);
void callNativeModules(Value&&);
Expand Down
29 changes: 0 additions & 29 deletions ReactCommon/cxxreact/NativeToJsBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,35 +55,6 @@ class NativeToJsBridge {
*/
void invokeCallback(double callbackId, folly::dynamic&& args);

/**
* Executes a JS method on the given executor synchronously, returning its
* return value. JSException will be thrown if JS throws an exception;
* another standard exception may be thrown for C++ bridge failures, or if
* the executor is not capable of synchronous calls.
*
* This method is experimental, and may be modified or removed.
*
* loadApplicationScriptSync() must be called and finished executing
* before callFunctionSync().
*/
template <typename T>
Value callFunctionSync(const std::string& module, const std::string& method, T&& args) {
if (*m_destroyed) {
throw std::logic_error(
folly::to<std::string>("Synchronous call to ", module, ".", method,
" after bridge is destroyed"));
}

JSCExecutor *jscExecutor = dynamic_cast<JSCExecutor*>(m_executor.get());
if (!jscExecutor) {
throw std::invalid_argument(
folly::to<std::string>("Executor type ", typeid(m_executor.get()).name(),
" does not support synchronous calls"));
}

return jscExecutor->callFunctionSync(module, method, std::forward<T>(args));
}

/**
* Starts the JS application. If bundleRegistry is non-null, then it is
* used to fetch JavaScript modules as individual scripts.
Expand Down

1 comment on commit 19a4a7d

@Grebenyukse
Copy link

@Grebenyukse Grebenyukse commented on 19a4a7d Jun 6, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this code has been removed?
What should I use instead?
I'm trying to update legacy project that uses it.

Please sign in to comment.