Permalink
Browse files

Drop support for webworkers

Reviewed By: AaaChiuuu

Differential Revision: D4916449

fbshipit-source-id: a447233d3b7cfee98db2ce00f1c0505d513e2429
  • Loading branch information...
javache authored and facebook-github-bot committed Apr 25, 2017
1 parent a20882f commit 34bc6bd2aec77f730c43403c0625c74cec945e57
Showing with 268 additions and 1,641 deletions.
  1. +4 −10 React/CxxBridge/RCTCxxBridge.mm
  2. +2 −4 React/CxxModule/RCTNativeModule.h
  3. +2 −7 React/CxxModule/RCTNativeModule.mm
  4. +0 −36 React/ReactCxx.xcodeproj/project.pbxproj
  5. +0 −2 ReactAndroid/src/androidTest/java/com/facebook/react/testing/ReactIntegrationTestCase.java
  6. +0 −3 ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java
  7. +0 −5 ReactAndroid/src/main/java/com/facebook/react/bridge/BaseJavaModule.java
  8. +2 −4 ReactAndroid/src/main/java/com/facebook/react/bridge/CallbackImpl.java
  9. +0 −3 ReactAndroid/src/main/java/com/facebook/react/bridge/CatalystInstance.java
  10. +0 −24 ReactAndroid/src/main/java/com/facebook/react/bridge/ExecutorToken.java
  11. +0 −1 ReactAndroid/src/main/java/com/facebook/react/bridge/JSInstance.java
  12. +7 −25 ReactAndroid/src/main/java/com/facebook/react/bridge/JavaScriptModuleRegistry.java
  13. +1 −27 ReactAndroid/src/main/java/com/facebook/react/bridge/NativeModule.java
  14. +0 −22 ReactAndroid/src/main/java/com/facebook/react/bridge/OnExecutorUnregisteredListener.java
  15. +0 −9 ReactAndroid/src/main/java/com/facebook/react/bridge/ReactContext.java
  16. +0 −15 ReactAndroid/src/main/java/com/facebook/react/bridge/SupportsWebWorkers.java
  17. +0 −37 ReactAndroid/src/main/java/com/facebook/react/common/ApplicationHolder.java
  18. +7 −23 ReactAndroid/src/main/java/com/facebook/react/cxxbridge/CatalystInstanceImpl.java
  19. +0 −6 ReactAndroid/src/main/java/com/facebook/react/cxxbridge/CxxModuleWrapperBase.java
  20. 0 ReactAndroid/src/main/java/com/facebook/react/cxxbridge/ExecutorToken.java
  21. +38 −66 ReactAndroid/src/main/java/com/facebook/react/cxxbridge/JavaMethodWrapper.java
  22. +2 −8 ReactAndroid/src/main/java/com/facebook/react/cxxbridge/JavaModuleWrapper.java
  23. +0 −7 ReactAndroid/src/main/java/com/facebook/react/cxxbridge/ModuleHolder.java
  24. +0 −25 ReactAndroid/src/main/java/com/facebook/react/module/annotations/ReactModule.java
  25. +0 −7 ReactAndroid/src/main/java/com/facebook/react/module/model/ReactModuleInfo.java
  26. +0 −1 ReactAndroid/src/main/java/com/facebook/react/module/processing/ReactModuleSpecProcessor.java
  27. +0 −2 ReactAndroid/src/main/java/com/facebook/react/modules/core/DeviceEventManagerModule.java
  28. +0 −1 ReactAndroid/src/main/jni/xreact/Android.mk
  29. +0 −1 ReactAndroid/src/main/jni/xreact/jni/Android.mk
  30. +0 −1 ReactAndroid/src/main/jni/xreact/jni/BUCK
  31. +6 −21 ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.cpp
  32. +3 −5 ReactAndroid/src/main/jni/xreact/jni/CatalystInstanceImpl.h
  33. +0 −25 ReactAndroid/src/main/jni/xreact/jni/JExecutorToken.cpp
  34. +0 −61 ReactAndroid/src/main/jni/xreact/jni/JExecutorToken.h
  35. +0 −25 ReactAndroid/src/main/jni/xreact/jni/JSLoader.cpp
  36. +0 −6 ReactAndroid/src/main/jni/xreact/jni/JSLoader.h
  37. +16 −29 ReactAndroid/src/main/jni/xreact/jni/JavaModuleWrapper.cpp
  38. +5 −7 ReactAndroid/src/main/jni/xreact/jni/JavaModuleWrapper.h
  39. +0 −32 ReactAndroid/src/main/jni/xreact/jni/JniWebWorkers.h
  40. +24 −27 ReactAndroid/src/main/jni/xreact/jni/MethodInvoker.cpp
  41. +2 −2 ReactAndroid/src/main/jni/xreact/jni/MethodInvoker.h
  42. +48 −79 ReactAndroid/src/main/jni/xreact/jni/OnLoad.cpp
  43. +0 −50 ReactAndroid/src/main/jni/xreact/jni/WebWorkers.h
  44. +4 −4 ReactAndroid/src/test/java/com/facebook/react/cxxbridge/BaseJavaModuleTest.java
  45. +0 −1 ReactCommon/cxxreact/Android.mk
  46. +0 −3 ReactCommon/cxxreact/BUCK
  47. +8 −14 ReactCommon/cxxreact/CxxNativeModule.cpp
  48. +3 −5 ReactCommon/cxxreact/CxxNativeModule.h
  49. +0 −4 ReactCommon/cxxreact/Executor.h
  50. +0 −54 ReactCommon/cxxreact/ExecutorToken.h
  51. +0 −25 ReactCommon/cxxreact/ExecutorTokenFactory.h
  52. +4 −9 ReactCommon/cxxreact/Instance.cpp
  53. +4 −9 ReactCommon/cxxreact/Instance.h
  54. +1 −237 ReactCommon/cxxreact/JSCExecutor.cpp
  55. +3 −53 ReactCommon/cxxreact/JSCExecutor.h
  56. +0 −135 ReactCommon/cxxreact/JSCWebWorker.cpp
  57. +0 −93 ReactCommon/cxxreact/JSCWebWorker.h
  58. +4 −5 ReactCommon/cxxreact/ModuleRegistry.cpp
  59. +2 −4 ReactCommon/cxxreact/ModuleRegistry.h
  60. +3 −4 ReactCommon/cxxreact/NativeModule.h
  61. +54 −156 ReactCommon/cxxreact/NativeToJsBridge.cpp
  62. +9 −58 ReactCommon/cxxreact/NativeToJsBridge.h
  63. +0 −6 ReactCommon/cxxreact/Platform.cpp
  64. +0 −11 ReactCommon/cxxreact/Platform.h
@@ -121,10 +121,6 @@ void onBatchComplete() override {
}
void incrementPendingJSCalls() override {}
void decrementPendingJSCalls() override {}
ExecutorToken createExecutorToken() override {
return ExecutorToken(std::make_shared<PlatformExecutorToken>());
}
void onExecutorStopped(ExecutorToken) override {}
};
@implementation RCTCxxBridge
@@ -289,7 +285,7 @@ - (void)start
[self.delegate respondsToSelector:@selector(shouldBridgeUseCustomJSC:)] &&
[self.delegate shouldBridgeUseCustomJSC:self];
// The arg is a cache dir. It's not used with standard JSC.
executorFactory.reset(new JSCExecutorFactory("", folly::dynamic::object
executorFactory.reset(new JSCExecutorFactory(folly::dynamic::object
("UseCustomJSC", (bool)useCustomJSC)
#if RCT_PROFILE
("StartSamplingProfilerOnInit", (bool)self.devSettings.startSamplingProfilerOnLaunch)
@@ -1000,8 +996,7 @@ - (void)enqueueJSCall:(NSString *)module method:(NSString *)method args:(NSArray
RCTProfileEndFlowEvent();
if (self->_reactInstance) {
self->_reactInstance->callJSFunction(self->_reactInstance->getMainExecutorToken(),
[module UTF8String], [method UTF8String],
self->_reactInstance->callJSFunction([module UTF8String], [method UTF8String],
[RCTConvert folly_dynamic:args ?: @[]]);
if (completion) {
@@ -1033,7 +1028,7 @@ - (void)enqueueCallback:(NSNumber *)cbID args:(NSArray *)args
if (self->_reactInstance)
self->_reactInstance->callJSCallback(
self->_reactInstance->getMainExecutorToken(), [cbID unsignedLongLongValue],
[cbID unsignedLongLongValue],
[RCTConvert folly_dynamic:args ?: @[]]);
}];
}
@@ -1046,8 +1041,7 @@ - (void)_immediatelyCallTimer:(NSNumber *)timer
RCTAssertJSThread();
if (_reactInstance)
_reactInstance->callJSFunction(_reactInstance->getMainExecutorToken(),
"JSTimersExecution", "callTimers",
_reactInstance->callJSFunction("JSTimersExecution", "callTimers",
folly::dynamic::array(folly::dynamic::array([timer doubleValue])));
}
@@ -20,10 +20,8 @@ class RCTNativeModule : public NativeModule {
std::string getName() override;
std::vector<MethodDescriptor> getMethods() override;
folly::dynamic getConstants() override;
bool supportsWebWorkers() override;
void invoke(ExecutorToken token, unsigned int methodId, folly::dynamic &&params) override;
MethodCallResult callSerializableNativeHook(ExecutorToken token, unsigned int reactMethodId,
folly::dynamic &&params) override;
void invoke(unsigned int methodId, folly::dynamic &&params) override;
MethodCallResult callSerializableNativeHook(unsigned int reactMethodId, folly::dynamic &&params) override;
private:
__weak RCTBridge *m_bridge;
@@ -50,11 +50,7 @@
return ret;
}
bool RCTNativeModule::supportsWebWorkers() {
return false;
}
void RCTNativeModule::invoke(ExecutorToken token, unsigned int methodId, folly::dynamic &&params) {
void RCTNativeModule::invoke(unsigned int methodId, folly::dynamic &&params) {
// The BatchedBridge version of this buckets all the callbacks by thread, and
// queues one block on each. This is much simpler; we'll see how it goes and
// iterate.
@@ -103,8 +99,7 @@
}
}
MethodCallResult RCTNativeModule::callSerializableNativeHook(
ExecutorToken token, unsigned int reactMethodId, folly::dynamic &&params) {
MethodCallResult RCTNativeModule::callSerializableNativeHook(unsigned int reactMethodId, folly::dynamic &&params) {
RCTFatal(RCTErrorWithMessage(@"callSerializableNativeHook is not yet supported on iOS"));
return folly::none;
}

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -28,7 +28,6 @@
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.SoftAssertions;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.common.ApplicationHolder;
import com.facebook.react.common.futures.SimpleSettableFuture;
import com.facebook.react.devsupport.interfaces.DevSupportManager;
import com.facebook.react.modules.core.Timing;
@@ -178,7 +177,6 @@ public void waitForBridgeAndUIIdle() {
protected void setUp() throws Exception {
super.setUp();
SoLoader.init(getContext(), /* native exopackage */ false);
ApplicationHolder.setApplication((Application) getContext().getApplicationContext());
}
@Override
@@ -42,7 +42,6 @@
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.WritableNativeMap;
import com.facebook.react.bridge.queue.ReactQueueConfigurationSpec;
import com.facebook.react.common.ApplicationHolder;
import com.facebook.react.common.LifecycleState;
import com.facebook.react.common.ReactConstants;
import com.facebook.react.common.annotations.VisibleForTesting;
@@ -229,8 +228,6 @@ public static ReactInstanceManagerBuilder builder() {
initializeSoLoaderIfNecessary(applicationContext);
// TODO(9577825): remove this
ApplicationHolder.setApplication((Application) applicationContext.getApplicationContext());
DisplayMetricsHolder.initDisplayMetricsIfNotInitialized(applicationContext);
mApplicationContext = applicationContext;
@@ -66,11 +66,6 @@ public void onCatalystInstanceDestroy() {
// do nothing
}
@Override
public boolean supportsWebWorkers() {
return false;
}
public boolean hasConstants() {
return false;
}
@@ -15,13 +15,11 @@
public final class CallbackImpl implements Callback {
private final JSInstance mJSInstance;
private final ExecutorToken mExecutorToken;
private final int mCallbackId;
private boolean mInvoked;
public CallbackImpl(JSInstance jsInstance, ExecutorToken executorToken, int callbackId) {
public CallbackImpl(JSInstance jsInstance, int callbackId) {
mJSInstance = jsInstance;
mExecutorToken = executorToken;
mCallbackId = callbackId;
mInvoked = false;
}
@@ -33,7 +31,7 @@ public void invoke(Object... args) {
"module. This callback type only permits a single invocation from "+
"native code.");
}
mJSInstance.invokeCallback(mExecutorToken, mCallbackId, Arguments.fromJavaArgs(args));
mJSInstance.invokeCallback(mCallbackId, Arguments.fromJavaArgs(args));
mInvoked = true;
}
}
@@ -37,12 +37,10 @@
// which this prevents.
@Override @DoNotStrip
void invokeCallback(
ExecutorToken executorToken,
int callbackID,
NativeArray arguments);
@DoNotStrip
void callFunction(
ExecutorToken executorToken,
String module,
String method,
NativeArray arguments);
@@ -63,7 +61,6 @@ void callFunction(
ReactQueueConfiguration getReactQueueConfiguration();
<T extends JavaScriptModule> T getJSModule(Class<T> jsInterface);
<T extends JavaScriptModule> T getJSModule(ExecutorToken executorToken, Class<T> jsInterface);
<T extends NativeModule> boolean hasNativeModule(Class<T> nativeModuleInterface);
<T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface);
Collection<NativeModule> getNativeModules();
@@ -1,24 +0,0 @@
package com.facebook.react.bridge;
import com.facebook.jni.HybridData;
import com.facebook.proguard.annotations.DoNotStrip;
/**
* Class corresponding to a JS VM that can call into native modules. In Java, this should
* just be treated as a black box to be used to help the framework route native->JS calls back to
* the proper JS VM. See {@link ReactContext#getJSModule(ExecutorToken, Class)} and
* {@link BaseJavaModule#supportsWebWorkers()}.
*
* Note: If your application doesn't use web workers, it will only have a single ExecutorToken
* per instance of React Native.
*/
@DoNotStrip
public class ExecutorToken {
private final HybridData mHybridData;
@DoNotStrip
private ExecutorToken(HybridData hybridData) {
mHybridData = hybridData;
}
}
@@ -16,7 +16,6 @@
*/
public interface JSInstance {
void invokeCallback(
ExecutorToken executorToken,
int callbackID,
NativeArray arguments);
// TODO if this interface survives refactoring, think about adding
@@ -31,29 +31,21 @@
* JavaScript.
*/
public class JavaScriptModuleRegistry {
private final WeakHashMap<ExecutorToken, HashMap<Class<? extends JavaScriptModule>, JavaScriptModule>> mModuleInstances;
private final HashMap<Class<? extends JavaScriptModule>, JavaScriptModule> mModuleInstances;
private final HashMap<Class<? extends JavaScriptModule>, JavaScriptModuleRegistration> mModuleRegistrations;
public JavaScriptModuleRegistry(List<JavaScriptModuleRegistration> config) {
mModuleInstances = new WeakHashMap<>();
mModuleInstances = new HashMap<>();
mModuleRegistrations = new HashMap<>();
for (JavaScriptModuleRegistration registration : config) {
mModuleRegistrations.put(registration.getModuleInterface(), registration);
}
}
public synchronized <T extends JavaScriptModule> T getJavaScriptModule(
CatalystInstance instance,
ExecutorToken executorToken,
Class<T> moduleInterface) {
HashMap<Class<? extends JavaScriptModule>, JavaScriptModule> instancesForContext =
mModuleInstances.get(executorToken);
if (instancesForContext == null) {
instancesForContext = new HashMap<>();
mModuleInstances.put(executorToken, instancesForContext);
}
JavaScriptModule module = instancesForContext.get(moduleInterface);
CatalystInstance instance,
Class<T> moduleInterface) {
JavaScriptModule module = mModuleInstances.get(moduleInterface);
if (module != null) {
return (T) module;
}
@@ -65,8 +57,8 @@ public JavaScriptModuleRegistry(List<JavaScriptModuleRegistration> config) {
JavaScriptModule interfaceProxy = (JavaScriptModule) Proxy.newProxyInstance(
moduleInterface.getClassLoader(),
new Class[]{moduleInterface},
new JavaScriptModuleInvocationHandler(executorToken, instance, registration));
instancesForContext.put(moduleInterface, interfaceProxy);
new JavaScriptModuleInvocationHandler(instance, registration));
mModuleInstances.put(moduleInterface, interfaceProxy);
return (T) interfaceProxy;
}
@@ -85,30 +77,20 @@ public JavaScriptModuleRegistry build() {
}
private static class JavaScriptModuleInvocationHandler implements InvocationHandler {
private final WeakReference<ExecutorToken> mExecutorToken;
private final CatalystInstance mCatalystInstance;
private final JavaScriptModuleRegistration mModuleRegistration;
public JavaScriptModuleInvocationHandler(
ExecutorToken executorToken,
CatalystInstance catalystInstance,
JavaScriptModuleRegistration moduleRegistration) {
mExecutorToken = new WeakReference<>(executorToken);
mCatalystInstance = catalystInstance;
mModuleRegistration = moduleRegistration;
}
@Override
public @Nullable Object invoke(Object proxy, Method method, @Nullable Object[] args) throws Throwable {
ExecutorToken executorToken = mExecutorToken.get();
if (executorToken == null) {
FLog.w(ReactConstants.TAG, "Dropping JS call, ExecutorToken went away...");
return null;
}
NativeArray jsArgs = args != null ? Arguments.fromJavaArgs(args) : new WritableNativeArray();
mCatalystInstance.callFunction(
executorToken,
mModuleRegistration.getName(),
method.getName(),
jsArgs
@@ -9,10 +9,7 @@
package com.facebook.react.bridge;
import javax.annotation.Nullable;
import java.lang.reflect.Method;
import java.util.Map;
/**
* A native module whose API can be provided to JS catalyst instances. {@link NativeModule}s whose
@@ -23,7 +20,7 @@
*/
public interface NativeModule {
interface NativeMethod {
void invoke(JSInstance jsInstance, ExecutorToken executorToken, ReadableNativeArray parameters);
void invoke(JSInstance jsInstance, ReadableNativeArray parameters);
String getType();
}
@@ -52,27 +49,4 @@
* Called before {CatalystInstance#onHostDestroy}
*/
void onCatalystInstanceDestroy();
/**
* In order to support web workers, a module must be aware that it can be invoked from multiple
* different JS VMs. Supporting web workers means recognizing things like:
*
* 1) ids (e.g. timer ids, request ids, etc.) may only unique on a per-VM basis
* 2) the module needs to make sure to enqueue callbacks and JS module calls to the correct VM
*
* In order to facilitate this, modules that support web workers will have all their @ReactMethod-
* annotated methods passed a {@link ExecutorToken} as the first parameter before any arguments
* from JS. This ExecutorToken internally maps to a specific JS VM and can be used by the
* framework to route calls appropriately. In order to make JS module calls correctly, start using
* the version of {@link ReactContext#getJSModule(ExecutorToken, Class)} that takes an
* ExecutorToken. It will ensure that any calls you dispatch to the returned object will go to
* the right VM. For Callbacks, you don't have to do anything special -- the framework
* automatically tags them with the correct ExecutorToken when the are created.
*
* Note: even though calls can come from multiple JS VMs on multiple threads, calls to this module
* will still only occur on a single thread.
*
* @return whether this module supports web workers.
*/
boolean supportsWebWorkers();
}
@@ -1,22 +0,0 @@
/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/
package com.facebook.react.bridge;
/**
* Interface for a module that will be notified when JS executors have been unregistered from the bridge.
* Note that this will NOT notify listeners about the main executor being destroyed: use
* {@link NativeModule#onCatalystInstanceDestroy()} for that. Once a module has received a
* {@link NativeModule#onCatalystInstanceDestroy()} call, it will not receive any onExecutorUnregistered
* calls.
*/
public interface OnExecutorUnregisteredListener {
void onExecutorDestroyed(ExecutorToken executorToken);
}
@@ -107,15 +107,6 @@ public Object getSystemService(String name) {
return mCatalystInstance.getJSModule(jsInterface);
}
public <T extends JavaScriptModule> T getJSModule(
ExecutorToken executorToken,
Class<T> jsInterface) {
if (mCatalystInstance == null) {
throw new RuntimeException(EARLY_JS_ACCESS_EXCEPTION_MESSAGE);
}
return mCatalystInstance.getJSModule(executorToken, jsInterface);
}
public <T extends NativeModule> boolean hasNativeModule(Class<T> nativeModuleInterface) {
if (mCatalystInstance == null) {
throw new RuntimeException(
@@ -1,15 +0,0 @@
// Copyright 2004-present Facebook. All Rights Reserved.
package com.facebook.react.bridge;
import java.lang.annotation.Retention;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Annotation indicating that a JS module should be made available to web
* workers spawned by the main JS executor.
*/
@Retention(RUNTIME)
public @interface SupportsWebWorkers {
}
Oops, something went wrong.

0 comments on commit 34bc6bd

Please sign in to comment.