diff --git a/RNTester/android/app/build.gradle b/RNTester/android/app/build.gradle index 0d6c9af3e2f..403876d7f67 100644 --- a/RNTester/android/app/build.gradle +++ b/RNTester/android/app/build.gradle @@ -68,7 +68,10 @@ project.ext.react = [ bundleAssetName: "RNTesterApp.android.bundle", entryFile: file("../../js/RNTesterApp.android.js"), root: "$rootDir", - inputExcludes: ["android/**", "./**", ".gradle/**"] + inputExcludes: ["android/**", "./**", ".gradle/**"], + composeSourceMapsPath: "$rootDir/scripts/compose-source-maps.js", + hermesCommand: "../../../node_modules/hermesvm/%OS-BIN%/hermes", + enableHermesForVariant: { def v -> v.name.contains("hermes") } ] apply from: "../../../react.gradle" @@ -105,6 +108,16 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } + flavorDimensions "vm" + productFlavors { + hermes { + dimension "vm" + } + jsc { + dimension "vm" + } + } + defaultConfig { applicationId "com.facebook.react.uiapp" minSdkVersion 16 @@ -138,6 +151,12 @@ android { signingConfig signingConfigs.release } } + packagingOptions { + pickFirst '**/armeabi-v7a/libc++_shared.so' + pickFirst '**/x86/libc++_shared.so' + pickFirst '**/arm64-v8a/libc++_shared.so' + pickFirst '**/x86_64/libc++_shared.so' + } } dependencies { @@ -146,6 +165,10 @@ dependencies { // Build React Native from source implementation project(':ReactAndroid') + def hermesPath = '$projectDir/../../../../node_modules/hermesvm/android/' + debugImplementation files(hermesPath + "hermes-debug.aar") + releaseImplementation files(hermesPath + "hermes-release.aar") + if (useIntlJsc) { implementation 'org.webkit:android-jsc-intl:+' } else { diff --git a/RNTester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java b/RNTester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java index bbfbd557417..f6f33b6e2fe 100644 --- a/RNTester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java +++ b/RNTester/android/app/src/main/java/com/facebook/react/uiapp/RNTesterApplication.java @@ -13,6 +13,7 @@ import com.facebook.react.ReactNativeHost; import com.facebook.react.ReactPackage; import com.facebook.react.shell.MainReactPackage; import com.facebook.react.views.text.ReactFontManager; +import com.facebook.soloader.SoLoader; import java.util.Arrays; import java.util.List; @@ -44,6 +45,7 @@ public class RNTesterApplication extends Application implements ReactApplication public void onCreate() { ReactFontManager.getInstance().addCustomFont(this, "Rubik", R.font.rubik); super.onCreate(); + SoLoader.init(this, /* native exopackage */ false); } @Override diff --git a/ReactAndroid/build.gradle b/ReactAndroid/build.gradle index f04bb4ad12d..5d8a62ae66a 100644 --- a/ReactAndroid/build.gradle +++ b/ReactAndroid/build.gradle @@ -91,6 +91,27 @@ task prepareFolly(dependsOn: dependenciesPath ? [] : [downloadFolly], type: Copy into("$thirdPartyNdkDir/folly") } +task prepareHermes() { + def hermesAAR = file("$projectDir/../node_modules/hermesvm/android/hermes-debug.aar") + if (!hermesAAR.exists()) { + // For an app to build from RN source, hermesvm is located at /path/to/app/node_modules + // and $projectDir is located at /path/to/app/node_modules/react-native/ReactAndroid + hermesAAR = file("$projectDir/../../hermesvm/android/hermes-debug.aar") + + if (!hermesAAR.exists()) { + // At Facebook, this file is in a different folder + hermesAAR = file("$projectDir/../../node_modules/hermesvm/android/hermes-debug.aar") + } + } + def soFiles = zipTree(hermesAAR).matching({ it.include "**/*.so" }) + + copy { + from soFiles + from "src/main/jni/first-party/hermes/Android.mk" + into "$thirdPartyNdkDir/hermes" + } +} + task downloadGlog(dependsOn: createNativeDepsDirectories, type: Download) { src("https://github.com/google/glog/archive/v${GLOG_VERSION}.tar.gz") onlyIfNewer(true) @@ -232,7 +253,7 @@ def getNdkBuildFullPath() { return ndkBuildFullPath } -task buildReactNdkLib(dependsOn: [prepareJSC, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog], type: Exec) { +task buildReactNdkLib(dependsOn: [prepareJSC, prepareHermes, prepareBoost, prepareDoubleConversion, prepareFolly, prepareGlog], type: Exec) { inputs.dir("$projectDir/../ReactCommon") inputs.dir("src/main/jni") outputs.dir("$buildDir/react-ndk/all") @@ -269,6 +290,7 @@ task packageReactNdkLibs(dependsOn: buildReactNdkLib, type: Copy) { from("$buildDir/react-ndk/all") into("$buildDir/react-ndk/exported") exclude("**/libjsc.so") + exclude("**/libhermes.so") } task packageReactNdkLibsForBuck(dependsOn: packageReactNdkLibs, type: Copy) { diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/BUCK b/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/BUCK new file mode 100644 index 00000000000..b27cc802321 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/BUCK @@ -0,0 +1,9 @@ +load("//tools/build_defs/oss:rn_defs.bzl", "rn_android_library") + +rn_android_library( + name = "instrumentation", + srcs = glob(["**/*.java"]), + visibility = [ + "PUBLIC", + ], +) diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.h b/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.h new file mode 100644 index 00000000000..cc34bc0f889 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.h @@ -0,0 +1,48 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + */ +#include +#include + +namespace facebook { +namespace jsi { +namespace jni { + +namespace jni = ::facebook::jni; + +class HermesMemoryDumper : public jni::JavaClass { + public: + constexpr static auto kJavaDescriptor = + "Lcom/facebook/hermes/instrumentation/HermesMemoryDumper;"; + + bool shouldSaveSnapshot() { + static auto shouldSaveSnapshotMethod = + javaClassStatic()->getMethod("shouldSaveSnapshot"); + return shouldSaveSnapshotMethod(self()); + } + + std::string getInternalStorage() { + static auto getInternalStorageMethod = + javaClassStatic()->getMethod("getInternalStorage"); + return getInternalStorageMethod(self())->toStdString(); + } + + std::string getId() { + static auto getInternalStorageMethod = + javaClassStatic()->getMethod("getId"); + return getInternalStorageMethod(self())->toStdString(); + } + + void setMetaData(std::string crashId) { + static auto getIdMethod = + javaClassStatic()->getMethod("setMetaData"); + getIdMethod(self(), crashId); + } +}; + +} // namespace jni +} // namespace jsi +} // namespace facebook diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.java b/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.java new file mode 100644 index 00000000000..3cc522fd456 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/instrumentation/HermesMemoryDumper.java @@ -0,0 +1,17 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + *

This source code is licensed under the MIT license found in the LICENSE file in the root + * directory of this source tree. + */ +package com.facebook.hermes.instrumentation; + +public interface HermesMemoryDumper { + boolean shouldSaveSnapshot(); + + String getInternalStorage(); + + String getId(); + + void setMetaData(String crashId); +} diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/Android.mk b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/Android.mk new file mode 100644 index 00000000000..2db6747de96 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/Android.mk @@ -0,0 +1,40 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +REACT_NATIVE := $(LOCAL_PATH)/../../../../../../../.. + +LOCAL_MODULE := hermes-executor-release + +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) + +LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(REACT_NATIVE)/node_modules/hermesvm/android/include $(REACT_NATIVE)/../hermesvm/android/include $(REACT_NATIVE)/../node_modules/hermesvm/include + +LOCAL_CPP_FEATURES := exceptions + +LOCAL_STATIC_LIBRARIES := libjsireact libjsi +LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni libhermes + +include $(BUILD_SHARED_LIBRARY) + + +include $(CLEAR_VARS) +REACT_NATIVE := $(LOCAL_PATH)/../../../../../../../.. + +LOCAL_MODULE := hermes-executor-debug +LOCAL_CFLAGS := -DHERMES_ENABLE_DEBUGGER=1 + +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) + +LOCAL_C_INCLUDES := $(LOCAL_PATH) $(REACT_NATIVE)/ReactCommon/jsi $(REACT_NATIVE)/node_modules/hermesvm/android/include $(REACT_NATIVE)/../hermesvm/android/include $(REACT_NATIVE)/../node_modules/hermesvm/include + +LOCAL_CPP_FEATURES := exceptions + +LOCAL_STATIC_LIBRARIES := libjsireact libjsi libhermes-inspector +LOCAL_SHARED_LIBRARIES := libfolly_json libfb libreactnativejni libhermes + +include $(BUILD_SHARED_LIBRARY) diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java new file mode 100644 index 00000000000..bd562f03e0b --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutor.java @@ -0,0 +1,68 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + *

This source code is licensed under the MIT license found in the LICENSE file in the root + * directory of this source tree. + */ +package com.facebook.hermes.reactexecutor; + +import com.facebook.hermes.instrumentation.HermesMemoryDumper; +import com.facebook.jni.HybridData; +import com.facebook.react.bridge.JavaScriptExecutor; +import com.facebook.soloader.SoLoader; +import javax.annotation.Nullable; + +public class HermesExecutor extends JavaScriptExecutor { + private static String mode_; + + static { + // libhermes must be loaded explicitly to invoke its JNI_OnLoad. + SoLoader.loadLibrary("hermes"); + try { + SoLoader.loadLibrary("hermes-executor-release"); + mode_ = "Release"; + } catch (UnsatisfiedLinkError e) { + SoLoader.loadLibrary("hermes-executor-debug"); + mode_ = "Debug"; + } + } + + HermesExecutor(@Nullable RuntimeConfig config) { + super( + config == null + ? initHybridDefaultConfig() + : initHybrid( + config.heapSizeMB, + config.es6Symbol, + config.bytecodeWarmupPercent, + config.tripWireEnabled, + config.heapDumper, + config.tripWireCooldownMS, + config.tripWireLimitBytes)); + } + + @Override + public String getName() { + return "HermesExecutor" + mode_; + } + + /** + * Return whether this class can load a file at the given path, based on a binary compatibility + * check between the contents of the file and the Hermes VM. + * + * @param path the path containing the file to inspect. + * @return whether the given file is compatible with the Hermes VM. + */ + public static native boolean canLoadFile(String path); + + private static native HybridData initHybridDefaultConfig(); + + private static native HybridData initHybrid( + long heapSizeMB, + boolean es6Symbol, + int bytecodeWarmupPercent, + boolean tripWireEnabled, + @Nullable HermesMemoryDumper heapDumper, + long tripWireCooldownMS, + long tripWireLimitBytes); +} diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.cpp b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.cpp new file mode 100644 index 00000000000..db02a2d5c90 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.cpp @@ -0,0 +1,230 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "HermesExecutorFactory.h" + +#include + +#include +#include +#include +#include + +#ifdef HERMES_ENABLE_DEBUGGER +#include +#include +#endif + +#include "JSITracing.h" + +using namespace facebook::hermes; +using namespace facebook::jsi; + +namespace facebook { +namespace react { + +namespace { + +std::unique_ptr makeHermesRuntimeSystraced( + const ::hermes::vm::RuntimeConfig &runtimeConfig) { + SystraceSection s("HermesExecutorFactory::makeHermesRuntimeSystraced"); + return hermes::makeHermesRuntime(runtimeConfig); +} + +#ifdef HERMES_ENABLE_DEBUGGER + +class HermesExecutorRuntimeAdapter + : public facebook::hermes::inspector::RuntimeAdapter { + public: + HermesExecutorRuntimeAdapter( + std::shared_ptr runtime, + HermesRuntime &hermesRuntime, + std::shared_ptr thread) + : runtime_(runtime), + hermesRuntime_(hermesRuntime), + thread_(std::move(thread)) {} + + virtual ~HermesExecutorRuntimeAdapter() = default; + + HermesRuntime &getRuntime() override { + return hermesRuntime_; + } + + void tickleJs() override { + // The queue will ensure that runtime_ is still valid when this + // gets invoked. + // clang-format off + thread_->runOnQueue([&runtime = hermesRuntime_]() { + // clang-format on + auto func = runtime.global().getPropertyAsFunction(runtime, "__tickleJs"); + func.call(runtime); + }); + } + + private: + std::shared_ptr runtime_; + HermesRuntime &hermesRuntime_; + + std::shared_ptr thread_; +}; + +#endif + +struct ReentrancyCheck { +// This is effectively a very subtle and complex assert, so only +// include it in builds which would include asserts. +#ifndef NDEBUG + ReentrancyCheck() : tid(std::thread::id()), depth(0) {} + + void before() { + std::thread::id this_id = std::this_thread::get_id(); + std::thread::id expected = std::thread::id(); + + // A note on memory ordering: the main purpose of these checks is + // to observe a before/before race, without an intervening after. + // This will be detected by the compare_exchange_strong atomicity + // properties, regardless of memory order. + // + // For everything else, it is easiest to think of 'depth' as a + // proxy for any access made inside the VM. If access to depth + // are reordered incorrectly, the same could be true of any other + // operation made by the VM. In fact, using acquire/release + // memory ordering could create barriers which mask a programmer + // error. So, we use relaxed memory order, to avoid masking + // actual ordering errors. Although, in practice, ordering errors + // of this sort would be surprising, because the decorator would + // need to call after() without before(). + + if (tid.compare_exchange_strong( + expected, this_id, std::memory_order_relaxed)) { + // Returns true if tid and expected were the same. If they + // were, then the stored tid referred to no thread, and we + // atomically saved this thread's tid. Now increment depth. + assert(depth == 0 && "No thread id, but depth != 0"); + ++depth; + } else if (expected == this_id) { + // If the stored tid referred to a thread, expected was set to + // that value. If that value is this thread's tid, that's ok, + // just increment depth again. + assert(depth != 0 && "Thread id was set, but depth == 0"); + ++depth; + } else { + // The stored tid was some other thread. This indicates a bad + // programmer error, where VM methods were called on two + // different threads unsafely. Fail fast (and hard) so the + // crash can be analyzed. + __builtin_trap(); + } + } + + void after() { + assert( + tid.load(std::memory_order_relaxed) == std::this_thread::get_id() && + "No thread id in after()"); + if (--depth == 0) { + // If we decremented depth to zero, store no-thread into tid. + std::thread::id expected = std::this_thread::get_id(); + bool didWrite = tid.compare_exchange_strong( + expected, std::thread::id(), std::memory_order_relaxed); + assert(didWrite && "Decremented to zero, but no tid write"); + } + } + + std::atomic tid; + // This is not atomic, as it is only written or read from the owning + // thread. + unsigned int depth; +#endif +}; + +// This adds ReentrancyCheck and debugger enable/teardown to the given +// Runtime. +class DecoratedRuntime : public jsi::WithRuntimeDecorator { + public: + // The first argument may be a tracing runtime which itself + // decorates the real HermesRuntime, depending on the build config. + // The second argument is the the real HermesRuntime as well to + // manage the debugger registration. + DecoratedRuntime( + std::unique_ptr runtime, + HermesRuntime &hermesRuntime, + std::shared_ptr jsQueue) + : jsi::WithRuntimeDecorator(*runtime, reentrancyCheck_), + runtime_(std::move(runtime)), + hermesRuntime_(hermesRuntime) { +#ifdef HERMES_ENABLE_DEBUGGER + auto adapter = std::make_unique( + runtime_, hermesRuntime_, jsQueue); + facebook::hermes::inspector::chrome::enableDebugging( + std::move(adapter), "Hermes React Native"); +#else + (void)hermesRuntime_; +#endif + } + + ~DecoratedRuntime() { +#ifdef HERMES_ENABLE_DEBUGGER + facebook::hermes::inspector::chrome::disableDebugging(hermesRuntime_); +#endif + } + + private: + // runtime_ is a TracingRuntime, but we don't need to worry about + // the details. hermesRuntime is a reference to the HermesRuntime + // managed by the TracingRuntime. + // + // HermesExecutorRuntimeAdapter requirements are kept, because the + // dtor will disable debugging on the HermesRuntime before the + // member managing it is destroyed. + + std::shared_ptr runtime_; + ReentrancyCheck reentrancyCheck_; + HermesRuntime &hermesRuntime_; +}; + +} // namespace + +std::unique_ptr HermesExecutorFactory::createJSExecutor( + std::shared_ptr delegate, + std::shared_ptr jsQueue) { + std::unique_ptr hermesRuntime = + makeHermesRuntimeSystraced(runtimeConfig_); + HermesRuntime& hermesRuntimeRef = *hermesRuntime; + auto decoratedRuntime = std::make_shared( + makeTracingHermesRuntime(std::move(hermesRuntime), runtimeConfig_), + hermesRuntimeRef, + jsQueue); + + // So what do we have now? + // DecoratedRuntime -> TracingRuntime -> HermesRuntime + // + // DecoratedRuntime is held by JSIExecutor. When it gets used, it + // will check that it's on the right thread, do any necessary trace + // logging, then call the real HermesRuntime. When it is destroyed, + // it will shut down the debugger before the HermesRuntime is. In + // the normal case where tracing and debugging are not compiled in, + // all that's left is the thread checking. + + // Add js engine information to Error.prototype so in error reporting we + // can send this information. + auto errorPrototype = + decoratedRuntime->global() + .getPropertyAsObject(*decoratedRuntime, "Error") + .getPropertyAsObject(*decoratedRuntime, "prototype"); + errorPrototype.setProperty(*decoratedRuntime, "jsEngine", "hermes"); + + return std::make_unique( + decoratedRuntime, delegate, jsQueue, timeoutInvoker_, runtimeInstaller_); +} + +HermesExecutor::HermesExecutor( + std::shared_ptr runtime, + std::shared_ptr delegate, + std::shared_ptr jsQueue, + const JSIScopedTimeoutInvoker &timeoutInvoker, + RuntimeInstaller runtimeInstaller) + : JSIExecutor(runtime, delegate, timeoutInvoker, runtimeInstaller) { + jsi::addNativeTracingHooks(*runtime); +} + +} // namespace react +} // namespace facebook diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.h b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.h new file mode 100644 index 00000000000..5913317e243 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.h @@ -0,0 +1,50 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include +#include +#include + +namespace facebook { +namespace react { + +class HermesExecutorFactory : public JSExecutorFactory { + public: + explicit HermesExecutorFactory( + JSIExecutor::RuntimeInstaller runtimeInstaller, + const JSIScopedTimeoutInvoker& timeoutInvoker = + JSIExecutor::defaultTimeoutInvoker, + ::hermes::vm::RuntimeConfig runtimeConfig = ::hermes::vm::RuntimeConfig()) + : runtimeInstaller_(runtimeInstaller), + timeoutInvoker_(timeoutInvoker), + runtimeConfig_(std::move(runtimeConfig)) { + assert(timeoutInvoker_ && "Should not have empty timeoutInvoker"); + } + + std::unique_ptr createJSExecutor( + std::shared_ptr delegate, + std::shared_ptr jsQueue) override; + + private: + JSIExecutor::RuntimeInstaller runtimeInstaller_; + JSIScopedTimeoutInvoker timeoutInvoker_; + ::hermes::vm::RuntimeConfig runtimeConfig_; +}; + +class HermesExecutor : public JSIExecutor { + public: + HermesExecutor( + std::shared_ptr runtime, + std::shared_ptr delegate, + std::shared_ptr jsQueue, + const JSIScopedTimeoutInvoker& timeoutInvoker, + RuntimeInstaller runtimeInstaller); + + private: + JSIScopedTimeoutInvoker timeoutInvoker_; +}; + +} // namespace react +} // namespace facebook diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.java b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.java new file mode 100644 index 00000000000..1c8e0645a50 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/HermesExecutorFactory.java @@ -0,0 +1,40 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + *

This source code is licensed under the MIT license found in the LICENSE file in the root + * directory of this source tree. + */ +package com.facebook.hermes.reactexecutor; + +import com.facebook.react.bridge.JavaScriptExecutor; +import com.facebook.react.bridge.JavaScriptExecutorFactory; + +public class HermesExecutorFactory implements JavaScriptExecutorFactory { + private static final String TAG = "Hermes"; + + private final RuntimeConfig mConfig; + + public HermesExecutorFactory() { + this(null); + } + + public HermesExecutorFactory(RuntimeConfig config) { + mConfig = config; + } + + @Override + public JavaScriptExecutor create() { + return new HermesExecutor(mConfig); + } + + @Override + public void startSamplingProfiler() {} + + @Override + public void stopSamplingProfiler(String filename) {} + + @Override + public String toString() { + return "JSIExecutor+HermesRuntime"; + } +} diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/JSITracing.cpp b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/JSITracing.cpp new file mode 100644 index 00000000000..8514a3eaafa --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/JSITracing.cpp @@ -0,0 +1,15 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + */ +#include "JSITracing.h" + +namespace facebook { +namespace jsi { +void addNativeTracingHooks(Runtime &rt) { + assert(false && "unimplemented"); +} +} // namespace jsi +} // namespace facebook diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/JSITracing.h b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/JSITracing.h new file mode 100644 index 00000000000..80bbf9beb9f --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/JSITracing.h @@ -0,0 +1,15 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + */ +#include + +namespace facebook { +namespace jsi { + +void addNativeTracingHooks(Runtime &rt); + +} // namespace jsi +} // namespace facebook diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/OnLoad.cpp b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/OnLoad.cpp new file mode 100644 index 00000000000..5e14c5c4a0a --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/OnLoad.cpp @@ -0,0 +1,154 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the LICENSE + * file in the root directory of this source tree. + */ +#include <../instrumentation/HermesMemoryDumper.h> +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace facebook { +namespace react { + +/// Converts a duration given as a long from Java, into a std::chrono duration. +static constexpr std::chrono::hours msToHours(jlong ms) { + using namespace std::chrono; + return duration_cast(milliseconds(ms)); +} + +static ::hermes::vm::RuntimeConfig makeRuntimeConfig( + jlong heapSizeMB, + bool es6Symbol, + jint bytecodeWarmupPercent, + bool tripWireEnabled, + jni::alias_ref heapDumper, + jlong tripWireCooldownMS, + jlong tripWireLimitBytes) { + namespace vm = ::hermes::vm; + auto gcConfigBuilder = + vm::GCConfig::Builder() + .withMaxHeapSize(heapSizeMB << 20) + .withName("RN") + // For the next two arguments: avoid GC before TTI by initializing the + // runtime to allocate directly in the old generation, but revert to + // normal operation when we reach the (first) TTI point. + .withAllocInYoung(false) + .withRevertToYGAtTTI(true); + + if (tripWireEnabled) { + assert( + heapDumper && + "Must provide a heap dumper instance if tripwire is enabled"); + + gcConfigBuilder.withTripwireConfig( + vm::GCTripwireConfig::Builder() + .withLimit(tripWireLimitBytes) + .withCooldown(msToHours(tripWireCooldownMS)) + .withCallback([globalHeapDumper = jni::make_global(heapDumper)]( + vm::GCTripwireContext &ctx) mutable { + if (!globalHeapDumper->shouldSaveSnapshot()) { + return; + } + + std::string crashId = globalHeapDumper->getId(); + std::string path = globalHeapDumper->getInternalStorage(); + path += "/dump_"; + path += crashId; + path += ".hermes"; + + bool successful = ctx.createSnapshotToFile(path, true); + if (!successful) { + LOG(ERROR) << "Failed to write Hermes Memory Dump to " << path + << "\n"; + return; + } + + LOG(INFO) << "Hermes Memory Dump saved on: " << path << "\n"; + globalHeapDumper->setMetaData(crashId); + }) + .build()); + } + + return vm::RuntimeConfig::Builder() + .withGCConfig(gcConfigBuilder.build()) + .withES6Symbol(es6Symbol) + .withBytecodeWarmupPercent(bytecodeWarmupPercent) + .build(); +} + +static void installBindings(jsi::Runtime &runtime) { + react::Logger androidLogger = + static_cast( + &reactAndroidLoggingHook); + react::bindNativeLogger(runtime, androidLogger); +} + +class HermesExecutorHolder + : public jni::HybridClass { + public: + static constexpr auto kJavaDescriptor = + "Lcom/facebook/hermes/reactexecutor/HermesExecutor;"; + + static jni::local_ref initHybridDefaultConfig( + jni::alias_ref) { + JReactMarker::setLogPerfMarkerIfNeeded(); + + return makeCxxInstance( + folly::make_unique(installBindings)); + } + + static jni::local_ref initHybrid( + jni::alias_ref, + jlong heapSizeMB, + bool es6Symbol, + jint bytecodeWarmupPercent, + bool tripWireEnabled, + jni::alias_ref heapDumper, + jlong tripWireCooldownMS, + jlong tripWireLimitBytes) { + JReactMarker::setLogPerfMarkerIfNeeded(); + auto runtimeConfig = makeRuntimeConfig( + heapSizeMB, + es6Symbol, + bytecodeWarmupPercent, + tripWireEnabled, + heapDumper, + tripWireCooldownMS, + tripWireLimitBytes); + return makeCxxInstance(folly::make_unique( + installBindings, JSIExecutor::defaultTimeoutInvoker, runtimeConfig)); + } + + static bool canLoadFile(jni::alias_ref, const std::string &path) { + return true; + } + + static void registerNatives() { + registerHybrid( + {makeNativeMethod("initHybrid", HermesExecutorHolder::initHybrid), + makeNativeMethod( + "initHybridDefaultConfig", + HermesExecutorHolder::initHybridDefaultConfig), + makeNativeMethod("canLoadFile", HermesExecutorHolder::canLoadFile)}); + } + + private: + friend HybridBase; + using HybridBase::HybridBase; +}; + +} // namespace react +} // namespace facebook + +JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { + return facebook::jni::initialize( + vm, [] { facebook::react::HermesExecutorHolder::registerNatives(); }); +} diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/RuntimeConfig.java b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/RuntimeConfig.java new file mode 100644 index 00000000000..920621cbe2b --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/RuntimeConfig.java @@ -0,0 +1,22 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + *

This source code is licensed under the MIT license found in the LICENSE file in the root + * directory of this source tree. + */ +package com.facebook.hermes.reactexecutor; + +import com.facebook.hermes.instrumentation.HermesMemoryDumper; +import javax.annotation.Nullable; + +/** Holds runtime configuration for a Hermes VM instance (master or snapshot). */ +public final class RuntimeConfig { + public long heapSizeMB; + public boolean enableSampledStats; + public boolean es6Symbol; + public int bytecodeWarmupPercent; + public boolean tripWireEnabled; + @Nullable public HermesMemoryDumper heapDumper; + public long tripWireCooldownMS; + public long tripWireLimitBytes; +} diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/fbjni.pro b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/fbjni.pro new file mode 100644 index 00000000000..09fad6a9e4a --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/reactexecutor/fbjni.pro @@ -0,0 +1,16 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +# For common use cases for the hybrid pattern, keep symbols which may +# be referenced only from C++. + +-keepclassmembers class * { + com.facebook.jni.HybridData *; + (com.facebook.jni.HybridData); +} + +-keepclasseswithmembers class * { + com.facebook.jni.HybridData *; +} diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/unicode/AndroidUnicodeUtils.java b/ReactAndroid/src/main/java/com/facebook/hermes/unicode/AndroidUnicodeUtils.java new file mode 100644 index 00000000000..650a5bdaec5 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/unicode/AndroidUnicodeUtils.java @@ -0,0 +1,81 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + *

This source code is licensed under the MIT license found in the LICENSE file in the root + * directory of this source tree. + */ +package com.facebook.hermes.unicode; + +import com.facebook.proguard.annotations.DoNotStrip; +import java.text.Collator; +import java.text.DateFormat; +import java.text.Normalizer; +import java.util.Locale; + +// TODO: use com.facebook.common.locale.Locales.getApplicationLocale() as the current locale, +// rather than the device locale. This is challenging because getApplicationLocale() is only +// available via DI. +@DoNotStrip +public class AndroidUnicodeUtils { + @DoNotStrip + public static int localeCompare(String left, String right) { + Collator collator = Collator.getInstance(); + return collator.compare(left, right); + } + + @DoNotStrip + public static String dateFormat(double unixtimeMs, boolean formatDate, boolean formatTime) { + DateFormat format; + if (formatDate && formatTime) { + format = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); + } else if (formatDate) { + format = DateFormat.getDateInstance(DateFormat.MEDIUM); + } else if (formatTime) { + format = DateFormat.getTimeInstance(DateFormat.MEDIUM); + } else { + throw new RuntimeException("Bad dateFormat configuration"); + } + return format.format((long) unixtimeMs).toString(); + } + + @DoNotStrip + public static String convertToCase(String input, int targetCase, boolean useCurrentLocale) { + // These values must match CaseConversion in PlatformUnicode.h + final int targetUppercase = 0; + final int targetLowercase = 1; + // Note Java's case conversions use the user's locale. For example "I".toLowerCase() + // will produce a dotless i. From Java's docs: "To obtain correct results for locale + // insensitive strings, use toLowerCase(Locale.ENGLISH)." + Locale locale = useCurrentLocale ? Locale.getDefault() : Locale.ENGLISH; + switch (targetCase) { + case targetLowercase: + return input.toLowerCase(locale); + case targetUppercase: + return input.toUpperCase(locale); + default: + throw new RuntimeException("Invalid target case"); + } + } + + @DoNotStrip + public static String normalize(String input, int form) { + // Values must match NormalizationForm in PlatformUnicode.h. + final int formC = 0; + final int formD = 1; + final int formKC = 2; + final int formKD = 3; + + switch (form) { + case formC: + return Normalizer.normalize(input, Normalizer.Form.NFC); + case formD: + return Normalizer.normalize(input, Normalizer.Form.NFD); + case formKC: + return Normalizer.normalize(input, Normalizer.Form.NFKC); + case formKD: + return Normalizer.normalize(input, Normalizer.Form.NFKD); + default: + throw new RuntimeException("Invalid form"); + } + } +} diff --git a/ReactAndroid/src/main/java/com/facebook/hermes/unicode/BUCK b/ReactAndroid/src/main/java/com/facebook/hermes/unicode/BUCK new file mode 100644 index 00000000000..8f5636e1662 --- /dev/null +++ b/ReactAndroid/src/main/java/com/facebook/hermes/unicode/BUCK @@ -0,0 +1,12 @@ +load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "rn_android_library") + +rn_android_library( + name = "unicode", + srcs = glob(["**/*.java"]), + visibility = [ + "PUBLIC", + ], + deps = [ + react_native_dep("java/com/facebook/proguard/annotations:annotations"), + ], +) diff --git a/ReactAndroid/src/main/java/com/facebook/jni/NativeRunnable.java b/ReactAndroid/src/main/java/com/facebook/jni/NativeRunnable.java index 290de68d91f..6c35d45d6a7 100644 --- a/ReactAndroid/src/main/java/com/facebook/jni/NativeRunnable.java +++ b/ReactAndroid/src/main/java/com/facebook/jni/NativeRunnable.java @@ -12,8 +12,9 @@ import com.facebook.proguard.annotations.DoNotStrip; @DoNotStrip public class NativeRunnable implements Runnable { - private final HybridData mHybridData; + @DoNotStrip private final HybridData mHybridData; + @DoNotStrip private NativeRunnable(HybridData hybridData) { mHybridData = hybridData; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/BUCK b/ReactAndroid/src/main/java/com/facebook/react/BUCK index f5f371753de..58b58dcb46e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/BUCK +++ b/ReactAndroid/src/main/java/com/facebook/react/BUCK @@ -21,6 +21,7 @@ rn_android_library( react_native_dep("libraries/soloader/java/com/facebook/soloader:soloader"), react_native_dep("third-party/java/infer-annotations:infer-annotations"), react_native_dep("third-party/java/jsr-305:jsr-305"), + react_native_dep("java/com/facebook/hermes/reactexecutor:reactexecutor"), react_native_target("java/com/facebook/debug/holder:holder"), react_native_target("java/com/facebook/debug/tags:tags"), react_native_target("java/com/facebook/react/bridge:bridge"), diff --git a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java index 0c4b2b83146..e58b8cc4550 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java +++ b/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManagerBuilder.java @@ -10,6 +10,7 @@ import static com.facebook.react.modules.systeminfo.AndroidInfoHelpers.getFriend import android.app.Activity; import android.app.Application; import androidx.annotation.Nullable; +import com.facebook.hermes.reactexecutor.HermesExecutorFactory; import com.facebook.infer.annotation.Assertions; import com.facebook.react.bridge.JSBundleLoader; import com.facebook.react.bridge.JSIModulePackage; @@ -24,6 +25,7 @@ import com.facebook.react.jscexecutor.JSCExecutorFactory; import com.facebook.react.modules.core.DefaultHardwareBackBtnHandler; import com.facebook.react.packagerconnection.RequestHandler; import com.facebook.react.uimanager.UIImplementationProvider; +import com.facebook.soloader.SoLoader; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -260,7 +262,7 @@ public class ReactInstanceManagerBuilder { mCurrentActivity, mDefaultHardwareBackBtnHandler, mJavaScriptExecutorFactory == null - ? new JSCExecutorFactory(appName, deviceName) + ? getDefaultJSExecutorFactory(appName, deviceName) : mJavaScriptExecutorFactory, (mJSBundleLoader == null && mJSBundleAssetUrl != null) ? JSBundleLoader.createAssetLoader( @@ -281,4 +283,15 @@ public class ReactInstanceManagerBuilder { mJSIModulesPackage, mCustomPackagerCommandHandlers); } + + private JavaScriptExecutorFactory getDefaultJSExecutorFactory(String appName, String deviceName) { + try { + // If JSC is included, use it as normal + SoLoader.loadLibrary("jscexecutor"); + return new JSCExecutorFactory(appName, deviceName); + } catch (UnsatisfiedLinkError jscE) { + // Otherwise use Hermes + return new HermesExecutorFactory(); + } + } } diff --git a/ReactAndroid/src/main/jni/Application.mk b/ReactAndroid/src/main/jni/Application.mk index 017ddd7bc46..84eae80adf4 100644 --- a/ReactAndroid/src/main/jni/Application.mk +++ b/ReactAndroid/src/main/jni/Application.mk @@ -26,9 +26,9 @@ NDK_MODULE_PATH := $(APP_MK_DIR)$(HOST_DIRSEP)$(THIRD_PARTY_NDK_DIR)$(HOST_DIRSE APP_STL := c++_shared -# Make sure every shared lib includes a .note.gnu.build-id header -APP_CFLAGS := -Wall -Werror -fexceptions -frtti +APP_CFLAGS := -Wall -Werror -fexceptions -frtti -DWITH_INSPECTOR=1 APP_CPPFLAGS := -std=c++1y +# Make sure every shared lib includes a .note.gnu.build-id header APP_LDFLAGS := -Wl,--build-id NDK_TOOLCHAIN_VERSION := clang diff --git a/ReactAndroid/src/main/jni/first-party/hermes/Android.mk b/ReactAndroid/src/main/jni/first-party/hermes/Android.mk new file mode 100644 index 00000000000..6d82b06d18f --- /dev/null +++ b/ReactAndroid/src/main/jni/first-party/hermes/Android.mk @@ -0,0 +1,5 @@ +LOCAL_PATH:= $(call my-dir) +include $(CLEAR_VARS) +LOCAL_MODULE:= hermes +LOCAL_SRC_FILES := jni/$(TARGET_ARCH_ABI)/libhermes.so +include $(PREBUILT_SHARED_LIBRARY) diff --git a/ReactAndroid/src/main/jni/react/jni/Android.mk b/ReactAndroid/src/main/jni/react/jni/Android.mk index b2422db9659..e687f40c170 100644 --- a/ReactAndroid/src/main/jni/react/jni/Android.mk +++ b/ReactAndroid/src/main/jni/react/jni/Android.mk @@ -68,6 +68,7 @@ $(call import-module,cxxreact) $(call import-module,jsi) $(call import-module,jsiexecutor) $(call import-module,jscallinvoker) +$(call import-module,hermes) include $(REACT_SRC_DIR)/turbomodule/core/jni/Android.mk diff --git a/ReactCommon/cxxreact/Android.mk b/ReactCommon/cxxreact/Android.mk index e0bee78c350..5ac26f435c4 100644 --- a/ReactCommon/cxxreact/Android.mk +++ b/ReactCommon/cxxreact/Android.mk @@ -30,3 +30,4 @@ $(call import-module,jsc) $(call import-module,glog) $(call import-module,jsi) $(call import-module,jsinspector) +$(call import-module,hermes/inspector) diff --git a/ReactCommon/hermes/inspector/.clang-format b/ReactCommon/hermes/inspector/.clang-format new file mode 100644 index 00000000000..550292f9506 --- /dev/null +++ b/ReactCommon/hermes/inspector/.clang-format @@ -0,0 +1,87 @@ +--- +AccessModifierOffset: -1 +AlignAfterOpenBracket: AlwaysBreak +AlignConsecutiveAssignments: false +AlignConsecutiveDeclarations: false +AlignEscapedNewlinesLeft: true +AlignOperands: false +AlignTrailingComments: false +AllowAllParametersOfDeclarationOnNextLine: false +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortFunctionsOnASingleLine: Empty +AllowShortIfStatementsOnASingleLine: false +AllowShortLoopsOnASingleLine: false +AlwaysBreakAfterReturnType: None +AlwaysBreakBeforeMultilineStrings: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: false +BinPackParameters: false +BraceWrapping: + AfterClass: false + AfterControlStatement: false + AfterEnum: false + AfterFunction: false + AfterNamespace: false + AfterObjCDeclaration: false + AfterStruct: false + AfterUnion: false + BeforeCatch: false + BeforeElse: false + IndentBraces: false +BreakBeforeBinaryOperators: None +BreakBeforeBraces: Attach +BreakBeforeTernaryOperators: true +BreakConstructorInitializersBeforeComma: false +BreakAfterJavaFieldAnnotations: false +BreakStringLiterals: false +ColumnLimit: 80 +CommentPragmas: '^ IWYU pragma:' +ConstructorInitializerAllOnOneLineOrOnePerLine: true +ConstructorInitializerIndentWidth: 4 +ContinuationIndentWidth: 4 +Cpp11BracedListStyle: true +DerivePointerAlignment: false +DisableFormat: false +ForEachMacros: [ FOR_EACH_RANGE, FOR_EACH, ] +IncludeCategories: + - Regex: '^<.*\.h(pp)?>' + Priority: 1 + - Regex: '^<.*' + Priority: 2 + - Regex: '.*' + Priority: 3 +IndentCaseLabels: true +IndentWidth: 2 +IndentWrappedFunctionNames: false +KeepEmptyLinesAtTheStartOfBlocks: false +MacroBlockBegin: '' +MacroBlockEnd: '' +MaxEmptyLinesToKeep: 1 +NamespaceIndentation: None +ObjCBlockIndentWidth: 2 +ObjCSpaceAfterProperty: false +ObjCSpaceBeforeProtocolList: false +PenaltyBreakBeforeFirstCallParameter: 1 +PenaltyBreakComment: 300 +PenaltyBreakFirstLessLess: 120 +PenaltyBreakString: 1000 +PenaltyExcessCharacter: 1000000 +PenaltyReturnTypeOnItsOwnLine: 200 +PointerAlignment: Right +ReflowComments: true +SortIncludes: true +SpaceAfterCStyleCast: false +SpaceBeforeAssignmentOperators: true +SpaceBeforeParens: ControlStatements +SpaceInEmptyParentheses: false +SpacesBeforeTrailingComments: 1 +SpacesInAngles: false +SpacesInContainerLiterals: true +SpacesInCStyleCastParentheses: false +SpacesInParentheses: false +SpacesInSquareBrackets: false +Standard: Cpp11 +TabWidth: 8 +UseTab: Never +... diff --git a/ReactCommon/hermes/inspector/Android.mk b/ReactCommon/hermes/inspector/Android.mk new file mode 100644 index 00000000000..cc40ab8601f --- /dev/null +++ b/ReactCommon/hermes/inspector/Android.mk @@ -0,0 +1,26 @@ +# Copyright (c) Facebook, Inc. and its affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +LOCAL_PATH := $(call my-dir) + +include $(CLEAR_VARS) +REACT_NATIVE := $(LOCAL_PATH)/../../.. + +LOCAL_MODULE := hermes-inspector + +LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp $(LOCAL_PATH)/detail/*.cpp $(LOCAL_PATH)/chrome/*.cpp) + +LOCAL_C_ROOT := $(LOCAL_PATH)/../.. + +LOCAL_CFLAGS := -DHERMES_ENABLE_DEBUGGER=1 +LOCAL_C_INCLUDES := $(LOCAL_C_ROOT) $(REACT_NATIVE)/ReactCommon/jsi $(REACT_NATIVE)/node_modules/hermesvm/android/include $(REACT_NATIVE)/../hermesvm/android/include $(REACT_NATIVE)/../node_modules/hermesvm/include +LOCAL_EXPORT_C_INCLUDES := $(LOCAL_C_ROOT) + +LOCAL_CPP_FEATURES := exceptions + +LOCAL_STATIC_LIBRARIES := libjsi +LOCAL_SHARED_LIBRARIES := jsinspector libfb libfolly_futures libfolly_json libhermes + +include $(BUILD_SHARED_LIBRARY) diff --git a/ReactCommon/hermes/inspector/AsyncPauseState.h b/ReactCommon/hermes/inspector/AsyncPauseState.h new file mode 100644 index 00000000000..a5aa57385e0 --- /dev/null +++ b/ReactCommon/hermes/inspector/AsyncPauseState.h @@ -0,0 +1,29 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +namespace facebook { +namespace hermes { +namespace inspector { + +/** + * AsyncPauseState is used to track whether we requested an async pause from a + * running VM, and whether the pause was initiated by us or by the client. + */ +enum class AsyncPauseState { + /// None means there is no pending async pause in the VM. + None, + + /// Implicit means we requested an async pause from the VM to service an op + /// that can only be performed while paused, like setting a breakpoint. An + /// impliict pause can be upgraded to an explicit pause if the client later + /// explicitly requests a pause. + Implicit, + + /// Explicit means that the client requested the pause by calling pause(). + Explicit +}; + +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/DEFS.bzl b/ReactCommon/hermes/inspector/DEFS.bzl new file mode 100644 index 00000000000..a55bb00adff --- /dev/null +++ b/ReactCommon/hermes/inspector/DEFS.bzl @@ -0,0 +1,7 @@ +load("@fbsource//xplat/hermes/defs:hermes.bzl", "hermes_is_debugger_enabled") + +def hermes_inspector_dep_list(): + return [ + "fbsource//xplat/hermes-inspector:chrome", + "fbsource//xplat/hermes-inspector:inspectorlib", + ] if hermes_is_debugger_enabled() else [] diff --git a/ReactCommon/hermes/inspector/Exceptions.h b/ReactCommon/hermes/inspector/Exceptions.h new file mode 100644 index 00000000000..7808b019dfd --- /dev/null +++ b/ReactCommon/hermes/inspector/Exceptions.h @@ -0,0 +1,44 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include + +namespace facebook { +namespace hermes { +namespace inspector { + +class AlreadyEnabledException : public std::runtime_error { + public: + AlreadyEnabledException() + : std::runtime_error("can't enable: debugger already enabled") {} +}; + +class NotEnabledException : public std::runtime_error { + public: + NotEnabledException(const std::string &cmd) + : std::runtime_error("debugger can't perform " + cmd + ": not enabled") {} +}; + +class InvalidStateException : public std::runtime_error { + public: + InvalidStateException( + const std::string &cmd, + const std::string &curState, + const std::string &expectedState) + : std::runtime_error( + "debugger can't perform " + cmd + ": in " + curState + + ", expected " + expectedState) {} +}; + +class MultipleCommandsPendingException : public std::runtime_error { + public: + MultipleCommandsPendingException(const std::string &cmd) + : std::runtime_error( + "debugger can't perform " + cmd + + ": a step or resume is already pending") {} +}; + +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/Inspector.cpp b/ReactCommon/hermes/inspector/Inspector.cpp new file mode 100644 index 00000000000..ea3c8b3024f --- /dev/null +++ b/ReactCommon/hermes/inspector/Inspector.cpp @@ -0,0 +1,582 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "Inspector.h" +#include "Exceptions.h" +#include "InspectorState.h" + +#include +#include + +#include +#include +#include + +// This is here, instead of linking against +// folly/futures/Future.cpp, to avoid pulling in another pile of +// dependencies, including the separate dependency libevent. This is +// likely specific to the version of folly RN uses, so may need to be +// changed. Even better, perhaps folly can be refactored to simplify +// this. + +template class folly::Future; + +namespace folly { +namespace futures { + +Future sleep(Duration dur, Timekeeper *tk) { + LOG(FATAL) << "folly::futures::sleep() not implemented"; +} + +} // namespace futures + +namespace detail { + +std::shared_ptr getTimekeeperSingleton() { + LOG(FATAL) << "folly::detail::getTimekeeperSingleton() not implemented"; +} + +} // namespace detail +} // namespace folly + +// + +namespace facebook { +namespace hermes { +namespace inspector { + +using folly::Unit; + +namespace debugger = ::facebook::hermes::debugger; + +/** + * Threading notes: + * + * 1. mutex_ must be held before using state_ or any InspectorState methods. + * 2. Methods that are callable by the client (like enable, resume, etc.) call + * various InspectorState methods via state_. This implies that they must + * acquire mutex_. + * 3. Since some InspectorState methods call back out to the client (e.g. via + * fulfilling promises, or via the InspectorObserver callbacks), we have to + * be careful about reentrancy from a callback causing a deadlock when (1) + * and (2) interact. Consider: + * + * 1) Debugger pauses, which causes InspectorObserve::onPause to fire. + * onPause is called by InspectorState::Paused::onEnter on the JS + * thread with mutex_ held. + * 2) Client calls setBreakpoint from the onPause callback. + * 3) If setBreakpoint directly tried to acquire mutex_ here, we would + * deadlock since our thread already owns the mutex_ (see 1). + * + * For this reason, all client-facing methods are executed on executor_, which + * runs on its own thread. The pattern is: + * + * 1. The client-facing method foo (e.g. enable) enqueues a call to + * fooOnExecutor (e.g. enableOnExecutor) on executor_. + * 2. fooOnExecutor is responsible for acquiring mutex_. + * + */ + +// TODO: read this out of an env variable or config +static constexpr bool kShouldLog = true; + +// Logging state transitions is done outside of transition() in a macro so that +// function and line numbers in the log will be accurate. +#define TRANSITION(nextState) \ + do { \ + if (kShouldLog) { \ + if (state_ == nullptr) { \ + LOG(INFO) << "Inspector::" << __func__ \ + << " transitioning to initial state " << *(nextState); \ + } else { \ + LOG(INFO) << "Inspector::" << __func__ << " transitioning from " \ + << *state_ << " to " << *(nextState); \ + } \ + } \ + transition((nextState)); \ + } while (0) + +Inspector::Inspector( + std::shared_ptr adapter, + InspectorObserver &observer, + bool pauseOnFirstStatement) + : adapter_(adapter), + debugger_(adapter->getRuntime().getDebugger()), + observer_(observer), + executor_(std::make_unique("hermes-inspector")) { + // TODO (t26491391): make tickleJs a real Hermes runtime API + const char *src = "function __tickleJs() { return Math.random(); }"; + adapter->getRuntime().debugJavaScript(src, "__tickleJsHackUrl", {}); + + { + std::lock_guard lock(mutex_); + + if (pauseOnFirstStatement) { + TRANSITION(std::make_unique(*this)); + } else { + TRANSITION(std::make_unique(*this)); + } + } + + debugger_.setShouldPauseOnScriptLoad(true); + debugger_.setEventObserver(this); +} + +Inspector::~Inspector() { + // TODO: think about expected detach flow + debugger_.setEventObserver(nullptr); +} + +void Inspector::installConsoleFunction( + jsi::Object &console, + const std::string &name, + const std::string &chromeTypeDefault = "") { + jsi::Runtime &rt = adapter_->getRuntime(); + auto chromeType = chromeTypeDefault == "" ? name : chromeTypeDefault; + auto nameID = jsi::PropNameID::forUtf8(rt, name); + auto weakInspector = std::weak_ptr(shared_from_this()); + console.setProperty( + rt, + nameID, + jsi::Function::createFromHostFunction( + rt, + nameID, + 1, + [weakInspector, chromeType]( + jsi::Runtime &runtime, + const jsi::Value &thisVal, + const jsi::Value *args, + size_t count) { + if (auto inspector = weakInspector.lock()) { + jsi::Array argsArray(runtime, count); + for (size_t index = 0; index < count; ++index) + argsArray.setValueAtIndex(runtime, index, args[index]); + inspector->logMessage( + ConsoleMessageInfo{chromeType, std::move(argsArray)}); + } + + return jsi::Value::undefined(); + })); +} + +void Inspector::installLogHandler() { + jsi::Runtime &rt = adapter_->getRuntime(); + auto console = jsi::Object(rt); + installConsoleFunction(console, "assert"); + installConsoleFunction(console, "clear"); + installConsoleFunction(console, "debug"); + installConsoleFunction(console, "dir"); + installConsoleFunction(console, "dirxml"); + installConsoleFunction(console, "error"); + installConsoleFunction(console, "group", "startGroup"); + installConsoleFunction(console, "groupCollapsed", "startGroupCollapsed"); + installConsoleFunction(console, "groupEnd", "endGroup"); + installConsoleFunction(console, "info"); + installConsoleFunction(console, "log"); + installConsoleFunction(console, "profile"); + installConsoleFunction(console, "profileEnd"); + installConsoleFunction(console, "table"); + installConsoleFunction(console, "trace"); + installConsoleFunction(console, "warn", "warning"); + rt.global().setProperty(rt, "console", console); +} + +void Inspector::triggerAsyncPause(bool andTickle) { + // In order to ensure that we pause soon, we both set the async pause flag on + // the runtime, and we run a bit of dummy JS to ensure we enter the Hermes + // interpreter loop. + debugger_.triggerAsyncPause(); + + if (andTickle) { + // We run the dummy JS on a background thread to avoid any reentrancy issues + // in case this thread is called with the inspector mutex held. + std::shared_ptr adapter = adapter_; + detail::Thread tickleJsLater( + "inspectorTickleJs", [adapter]() { adapter->tickleJs(); }); + tickleJsLater.detach(); + } +} + +void Inspector::notifyContextCreated() { + observer_.onContextCreated(*this); +} + +ScriptInfo Inspector::getScriptInfoFromTopCallFrame() { + ScriptInfo info{}; + auto stackTrace = debugger_.getProgramState().getStackTrace(); + + if (stackTrace.callFrameCount() > 0) { + uint32_t i = stackTrace.callFrameCount() - 1; + debugger::SourceLocation loc = stackTrace.callFrameForIndex(i).location; + + info.fileId = loc.fileId; + info.fileName = loc.fileName; + info.sourceMappingUrl = debugger_.getSourceMappingUrl(info.fileId); + } + + return info; +} + +void Inspector::addCurrentScriptToLoadedScripts() { + ScriptInfo info = getScriptInfoFromTopCallFrame(); + + if (!loadedScripts_.count(info.fileId)) { + loadedScripts_[info.fileId] = LoadedScriptInfo{std::move(info), false}; + } +} + +void Inspector::removeAllBreakpoints() { + debugger_.deleteAllBreakpoints(); +} + +void Inspector::resetScriptsLoaded() { + for (auto &it : loadedScripts_) { + it.second.notifiedClient = false; + } +} + +void Inspector::notifyScriptsLoaded() { + for (auto &it : loadedScripts_) { + LoadedScriptInfo &loadedScriptInfo = it.second; + + if (!loadedScriptInfo.notifiedClient) { + loadedScriptInfo.notifiedClient = true; + observer_.onScriptParsed(*this, loadedScriptInfo.info); + } + } +} + +folly::Future Inspector::disable() { + auto promise = std::make_shared>(); + + executor_->add([this, promise] { disableOnExecutor(promise); }); + + return promise->getFuture(); +} + +folly::Future Inspector::enable() { + auto promise = std::make_shared>(); + + executor_->add([this, promise] { enableOnExecutor(promise); }); + + return promise->getFuture(); +} + +folly::Future Inspector::executeIfEnabled( + const std::string &description, + folly::Function func) { + auto promise = std::make_shared>(); + + executor_->add( + [this, description, func = std::move(func), promise]() mutable { + executeIfEnabledOnExecutor(description, std::move(func), promise); + }); + + return promise->getFuture(); +} + +folly::Future Inspector::setBreakpoint( + debugger::SourceLocation loc, + folly::Optional condition) { + auto promise = std::make_shared>(); + + executor_->add([this, loc, condition, promise] { + setBreakpointOnExecutor(loc, condition, promise); + }); + + return promise->getFuture(); +} + +folly::Future Inspector::removeBreakpoint( + debugger::BreakpointID breakpointId) { + auto promise = std::make_shared>(); + + executor_->add([this, breakpointId, promise] { + removeBreakpointOnExecutor(breakpointId, promise); + }); + + return promise->getFuture(); +} + +folly::Future Inspector::logMessage(ConsoleMessageInfo info) { + auto promise = std::make_shared>(); + + executor_->add([this, + pInfo = std::make_unique(std::move(info)), + promise] { logOnExecutor(std::move(*pInfo), promise); }); + + return promise->getFuture(); +} + +folly::Future Inspector::setPendingCommand(debugger::Command command) { + auto promise = std::make_shared>(); + + executor_->add([this, promise, cmd = std::move(command)]() mutable { + setPendingCommandOnExecutor(std::move(cmd), promise); + }); + + return promise->getFuture(); +} + +folly::Future Inspector::resume() { + return setPendingCommand(debugger::Command::continueExecution()); +} + +folly::Future Inspector::stepIn() { + return setPendingCommand(debugger::Command::step(debugger::StepMode::Into)); +} + +folly::Future Inspector::stepOver() { + return setPendingCommand(debugger::Command::step(debugger::StepMode::Over)); +} + +folly::Future Inspector::stepOut() { + return setPendingCommand(debugger::Command::step(debugger::StepMode::Out)); +} + +folly::Future Inspector::pause() { + auto promise = std::make_shared>(); + + executor_->add([this, promise]() { pauseOnExecutor(promise); }); + + return promise->getFuture(); +} + +folly::Future Inspector::evaluate( + uint32_t frameIndex, + const std::string &src, + folly::Function + resultTransformer) { + auto promise = std::make_shared>(); + + executor_->add([this, + frameIndex, + src, + promise, + resultTransformer = std::move(resultTransformer)]() mutable { + evaluateOnExecutor(frameIndex, src, promise, std::move(resultTransformer)); + }); + + return promise->getFuture(); +} + +folly::Future Inspector::setPauseOnExceptions( + const debugger::PauseOnThrowMode &mode) { + auto promise = std::make_shared>(); + + executor_->add([this, mode, promise]() mutable { + setPauseOnExceptionsOnExecutor(mode, promise); + }); + + return promise->getFuture(); +}; + +debugger::Command Inspector::didPause(debugger::Debugger &debugger) { + std::unique_lock lock(mutex_); + + if (kShouldLog) { + LOG(INFO) << "received didPause for reason: " + << static_cast(debugger.getProgramState().getPauseReason()) + << " in state: " << *state_; + } + + while (true) { + /* + * Keep sending the onPause event to the current state until we get a + * command to return. For instance, this handles the transition from + * Running to Paused to Running: + * + * 1) (R => P) We're currently in Running, so we call Running::didPause, + * which returns {nextState: Paused, command: null}. There isn't a + * command to return yet. + * 2) (P => R) Now we're in Paused, so we call Paused::didPause, which + * returns {nextState: Running, command: someCommand} where someCommand + * is non-null (e.g. continue or step over). This terminates the loop. + */ + auto result = state_->didPause(lock); + + std::unique_ptr nextState = std::move(result.first); + if (nextState) { + TRANSITION(std::move(nextState)); + } + + std::unique_ptr command = std::move(result.second); + if (command) { + return std::move(*command); + } + } +} + +void Inspector::breakpointResolved( + debugger::Debugger &debugger, + debugger::BreakpointID breakpointId) { + std::unique_lock lock(mutex_); + + debugger::BreakpointInfo info = debugger.getBreakpointInfo(breakpointId); + observer_.onBreakpointResolved(*this, info); +} + +void Inspector::transition(std::unique_ptr nextState) { + assert(nextState); + assert(state_ != nextState); + + std::unique_ptr prevState = std::move(state_); + state_ = std::move(nextState); + state_->onEnter(prevState.get()); +} + +void Inspector::disableOnExecutor( + std::shared_ptr> promise) { + std::lock_guard lock(mutex_); + + debugger_.setIsDebuggerAttached(false); + + state_->detach(promise); +} + +void Inspector::enableOnExecutor( + std::shared_ptr> promise) { + std::lock_guard lock(mutex_); + + auto result = state_->enable(); + + /** + * We fulfill the promise before changing state because fulfilling the promise + * responds to the Debugger.enable request, and changing state could send a + * notification (like Debugger.paused). It seems like a good idea to respond + * to enable before sending out any notifications. + */ + bool enabled = result.second; + if (enabled) { + debugger_.setIsDebuggerAttached(true); + promise->setValue(); + } else { + promise->setException(AlreadyEnabledException()); + } + + std::unique_ptr nextState = std::move(result.first); + if (nextState) { + TRANSITION(std::move(nextState)); + } +} + +void Inspector::executeIfEnabledOnExecutor( + const std::string &description, + folly::Function func, + std::shared_ptr> promise) { + std::lock_guard lock(mutex_); + + if (!state_->isPaused() && !state_->isRunning()) { + promise->setException(InvalidStateException( + description, state_->description(), "paused or running")); + return; + } + + folly::Func wrappedFunc = [this, func = std::move(func)]() mutable { + func(debugger_.getProgramState()); + }; + + state_->pushPendingFunc( + [wrappedFunc = std::move(wrappedFunc), promise]() mutable { + wrappedFunc(); + promise->setValue(); + }); +} + +void Inspector::setBreakpointOnExecutor( + debugger::SourceLocation loc, + folly::Optional condition, + std::shared_ptr> promise) { + std::lock_guard lock(mutex_); + + bool pushed = state_->pushPendingFunc([this, loc, condition, promise] { + debugger::BreakpointID id = debugger_.setBreakpoint(loc); + debugger::BreakpointInfo info{debugger::kInvalidBreakpoint}; + if (id != debugger::kInvalidBreakpoint) { + info = debugger_.getBreakpointInfo(id); + + if (condition) { + debugger_.setBreakpointCondition(id, condition.value()); + } + } + + promise->setValue(std::move(info)); + }); + + if (!pushed) { + promise->setException(NotEnabledException("setBreakpoint")); + } +} + +void Inspector::removeBreakpointOnExecutor( + debugger::BreakpointID breakpointId, + std::shared_ptr> promise) { + std::lock_guard lock(mutex_); + + bool pushed = state_->pushPendingFunc([this, breakpointId, promise] { + debugger_.deleteBreakpoint(breakpointId); + promise->setValue(); + }); + + if (!pushed) { + promise->setException(NotEnabledException("removeBreakpoint")); + } +} + +void Inspector::logOnExecutor( + ConsoleMessageInfo info, + std::shared_ptr> promise) { + std::lock_guard lock(mutex_); + + state_->pushPendingFunc([this, info = std::move(info)] { + observer_.onMessageAdded(*this, info); + }); + + promise->setValue(); +} + +void Inspector::setPendingCommandOnExecutor( + debugger::Command command, + std::shared_ptr> promise) { + std::lock_guard lock(mutex_); + + state_->setPendingCommand(std::move(command), promise); +} + +void Inspector::pauseOnExecutor(std::shared_ptr> promise) { + std::lock_guard lock(mutex_); + + bool canPause = state_->pause(); + + if (canPause) { + promise->setValue(); + } else { + promise->setException(NotEnabledException("pause")); + } +} + +void Inspector::evaluateOnExecutor( + uint32_t frameIndex, + const std::string &src, + std::shared_ptr> promise, + folly::Function + resultTransformer) { + std::lock_guard lock(mutex_); + + state_->pushPendingEval( + frameIndex, src, promise, std::move(resultTransformer)); +} + +void Inspector::setPauseOnExceptionsOnExecutor( + const debugger::PauseOnThrowMode &mode, + std::shared_ptr> promise) { + std::lock_guard local(mutex_); + + state_->pushPendingFunc([this, mode, promise] { + debugger_.setPauseOnThrowMode(mode); + promise->setValue(); + }); +} + +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/Inspector.h b/ReactCommon/hermes/inspector/Inspector.h new file mode 100644 index 00000000000..399b720cf2a --- /dev/null +++ b/ReactCommon/hermes/inspector/Inspector.h @@ -0,0 +1,306 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { + +class Inspector; +class InspectorState; + +/** + * ScriptInfo contains info about loaded scripts. + */ +struct ScriptInfo { + uint32_t fileId{}; + std::string fileName; + std::string sourceMappingUrl; +}; + +struct ConsoleMessageInfo { + std::string source; + std::string level; + std::string url; + int line; + int column; + + jsi::Array args; + + ConsoleMessageInfo(std::string level, jsi::Array args) + : source("console-api"), + level(level), + url(""), + line(-1), + column(-1), + args(std::move(args)) {} +}; + +/** + * InspectorObserver notifies the observer of events that occur in the VM. + */ +class InspectorObserver { + public: + virtual ~InspectorObserver() = default; + + /// onContextCreated fires when the VM is created. + virtual void onContextCreated(Inspector &inspector) = 0; + + /// onBreakpointResolve fires when a lazy breakpoint is resolved. + virtual void onBreakpointResolved( + Inspector &inspector, + const facebook::hermes::debugger::BreakpointInfo &info) = 0; + + /// onPause fires when VM transitions from running to paused state. This is + /// called directly on the JS thread while the VM is paused, so the receiver + /// can call debugger::ProgramState methods safely. + virtual void onPause( + Inspector &inspector, + const facebook::hermes::debugger::ProgramState &state) = 0; + + /// onResume fires when VM transitions from paused to running state. + virtual void onResume(Inspector &inspector) = 0; + + /// onScriptParsed fires when after the VM parses a script. + virtual void onScriptParsed(Inspector &inspector, const ScriptInfo &info) = 0; + + // onMessageAdded fires when new console message is added. + virtual void onMessageAdded( + Inspector &inspector, + const ConsoleMessageInfo &info) = 0; +}; + +/** + * Inspector implements a future-based interface over the low-level Hermes + * debugging API. + */ +class Inspector : public facebook::hermes::debugger::EventObserver, + public std::enable_shared_from_this { + public: + /** + * Inspector's constructor should be used to install the inspector on the + * provided runtime before any JS executes in the runtime. + */ + Inspector( + std::shared_ptr adapter, + InspectorObserver &observer, + bool pauseOnFirstStatement); + ~Inspector(); + + /** + * disable turns off the inspector. All of the subsequent methods will not do + * anything unless the inspector is enabled. + */ + folly::Future disable(); + + /** + * enable turns on the inspector. All of the subsequent methods will not do + * anything unless the inspector is enabled. The returned future succeeds when + * the debugger is enabled, or fails with AlreadyEnabledException if the + * debugger was already enabled. + */ + folly::Future enable(); + + /** + * installs console log handler. Ideally this should be done inside + * constructor, but because it uses shared_from_this we can't do this + * in constructor. + */ + void installLogHandler(); + + /** + * executeIfEnabled executes the provided callback *on the JS thread with the + * inspector lock held*. Execution can be implicitly requested while running. + * The inspector lock: + * + * 1) Protects VM state transitions. This means that the VM is guaranteed to + * stay in the paused or running state for the duration of the callback. + * 2) Protects InspectorObserver callbacks. This means that if some shared + * data is accessed only in InspectorObserver and executeIfEnabled + * callbacks, it does not need to be locked, since it's already protected + * by the inspector lock. + * + * The returned future resolves to true in the VM can be paused, or + * fails with IllegalStateException otherwise. The description is only used + * to populate the IllegalStateException with more useful info on failure. + */ + folly::Future executeIfEnabled( + const std::string &description, + folly::Function + func); + + /** + * setBreakpoint can be called at any time after the debugger is enabled to + * set a breakpoint in the VM. The future is fulfilled with the resolved + * breakpoint info. + * + * Resolving a breakpoint takes an indeterminate amount of time since Hermes + * only resolves breakpoints when the debugger is able to actively pause JS + * execution. + */ + folly::Future setBreakpoint( + facebook::hermes::debugger::SourceLocation loc, + folly::Optional condition = folly::none); + + folly::Future removeBreakpoint( + facebook::hermes::debugger::BreakpointID loc); + + /** + * logs console message. + */ + folly::Future logMessage(ConsoleMessageInfo info); + + /** + * resume and step methods are only valid when the VM is currently paused. The + * returned future suceeds when the VM resumes execution, or fails with an + * InvalidStateException otherwise. + */ + folly::Future resume(); + folly::Future stepIn(); + folly::Future stepOver(); + folly::Future stepOut(); + + /** + * pause can be issued at any time while the inspector is enabled. It requests + * the VM to asynchronously break execution. The returned future suceeds if + * the VM can be paused in this state and fails with InvalidStateException if + * otherwise. + */ + folly::Future pause(); + + /** + * evaluate runs JavaScript code within the context of a call frame. The + * returned promise is fulfilled with an eval result if it's possible to + * evaluate code in the current state or fails with InvalidStateException + * otherwise. + */ + folly::Future evaluate( + uint32_t frameIndex, + const std::string &src, + folly::Function + resultTransformer); + + folly::Future setPauseOnExceptions( + const facebook::hermes::debugger::PauseOnThrowMode &mode); + + /** + * didPause implements the pause callback from Hermes. This callback arrives + * on the JS thread. + */ + facebook::hermes::debugger::Command didPause( + facebook::hermes::debugger::Debugger &debugger) override; + + /** + * breakpointResolved implements the breakpointResolved callback from Hermes. + */ + void breakpointResolved( + facebook::hermes::debugger::Debugger &debugger, + facebook::hermes::debugger::BreakpointID breakpointId) override; + + private: + friend class InspectorState; + + void triggerAsyncPause(bool andTickle); + + void notifyContextCreated(); + + ScriptInfo getScriptInfoFromTopCallFrame(); + + void addCurrentScriptToLoadedScripts(); + void removeAllBreakpoints(); + void resetScriptsLoaded(); + void notifyScriptsLoaded(); + + folly::Future setPendingCommand(debugger::Command command); + + void transition(std::unique_ptr nextState); + + // All methods that end with OnExecutor run on executor_. + void disableOnExecutor(std::shared_ptr> promise); + + void enableOnExecutor(std::shared_ptr> promise); + + void executeIfEnabledOnExecutor( + const std::string &description, + folly::Function + func, + std::shared_ptr> promise); + + void setBreakpointOnExecutor( + debugger::SourceLocation loc, + folly::Optional condition, + std::shared_ptr< + folly::Promise> promise); + + void removeBreakpointOnExecutor( + debugger::BreakpointID breakpointId, + std::shared_ptr> promise); + + void logOnExecutor( + ConsoleMessageInfo info, + std::shared_ptr> promise); + + void setPendingCommandOnExecutor( + facebook::hermes::debugger::Command command, + std::shared_ptr> promise); + + void pauseOnExecutor(std::shared_ptr> promise); + + void evaluateOnExecutor( + uint32_t frameIndex, + const std::string &src, + std::shared_ptr> + promise, + folly::Function + resultTransformer); + + void setPauseOnExceptionsOnExecutor( + const facebook::hermes::debugger::PauseOnThrowMode &mode, + std::shared_ptr> promise); + + void installConsoleFunction( + jsi::Object &console, + const std::string &name, + const std::string &chromeType); + + std::shared_ptr adapter_; + facebook::hermes::debugger::Debugger &debugger_; + InspectorObserver &observer_; + + // All client methods (e.g. enable, setBreakpoint, resume, etc.) are executed + // on executor_ to prevent deadlocking on mutex_. See the implementation for + // more comments on the threading invariants used in this class. + std::unique_ptr executor_; + + // All of the following member variables are guarded by mutex_. + std::mutex mutex_; + std::unique_ptr state_; + + // See the InspectorState::Running implementation for an explanation for why + // this state is here rather than in the Running class. + AsyncPauseState pendingPauseState_ = AsyncPauseState::None; + + // All scripts loaded in to the VM, along with whether we've notified the + // client about the script yet. + struct LoadedScriptInfo { + ScriptInfo info; + bool notifiedClient; + }; + std::unordered_map loadedScripts_; +}; + +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/InspectorState.cpp b/ReactCommon/hermes/inspector/InspectorState.cpp new file mode 100644 index 00000000000..f8c977649f0 --- /dev/null +++ b/ReactCommon/hermes/inspector/InspectorState.cpp @@ -0,0 +1,476 @@ +#include "InspectorState.h" + +#include + +namespace facebook { +namespace hermes { +namespace inspector { + +using folly::Unit; + +namespace debugger = ::facebook::hermes::debugger; + +namespace { + +std::unique_ptr makeContinueCommand() { + return std::make_unique( + debugger::Command::continueExecution()); +} + +} // namespace + +std::ostream &operator<<(std::ostream &os, const InspectorState &state) { + return os << state.description(); +} + +/* + * InspectorState::RunningDetached + */ + +std::pair InspectorState::RunningDetached::didPause( + MonitorLock &lock) { + debugger::PauseReason reason = getPauseReason(); + + if (reason == debugger::PauseReason::DebuggerStatement) { + return std::make_pair( + InspectorState::PausedWaitEnable::make(inspector_), nullptr); + } + + if (reason == debugger::PauseReason::ScriptLoaded) { + inspector_.addCurrentScriptToLoadedScripts(); + } + + return std::make_pair( + nullptr, makeContinueCommand()); +} + +std::pair InspectorState::RunningDetached::enable() { + return std::make_pair( + InspectorState::Running::make(inspector_), true); +} + +/* + * InspectorState::RunningWaitEnable + */ + +std::pair InspectorState::RunningWaitEnable::didPause( + MonitorLock &lock) { + // If we started in RWE, then we asked for the VM to break on the first + // statement, and the first pause should be because of a script load. + assert(getPauseReason() == debugger::PauseReason::ScriptLoaded); + inspector_.addCurrentScriptToLoadedScripts(); + + return std::make_pair( + InspectorState::PausedWaitEnable::make(inspector_), nullptr); +} + +std::pair InspectorState::RunningWaitEnable::enable() { + return std::make_pair( + InspectorState::RunningWaitPause::make(inspector_), true); +} + +/* + * InspectorState::RunningWaitPause + */ +std::pair InspectorState::RunningWaitPause::didPause( + MonitorLock &lock) { + // If we are in RWP, then we asked for the VM to break on the first + // statement, and the first pause should be because of a script load. + assert(getPauseReason() == debugger::PauseReason::ScriptLoaded); + inspector_.addCurrentScriptToLoadedScripts(); + + return std::make_pair( + InspectorState::Paused::make(inspector_), nullptr); +} + +/* + * InspectorState::PausedWaitEnable + */ + +std::pair InspectorState::PausedWaitEnable::didPause( + MonitorLock &lock) { + if (getPauseReason() == debugger::PauseReason::ScriptLoaded) { + inspector_.addCurrentScriptToLoadedScripts(); + } + + while (!enabled_) { + /* + * The call to wait temporarily relinquishes the inspector mutex. This is + * safe because no other PausedWaitEnable event handler directly transitions + * out of PausedWaitEnable. So we know that our state is the active state + * both before and after the call to wait. This preserves the invariant that + * the inspector state is not modified during the execution of this method. + * + * Instead, PausedWaitEnable::enable indirectly induces the state transition + * out of PausedWaitEnable by signaling us via enabledCondition_. + */ + enabledCondition_.wait(lock); + + assert(inspector_.state_.get() == this); + } + + return std::make_pair( + InspectorState::Paused::make(inspector_), nullptr); +} + +std::pair InspectorState::PausedWaitEnable::enable() { + if (enabled_) { + // Someone already called enable before and we're just waiting for the + // condition variable to wake up didPause. + return std::make_pair(nullptr, false); + } + + enabled_ = true; + enabledCondition_.notify_one(); + return std::make_pair(nullptr, true); +} + +/* + * InspectorState::Running + * + * # Async Pauses + * + * We distinguish between implicit and explicit async pauses. An implicit async + * pause is requested by the inspector itself to service a request that requires + * the VM to be paused (e.g. to set a breakpoint). This is different from an + * explicit async pause requested by the user by hitting the pause button in the + * debugger UI. + * + * The async pause state must live in the Inspector class instead of the Running + * class because of potential races between when the implicit pause is requested + * and when it's serviced. Consider: + * + * 1. We request an implicit pause (e.g. to set a breakpoint). + * 2. An existing breakpoint fires, moving us from Running => Paused. + * 3. Client resumes execution, moving us from Paused => Running. + * 4. Now the debugger notices the async pause flag we set in (1), which pauses + * us again, causing Running::didPause to run. + * + * In this case, the Running state instance from (1) is no longer the same as + * the Running state instance in (4). But the running state instance in (4) + * needs to know that we requested the async break sometime in the past so it + * knows to automatically continue in the didPause callback. Therefore the async + * break state has to be stored in the long-lived Inspector class rather than in + * the short-lived Running class. + */ + +void InspectorState::Running::onEnter(InspectorState *prevState) { + if (prevState) { + if (prevState->isPaused()) { + inspector_.observer_.onResume(inspector_); + } else { + // send context created and script load notifications if we just enabled + // the debugger + inspector_.notifyContextCreated(); + inspector_.notifyScriptsLoaded(); + } + } +} + +void InspectorState::Running::detach( + std::shared_ptr> promise) { + pushPendingFunc([this, promise] { + pendingDetach_ = promise; + + inspector_.removeAllBreakpoints(); + inspector_.resetScriptsLoaded(); + }); +} + +std::pair InspectorState::Running::didPause( + MonitorLock &lock) { + debugger::PauseReason reason = getPauseReason(); + + for (auto &func : pendingFuncs_) { + func(); + } + pendingFuncs_.clear(); + + if (pendingDetach_) { + // Clear any pending pause state back to no requests for the next attach + inspector_.pendingPauseState_ = AsyncPauseState::None; + + // Ensure we fulfill any pending ScriptLoaded requests + if (reason == debugger::PauseReason::ScriptLoaded) { + inspector_.addCurrentScriptToLoadedScripts(); + } + + // Fail any in-flight Eval requests + if (pendingEvalPromise_) { + pendingEvalPromise_->setException(NotEnabledException("eval")); + } + + // if we requested the break implicitly to clear state and detach, + // transition to RunningDetached + pendingDetach_->setValue(); + + return std::make_pair( + InspectorState::RunningDetached::make(inspector_), + makeContinueCommand()); + } + + if (reason == debugger::PauseReason::AsyncTrigger) { + AsyncPauseState &pendingPauseState = inspector_.pendingPauseState_; + + switch (pendingPauseState) { + case AsyncPauseState::None: + // shouldn't ever async break without us asking first + assert(false); + break; + case AsyncPauseState::Implicit: + pendingPauseState = AsyncPauseState::None; + break; + case AsyncPauseState::Explicit: + // explicit break was requested by user, so go to Paused state + pendingPauseState = AsyncPauseState::None; + return std::make_pair( + InspectorState::Paused::make(inspector_), nullptr); + } + } else if (reason == debugger::PauseReason::ScriptLoaded) { + inspector_.addCurrentScriptToLoadedScripts(); + inspector_.notifyScriptsLoaded(); + } else if (reason == debugger::PauseReason::EvalComplete) { + assert(pendingEvalPromise_); + + pendingEvalResultTransformer_( + inspector_.debugger_.getProgramState().getEvalResult()); + pendingEvalPromise_->setValue( + inspector_.debugger_.getProgramState().getEvalResult()); + pendingEvalPromise_.reset(); + } else /* other cases imply a transition to Pause */ { + return std::make_pair( + InspectorState::Paused::make(inspector_), nullptr); + } + + if (!pendingEvals_.empty()) { + assert(!pendingEvalPromise_); + + auto eval = std::make_unique(std::move(pendingEvals_.front())); + pendingEvals_.pop(); + + pendingEvalPromise_ = eval->promise; + pendingEvalResultTransformer_ = std::move(eval->resultTransformer); + + return std::make_pair( + nullptr, std::make_unique(std::move(eval->command))); + } + + return std::make_pair( + nullptr, makeContinueCommand()); +} + +bool InspectorState::Running::pushPendingFunc(folly::Func func) { + pendingFuncs_.emplace_back(std::move(func)); + + if (inspector_.pendingPauseState_ == AsyncPauseState::None) { + inspector_.pendingPauseState_ = AsyncPauseState::Implicit; + inspector_.triggerAsyncPause(true); + } + + return true; +} + +void InspectorState::Running::pushPendingEval( + uint32_t frameIndex, + const std::string &src, + std::shared_ptr> promise, + folly::Function + resultTransformer) { + PendingEval pendingEval{debugger::Command::eval(src, frameIndex), + promise, + std::move(resultTransformer)}; + + pendingEvals_.emplace(std::move(pendingEval)); + + if (inspector_.pendingPauseState_ == AsyncPauseState::None) { + inspector_.pendingPauseState_ = AsyncPauseState::Implicit; + } + + inspector_.triggerAsyncPause(true); +} + +bool InspectorState::Running::pause() { + AsyncPauseState &pendingPauseState = inspector_.pendingPauseState_; + bool canPause = false; + + switch (pendingPauseState) { + case AsyncPauseState::None: + // haven't yet requested a pause, so do it now + inspector_.triggerAsyncPause(false); + pendingPauseState = AsyncPauseState::Explicit; + canPause = true; + break; + case AsyncPauseState::Implicit: + // already requested an implicit pause on our own, upgrade it to an + // explicit pause + pendingPauseState = AsyncPauseState::Explicit; + canPause = true; + break; + case AsyncPauseState::Explicit: + // client already requested a pause that hasn't occurred yet + canPause = false; + break; + } + + return canPause; +} + +/* + * InspectorState::Paused + */ + +void InspectorState::Paused::onEnter(InspectorState *prevState) { + // send script load notifications if we just enabled the debugger + if (prevState && !prevState->isRunning()) { + inspector_.notifyContextCreated(); + inspector_.notifyScriptsLoaded(); + } + + const debugger::ProgramState &state = inspector_.debugger_.getProgramState(); + inspector_.observer_.onPause(inspector_, state); +} + +std::pair InspectorState::Paused::didPause( + std::unique_lock &lock) { + switch (getPauseReason()) { + case debugger::PauseReason::AsyncTrigger: + inspector_.pendingPauseState_ = AsyncPauseState::None; + break; + case debugger::PauseReason::EvalComplete: { + assert(pendingEvalPromise_); + pendingEvalResultTransformer_( + inspector_.debugger_.getProgramState().getEvalResult()); + pendingEvalPromise_->setValue( + inspector_.debugger_.getProgramState().getEvalResult()); + pendingEvalPromise_.reset(); + } break; + case debugger::PauseReason::ScriptLoaded: + inspector_.addCurrentScriptToLoadedScripts(); + inspector_.notifyScriptsLoaded(); + break; + default: + break; + } + + std::unique_ptr eval; + std::unique_ptr resumeOrStep; + + while (!eval && !resumeOrStep && !pendingDetach_) { + { + while (!pendingCommand_ && pendingEvals_.empty() && + pendingFuncs_.empty()) { + /* + * The call to wait temporarily relinquishes the inspector mutex. This + * is safe because no other Paused event handler directly transitions + * out of Paused. So we know that our state is the active state both + * before and after the call to wait. This preserves the invariant that + * the inspector state is not modified during the execution of this + * method. + */ + hasPendingWork_.wait(lock); + } + + assert(inspector_.state_.get() == this); + } + + if (!pendingEvals_.empty()) { + eval = std::make_unique(std::move(pendingEvals_.front())); + pendingEvals_.pop(); + } else if (pendingCommand_) { + resumeOrStep.swap(pendingCommand_); + } + + for (auto &func : pendingFuncs_) { + func(); + } + pendingFuncs_.clear(); + } + + if (pendingDetach_) { + if (pendingEvalPromise_) { + pendingEvalPromise_->setException(NotEnabledException("eval")); + } + + if (resumeOrStep) { + resumeOrStep->promise->setValue(); + } + + pendingDetach_->setValue(); + + // Send resume so client-side UI doesn't stay stuck at the breakpoint UI + inspector_.observer_.onResume(inspector_); + + return std::make_pair( + InspectorState::RunningDetached::make(inspector_), + makeContinueCommand()); + } + + if (eval) { + assert(!pendingEvalPromise_); + pendingEvalPromise_ = eval->promise; + pendingEvalResultTransformer_ = std::move(eval->resultTransformer); + + return std::make_pair( + nullptr, std::make_unique(std::move(eval->command))); + } + + assert(resumeOrStep); + resumeOrStep->promise->setValue(); + + return std::make_pair( + InspectorState::Running::make(inspector_), + std::make_unique(std::move(resumeOrStep->command))); +} + +void InspectorState::Paused::detach( + std::shared_ptr> promise) { + pushPendingFunc([this, promise] { + pendingDetach_ = promise; + + inspector_.removeAllBreakpoints(); + inspector_.resetScriptsLoaded(); + }); +} + +bool InspectorState::Paused::pushPendingFunc(folly::Func func) { + pendingFuncs_.emplace_back(std::move(func)); + hasPendingWork_.notify_one(); + + return true; +} + +void InspectorState::Paused::pushPendingEval( + uint32_t frameIndex, + const std::string &src, + std::shared_ptr> promise, + folly::Function + resultTransformer) { + // Shouldn't allow the client to eval if there's already a pending resume/step + if (pendingCommand_) { + promise->setException(MultipleCommandsPendingException("eval")); + return; + } + + PendingEval pendingEval{debugger::Command::eval(src, frameIndex), + promise, + std::move(resultTransformer)}; + pendingEvals_.emplace(std::move(pendingEval)); + hasPendingWork_.notify_one(); +} + +void InspectorState::Paused::setPendingCommand( + debugger::Command command, + std::shared_ptr> promise) { + if (pendingCommand_) { + promise->setException(MultipleCommandsPendingException("cmd")); + return; + } + + pendingCommand_ = + std::make_unique(std::move(command), promise); + hasPendingWork_.notify_one(); +} + +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/InspectorState.h b/ReactCommon/hermes/inspector/InspectorState.h new file mode 100644 index 00000000000..f2702db92e1 --- /dev/null +++ b/ReactCommon/hermes/inspector/InspectorState.h @@ -0,0 +1,400 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { + +using NextStatePtr = std::unique_ptr; +using CommandPtr = std::unique_ptr; +using MonitorLock = std::unique_lock; + +/** + * InspectorState encapsulates a single state in the Inspector FSM. Events in + * the FSM are modeled as methods in InspectorState. + * + * Some events may cause state transitions. The next state is returned via a + * pointer to the next InspectorState. + * + * We assume that the Inspector's mutex is held across all calls to + * InspectorState methods. For more threading notes, see the Inspector + * implementation. + */ +class InspectorState { + public: + InspectorState(Inspector &inspector) : inspector_(inspector) {} + virtual ~InspectorState() = default; + /** + * onEnter is called when entering the state. prevState may be null when + * transitioning into an initial state. + */ + virtual void onEnter(InspectorState *prevState) {} + + /* + * Events that may cause a state transition. + */ + + /** + * detach clears all debuger state and transitions to RunningDetached. + */ + virtual void detach(std::shared_ptr> promise) { + // As we're not attached we'd like for the operation to be idempotent + promise->setValue(); + } + + /** + * didPause handles the didPause callback from the debugger. It takes the lock + * associated with the Inspector's mutex by reference in case we need to + * temporarily relinquish the lock (e.g. via condition_variable::wait). + */ + virtual std::pair didPause(MonitorLock &lock) = 0; + + /** + * enable handles the enable event from the client. + */ + virtual std::pair enable() { + return std::make_pair(nullptr, false); + } + + /* + * Events that don't cause a state transition. + */ + + /** + * pushPendingFunc appends a function to run the next time the debugger + * pauses, either explicitly while paused or implicitly while running. + * Returns false if it's not possible to push a func in this state. + */ + virtual bool pushPendingFunc(folly::Func func) { + return false; + } + + /** + * pushPendingEval appends an eval request to run the next time the debugger + * pauses, either explicitly while paused or implicitly while running. + * resultTransformer function will be called with EvalResult before returning + * result so that we can manipulate EvalResult while the VM is paused. + */ + virtual void pushPendingEval( + uint32_t frameIndex, + const std::string &src, + std::shared_ptr> + promise, + folly::Function + resultTransformer) { + promise->setException( + InvalidStateException("eval", description(), "paused or running")); + } + + /** + * setPendingCommand sets a command to break the debugger out of the didPause + * run loop. If it's not possible to set a pending command in this state, the + * promise fails with InvalidStateException. Otherwise, the promise resolves + * to true when the command actually executes. + */ + virtual void setPendingCommand( + debugger::Command command, + std::shared_ptr> promise) { + promise->setException( + InvalidStateException("cmd", description(), "paused")); + } + + /** + * pause requests an async pause from the VM. + */ + virtual bool pause() { + return false; + } + + /* + * Convenience functions for determining the concrete type and description + * for a state instance without RTTI. + */ + + virtual bool isRunningDetached() const { + return false; + } + virtual bool isRunningWaitEnable() const { + return false; + } + virtual bool isRunningWaitPause() const { + return false; + } + virtual bool isPausedWaitEnable() const { + return false; + } + virtual bool isRunning() const { + return false; + } + virtual bool isPaused() const { + return false; + } + + virtual const char *description() const = 0; + friend std::ostream &operator<<( + std::ostream &os, + const InspectorState &state); + + class RunningDetached; + class RunningWaitEnable; + class RunningWaitPause; + class PausedWaitEnable; + class Running; + class Paused; + + protected: + debugger::PauseReason getPauseReason() { + return inspector_.debugger_.getProgramState().getPauseReason(); + } + + private: + Inspector &inspector_; +}; + +extern std::ostream &operator<<(std::ostream &os, const InspectorState &state); + +/** + * RunningDetached is the initial state when we're associated with a VM that + * initially has no breakpoints. + */ +class InspectorState::RunningDetached : public InspectorState { + public: + static std::unique_ptr make(Inspector &inspector) { + return std::make_unique(inspector); + } + + RunningDetached(Inspector &inspector) : InspectorState(inspector) {} + ~RunningDetached() {} + + std::pair didPause(MonitorLock &lock) override; + std::pair enable() override; + + bool isRunningDetached() const override { + return true; + } + + const char *description() const override { + return "RunningDetached"; + } +}; + +/** + * RunningWaitEnable is the initial state when we're associated with a VM that + * has a breakpoint on the first statement. + */ +class InspectorState::RunningWaitEnable : public InspectorState { + public: + static std::unique_ptr make(Inspector &inspector) { + return std::make_unique(inspector); + } + + RunningWaitEnable(Inspector &inspector) : InspectorState(inspector) {} + ~RunningWaitEnable() {} + + std::pair didPause(MonitorLock &lock) override; + std::pair enable() override; + + bool isRunningWaitEnable() const override { + return true; + } + + const char *description() const override { + return "RunningWaitEnable"; + } +}; + +/** + * RunningWaitPause is the state when we've received enable call, but + * waiting for didPause because we need to pause on the first statement. + */ +class InspectorState::RunningWaitPause : public InspectorState { + public: + static std::unique_ptr make(Inspector &inspector) { + return std::make_unique(inspector); + } + + std::pair didPause(MonitorLock &lock) override; + + RunningWaitPause(Inspector &inspector) : InspectorState(inspector) {} + ~RunningWaitPause() {} + + bool isRunningWaitPause() const override { + return true; + } + + const char *description() const override { + return "RunningWaitPause"; + } +}; + +/** + * PausedWaitEnable is the state when we're in a didPause callback and we're + * waiting for the client to call enable. + */ +class InspectorState::PausedWaitEnable : public InspectorState { + public: + static std::unique_ptr make(Inspector &inspector) { + return std::make_unique(inspector); + } + + PausedWaitEnable(Inspector &inspector) : InspectorState(inspector) {} + ~PausedWaitEnable() {} + + std::pair didPause(MonitorLock &lock) override; + std::pair enable() override; + + bool isPausedWaitEnable() const override { + return true; + } + + const char *description() const override { + return "PausedWaitEnable"; + } + + private: + bool enabled_ = false; + std::condition_variable enabledCondition_; +}; + +/** + * PendingEval holds an eval command and a promise that is fulfilled with the + * eval result. + */ +struct PendingEval { + debugger::Command command; + std::shared_ptr> + promise; + folly::Function + resultTransformer; +}; + +/** + * Running is the state when we're enabled and not currently paused, e.g. when + * we're actively executing JS. + * + * Note that we can be in the running state even if we're not actively running + * JS. For instance, React Native could be blocked in a native message queue + * waiting for the next message to process outside of the call in to Hermes. + * That still counts as Running in this FSM. + */ +class InspectorState::Running : public InspectorState { + public: + static std::unique_ptr make(Inspector &inspector) { + return std::make_unique(inspector); + } + + Running(Inspector &inspector) : InspectorState(inspector) {} + ~Running() {} + + void onEnter(InspectorState *prevState) override; + + void detach(std::shared_ptr> promise) override; + + std::pair didPause(MonitorLock &lock) override; + bool pushPendingFunc(folly::Func func) override; + void pushPendingEval( + uint32_t frameIndex, + const std::string &src, + std::shared_ptr> + promise, + folly::Function + resultTransformer) override; + bool pause() override; + + bool isRunning() const override { + return true; + } + + const char *description() const override { + return "Running"; + } + + private: + std::vector pendingFuncs_; + std::queue pendingEvals_; + std::shared_ptr> + pendingEvalPromise_; + folly::Function + pendingEvalResultTransformer_; + std::shared_ptr> pendingDetach_; +}; + +/** + * PendingCommand holds a resume or step command and a promise that is fulfilled + * just before the debugger resumes or steps. + */ +struct PendingCommand { + PendingCommand( + debugger::Command command, + std::shared_ptr> promise) + : command(std::move(command)), promise(promise) {} + + debugger::Command command; + std::shared_ptr> promise; +}; + +/** + * Paused is the state when we're enabled and and currently in a didPause + * callback. + */ +class InspectorState::Paused : public InspectorState { + public: + static std::unique_ptr make(Inspector &inspector) { + return std::make_unique(inspector); + } + + Paused(Inspector &inspector) : InspectorState(inspector) {} + ~Paused() {} + + void onEnter(InspectorState *prevState) override; + + void detach(std::shared_ptr> promise) override; + + std::pair didPause(MonitorLock &lock) override; + bool pushPendingFunc(folly::Func func) override; + void pushPendingEval( + uint32_t frameIndex, + const std::string &src, + std::shared_ptr> + promise, + folly::Function + resultTransformer) override; + void setPendingCommand( + debugger::Command command, + std::shared_ptr> promise) override; + + bool isPaused() const override { + return true; + } + + const char *description() const override { + return "Paused"; + } + + private: + std::condition_variable hasPendingWork_; + std::vector pendingFuncs_; + std::queue pendingEvals_; + std::shared_ptr> + pendingEvalPromise_; + folly::Function + pendingEvalResultTransformer_; + std::unique_ptr pendingCommand_; + std::shared_ptr> pendingDetach_; +}; + +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/README.md b/ReactCommon/hermes/inspector/README.md new file mode 100644 index 00000000000..d889de740b8 --- /dev/null +++ b/ReactCommon/hermes/inspector/README.md @@ -0,0 +1,113 @@ +hermes-inspector provides a bridge between the low-level debugging API exposed +by Hermes and higher-level debugging protocols such as the Chrome DevTools +protocol. + +# Targets + + - chrome: classes that implement the Chrome DevTools Protocol adapter. Sits on + top of classes provided by the inspector target. + - detail: utility classes and functions + - inspector: protocol-independent classes that sit on top of the low-level + Hermes debugging API. + +# Testing + +Tests are implemented using gtest. Debug logging is enabled for tests, and you +can get debug logs to show even when tests are passing by running the test +executable directly: + +``` +$ buck build fbsource//xplat/hermes-inspector:chrome-tests +$ buck-out/gen/hermes-inspector/chrome-tests +[...] +``` + +You can use standard gtest filters to only execute a particular set of tests: + +``` +$ buck-out/gen/hermes-inspector/chrome-tests \ + --gtest_filter='ConnectionTests.testSetBreakpoint' +``` + +You can debug the tests using lldb or gdb: + +``` +$ lldb buck-out/gen/hermes-inspector/chrome-tests +$ gdb buck-out/gen/hermes-inspector/chrome-tests +``` + +# Formatting + +Make sure the code is formatted using the hermes clang-format rules before +committing: + +``` +$ xplat/hermes-inspector/tools/format +``` + +We follow the clang format rules used by the rest of the Hermes project. + +# Adding Support For New Message Types + +To add support for a new Chrome DevTools protocol message, add the message you +want to add to tools/message_types.txt, and re-run the message types generator: + +``` +$ xplat/hermes-inspector/tools/run_msggen +``` + +This will generate C++ structs for the new message type in +`chrome/MessageTypes.{h,cpp}`. + +You'll then need to: + +1. Implement a message handler for the new message type in `chrome::Connection`. +2. Implement a public API for the new message type in `Inspector`. This will + most likely return a `folly::Future` that the message handler in (1) can use + for chaining. +3. Implement a private API for the new message type in `Inspector` that performs + the logic in Inspector's executor. (Inspector.cpp contains a comment + explaining why the executor is necessary.) +4. Optionally, implement a method for the new message type in `InspectorState`. + In most cases this is probably not necessary--one of the existing methods in + `InspectorState` will work. + +For a diff that illustrates these steps, take a look at D6601459. + +# Testing Integration With Nuclide and Apps + +For now, the quickest way to use hermes-inspector in an app is with Eats. First, +make sure the packager is running: + +``` +$ js1 run +``` + +Then, on Android, build the fbeats target: + +``` +$ buck install --run fbeats +``` + +On iOS, build the `//Apps/Internal/Eats:Eats` target: + +``` +$ buck install --run //Apps/Internal/Eats:Eats +``` + +You can also build `Eats` in Xcode using `arc focus` if you prefer an +IDE: + +``` +$ arc focus --force-build \ + -b //Apps/Internal/Eats:Eats \ + cxxreact fbsource//xplat/hermes/API:HermesAPI fbsource//xplat/hermes/lib/VM:VM jsi \ + jsinspector hermes-inspector FBReactKit FBReactModule FBCatalystWrapper \ + fbsource//xplat/js:React fbsource//xplat/js/react-native-github:ReactInternal +``` + +For all the above commands, if you want to build the inspector `-O0` for better +debug info, add the argument `--config hermes.build_mode=dbg`. + +You should then be able to launch the app and see it listed in the list of +Mobile JS contexts in the Nuclide debugger. diff --git a/ReactCommon/hermes/inspector/RuntimeAdapter.cpp b/ReactCommon/hermes/inspector/RuntimeAdapter.cpp new file mode 100644 index 00000000000..ca98d98ad88 --- /dev/null +++ b/ReactCommon/hermes/inspector/RuntimeAdapter.cpp @@ -0,0 +1,25 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "RuntimeAdapter.h" + +namespace facebook { +namespace hermes { +namespace inspector { + +RuntimeAdapter::~RuntimeAdapter() = default; + +void RuntimeAdapter::tickleJs() {} + +SharedRuntimeAdapter::SharedRuntimeAdapter( + std::shared_ptr runtime) + : runtime_(std::move(runtime)) {} + +SharedRuntimeAdapter::~SharedRuntimeAdapter() = default; + +HermesRuntime &SharedRuntimeAdapter::getRuntime() { + return *runtime_; +} + +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/RuntimeAdapter.h b/ReactCommon/hermes/inspector/RuntimeAdapter.h new file mode 100644 index 00000000000..5ad5ba845d5 --- /dev/null +++ b/ReactCommon/hermes/inspector/RuntimeAdapter.h @@ -0,0 +1,59 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include + +#include + +namespace facebook { +namespace hermes { +namespace inspector { + +/** + * RuntimeAdapter encapsulates a HermesRuntime object. The underlying Hermes + * runtime object should stay alive for at least as long as the RuntimeAdapter + * is alive. + */ +class RuntimeAdapter { + public: + virtual ~RuntimeAdapter() = 0; + + /// getRuntime should return the Hermes runtime encapsulated by this adapter. + virtual HermesRuntime &getRuntime() = 0; + + /// tickleJs is a method that subclasses can choose to override to make the + /// inspector more responsive. If overridden, it should call the "__tickleJs" + /// function. The call should occur with appropriate locking (e.g. via a + /// thread-safe runtime instance, or by enqueuing the call on to a dedicated + /// JS thread). + /// + /// This makes the inspector more responsive because it gives the inspector + /// the ability to force the process to enter the Hermes interpreter loop + /// soon. This is important because the inspector can only do a number of + /// important operations (like manipulating breakpoints) within the context of + /// a Hermes interperter loop. + /// + /// The default implementation does nothing. + virtual void tickleJs(); +}; + +/** + * SharedRuntimeAdapter is a simple implementation of RuntimeAdapter that + * uses shared_ptr to hold on to the runtime. It's generally only used in tests, + * since it does not implement tickleJs. + */ +class SharedRuntimeAdapter : public RuntimeAdapter { + public: + SharedRuntimeAdapter(std::shared_ptr runtime); + virtual ~SharedRuntimeAdapter(); + + HermesRuntime &getRuntime() override; + + private: + std::shared_ptr runtime_; +}; + +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/AutoAttachUtils.cpp b/ReactCommon/hermes/inspector/chrome/AutoAttachUtils.cpp new file mode 100644 index 00000000000..ee4b1d9bc30 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/AutoAttachUtils.cpp @@ -0,0 +1,127 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "AutoAttachUtils.h" + +#include +#include +#include + +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +// The following code is copied from +// https://phabricator.intern.facebook.com/diffusion/FBS/browse/master/xplat/js/react-native-github/ReactCommon/cxxreact/JSCExecutor.cpp;431c4d01b7072d9a1a52f8bd6c6ba2ff3e47e25d$250 +bool isNetworkInspected( + const std::string &owner, + const std::string &app, + const std::string &device) { + auto connect_socket = [](int socket_desc, std::string address, int port) { + if (socket_desc < 0) { + close(socket_desc); + return false; + } + + struct timeval tv; + tv.tv_sec = 1; + tv.tv_usec = 0; + auto sock_opt_rcv_resp = setsockopt( + socket_desc, + SOL_SOCKET, + SO_RCVTIMEO, + (const char *)&tv, + sizeof(struct timeval)); + if (sock_opt_rcv_resp < 0) { + close(socket_desc); + return false; + } + + auto sock_opt_snd_resp = setsockopt( + socket_desc, + SOL_SOCKET, + SO_SNDTIMEO, + (const char *)&tv, + sizeof(struct timeval)); + if (sock_opt_snd_resp < 0) { + close(socket_desc); + return false; + } + + struct sockaddr_in server; + server.sin_addr.s_addr = inet_addr(address.c_str()); + server.sin_family = AF_INET; + server.sin_port = htons(port); + auto connect_resp = + ::connect(socket_desc, (struct sockaddr *)&server, sizeof(server)); + if (connect_resp < 0) { + ::close(socket_desc); + return false; + } + + return true; + }; + + int socket_desc = socket(AF_INET, SOCK_STREAM, 0); + + if (!connect_socket(socket_desc, "127.0.0.1", 8082)) { +#if defined(__ANDROID__) + socket_desc = socket(AF_INET, SOCK_STREAM, 0); + if (!connect_socket(socket_desc, "10.0.2.2", 8082) /* emulator */) { + socket_desc = socket(AF_INET, SOCK_STREAM, 0); + if (!connect_socket(socket_desc, "10.0.3.2", 8082) /* genymotion */) { + return false; + } + } +#else //! defined(__ANDROID__) + return false; +#endif // defined(__ANDROID__) + } + + std::string escapedOwner = + folly::uriEscape(owner, folly::UriEscapeMode::QUERY); + std::string escapedApp = + folly::uriEscape(app, folly::UriEscapeMode::QUERY); + std::string escapedDevice = + folly::uriEscape(device, folly::UriEscapeMode::QUERY); + std::string msg = folly::to( + "GET /autoattach?title=", + escapedOwner, + "&app=", + escapedApp, + "&device=", + escapedDevice, + " HTTP/1.1\r\n\r\n"); + auto send_resp = ::send(socket_desc, msg.c_str(), msg.length(), 0); + if (send_resp < 0) { + close(socket_desc); + return false; + } + + char server_reply[200]; + server_reply[199] = '\0'; + auto recv_resp = + ::recv(socket_desc, server_reply, sizeof(server_reply) - 1, 0); + if (recv_resp < 0) { + close(socket_desc); + return false; + } + + std::string response(server_reply); + if (response.size() < 25) { + close(socket_desc); + return false; + } + auto responseCandidate = response.substr(response.size() - 25); + auto found = + responseCandidate.find("{\"autoattach\":true}") != std::string::npos; + close(socket_desc); + return found; +} + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/AutoAttachUtils.h b/ReactCommon/hermes/inspector/chrome/AutoAttachUtils.h new file mode 100644 index 00000000000..39ec60520b0 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/AutoAttachUtils.h @@ -0,0 +1,19 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +bool isNetworkInspected( + const std::string &owner, + const std::string &app, + const std::string &device); +} +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/Connection.cpp b/ReactCommon/hermes/inspector/chrome/Connection.cpp new file mode 100644 index 00000000000..279f948f64c --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/Connection.cpp @@ -0,0 +1,668 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "Connection.h" + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +using ::facebook::react::ILocalConnection; +using ::facebook::react::IRemoteConnection; +using ::folly::Unit; + +namespace debugger = ::facebook::hermes::debugger; +namespace inspector = ::facebook::hermes::inspector; +namespace m = ::facebook::hermes::inspector::chrome::message; + +/* + * Connection::Impl + */ + +class Connection::Impl : public inspector::InspectorObserver, + public message::RequestHandler { + public: + Impl( + std::unique_ptr adapter, + const std::string &title, + bool waitForDebugger); + ~Impl(); + + HermesRuntime &getRuntime(); + std::string getTitle() const; + + bool connect(std::unique_ptr remoteConn); + bool disconnect(); + void sendMessage(std::string str); + + /* InspectorObserver overrides */ + void onBreakpointResolved( + Inspector &inspector, + const debugger::BreakpointInfo &info) override; + void onContextCreated(Inspector &inspector) override; + void onPause(Inspector &inspector, const debugger::ProgramState &state) + override; + void onResume(Inspector &inspector) override; + void onScriptParsed(Inspector &inspector, const ScriptInfo &info) override; + void onMessageAdded(Inspector &inspector, const ConsoleMessageInfo &info) + override; + + /* RequestHandler overrides */ + void handle(const m::UnknownRequest &req) override; + void handle(const m::debugger::DisableRequest &req) override; + void handle(const m::debugger::EnableRequest &req) override; + void handle(const m::debugger::EvaluateOnCallFrameRequest &req) override; + void handle(const m::debugger::PauseRequest &req) override; + void handle(const m::debugger::RemoveBreakpointRequest &req) override; + void handle(const m::debugger::ResumeRequest &req) override; + void handle(const m::debugger::SetBreakpointByUrlRequest &req) override; + void handle(const m::debugger::SetPauseOnExceptionsRequest &req) override; + void handle(const m::debugger::StepIntoRequest &req) override; + void handle(const m::debugger::StepOutRequest &req) override; + void handle(const m::debugger::StepOverRequest &req) override; + void handle(const m::runtime::EvaluateRequest &req) override; + void handle(const m::runtime::GetPropertiesRequest &req) override; + + private: + std::vector makePropsFromScope( + std::pair frameAndScopeIndex, + const std::string &objectGroup, + const debugger::ProgramState &state); + std::vector makePropsFromValue( + const jsi::Value &value, + const std::string &objectGroup, + bool onlyOwnProperties); + + void sendToClient(const std::string &str); + void sendResponseToClient(const m::Response &resp); + folly::Function sendErrorToClient(int id); + void sendResponseToClientViaExecutor(int id); + void sendResponseToClientViaExecutor(folly::Future future, int id); + void sendNotificationToClientViaExecutor(const m::Notification ¬e); + + std::shared_ptr runtimeAdapter_; + std::string title_; + + // connected_ is protected by connectionMutex_. + std::mutex connectionMutex_; + bool connected_; + + // parsedScripts_ list stores file names of all scripts that have been + // parsed so that we could find script's file name by regex. + // This is similar to Inspector's loadedScripts_ map but we want to + // store this info here because searching file name that matches + // given regex (on setBreakpointByUrl command) is more related to Chrome + // protocol than to Hermes inspector. + // Access is protected by parsedScriptsMutex_. + std::mutex parsedScriptsMutex_; + std::vector parsedScripts_; + + // The rest of these member variables are only accessed via executor_. + std::unique_ptr executor_; + std::unique_ptr remoteConn_; + std::shared_ptr inspector_; + + // objTable_ is protected by the inspector lock. It should only be accessed + // when the VM is paused, e.g. in an InspectorObserver callback or in an + // executeIfEnabled callback. + RemoteObjectsTable objTable_; +}; + +Connection::Impl::Impl( + std::unique_ptr adapter, + const std::string &title, + bool waitForDebugger) + : runtimeAdapter_(std::move(adapter)), + title_(title), + connected_(false), + executor_(std::make_unique( + "hermes-chrome-inspector-conn")), + remoteConn_(nullptr), + inspector_(std::make_shared( + runtimeAdapter_, + *this, + waitForDebugger)) { + inspector_->installLogHandler(); +} + +Connection::Impl::~Impl() = default; + +HermesRuntime &Connection::Impl::getRuntime() { + return runtimeAdapter_->getRuntime(); +} + +std::string Connection::Impl::getTitle() const { + return title_; +} + +bool Connection::Impl::connect(std::unique_ptr remoteConn) { + assert(remoteConn); + std::lock_guard lock(connectionMutex_); + + if (connected_) { + return false; + } + + connected_ = true; + executor_->add([this, remoteConn = std::move(remoteConn)]() mutable { + remoteConn_ = std::move(remoteConn); + }); + + return true; +} + +bool Connection::Impl::disconnect() { + std::lock_guard lock(connectionMutex_); + + if (!connected_) { + return false; + } + + connected_ = false; + + inspector_->disable().via(executor_.get()).thenValue([this](auto &&) { + // HACK: We purposely call RemoteConnection::onDisconnect on a *different* + // rather than on this thread (the executor thread). This is to prevent this + // scenario: + // + // 1. RemoteConnection::onDisconnect runs on the executor thread + // 2. onDisconnect through a long chain of calls causes the Connection + // destructor to run + // 3. The Connection destructor causes the SerialExecutor destructor to run. + // 4. The SerialExecutor destructor waits for all outstanding work items to + // finish via a call to join(). + // 5. join() fails, since the executor thread is trying to join against + // itself. + // + // To prevent this chain of events, we always call onDisconnect on a + // different thread. + // + // See P59135203 for an example stack trace. + // + // One more hack: we use release() and delete instead of unique_ptr because + // detail::Thread expects a std::function, and std::function cannot capture + // move-only types like unique_ptr. + auto conn = remoteConn_.release(); + inspector::detail::Thread disconnectLaterThread{ + "hermes-chrome-inspector-conn-disconnect", [conn] { + conn->onDisconnect(); + delete conn; + }}; + disconnectLaterThread.detach(); + }); + + return true; +} + +void Connection::Impl::sendMessage(std::string str) { + executor_->add([this, str = std::move(str)]() mutable { + folly::Try> maybeReq = + m::Request::fromJson(str); + + if (maybeReq.hasException()) { + LOG(ERROR) << "Invalid request `" << str + << "`: " << maybeReq.exception().what(); + return; + } + + auto &req = maybeReq.value(); + if (req) { + req->accept(*this); + } + }); +} + +/* + * InspectorObserver overrides + */ + +void Connection::Impl::onBreakpointResolved( + Inspector &inspector, + const debugger::BreakpointInfo &info) { + m::debugger::BreakpointResolvedNotification note; + note.breakpointId = folly::to(info.id); + note.location = m::debugger::makeLocation(info.resolvedLocation); + sendNotificationToClientViaExecutor(note); +} + +void Connection::Impl::onContextCreated(Inspector &inspector) { + // Right now, Hermes only has the notion of one JS context per VM instance, + // so we just always name the single JS context with id=1 and name=hermes. + m::runtime::ExecutionContextCreatedNotification note; + note.context.id = 1; + note.context.name = "hermes"; + + // isDefault and isPageContext are custom properties that the legacy RN to + // JSC adapter set for some unknown reason. + note.context.isDefault = true; + note.context.isPageContext = true; + + sendNotificationToClientViaExecutor(note); +} + +void Connection::Impl::onPause( + Inspector &inspector, + const debugger::ProgramState &state) { + m::debugger::PausedNotification note; + note.callFrames = m::debugger::makeCallFrames(state, objTable_, getRuntime()); + + switch (state.getPauseReason()) { + case debugger::PauseReason::Breakpoint: + // use other, chrome protocol has no reason specifically for breakpoints + note.reason = "other"; + +// TODO: hermes hasn't implemented ProgramState::getBreakpoint yet +#if HERMES_SUPPORTS_STATE_GET_BREAKPOINT + note.hitBreakpoints = std::vector(); + note.hitBreakpoints->emplace_back( + folly::to(state.getBreakpoint())); +#endif + + break; + case debugger::PauseReason::Exception: + note.reason = "exception"; + break; + default: + note.reason = "other"; + break; + } + + sendNotificationToClientViaExecutor(note); +} + +void Connection::Impl::onResume(Inspector &inspector) { + objTable_.releaseObjectGroup(BacktraceObjectGroup); + + m::debugger::ResumedNotification note; + sendNotificationToClientViaExecutor(note); +} + +void Connection::Impl::onScriptParsed( + Inspector &inspector, + const ScriptInfo &info) { + m::debugger::ScriptParsedNotification note; + note.scriptId = folly::to(info.fileId); + note.url = info.fileName; + + if (!info.sourceMappingUrl.empty()) { + note.sourceMapURL = info.sourceMappingUrl; + } + + { + std::lock_guard lock(parsedScriptsMutex_); + parsedScripts_.push_back(info.fileName); + } + + sendNotificationToClientViaExecutor(note); +} + +void Connection::Impl::onMessageAdded( + facebook::hermes::inspector::Inspector &inspector, + const ConsoleMessageInfo &info) { + m::runtime::ConsoleAPICalledNotification apiCalledNote; + apiCalledNote.type = info.level; + + size_t argsSize = info.args.size(getRuntime()); + for (size_t index = 0; index < argsSize; ++index) { + apiCalledNote.args.push_back(m::runtime::makeRemoteObject( + getRuntime(), + info.args.getValueAtIndex(getRuntime(), index), + objTable_, + "ConsoleObjectGroup")); + } + + sendNotificationToClientViaExecutor(apiCalledNote); +} + +/* + * RequestHandler overrides + */ + +void Connection::Impl::handle(const m::UnknownRequest &req) { + LOG(INFO) << "responding ok to unknown request: " << req.toDynamic(); + sendResponseToClientViaExecutor(req.id); +} + +void Connection::Impl::handle(const m::debugger::DisableRequest &req) { + sendResponseToClientViaExecutor(inspector_->disable(), req.id); +} + +void Connection::Impl::handle(const m::debugger::EnableRequest &req) { + sendResponseToClientViaExecutor(inspector_->enable(), req.id); +} + +void Connection::Impl::handle( + const m::debugger::EvaluateOnCallFrameRequest &req) { + auto remoteObjPtr = std::make_shared(); + + inspector_ + ->evaluate( + atoi(req.callFrameId.c_str()), + req.expression, + [this, remoteObjPtr, objectGroup = req.objectGroup]( + const facebook::hermes::debugger::EvalResult + &evalResult) mutable { + *remoteObjPtr = m::runtime::makeRemoteObject( + getRuntime(), + evalResult.value, + objTable_, + objectGroup.value_or("")); + }) + .via(executor_.get()) + .thenValue( + [this, id = req.id, remoteObjPtr](debugger::EvalResult result) { + m::debugger::EvaluateOnCallFrameResponse resp; + resp.id = id; + + if (result.isException) { + resp.exceptionDetails = + m::runtime::makeExceptionDetails(result.exceptionDetails); + } else { + resp.result = *remoteObjPtr; + } + + sendResponseToClient(resp); + }) + .thenError(sendErrorToClient(req.id)); +} + +void Connection::Impl::handle(const m::runtime::EvaluateRequest &req) { + auto remoteObjPtr = std::make_shared(); + + inspector_ + ->evaluate( + 0, // Top of the stackframe + req.expression, + [this, remoteObjPtr, objectGroup = req.objectGroup]( + const facebook::hermes::debugger::EvalResult + &evalResult) mutable { + *remoteObjPtr = m::runtime::makeRemoteObject( + getRuntime(), + evalResult.value, + objTable_, + objectGroup.value_or("ConsoleObjectGroup")); + }) + .via(executor_.get()) + .thenValue( + [this, id = req.id, remoteObjPtr](debugger::EvalResult result) { + m::debugger::EvaluateOnCallFrameResponse resp; + resp.id = id; + + if (result.isException) { + resp.exceptionDetails = + m::runtime::makeExceptionDetails(result.exceptionDetails); + } else { + resp.result = *remoteObjPtr; + } + + sendResponseToClient(resp); + }) + .thenError(sendErrorToClient(req.id)); +} + +void Connection::Impl::handle(const m::debugger::PauseRequest &req) { + sendResponseToClientViaExecutor(inspector_->pause(), req.id); +} + +void Connection::Impl::handle(const m::debugger::RemoveBreakpointRequest &req) { + auto breakpointId = folly::to(req.breakpointId); + sendResponseToClientViaExecutor( + inspector_->removeBreakpoint(breakpointId), req.id); +} + +void Connection::Impl::handle(const m::debugger::ResumeRequest &req) { + sendResponseToClientViaExecutor(inspector_->resume(), req.id); +} + +void Connection::Impl::handle( + const m::debugger::SetBreakpointByUrlRequest &req) { + debugger::SourceLocation loc; + + { + std::lock_guard lock(parsedScriptsMutex_); + setHermesLocation(loc, req, parsedScripts_); + } + + inspector_->setBreakpoint(loc, req.condition) + .via(executor_.get()) + .thenValue([this, id = req.id](debugger::BreakpointInfo info) { + m::debugger::SetBreakpointByUrlResponse resp; + resp.id = id; + resp.breakpointId = folly::to(info.id); + + if (info.resolved) { + resp.locations.emplace_back( + m::debugger::makeLocation(info.resolvedLocation)); + } + + sendResponseToClient(resp); + }) + .thenError(sendErrorToClient(req.id)); +} + +void Connection::Impl::handle( + const m::debugger::SetPauseOnExceptionsRequest &req) { + debugger::PauseOnThrowMode mode = debugger::PauseOnThrowMode::None; + + if (req.state == "none") { + mode = debugger::PauseOnThrowMode::None; + } else if (req.state == "all") { + mode = debugger::PauseOnThrowMode::All; + } else if (req.state == "uncaught") { + mode = debugger::PauseOnThrowMode::Uncaught; + } else { + sendErrorToClient(req.id); + } + + sendResponseToClientViaExecutor( + inspector_->setPauseOnExceptions(mode), req.id); +} + +void Connection::Impl::handle(const m::debugger::StepIntoRequest &req) { + sendResponseToClientViaExecutor(inspector_->stepIn(), req.id); +} + +void Connection::Impl::handle(const m::debugger::StepOutRequest &req) { + sendResponseToClientViaExecutor(inspector_->stepOut(), req.id); +} + +void Connection::Impl::handle(const m::debugger::StepOverRequest &req) { + sendResponseToClientViaExecutor(inspector_->stepOver(), req.id); +} + +std::vector +Connection::Impl::makePropsFromScope( + std::pair frameAndScopeIndex, + const std::string &objectGroup, + const debugger::ProgramState &state) { + std::vector result; + + uint32_t frameIndex = frameAndScopeIndex.first; + uint32_t scopeIndex = frameAndScopeIndex.second; + debugger::LexicalInfo lexicalInfo = state.getLexicalInfo(frameIndex); + uint32_t varCount = lexicalInfo.getVariablesCountInScope(scopeIndex); + + for (uint32_t varIndex = 0; varIndex < varCount; varIndex++) { + debugger::VariableInfo varInfo = + state.getVariableInfo(frameIndex, scopeIndex, varIndex); + + m::runtime::PropertyDescriptor desc; + desc.name = varInfo.name; + desc.value = m::runtime::makeRemoteObject( + getRuntime(), varInfo.value, objTable_, objectGroup); + + result.emplace_back(std::move(desc)); + } + + return result; +} + +std::vector +Connection::Impl::makePropsFromValue( + const jsi::Value &value, + const std::string &objectGroup, + bool onlyOwnProperties) { + std::vector result; + + if (value.isObject()) { + HermesRuntime &runtime = getRuntime(); + jsi::Object obj = value.getObject(runtime); + + // TODO(hypuk): obj.getPropertyNames only returns enumerable properties. + jsi::Array propNames = onlyOwnProperties + ? runtime.global() + .getPropertyAsObject(runtime, "Object") + .getPropertyAsFunction(runtime, "getOwnPropertyNames") + .call(runtime, obj) + .getObject(runtime) + .getArray(runtime) + : obj.getPropertyNames(runtime); + + size_t propCount = propNames.length(runtime); + for (size_t i = 0; i < propCount; i++) { + jsi::String propName = + propNames.getValueAtIndex(runtime, i).getString(runtime); + + m::runtime::PropertyDescriptor desc; + desc.name = propName.utf8(runtime); + + jsi::Value propValue = obj.getProperty(runtime, propName); + desc.value = m::runtime::makeRemoteObject( + runtime, propValue, objTable_, objectGroup); + + result.emplace_back(std::move(desc)); + } + + if (onlyOwnProperties) { + jsi::Value proto = runtime.global() + .getPropertyAsObject(runtime, "Object") + .getPropertyAsFunction(runtime, "getPrototypeOf") + .call(runtime, obj); + if (!proto.isNull()) { + m::runtime::PropertyDescriptor desc; + desc.name = "__proto__"; + desc.value = m::runtime::makeRemoteObject( + runtime, proto, objTable_, objectGroup); + result.emplace_back(std::move(desc)); + } + } + } + + return result; +} + +void Connection::Impl::handle(const m::runtime::GetPropertiesRequest &req) { + auto resp = std::make_shared(); + resp->id = req.id; + + inspector_ + ->executeIfEnabled( + "Runtime.getProperties", + [this, req, resp](const debugger::ProgramState &state) { + std::string objGroup = objTable_.getObjectGroup(req.objectId); + auto scopePtr = objTable_.getScope(req.objectId); + auto valuePtr = objTable_.getValue(req.objectId); + + if (scopePtr != nullptr) { + resp->result = makePropsFromScope(*scopePtr, objGroup, state); + } else if (valuePtr != nullptr) { + resp->result = makePropsFromValue( + *valuePtr, objGroup, req.ownProperties.value_or(true)); + } + }) + .via(executor_.get()) + .thenValue([this, resp](auto &&) { sendResponseToClient(*resp); }) + .thenError(sendErrorToClient(req.id)); +} + +/* + * Send-to-client methods + */ + +void Connection::Impl::sendToClient(const std::string &str) { + if (remoteConn_) { + remoteConn_->onMessage(str); + } +} + +void Connection::Impl::sendResponseToClient(const m::Response &resp) { + sendToClient(resp.toJson()); +} + +folly::Function +Connection::Impl::sendErrorToClient(int id) { + return [this, id](const std::exception &e) { + sendResponseToClient( + m::makeErrorResponse(id, m::ErrorCode::ServerError, e.what())); + }; +} + +void Connection::Impl::sendResponseToClientViaExecutor(int id) { + sendResponseToClientViaExecutor(folly::makeFuture(), id); +} + +void Connection::Impl::sendResponseToClientViaExecutor( + folly::Future future, + int id) { + future.via(executor_.get()) + .thenValue([this, id](const Unit &unit) { + sendResponseToClient(m::makeOkResponse(id)); + }) + .thenError(sendErrorToClient(id)); +} + +void Connection::Impl::sendNotificationToClientViaExecutor( + const m::Notification ¬e) { + executor_->add( + [this, noteJson = note.toJson()]() { sendToClient(noteJson); }); +} + +/* + * Connection + */ +Connection::Connection( + std::unique_ptr adapter, + const std::string &title, + bool waitForDebugger) + : impl_( + std::make_unique(std::move(adapter), title, waitForDebugger)) {} + +Connection::~Connection() = default; + +HermesRuntime &Connection::getRuntime() { + return impl_->getRuntime(); +} + +std::string Connection::getTitle() const { + return impl_->getTitle(); +} + +bool Connection::connect(std::unique_ptr remoteConn) { + return impl_->connect(std::move(remoteConn)); +} + +bool Connection::disconnect() { + return impl_->disconnect(); +} + +void Connection::sendMessage(std::string str) { + impl_->sendMessage(std::move(str)); +} + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/Connection.h b/ReactCommon/hermes/inspector/chrome/Connection.h new file mode 100644 index 00000000000..b6c8a41fbd0 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/Connection.h @@ -0,0 +1,58 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include +#include + +#include +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +/// Connection is a duplex connection between the client and the debugger. +class Connection { + public: + /// Connection constructor enables the debugger on the provided runtime. This + /// should generally called before you start running any JS in the runtime. + Connection( + std::unique_ptr adapter, + const std::string &title, + bool waitForDebugger = false); + ~Connection(); + + /// getRuntime returns the underlying runtime being debugged. + HermesRuntime &getRuntime(); + + /// getTitle returns the name of the friendly name of the runtime that's shown + /// to users in Nuclide. + std::string getTitle() const; + + /// connect attaches this connection to the runtime's debugger. Requests to + /// the debugger sent via send(). Replies and notifications from the debugger + /// are sent back to the client via IRemoteConnection::onMessage. + bool connect( + std::unique_ptr<::facebook::react::IRemoteConnection> remoteConn); + + /// disconnect disconnects this connection from the runtime's debugger + bool disconnect(); + + /// sendMessage delivers a JSON-encoded Chrome DevTools Protocol request to + /// the debugger. + void sendMessage(std::string str); + + private: + class Impl; + std::unique_ptr impl_; +}; + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/ConnectionDemux.cpp b/ReactCommon/hermes/inspector/chrome/ConnectionDemux.cpp new file mode 100644 index 00000000000..cb6b71651d6 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/ConnectionDemux.cpp @@ -0,0 +1,137 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "ConnectionDemux.h" +#include "AutoAttachUtils.h" +#include "Connection.h" + +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +using ::facebook::react::IInspector; +using ::facebook::react::ILocalConnection; +using ::facebook::react::IRemoteConnection; + +namespace { + +class LocalConnection : public ILocalConnection { + public: + LocalConnection( + std::shared_ptr conn, + std::shared_ptr> inspectedContexts); + ~LocalConnection(); + + void sendMessage(std::string message) override; + void disconnect() override; + + private: + std::shared_ptr conn_; + std::shared_ptr> inspectedContexts_; +}; + +LocalConnection::LocalConnection( + std::shared_ptr conn, + std::shared_ptr> inspectedContexts) + : conn_(conn), inspectedContexts_(inspectedContexts) { + inspectedContexts_->insert(conn->getTitle()); +} + +LocalConnection::~LocalConnection() = default; + +void LocalConnection::sendMessage(std::string str) { + conn_->sendMessage(std::move(str)); +} + +void LocalConnection::disconnect() { + inspectedContexts_->erase(conn_->getTitle()); + conn_->disconnect(); +} + +} // namespace + +ConnectionDemux::ConnectionDemux(facebook::react::IInspector &inspector) + : globalInspector_(inspector), + inspectedContexts_(std::make_shared>()) {} + +ConnectionDemux::~ConnectionDemux() = default; + +int ConnectionDemux::enableDebugging( + std::unique_ptr adapter, + const std::string &title) { + std::lock_guard lock(mutex_); + + // TODO(#22976087): workaround for ComponentScript contexts never being + // destroyed. + // + // After a reload, the old ComponentScript VM instance stays alive. When we + // register the new CS VM instance, check for any previous CS VM (via strcmp + // of title) and remove them. + std::vector pagesToDelete; + for (auto it = conns_.begin(); it != conns_.end(); ++it) { + if (it->second->getTitle() == title) { + pagesToDelete.push_back(it->first); + } + } + + for (auto pageId : pagesToDelete) { + removePage(pageId); + } + + // TODO(hypuk): Provide real app and device names. + auto waitForDebugger = + (inspectedContexts_->find(title) != inspectedContexts_->end()) || + isNetworkInspected(title, "app_name", "device_name"); + + return addPage( + std::make_shared(std::move(adapter), title, waitForDebugger)); +} + +void ConnectionDemux::disableDebugging(HermesRuntime &runtime) { + std::lock_guard lock(mutex_); + + for (auto &it : conns_) { + int pageId = it.first; + auto &conn = it.second; + + if (&(conn->getRuntime()) == &runtime) { + removePage(pageId); + + // must break here. removePage mutates conns_, so range-for iterator is + // now invalid. + break; + } + } +} + +int ConnectionDemux::addPage(std::shared_ptr conn) { + auto connectFunc = [conn, this](std::unique_ptr remoteConn) + -> std::unique_ptr { + if (!conn->connect(std::move(remoteConn))) { + return nullptr; + } + + return std::make_unique(conn, inspectedContexts_); + }; + + int pageId = globalInspector_.addPage( + conn->getTitle(), "Hermes", std::move(connectFunc)); + conns_[pageId] = std::move(conn); + + return pageId; +} + +void ConnectionDemux::removePage(int pageId) { + globalInspector_.removePage(pageId); + + auto conn = conns_.at(pageId); + conn->disconnect(); + conns_.erase(pageId); +} + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/ConnectionDemux.h b/ReactCommon/hermes/inspector/chrome/ConnectionDemux.h new file mode 100644 index 00000000000..b0dbed13d18 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/ConnectionDemux.h @@ -0,0 +1,52 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +/* + * ConnectionDemux keeps track of all debuggable Hermes runtimes (called + * "pages" in the higher-level React Native API) in this process. See + * Registration.h for documentation of the public API. + */ +class ConnectionDemux { + public: + explicit ConnectionDemux(facebook::react::IInspector &inspector); + ~ConnectionDemux(); + + ConnectionDemux(const ConnectionDemux &) = delete; + ConnectionDemux &operator=(const ConnectionDemux &) = delete; + + int enableDebugging( + std::unique_ptr adapter, + const std::string &title); + void disableDebugging(HermesRuntime &runtime); + + private: + int addPage(std::shared_ptr conn); + void removePage(int pageId); + + facebook::react::IInspector &globalInspector_; + + std::mutex mutex_; + std::unordered_map> conns_; + std::shared_ptr> inspectedContexts_; +}; + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/MessageConverters.cpp b/ReactCommon/hermes/inspector/chrome/MessageConverters.cpp new file mode 100644 index 00000000000..47589a2c5be --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/MessageConverters.cpp @@ -0,0 +1,215 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "MessageConverters.h" + +#include +#include + +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +namespace h = ::facebook::hermes; +namespace m = ::facebook::hermes::inspector::chrome::message; + +m::ErrorResponse +m::makeErrorResponse(int id, m::ErrorCode code, const std::string &message) { + m::ErrorResponse resp; + resp.id = id; + resp.code = static_cast(code); + resp.message = message; + return resp; +} + +m::OkResponse m::makeOkResponse(int id) { + m::OkResponse resp; + resp.id = id; + return resp; +} + +/* + * debugger message conversion helpers + */ + +m::debugger::Location m::debugger::makeLocation( + const h::debugger::SourceLocation &loc) { + m::debugger::Location result; + + result.scriptId = folly::to(loc.fileId); + m::setChromeLocation(result, loc); + + return result; +} + +m::debugger::CallFrame m::debugger::makeCallFrame( + uint32_t callFrameIndex, + const h::debugger::CallFrameInfo &callFrameInfo, + const h::debugger::LexicalInfo &lexicalInfo, + RemoteObjectsTable &objTable, + HermesRuntime &runtime, + const facebook::hermes::debugger::ProgramState &state) { + m::debugger::CallFrame result; + + result.callFrameId = folly::to(callFrameIndex); + result.functionName = callFrameInfo.functionName; + result.location = makeLocation(callFrameInfo.location); + + uint32_t scopeCount = lexicalInfo.getScopesCount(); + for (uint32_t scopeIndex = 0; scopeIndex < scopeCount; scopeIndex++) { + m::debugger::Scope scope; + + if (scopeIndex == scopeCount - 1) { + scope.type = "global"; + scope.name = "Global Scope"; + scope.object.objectId = + objTable.addValue(runtime.global(), BacktraceObjectGroup); + } else { + scope.type = "local"; + scope.name = "Scope " + folly::to(scopeIndex); + scope.object.objectId = objTable.addScope( + std::make_pair(callFrameIndex, scopeIndex), BacktraceObjectGroup); + } + + scope.object.type = "object"; + scope.object.className = "Object"; + result.scopeChain.emplace_back(std::move(scope)); + } + + result.thisObj.type = "object"; + result.thisObj.objectId = objTable.addValue( + state.getVariableInfoForThis(callFrameIndex).value, BacktraceObjectGroup); + + return result; +} + +std::vector m::debugger::makeCallFrames( + const h::debugger::ProgramState &state, + RemoteObjectsTable &objTable, + HermesRuntime &runtime) { + const h::debugger::StackTrace &stackTrace = state.getStackTrace(); + uint32_t count = stackTrace.callFrameCount(); + + std::vector result; + result.reserve(count); + + for (uint32_t i = 0; i < count; i++) { + h::debugger::CallFrameInfo callFrameInfo = stackTrace.callFrameForIndex(i); + h::debugger::LexicalInfo lexicalInfo = state.getLexicalInfo(i); + + result.emplace_back( + makeCallFrame(i, callFrameInfo, lexicalInfo, objTable, runtime, state)); + } + + return result; +} + +/* + * runtime message conversion helpers + */ + +m::runtime::CallFrame m::runtime::makeCallFrame( + const h::debugger::CallFrameInfo &info) { + m::runtime::CallFrame result; + + result.functionName = info.functionName; + result.scriptId = folly::to(info.location.fileId); + result.url = info.location.fileName; + m::setChromeLocation(result, info.location); + + return result; +} + +std::vector m::runtime::makeCallFrames( + const facebook::hermes::debugger::StackTrace &stackTrace) { + std::vector result; + result.reserve(stackTrace.callFrameCount()); + + for (size_t i = 0; i < stackTrace.callFrameCount(); i++) { + h::debugger::CallFrameInfo info = stackTrace.callFrameForIndex(i); + result.emplace_back(makeCallFrame(info)); + } + + return result; +} + +m::runtime::ExceptionDetails m::runtime::makeExceptionDetails( + const h::debugger::ExceptionDetails &details) { + m::runtime::ExceptionDetails result; + + result.text = details.text; + result.scriptId = folly::to(details.location.fileId); + result.url = details.location.fileName; + result.stackTrace = m::runtime::StackTrace(); + result.stackTrace->callFrames = makeCallFrames(details.getStackTrace()); + m::setChromeLocation(result, details.location); + + return result; +} + +m::runtime::RemoteObject m::runtime::makeRemoteObject( + facebook::jsi::Runtime &runtime, + const facebook::jsi::Value &value, + RemoteObjectsTable &objTable, + const std::string &objectGroup) { + m::runtime::RemoteObject result; + + if (value.isUndefined()) { + result.type = "undefined"; + } else if (value.isNull()) { + result.type = "object"; + result.subtype = "null"; + result.value = "null"; + } else if (value.isBool()) { + result.type = "boolean"; + result.value = value.getBool(); + } else if (value.isNumber()) { + double numberValue = value.getNumber(); + + result.type = "number"; + if (std::isnan(numberValue)) { + result.description = result.unserializableValue = "NaN"; + } else if (numberValue == -std::numeric_limits::infinity()) { + result.description = result.unserializableValue = "-Infinity"; + } else if (numberValue == std::numeric_limits::infinity()) { + result.description = result.unserializableValue = "Infinity"; + } else if (numberValue == 0.0 && std::signbit(numberValue)) { + result.description = result.unserializableValue = "-0"; + } else { + result.value = numberValue; + } + } else if (value.isString()) { + result.type = "string"; + result.value = value.getString(runtime).utf8(runtime); + } else if (value.isObject()) { + jsi::Object obj = value.getObject(runtime); + + if (obj.isFunction(runtime)) { + result.type = "function"; + result.value = ""; + } else if (obj.isArray(runtime)) { + auto array = obj.getArray(runtime); + size_t arrayCount = array.length(runtime); + + result.type = "object"; + result.subtype = "array"; + result.className = "Array"; + result.description = "Array(" + folly::to(arrayCount) + ")"; + } else { + result.type = "object"; + result.description = result.className = "Object"; + } + + result.objectId = + objTable.addValue(jsi::Value(std::move(obj)), objectGroup); + } + + return result; +} + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/MessageConverters.h b/ReactCommon/hermes/inspector/chrome/MessageConverters.h new file mode 100644 index 00000000000..90b818eb5b9 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/MessageConverters.h @@ -0,0 +1,121 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { +namespace message { + +template +void setHermesLocation( + facebook::hermes::debugger::SourceLocation &hermesLoc, + const T &chromeLoc, + const std::vector &parsedScripts) { + hermesLoc.line = chromeLoc.lineNumber + 1; + + if (chromeLoc.columnNumber.hasValue()) { + if (chromeLoc.columnNumber.value() == 0) { + // TODO: When CDTP sends a column number of 0, we send Hermes a column + // number of 1. For some reason, this causes Hermes to not be + // able to resolve breakpoints. + hermesLoc.column = ::facebook::hermes::debugger::kInvalidLocation; + } else { + hermesLoc.column = chromeLoc.columnNumber.value() + 1; + } + } + + if (chromeLoc.url.hasValue()) { + hermesLoc.fileName = chromeLoc.url.value(); + } else if (chromeLoc.urlRegex.hasValue()) { + const std::regex regex(chromeLoc.urlRegex.value()); + for (const auto &fileName : parsedScripts) { + if (std::regex_match(fileName, regex)) { + hermesLoc.fileName = fileName; + break; + } + } + } +} + +template +void setChromeLocation( + T &chromeLoc, + const facebook::hermes::debugger::SourceLocation &hermesLoc) { + if (hermesLoc.line != facebook::hermes::debugger::kInvalidLocation) { + chromeLoc.lineNumber = hermesLoc.line - 1; + } + + if (hermesLoc.column != facebook::hermes::debugger::kInvalidLocation) { + chromeLoc.columnNumber = hermesLoc.column - 1; + } +} + +/// ErrorCode magic numbers match JSC's (see InspectorBackendDispatcher.cpp) +enum class ErrorCode { + ParseError = -32700, + InvalidRequest = -32600, + MethodNotFound = -32601, + InvalidParams = -32602, + InternalError = -32603, + ServerError = -32000 +}; + +ErrorResponse +makeErrorResponse(int id, ErrorCode code, const std::string &message); + +OkResponse makeOkResponse(int id); + +namespace debugger { + +Location makeLocation(const facebook::hermes::debugger::SourceLocation &loc); + +CallFrame makeCallFrame( + uint32_t callFrameIndex, + const facebook::hermes::debugger::CallFrameInfo &callFrameInfo, + const facebook::hermes::debugger::LexicalInfo &lexicalInfo, + facebook::hermes::inspector::chrome::RemoteObjectsTable &objTable, + HermesRuntime &runtime, + const facebook::hermes::debugger::ProgramState &state); + +std::vector makeCallFrames( + const facebook::hermes::debugger::ProgramState &state, + facebook::hermes::inspector::chrome::RemoteObjectsTable &objTable, + HermesRuntime &runtime); + +} // namespace debugger + +namespace runtime { + +CallFrame makeCallFrame(const facebook::hermes::debugger::CallFrameInfo &info); + +std::vector makeCallFrames( + const facebook::hermes::debugger::StackTrace &stackTrace); + +ExceptionDetails makeExceptionDetails( + const facebook::hermes::debugger::ExceptionDetails &details); + +RemoteObject makeRemoteObject( + facebook::jsi::Runtime &runtime, + const facebook::jsi::Value &value, + facebook::hermes::inspector::chrome::RemoteObjectsTable &objTable, + const std::string &objectGroup); + +} // namespace runtime + +} // namespace message +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/MessageInterfaces.h b/ReactCommon/hermes/inspector/chrome/MessageInterfaces.h new file mode 100644 index 00000000000..0960de5b74f --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/MessageInterfaces.h @@ -0,0 +1,69 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include +#include + +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { +namespace message { + +struct RequestHandler; + +/// Serializable is an interface for objects that can be serialized to and from +/// JSON. +struct Serializable { + virtual ~Serializable() = default; + virtual folly::dynamic toDynamic() const = 0; + + std::string toJson() const { + return folly::toJson(toDynamic()); + } +}; + +/// Requests are sent from the debugger to the target. +struct Request : public Serializable { + static std::unique_ptr fromJsonThrowOnError(const std::string &str); + static folly::Try> fromJson(const std::string &str); + + Request() = default; + explicit Request(std::string method) : method(method) {} + + // accept dispatches to the appropriate handler method in RequestHandler based + // on the type of the request. + virtual void accept(RequestHandler &handler) const = 0; + + int id = 0; + std::string method; +}; + +/// Responses are sent from the target to the debugger in response to a Request. +struct Response : public Serializable { + Response() = default; + + int id = 0; +}; + +/// Notifications are sent from the target to the debugger. This is used to +/// notify the debugger about events that occur in the target, e.g. stopping +/// at a breakpoint. +struct Notification : public Serializable { + Notification() = default; + explicit Notification(std::string method) : method(method) {} + + std::string method; +}; + +} // namespace message +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/MessageTypes.cpp b/ReactCommon/hermes/inspector/chrome/MessageTypes.cpp new file mode 100644 index 00000000000..284d84c629c --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/MessageTypes.cpp @@ -0,0 +1,902 @@ +// Copyright 2004-present Facebook. All Rights Reserved. +// @generated <> + +#include "MessageTypes.h" + +#include "MessageTypesInlines.h" + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { +namespace message { + +using RequestBuilder = std::unique_ptr (*)(const dynamic &); + +namespace { + +template +std::unique_ptr makeUnique(const dynamic &obj) { + return std::make_unique(obj); +} + +} // namespace + +std::unique_ptr Request::fromJsonThrowOnError(const std::string &str) { + static std::unordered_map builders = { + {"Debugger.disable", makeUnique}, + {"Debugger.enable", makeUnique}, + {"Debugger.evaluateOnCallFrame", + makeUnique}, + {"Debugger.pause", makeUnique}, + {"Debugger.removeBreakpoint", + makeUnique}, + {"Debugger.resume", makeUnique}, + {"Debugger.setBreakpointByUrl", + makeUnique}, + {"Debugger.setPauseOnExceptions", + makeUnique}, + {"Debugger.stepInto", makeUnique}, + {"Debugger.stepOut", makeUnique}, + {"Debugger.stepOver", makeUnique}, + {"Runtime.evaluate", makeUnique}, + {"Runtime.getProperties", makeUnique}, + }; + + dynamic obj = folly::parseJson(str); + std::string method = obj.at("method").asString(); + + auto it = builders.find(method); + if (it == builders.end()) { + return std::make_unique(obj); + } + + auto builder = it->second; + return builder(obj); +} + +folly::Try> Request::fromJson(const std::string &str) { + return folly::makeTryWith( + [&str] { return Request::fromJsonThrowOnError(str); }); +} + +/// Types +debugger::Location::Location(const dynamic &obj) { + assign(scriptId, obj, "scriptId"); + assign(lineNumber, obj, "lineNumber"); + assign(columnNumber, obj, "columnNumber"); +} + +dynamic debugger::Location::toDynamic() const { + dynamic obj = dynamic::object; + + put(obj, "scriptId", scriptId); + put(obj, "lineNumber", lineNumber); + put(obj, "columnNumber", columnNumber); + return obj; +} + +runtime::RemoteObject::RemoteObject(const dynamic &obj) { + assign(type, obj, "type"); + assign(subtype, obj, "subtype"); + assign(className, obj, "className"); + assign(value, obj, "value"); + assign(unserializableValue, obj, "unserializableValue"); + assign(description, obj, "description"); + assign(objectId, obj, "objectId"); +} + +dynamic runtime::RemoteObject::toDynamic() const { + dynamic obj = dynamic::object; + + put(obj, "type", type); + put(obj, "subtype", subtype); + put(obj, "className", className); + put(obj, "value", value); + put(obj, "unserializableValue", unserializableValue); + put(obj, "description", description); + put(obj, "objectId", objectId); + return obj; +} + +runtime::CallFrame::CallFrame(const dynamic &obj) { + assign(functionName, obj, "functionName"); + assign(scriptId, obj, "scriptId"); + assign(url, obj, "url"); + assign(lineNumber, obj, "lineNumber"); + assign(columnNumber, obj, "columnNumber"); +} + +dynamic runtime::CallFrame::toDynamic() const { + dynamic obj = dynamic::object; + + put(obj, "functionName", functionName); + put(obj, "scriptId", scriptId); + put(obj, "url", url); + put(obj, "lineNumber", lineNumber); + put(obj, "columnNumber", columnNumber); + return obj; +} + +runtime::StackTrace::StackTrace(const dynamic &obj) { + assign(description, obj, "description"); + assign(callFrames, obj, "callFrames"); + assign(parent, obj, "parent"); +} + +dynamic runtime::StackTrace::toDynamic() const { + dynamic obj = dynamic::object; + + put(obj, "description", description); + put(obj, "callFrames", callFrames); + put(obj, "parent", parent); + return obj; +} + +runtime::ExceptionDetails::ExceptionDetails(const dynamic &obj) { + assign(exceptionId, obj, "exceptionId"); + assign(text, obj, "text"); + assign(lineNumber, obj, "lineNumber"); + assign(columnNumber, obj, "columnNumber"); + assign(scriptId, obj, "scriptId"); + assign(url, obj, "url"); + assign(stackTrace, obj, "stackTrace"); + assign(exception, obj, "exception"); + assign(executionContextId, obj, "executionContextId"); +} + +dynamic runtime::ExceptionDetails::toDynamic() const { + dynamic obj = dynamic::object; + + put(obj, "exceptionId", exceptionId); + put(obj, "text", text); + put(obj, "lineNumber", lineNumber); + put(obj, "columnNumber", columnNumber); + put(obj, "scriptId", scriptId); + put(obj, "url", url); + put(obj, "stackTrace", stackTrace); + put(obj, "exception", exception); + put(obj, "executionContextId", executionContextId); + return obj; +} + +debugger::Scope::Scope(const dynamic &obj) { + assign(type, obj, "type"); + assign(object, obj, "object"); + assign(name, obj, "name"); + assign(startLocation, obj, "startLocation"); + assign(endLocation, obj, "endLocation"); +} + +dynamic debugger::Scope::toDynamic() const { + dynamic obj = dynamic::object; + + put(obj, "type", type); + put(obj, "object", object); + put(obj, "name", name); + put(obj, "startLocation", startLocation); + put(obj, "endLocation", endLocation); + return obj; +} + +debugger::CallFrame::CallFrame(const dynamic &obj) { + assign(callFrameId, obj, "callFrameId"); + assign(functionName, obj, "functionName"); + assign(location, obj, "location"); + assign(url, obj, "url"); + assign(scopeChain, obj, "scopeChain"); + assign(thisObj, obj, "this"); + assign(returnValue, obj, "returnValue"); +} + +dynamic debugger::CallFrame::toDynamic() const { + dynamic obj = dynamic::object; + + put(obj, "callFrameId", callFrameId); + put(obj, "functionName", functionName); + put(obj, "location", location); + put(obj, "url", url); + put(obj, "scopeChain", scopeChain); + put(obj, "this", thisObj); + put(obj, "returnValue", returnValue); + return obj; +} + +runtime::ExecutionContextDescription::ExecutionContextDescription( + const dynamic &obj) { + assign(id, obj, "id"); + assign(origin, obj, "origin"); + assign(name, obj, "name"); + assign(auxData, obj, "auxData"); + assign(isPageContext, obj, "isPageContext"); + assign(isDefault, obj, "isDefault"); +} + +dynamic runtime::ExecutionContextDescription::toDynamic() const { + dynamic obj = dynamic::object; + + put(obj, "id", id); + put(obj, "origin", origin); + put(obj, "name", name); + put(obj, "auxData", auxData); + put(obj, "isPageContext", isPageContext); + put(obj, "isDefault", isDefault); + return obj; +} + +runtime::PropertyDescriptor::PropertyDescriptor(const dynamic &obj) { + assign(name, obj, "name"); + assign(value, obj, "value"); + assign(writable, obj, "writable"); + assign(get, obj, "get"); + assign(set, obj, "set"); + assign(configurable, obj, "configurable"); + assign(enumerable, obj, "enumerable"); + assign(wasThrown, obj, "wasThrown"); + assign(isOwn, obj, "isOwn"); + assign(symbol, obj, "symbol"); +} + +dynamic runtime::PropertyDescriptor::toDynamic() const { + dynamic obj = dynamic::object; + + put(obj, "name", name); + put(obj, "value", value); + put(obj, "writable", writable); + put(obj, "get", get); + put(obj, "set", set); + put(obj, "configurable", configurable); + put(obj, "enumerable", enumerable); + put(obj, "wasThrown", wasThrown); + put(obj, "isOwn", isOwn); + put(obj, "symbol", symbol); + return obj; +} + +runtime::InternalPropertyDescriptor::InternalPropertyDescriptor( + const dynamic &obj) { + assign(name, obj, "name"); + assign(value, obj, "value"); +} + +dynamic runtime::InternalPropertyDescriptor::toDynamic() const { + dynamic obj = dynamic::object; + + put(obj, "name", name); + put(obj, "value", value); + return obj; +} + +/// Requests +UnknownRequest::UnknownRequest() {} + +UnknownRequest::UnknownRequest(const dynamic &obj) { + assign(id, obj, "id"); + assign(method, obj, "method"); + assign(params, obj, "params"); +} + +dynamic UnknownRequest::toDynamic() const { + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + put(obj, "params", params); + return obj; +} + +void UnknownRequest::accept(RequestHandler &handler) const { + handler.handle(*this); +} + +debugger::DisableRequest::DisableRequest() : Request("Debugger.disable") {} + +debugger::DisableRequest::DisableRequest(const dynamic &obj) + : Request("Debugger.disable") { + assign(id, obj, "id"); + assign(method, obj, "method"); +} + +dynamic debugger::DisableRequest::toDynamic() const { + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + return obj; +} + +void debugger::DisableRequest::accept(RequestHandler &handler) const { + handler.handle(*this); +} + +debugger::EnableRequest::EnableRequest() : Request("Debugger.enable") {} + +debugger::EnableRequest::EnableRequest(const dynamic &obj) + : Request("Debugger.enable") { + assign(id, obj, "id"); + assign(method, obj, "method"); +} + +dynamic debugger::EnableRequest::toDynamic() const { + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + return obj; +} + +void debugger::EnableRequest::accept(RequestHandler &handler) const { + handler.handle(*this); +} + +debugger::EvaluateOnCallFrameRequest::EvaluateOnCallFrameRequest() + : Request("Debugger.evaluateOnCallFrame") {} + +debugger::EvaluateOnCallFrameRequest::EvaluateOnCallFrameRequest( + const dynamic &obj) + : Request("Debugger.evaluateOnCallFrame") { + assign(id, obj, "id"); + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(callFrameId, params, "callFrameId"); + assign(expression, params, "expression"); + assign(objectGroup, params, "objectGroup"); + assign(includeCommandLineAPI, params, "includeCommandLineAPI"); + assign(silent, params, "silent"); + assign(returnByValue, params, "returnByValue"); +} + +dynamic debugger::EvaluateOnCallFrameRequest::toDynamic() const { + dynamic params = dynamic::object; + put(params, "callFrameId", callFrameId); + put(params, "expression", expression); + put(params, "objectGroup", objectGroup); + put(params, "includeCommandLineAPI", includeCommandLineAPI); + put(params, "silent", silent); + put(params, "returnByValue", returnByValue); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; +} + +void debugger::EvaluateOnCallFrameRequest::accept( + RequestHandler &handler) const { + handler.handle(*this); +} + +debugger::PauseRequest::PauseRequest() : Request("Debugger.pause") {} + +debugger::PauseRequest::PauseRequest(const dynamic &obj) + : Request("Debugger.pause") { + assign(id, obj, "id"); + assign(method, obj, "method"); +} + +dynamic debugger::PauseRequest::toDynamic() const { + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + return obj; +} + +void debugger::PauseRequest::accept(RequestHandler &handler) const { + handler.handle(*this); +} + +debugger::RemoveBreakpointRequest::RemoveBreakpointRequest() + : Request("Debugger.removeBreakpoint") {} + +debugger::RemoveBreakpointRequest::RemoveBreakpointRequest(const dynamic &obj) + : Request("Debugger.removeBreakpoint") { + assign(id, obj, "id"); + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(breakpointId, params, "breakpointId"); +} + +dynamic debugger::RemoveBreakpointRequest::toDynamic() const { + dynamic params = dynamic::object; + put(params, "breakpointId", breakpointId); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; +} + +void debugger::RemoveBreakpointRequest::accept(RequestHandler &handler) const { + handler.handle(*this); +} + +debugger::ResumeRequest::ResumeRequest() : Request("Debugger.resume") {} + +debugger::ResumeRequest::ResumeRequest(const dynamic &obj) + : Request("Debugger.resume") { + assign(id, obj, "id"); + assign(method, obj, "method"); +} + +dynamic debugger::ResumeRequest::toDynamic() const { + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + return obj; +} + +void debugger::ResumeRequest::accept(RequestHandler &handler) const { + handler.handle(*this); +} + +debugger::SetBreakpointByUrlRequest::SetBreakpointByUrlRequest() + : Request("Debugger.setBreakpointByUrl") {} + +debugger::SetBreakpointByUrlRequest::SetBreakpointByUrlRequest( + const dynamic &obj) + : Request("Debugger.setBreakpointByUrl") { + assign(id, obj, "id"); + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(lineNumber, params, "lineNumber"); + assign(url, params, "url"); + assign(urlRegex, params, "urlRegex"); + assign(columnNumber, params, "columnNumber"); + assign(condition, params, "condition"); +} + +dynamic debugger::SetBreakpointByUrlRequest::toDynamic() const { + dynamic params = dynamic::object; + put(params, "lineNumber", lineNumber); + put(params, "url", url); + put(params, "urlRegex", urlRegex); + put(params, "columnNumber", columnNumber); + put(params, "condition", condition); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; +} + +void debugger::SetBreakpointByUrlRequest::accept( + RequestHandler &handler) const { + handler.handle(*this); +} + +debugger::SetPauseOnExceptionsRequest::SetPauseOnExceptionsRequest() + : Request("Debugger.setPauseOnExceptions") {} + +debugger::SetPauseOnExceptionsRequest::SetPauseOnExceptionsRequest( + const dynamic &obj) + : Request("Debugger.setPauseOnExceptions") { + assign(id, obj, "id"); + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(state, params, "state"); +} + +dynamic debugger::SetPauseOnExceptionsRequest::toDynamic() const { + dynamic params = dynamic::object; + put(params, "state", state); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; +} + +void debugger::SetPauseOnExceptionsRequest::accept( + RequestHandler &handler) const { + handler.handle(*this); +} + +debugger::StepIntoRequest::StepIntoRequest() : Request("Debugger.stepInto") {} + +debugger::StepIntoRequest::StepIntoRequest(const dynamic &obj) + : Request("Debugger.stepInto") { + assign(id, obj, "id"); + assign(method, obj, "method"); +} + +dynamic debugger::StepIntoRequest::toDynamic() const { + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + return obj; +} + +void debugger::StepIntoRequest::accept(RequestHandler &handler) const { + handler.handle(*this); +} + +debugger::StepOutRequest::StepOutRequest() : Request("Debugger.stepOut") {} + +debugger::StepOutRequest::StepOutRequest(const dynamic &obj) + : Request("Debugger.stepOut") { + assign(id, obj, "id"); + assign(method, obj, "method"); +} + +dynamic debugger::StepOutRequest::toDynamic() const { + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + return obj; +} + +void debugger::StepOutRequest::accept(RequestHandler &handler) const { + handler.handle(*this); +} + +debugger::StepOverRequest::StepOverRequest() : Request("Debugger.stepOver") {} + +debugger::StepOverRequest::StepOverRequest(const dynamic &obj) + : Request("Debugger.stepOver") { + assign(id, obj, "id"); + assign(method, obj, "method"); +} + +dynamic debugger::StepOverRequest::toDynamic() const { + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + return obj; +} + +void debugger::StepOverRequest::accept(RequestHandler &handler) const { + handler.handle(*this); +} + +runtime::EvaluateRequest::EvaluateRequest() : Request("Runtime.evaluate") {} + +runtime::EvaluateRequest::EvaluateRequest(const dynamic &obj) + : Request("Runtime.evaluate") { + assign(id, obj, "id"); + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(expression, params, "expression"); + assign(objectGroup, params, "objectGroup"); + assign(includeCommandLineAPI, params, "includeCommandLineAPI"); + assign(silent, params, "silent"); + assign(contextId, params, "contextId"); + assign(returnByValue, params, "returnByValue"); + assign(awaitPromise, params, "awaitPromise"); +} + +dynamic runtime::EvaluateRequest::toDynamic() const { + dynamic params = dynamic::object; + put(params, "expression", expression); + put(params, "objectGroup", objectGroup); + put(params, "includeCommandLineAPI", includeCommandLineAPI); + put(params, "silent", silent); + put(params, "contextId", contextId); + put(params, "returnByValue", returnByValue); + put(params, "awaitPromise", awaitPromise); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; +} + +void runtime::EvaluateRequest::accept(RequestHandler &handler) const { + handler.handle(*this); +} + +runtime::GetPropertiesRequest::GetPropertiesRequest() + : Request("Runtime.getProperties") {} + +runtime::GetPropertiesRequest::GetPropertiesRequest(const dynamic &obj) + : Request("Runtime.getProperties") { + assign(id, obj, "id"); + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(objectId, params, "objectId"); + assign(ownProperties, params, "ownProperties"); +} + +dynamic runtime::GetPropertiesRequest::toDynamic() const { + dynamic params = dynamic::object; + put(params, "objectId", objectId); + put(params, "ownProperties", ownProperties); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; +} + +void runtime::GetPropertiesRequest::accept(RequestHandler &handler) const { + handler.handle(*this); +} + +/// Responses +ErrorResponse::ErrorResponse(const dynamic &obj) { + assign(id, obj, "id"); + + dynamic error = obj.at("error"); + assign(code, error, "code"); + assign(message, error, "message"); + assign(data, error, "data"); +} + +dynamic ErrorResponse::toDynamic() const { + dynamic error = dynamic::object; + put(error, "code", code); + put(error, "message", message); + put(error, "data", data); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "error", std::move(error)); + return obj; +} + +OkResponse::OkResponse(const dynamic &obj) { + assign(id, obj, "id"); +} + +dynamic OkResponse::toDynamic() const { + dynamic result = dynamic::object; + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "result", std::move(result)); + return obj; +} + +debugger::EvaluateOnCallFrameResponse::EvaluateOnCallFrameResponse( + const dynamic &obj) { + assign(id, obj, "id"); + + dynamic res = obj.at("result"); + assign(result, res, "result"); + assign(exceptionDetails, res, "exceptionDetails"); +} + +dynamic debugger::EvaluateOnCallFrameResponse::toDynamic() const { + dynamic res = dynamic::object; + put(res, "result", result); + put(res, "exceptionDetails", exceptionDetails); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "result", std::move(res)); + return obj; +} + +debugger::SetBreakpointByUrlResponse::SetBreakpointByUrlResponse( + const dynamic &obj) { + assign(id, obj, "id"); + + dynamic res = obj.at("result"); + assign(breakpointId, res, "breakpointId"); + assign(locations, res, "locations"); +} + +dynamic debugger::SetBreakpointByUrlResponse::toDynamic() const { + dynamic res = dynamic::object; + put(res, "breakpointId", breakpointId); + put(res, "locations", locations); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "result", std::move(res)); + return obj; +} + +runtime::EvaluateResponse::EvaluateResponse(const dynamic &obj) { + assign(id, obj, "id"); + + dynamic res = obj.at("result"); + assign(result, res, "result"); + assign(exceptionDetails, res, "exceptionDetails"); +} + +dynamic runtime::EvaluateResponse::toDynamic() const { + dynamic res = dynamic::object; + put(res, "result", result); + put(res, "exceptionDetails", exceptionDetails); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "result", std::move(res)); + return obj; +} + +runtime::GetPropertiesResponse::GetPropertiesResponse(const dynamic &obj) { + assign(id, obj, "id"); + + dynamic res = obj.at("result"); + assign(result, res, "result"); + assign(internalProperties, res, "internalProperties"); + assign(exceptionDetails, res, "exceptionDetails"); +} + +dynamic runtime::GetPropertiesResponse::toDynamic() const { + dynamic res = dynamic::object; + put(res, "result", result); + put(res, "internalProperties", internalProperties); + put(res, "exceptionDetails", exceptionDetails); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "result", std::move(res)); + return obj; +} + +/// Notifications +debugger::BreakpointResolvedNotification::BreakpointResolvedNotification() + : Notification("Debugger.breakpointResolved") {} + +debugger::BreakpointResolvedNotification::BreakpointResolvedNotification( + const dynamic &obj) + : Notification("Debugger.breakpointResolved") { + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(breakpointId, params, "breakpointId"); + assign(location, params, "location"); +} + +dynamic debugger::BreakpointResolvedNotification::toDynamic() const { + dynamic params = dynamic::object; + put(params, "breakpointId", breakpointId); + put(params, "location", location); + + dynamic obj = dynamic::object; + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; +} + +debugger::PausedNotification::PausedNotification() + : Notification("Debugger.paused") {} + +debugger::PausedNotification::PausedNotification(const dynamic &obj) + : Notification("Debugger.paused") { + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(callFrames, params, "callFrames"); + assign(reason, params, "reason"); + assign(data, params, "data"); + assign(hitBreakpoints, params, "hitBreakpoints"); + assign(asyncStackTrace, params, "asyncStackTrace"); +} + +dynamic debugger::PausedNotification::toDynamic() const { + dynamic params = dynamic::object; + put(params, "callFrames", callFrames); + put(params, "reason", reason); + put(params, "data", data); + put(params, "hitBreakpoints", hitBreakpoints); + put(params, "asyncStackTrace", asyncStackTrace); + + dynamic obj = dynamic::object; + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; +} + +debugger::ResumedNotification::ResumedNotification() + : Notification("Debugger.resumed") {} + +debugger::ResumedNotification::ResumedNotification(const dynamic &obj) + : Notification("Debugger.resumed") { + assign(method, obj, "method"); +} + +dynamic debugger::ResumedNotification::toDynamic() const { + dynamic obj = dynamic::object; + put(obj, "method", method); + return obj; +} + +debugger::ScriptParsedNotification::ScriptParsedNotification() + : Notification("Debugger.scriptParsed") {} + +debugger::ScriptParsedNotification::ScriptParsedNotification(const dynamic &obj) + : Notification("Debugger.scriptParsed") { + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(scriptId, params, "scriptId"); + assign(url, params, "url"); + assign(startLine, params, "startLine"); + assign(startColumn, params, "startColumn"); + assign(endLine, params, "endLine"); + assign(endColumn, params, "endColumn"); + assign(executionContextId, params, "executionContextId"); + assign(hash, params, "hash"); + assign(executionContextAuxData, params, "executionContextAuxData"); + assign(sourceMapURL, params, "sourceMapURL"); +} + +dynamic debugger::ScriptParsedNotification::toDynamic() const { + dynamic params = dynamic::object; + put(params, "scriptId", scriptId); + put(params, "url", url); + put(params, "startLine", startLine); + put(params, "startColumn", startColumn); + put(params, "endLine", endLine); + put(params, "endColumn", endColumn); + put(params, "executionContextId", executionContextId); + put(params, "hash", hash); + put(params, "executionContextAuxData", executionContextAuxData); + put(params, "sourceMapURL", sourceMapURL); + + dynamic obj = dynamic::object; + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; +} + +runtime::ConsoleAPICalledNotification::ConsoleAPICalledNotification() + : Notification("Runtime.consoleAPICalled") {} + +runtime::ConsoleAPICalledNotification::ConsoleAPICalledNotification( + const dynamic &obj) + : Notification("Runtime.consoleAPICalled") { + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(type, params, "type"); + assign(args, params, "args"); + assign(executionContextId, params, "executionContextId"); + assign(timestamp, params, "timestamp"); + assign(stackTrace, params, "stackTrace"); +} + +dynamic runtime::ConsoleAPICalledNotification::toDynamic() const { + dynamic params = dynamic::object; + put(params, "type", type); + put(params, "args", args); + put(params, "executionContextId", executionContextId); + put(params, "timestamp", timestamp); + put(params, "stackTrace", stackTrace); + + dynamic obj = dynamic::object; + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; +} + +runtime::ExecutionContextCreatedNotification:: + ExecutionContextCreatedNotification() + : Notification("Runtime.executionContextCreated") {} + +runtime::ExecutionContextCreatedNotification:: + ExecutionContextCreatedNotification(const dynamic &obj) + : Notification("Runtime.executionContextCreated") { + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(context, params, "context"); +} + +dynamic runtime::ExecutionContextCreatedNotification::toDynamic() const { + dynamic params = dynamic::object; + put(params, "context", context); + + dynamic obj = dynamic::object; + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; +} + +} // namespace message +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/MessageTypes.h b/ReactCommon/hermes/inspector/chrome/MessageTypes.h new file mode 100644 index 00000000000..1a772a7a1e0 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/MessageTypes.h @@ -0,0 +1,499 @@ +// Copyright 2004-present Facebook. All Rights Reserved. +// @generated <> + +#pragma once + +#include + +#include + +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { +namespace message { + +struct UnknownRequest; + +namespace debugger { +using BreakpointId = std::string; +struct BreakpointResolvedNotification; +struct CallFrame; +using CallFrameId = std::string; +struct DisableRequest; +struct EnableRequest; +struct EvaluateOnCallFrameRequest; +struct EvaluateOnCallFrameResponse; +struct Location; +struct PauseRequest; +struct PausedNotification; +struct RemoveBreakpointRequest; +struct ResumeRequest; +struct ResumedNotification; +struct Scope; +struct ScriptParsedNotification; +struct SetBreakpointByUrlRequest; +struct SetBreakpointByUrlResponse; +struct SetPauseOnExceptionsRequest; +struct StepIntoRequest; +struct StepOutRequest; +struct StepOverRequest; +} // namespace debugger + +namespace runtime { +struct CallFrame; +struct ConsoleAPICalledNotification; +struct EvaluateRequest; +struct EvaluateResponse; +struct ExceptionDetails; +struct ExecutionContextCreatedNotification; +struct ExecutionContextDescription; +using ExecutionContextId = int; +struct GetPropertiesRequest; +struct GetPropertiesResponse; +struct InternalPropertyDescriptor; +struct PropertyDescriptor; +struct RemoteObject; +using RemoteObjectId = std::string; +using ScriptId = std::string; +struct StackTrace; +using Timestamp = double; +using UnserializableValue = std::string; +} // namespace runtime + +/// RequestHandler handles requests via the visitor pattern. +struct RequestHandler { + virtual ~RequestHandler() = default; + + virtual void handle(const UnknownRequest &req) = 0; + virtual void handle(const debugger::DisableRequest &req) = 0; + virtual void handle(const debugger::EnableRequest &req) = 0; + virtual void handle(const debugger::EvaluateOnCallFrameRequest &req) = 0; + virtual void handle(const debugger::PauseRequest &req) = 0; + virtual void handle(const debugger::RemoveBreakpointRequest &req) = 0; + virtual void handle(const debugger::ResumeRequest &req) = 0; + virtual void handle(const debugger::SetBreakpointByUrlRequest &req) = 0; + virtual void handle(const debugger::SetPauseOnExceptionsRequest &req) = 0; + virtual void handle(const debugger::StepIntoRequest &req) = 0; + virtual void handle(const debugger::StepOutRequest &req) = 0; + virtual void handle(const debugger::StepOverRequest &req) = 0; + virtual void handle(const runtime::EvaluateRequest &req) = 0; + virtual void handle(const runtime::GetPropertiesRequest &req) = 0; +}; + +/// NoopRequestHandler can be subclassed to only handle some requests. +struct NoopRequestHandler : public RequestHandler { + void handle(const UnknownRequest &req) override {} + void handle(const debugger::DisableRequest &req) override {} + void handle(const debugger::EnableRequest &req) override {} + void handle(const debugger::EvaluateOnCallFrameRequest &req) override {} + void handle(const debugger::PauseRequest &req) override {} + void handle(const debugger::RemoveBreakpointRequest &req) override {} + void handle(const debugger::ResumeRequest &req) override {} + void handle(const debugger::SetBreakpointByUrlRequest &req) override {} + void handle(const debugger::SetPauseOnExceptionsRequest &req) override {} + void handle(const debugger::StepIntoRequest &req) override {} + void handle(const debugger::StepOutRequest &req) override {} + void handle(const debugger::StepOverRequest &req) override {} + void handle(const runtime::EvaluateRequest &req) override {} + void handle(const runtime::GetPropertiesRequest &req) override {} +}; + +/// Types +struct debugger::Location : public Serializable { + Location() = default; + explicit Location(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + runtime::ScriptId scriptId{}; + int lineNumber{}; + folly::Optional columnNumber; +}; + +struct runtime::RemoteObject : public Serializable { + RemoteObject() = default; + explicit RemoteObject(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + std::string type; + folly::Optional subtype; + folly::Optional className; + folly::Optional value; + folly::Optional unserializableValue; + folly::Optional description; + folly::Optional objectId; +}; + +struct runtime::CallFrame : public Serializable { + CallFrame() = default; + explicit CallFrame(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + std::string functionName; + runtime::ScriptId scriptId{}; + std::string url; + int lineNumber{}; + int columnNumber{}; +}; + +struct runtime::StackTrace : public Serializable { + StackTrace() = default; + explicit StackTrace(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + folly::Optional description; + std::vector callFrames; + std::unique_ptr parent; +}; + +struct runtime::ExceptionDetails : public Serializable { + ExceptionDetails() = default; + explicit ExceptionDetails(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + int exceptionId{}; + std::string text; + int lineNumber{}; + int columnNumber{}; + folly::Optional scriptId; + folly::Optional url; + folly::Optional stackTrace; + folly::Optional exception; + folly::Optional executionContextId; +}; + +struct debugger::Scope : public Serializable { + Scope() = default; + explicit Scope(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + std::string type; + runtime::RemoteObject object{}; + folly::Optional name; + folly::Optional startLocation; + folly::Optional endLocation; +}; + +struct debugger::CallFrame : public Serializable { + CallFrame() = default; + explicit CallFrame(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + debugger::CallFrameId callFrameId{}; + std::string functionName; + debugger::Location location{}; + std::string url; + std::vector scopeChain; + runtime::RemoteObject thisObj{}; + folly::Optional returnValue; +}; + +struct runtime::ExecutionContextDescription : public Serializable { + ExecutionContextDescription() = default; + explicit ExecutionContextDescription(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + runtime::ExecutionContextId id{}; + std::string origin; + std::string name; + folly::Optional auxData; + folly::Optional isPageContext; + folly::Optional isDefault; +}; + +struct runtime::PropertyDescriptor : public Serializable { + PropertyDescriptor() = default; + explicit PropertyDescriptor(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + std::string name; + folly::Optional value; + folly::Optional writable; + folly::Optional get; + folly::Optional set; + bool configurable{}; + bool enumerable{}; + folly::Optional wasThrown; + folly::Optional isOwn; + folly::Optional symbol; +}; + +struct runtime::InternalPropertyDescriptor : public Serializable { + InternalPropertyDescriptor() = default; + explicit InternalPropertyDescriptor(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + std::string name; + folly::Optional value; +}; + +/// Requests +struct UnknownRequest : public Request { + UnknownRequest(); + explicit UnknownRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; + + folly::Optional params; +}; + +struct debugger::DisableRequest : public Request { + DisableRequest(); + explicit DisableRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; +}; + +struct debugger::EnableRequest : public Request { + EnableRequest(); + explicit EnableRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; +}; + +struct debugger::EvaluateOnCallFrameRequest : public Request { + EvaluateOnCallFrameRequest(); + explicit EvaluateOnCallFrameRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; + + debugger::CallFrameId callFrameId{}; + std::string expression; + folly::Optional objectGroup; + folly::Optional includeCommandLineAPI; + folly::Optional silent; + folly::Optional returnByValue; +}; + +struct debugger::PauseRequest : public Request { + PauseRequest(); + explicit PauseRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; +}; + +struct debugger::RemoveBreakpointRequest : public Request { + RemoveBreakpointRequest(); + explicit RemoveBreakpointRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; + + debugger::BreakpointId breakpointId{}; +}; + +struct debugger::ResumeRequest : public Request { + ResumeRequest(); + explicit ResumeRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; +}; + +struct debugger::SetBreakpointByUrlRequest : public Request { + SetBreakpointByUrlRequest(); + explicit SetBreakpointByUrlRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; + + int lineNumber{}; + folly::Optional url; + folly::Optional urlRegex; + folly::Optional columnNumber; + folly::Optional condition; +}; + +struct debugger::SetPauseOnExceptionsRequest : public Request { + SetPauseOnExceptionsRequest(); + explicit SetPauseOnExceptionsRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; + + std::string state; +}; + +struct debugger::StepIntoRequest : public Request { + StepIntoRequest(); + explicit StepIntoRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; +}; + +struct debugger::StepOutRequest : public Request { + StepOutRequest(); + explicit StepOutRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; +}; + +struct debugger::StepOverRequest : public Request { + StepOverRequest(); + explicit StepOverRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; +}; + +struct runtime::EvaluateRequest : public Request { + EvaluateRequest(); + explicit EvaluateRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; + + std::string expression; + folly::Optional objectGroup; + folly::Optional includeCommandLineAPI; + folly::Optional silent; + folly::Optional contextId; + folly::Optional returnByValue; + folly::Optional awaitPromise; +}; + +struct runtime::GetPropertiesRequest : public Request { + GetPropertiesRequest(); + explicit GetPropertiesRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; + + runtime::RemoteObjectId objectId{}; + folly::Optional ownProperties; +}; + +/// Responses +struct ErrorResponse : public Response { + ErrorResponse() = default; + explicit ErrorResponse(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + int code; + std::string message; + folly::Optional data; +}; + +struct OkResponse : public Response { + OkResponse() = default; + explicit OkResponse(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; +}; + +struct debugger::EvaluateOnCallFrameResponse : public Response { + EvaluateOnCallFrameResponse() = default; + explicit EvaluateOnCallFrameResponse(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + runtime::RemoteObject result{}; + folly::Optional exceptionDetails; +}; + +struct debugger::SetBreakpointByUrlResponse : public Response { + SetBreakpointByUrlResponse() = default; + explicit SetBreakpointByUrlResponse(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + debugger::BreakpointId breakpointId{}; + std::vector locations; +}; + +struct runtime::EvaluateResponse : public Response { + EvaluateResponse() = default; + explicit EvaluateResponse(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + runtime::RemoteObject result{}; + folly::Optional exceptionDetails; +}; + +struct runtime::GetPropertiesResponse : public Response { + GetPropertiesResponse() = default; + explicit GetPropertiesResponse(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + std::vector result; + folly::Optional> + internalProperties; + folly::Optional exceptionDetails; +}; + +/// Notifications +struct debugger::BreakpointResolvedNotification : public Notification { + BreakpointResolvedNotification(); + explicit BreakpointResolvedNotification(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + debugger::BreakpointId breakpointId{}; + debugger::Location location{}; +}; + +struct debugger::PausedNotification : public Notification { + PausedNotification(); + explicit PausedNotification(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + std::vector callFrames; + std::string reason; + folly::Optional data; + folly::Optional> hitBreakpoints; + folly::Optional asyncStackTrace; +}; + +struct debugger::ResumedNotification : public Notification { + ResumedNotification(); + explicit ResumedNotification(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; +}; + +struct debugger::ScriptParsedNotification : public Notification { + ScriptParsedNotification(); + explicit ScriptParsedNotification(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + runtime::ScriptId scriptId{}; + std::string url; + int startLine{}; + int startColumn{}; + int endLine{}; + int endColumn{}; + runtime::ExecutionContextId executionContextId{}; + std::string hash; + folly::Optional executionContextAuxData; + folly::Optional sourceMapURL; +}; + +struct runtime::ConsoleAPICalledNotification : public Notification { + ConsoleAPICalledNotification(); + explicit ConsoleAPICalledNotification(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + std::string type; + std::vector args; + runtime::ExecutionContextId executionContextId{}; + runtime::Timestamp timestamp{}; + folly::Optional stackTrace; +}; + +struct runtime::ExecutionContextCreatedNotification : public Notification { + ExecutionContextCreatedNotification(); + explicit ExecutionContextCreatedNotification(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + runtime::ExecutionContextDescription context{}; +}; + +} // namespace message +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/MessageTypesInlines.h b/ReactCommon/hermes/inspector/chrome/MessageTypesInlines.h new file mode 100644 index 00000000000..a6cd448ba5e --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/MessageTypesInlines.h @@ -0,0 +1,154 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include + +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { +namespace message { + +using dynamic = folly::dynamic; + +template +using optional = folly::Optional; + +template +struct is_vector : std::false_type {}; + +template +struct is_vector> : std::true_type {}; + +/// valueFromDynamic + +template +typename std::enable_if::value, T>::type +valueFromDynamic(const dynamic &obj) { + return T(obj); +} + +template +typename std::enable_if::value, T>::type valueFromDynamic( + const dynamic &obj) { + return obj.asInt(); +} + +template +typename std::enable_if::value, T>::type +valueFromDynamic(const dynamic &obj) { + return obj.asDouble(); +} + +template +typename std::enable_if::value, T>::type +valueFromDynamic(const dynamic &obj) { + return obj.asString(); +} + +template +typename std::enable_if::value, T>::type +valueFromDynamic(const dynamic &obj) { + return obj; +} + +template +typename std::enable_if::value, T>::type valueFromDynamic( + const dynamic &items) { + T result; + result.reserve(items.size()); + for (const auto &item : items) { + result.push_back(valueFromDynamic(item)); + } + return result; +} + +/// assign(lhs, obj, key) is a wrapper for: +/// +/// lhs = obj[key] +/// +/// It mainly exists so that we can choose the right version of valueFromDynamic +/// based on the type of lhs. + +template +void assign(T &lhs, const dynamic &obj, const U &key) { + lhs = valueFromDynamic(obj.at(key)); +} + +template +void assign(optional &lhs, const dynamic &obj, const U &key) { + auto it = obj.find(key); + if (it != obj.items().end()) { + lhs = valueFromDynamic(it->second); + } else { + lhs.clear(); + } +} + +template +void assign(std::unique_ptr &lhs, const dynamic &obj, const U &key) { + auto it = obj.find(key); + if (it != obj.items().end()) { + lhs = std::make_unique(valueFromDynamic(it->second)); + } else { + lhs.reset(); + } +} + +/// valueToDynamic + +inline dynamic valueToDynamic(const Serializable &value) { + return value.toDynamic(); +} + +template +typename std::enable_if::value, dynamic>::type +valueToDynamic(const T &item) { + return dynamic(item); +} + +template +dynamic valueToDynamic(const std::vector &items) { + dynamic result = dynamic::array; + for (const auto &item : items) { + result.push_back(valueToDynamic(item)); + } + return result; +} + +/// put(obj, key, value) is a wrapper for: +/// +/// obj[key] = valueToDynamic(value); + +template +void put(dynamic &obj, const K &key, const V &value) { + obj[key] = valueToDynamic(value); +} + +template +void put(dynamic &obj, const K &key, const optional &optValue) { + if (optValue.hasValue()) { + obj[key] = valueToDynamic(optValue.value()); + } else { + obj.erase(key); + } +} + +template +void put(dynamic &obj, const K &key, const std::unique_ptr &ptr) { + if (ptr.get()) { + obj[key] = valueToDynamic(*ptr); + } else { + obj.erase(key); + } +} + +} // namespace message +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/Registration.cpp b/ReactCommon/hermes/inspector/chrome/Registration.cpp new file mode 100644 index 00000000000..bee7d9abd87 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/Registration.cpp @@ -0,0 +1,33 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "Registration.h" +#include "ConnectionDemux.h" + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +namespace { + +ConnectionDemux &demux() { + static ConnectionDemux instance{facebook::react::getInspectorInstance()}; + return instance; +} + +} // namespace + +void enableDebugging( + std::unique_ptr adapter, + const std::string &title) { + demux().enableDebugging(std::move(adapter), title); +} + +void disableDebugging(HermesRuntime &runtime) { + demux().disableDebugging(runtime); +} + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/Registration.h b/ReactCommon/hermes/inspector/chrome/Registration.h new file mode 100644 index 00000000000..b9b0bdfbaf7 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/Registration.h @@ -0,0 +1,34 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include + +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +/* + * enableDebugging adds this runtime to the list of debuggable JS targets + * (called "pages" in the higher-leavel React Native API) in this process. It + * should be called before any JS runs in the runtime. + */ +extern void enableDebugging( + std::unique_ptr adapter, + const std::string &title); + +/* + * disableDebugging removes this runtime from the list of debuggable JS targets + * in this process. + */ +extern void disableDebugging(HermesRuntime &runtime); + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/RemoteObjectsTable.cpp b/ReactCommon/hermes/inspector/chrome/RemoteObjectsTable.cpp new file mode 100644 index 00000000000..9f8ab747842 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/RemoteObjectsTable.cpp @@ -0,0 +1,141 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "RemoteObjectsTable.h" + +#include + +#include + +namespace { + +bool isScopeId(int64_t id) { + return id < 0; +} + +bool isValueId(int64_t id) { + return id > 0; +} + +std::string toObjId(int64_t id) { + return folly::to(id); +} + +int64_t toId(const std::string &objId) { + return atoll(objId.c_str()); +} + +} // namespace + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +const char *BacktraceObjectGroup = "backtrace"; + +const char *ConsoleObjectGroup = "console"; + +RemoteObjectsTable::RemoteObjectsTable() = default; + +RemoteObjectsTable::~RemoteObjectsTable() = default; + +std::string RemoteObjectsTable::addScope( + std::pair frameAndScopeIndex, + const std::string &objectGroup) { + int64_t id = scopeId_--; + scopes_[id] = frameAndScopeIndex; + + if (!objectGroup.empty()) { + idToGroup_[id] = objectGroup; + groupToIds_[objectGroup].push_back(id); + } + + return toObjId(id); +} + +std::string RemoteObjectsTable::addValue( + ::facebook::jsi::Value value, + const std::string &objectGroup) { + int64_t id = valueId_++; + values_[id] = std::move(value); + + if (!objectGroup.empty()) { + idToGroup_[id] = objectGroup; + groupToIds_[objectGroup].push_back(id); + } + + return toObjId(id); +} + +const std::pair *RemoteObjectsTable::getScope( + const std::string &objId) const { + int64_t id = toId(objId); + if (!isScopeId(id)) { + return nullptr; + } + + auto it = scopes_.find(id); + if (it == scopes_.end()) { + return nullptr; + } + + return &it->second; +} + +const ::facebook::jsi::Value *RemoteObjectsTable::getValue( + const std::string &objId) const { + int64_t id = toId(objId); + if (!isValueId(id)) { + return nullptr; + } + + auto it = values_.find(id); + if (it == values_.end()) { + return nullptr; + } + + return &it->second; +} + +std::string RemoteObjectsTable::getObjectGroup(const std::string &objId) const { + int64_t id = toId(objId); + + auto it = idToGroup_.find(id); + if (it == idToGroup_.end()) { + return ""; + } + + return it->second; +} + +void RemoteObjectsTable::releaseObject(int64_t id) { + if (isScopeId(id)) { + scopes_.erase(id); + } else if (isValueId(id)) { + values_.erase(id); + } +} + +void RemoteObjectsTable::releaseObject(const std::string &objId) { + int64_t id = toId(objId); + releaseObject(id); +} + +void RemoteObjectsTable::releaseObjectGroup(const std::string &objectGroup) { + auto it = groupToIds_.find(objectGroup); + if (it == groupToIds_.end()) { + return; + } + + const auto &ids = it->second; + for (int64_t id : ids) { + releaseObject(id); + } + + groupToIds_.erase(it); +} + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/RemoteObjectsTable.h b/ReactCommon/hermes/inspector/chrome/RemoteObjectsTable.h new file mode 100644 index 00000000000..76cbded34d9 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/RemoteObjectsTable.h @@ -0,0 +1,119 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include +#include +#include + +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +/// Well-known object group names + +/** + * Objects created as a result of the Debugger.paused notification (e.g. scope + * objects) are placed in the "backtrace" object group. This object group is + * cleared when the VM resumes. + */ +extern const char *BacktraceObjectGroup; + +/** + * Objects that are created as a result of a console evaluation are placed in + * the "console" object group. This object group is cleared when the client + * clears the console. + */ +extern const char *ConsoleObjectGroup; + +/** + * RemoteObjectsTable manages the mapping of string object ids to scope metadata + * or actual JSI objects. The debugger vends these ids to the client so that the + * client can perform operations on the ids (e.g. enumerate properties on the + * object backed by the id). See Runtime.RemoteObjectId in the CDT docs for + * more details. + * + * Note that object handles are not ref-counted. Suppose an object foo is mapped + * to object id "objId" and is also in object group "objGroup". Then *either* of + * `releaseObject("objId")` or `releaseObjectGroup("objGroup")` will remove foo + * from the table. This matches the behavior of object groups in CDT. + */ +class RemoteObjectsTable { + public: + RemoteObjectsTable(); + ~RemoteObjectsTable(); + + RemoteObjectsTable(const RemoteObjectsTable &) = delete; + RemoteObjectsTable &operator=(const RemoteObjectsTable &) = delete; + + /** + * addScope adds the provided (frameIndex, scopeIndex) mapping to the table. + * If objectGroup is non-empty, then the scope object is also added to that + * object group for releasing via releaseObjectGroup. Returns an object id. + */ + std::string addScope( + std::pair frameAndScopeIndex, + const std::string &objectGroup); + + /** + * addValue adds the JSI value to the table. If objectGroup is non-empty, then + * the scope object is also added to that object group for releasing via + * releaseObjectGroup. Returns an object id. + */ + std::string addValue( + ::facebook::jsi::Value value, + const std::string &objectGroup); + + /** + * Retrieves the (frameIndex, scopeIndex) associated with this object id, or + * nullptr if no mapping exists. The pointer stays valid as long as you only + * call const methods on this class. + */ + const std::pair *getScope(const std::string &objId) const; + + /** + * Retrieves the JSI value associated with this object id, or nullptr if no + * mapping exists. The pointer stays valid as long as you only call const + * methods on this class. + */ + const ::facebook::jsi::Value *getValue(const std::string &objId) const; + + /** + * Retrieves the object group that this object id is in, or empty string if it + * isn't in an object group. The returned pointer is only guaranteed to be + * valid until the next call to this class. + */ + std::string getObjectGroup(const std::string &objId) const; + + /** + * Removes the scope or JSI value backed by the provided object ID from the + * table. + */ + void releaseObject(const std::string &objId); + + /** + * Removes all objects that are part of the provided object group from the + * table. + */ + void releaseObjectGroup(const std::string &objectGroup); + + private: + void releaseObject(int64_t id); + + int64_t scopeId_ = -1; + int64_t valueId_ = 1; + + std::unordered_map> scopes_; + std::unordered_map values_; + std::unordered_map idToGroup_; + std::unordered_map> groupToIds_; +}; + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/cli/main.cpp b/ReactCommon/hermes/inspector/chrome/cli/main.cpp new file mode 100644 index 00000000000..7713a0856f4 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/cli/main.cpp @@ -0,0 +1,197 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include + +using ::facebook::react::IRemoteConnection; + +namespace fbhermes = ::facebook::hermes; + +static const char *usageMessage = R"(hermes-chrome-debug-server script.js + +Uses Hermes to evaluate script.js within a debugging session. The process will +wait for Chrome DevTools Protocol requests on stdin and writes responses and +events to stdout. + +This can be used with a WebSocket bridge to host a Chrome DevTools Protocol +debug server. For instance, running this: + + websocketd --port=9999 hermes-chrome-debug-server script.js + +will run a WebSocket server on port 9999 that debugs script.js in Hermes. Chrome +can connect to this debugging session using a URL like this: + + chrome-devtools://devtools/bundled/inspector.html?experiments=false&v8only=true&ws=127.0.0.1:9999 + +Options: + + -l, --log: path to a file with pretty-printed protocol logs + -h, --help: this message +)"; + +static void usage() { + fputs(usageMessage, stderr); + exit(1); +} + +static std::string prettify(const std::string &str) { + try { + folly::dynamic obj = folly::parseJson(str); + return folly::toPrettyJson(obj); + } catch (...) { + // pass + } + return str; +} + +static FILE *logFile = stderr; + +static void setLogFilePath(const char *path) { + logFile = fopen(path, "w"); + + if (logFile == nullptr) { + perror("fopen couldn't open log file"); + exit(1); + } +} + +static void log(const std::string &str, bool isReq) { + fprintf(logFile, "%s %s\n\n", isReq ? "=>" : "<=", prettify(str).c_str()); +} + +static void logRequest(const std::string &str) { + log(str, true); +} + +static void sendResponse(const std::string &str) { + log(str, false); + printf("%s\n", str.c_str()); +} + +static std::string readScriptSource(const char *path) { + std::ifstream stream(path); + return std::string{std::istreambuf_iterator(stream), + std::istreambuf_iterator()}; +} + +static std::string getUrl(const char *path) { + char absPath[PATH_MAX] = {}; + realpath(path, absPath); + return std::string("file://") + absPath; +} + +static bool handleScriptSourceRequest( + const std::string &reqStr, + const std::string &scriptSource) { + auto req = folly::parseJson(reqStr); + + if (req.at("method") == "Debugger.getScriptSource") { + folly::dynamic result = folly::dynamic::object; + result["scriptSource"] = scriptSource; + + folly::dynamic resp = folly::dynamic::object; + resp["id"] = req.at("id"); + resp["result"] = std::move(result); + + sendResponse(folly::toJson(resp)); + + return true; + } + + return false; +} + +class RemoteConnection : public IRemoteConnection { + public: + void onMessage(std::string message) override { + sendResponse(message); + } + + void onDisconnect() override {} +}; + +static void runDebuggerLoop( + fbhermes::inspector::chrome::Connection &conn, + std::string scriptSource) { + conn.connect(std::make_unique()); + + std::string line; + while (std::getline(std::cin, line)) { + logRequest(line); + + if (!handleScriptSourceRequest(line, scriptSource)) { + conn.sendMessage(line); + } + } +} + +static void runScript(const std::string &scriptSource, const std::string &url) { + std::shared_ptr runtime( + fbhermes::makeHermesRuntime()); + auto adapter = + std::make_unique(runtime); + fbhermes::inspector::chrome::Connection conn( + std::move(adapter), "hermes-chrome-debug-server"); + std::thread debuggerLoop(runDebuggerLoop, std::ref(conn), scriptSource); + + fbhermes::HermesRuntime::DebugFlags flags{}; + runtime->debugJavaScript(scriptSource, url, flags); + + debuggerLoop.join(); +} + +int main(int argc, char **argv) { + const char *shortOpts = "l:h"; + const option longOpts[] = {{"log", 1, nullptr, 'l'}, + {"help", 0, nullptr, 'h'}, + {nullptr, 0, nullptr, 0}}; + + while (true) { + int opt = getopt_long(argc, argv, shortOpts, longOpts, nullptr); + if (opt == -1) { + break; + } + + switch (opt) { + case 'l': + setLogFilePath(optarg); + break; + case 'h': + usage(); + break; + default: + fprintf(stderr, "Unrecognized option: %c\n", opt); + usage(); + break; + } + } + + setbuf(logFile, nullptr); + setbuf(stdout, nullptr); + + if (optind + 1 != argc) { + usage(); + } + + const char *path = argv[optind]; + std::string scriptSource = readScriptSource(path); + std::string url = getUrl(path); + + runScript(scriptSource, url); + + fclose(logFile); + + return 0; +} diff --git a/ReactCommon/hermes/inspector/chrome/tests/AsyncHermesRuntime.cpp b/ReactCommon/hermes/inspector/chrome/tests/AsyncHermesRuntime.cpp new file mode 100644 index 00000000000..e4dc978937e --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/tests/AsyncHermesRuntime.cpp @@ -0,0 +1,131 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "AsyncHermesRuntime.h" + +#include +#include +#include + +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +namespace detail = facebook::hermes::inspector::detail; + +AsyncHermesRuntime::AsyncHermesRuntime() + : runtime_(facebook::hermes::makeHermesRuntime()), + executor_( + std::make_unique("async-hermes-runtime")) { + using namespace std::placeholders; + + runtime_->global().setProperty( + *runtime_, + "shouldStop", + jsi::Function::createFromHostFunction( + *runtime_, + jsi::PropNameID::forAscii(*runtime_, "shouldStop"), + 0, + std::bind(&AsyncHermesRuntime::shouldStop, this, _1, _2, _3, _4))); + + runtime_->global().setProperty( + *runtime_, + "storeValue", + jsi::Function::createFromHostFunction( + *runtime_, + jsi::PropNameID::forAscii(*runtime_, "storeValue"), + 0, + std::bind(&AsyncHermesRuntime::storeValue, this, _1, _2, _3, _4))); +} + +AsyncHermesRuntime::~AsyncHermesRuntime() { + stop(); + wait(); +} + +void AsyncHermesRuntime::executeScriptAsync( + const std::string &script, + const std::string &url, + HermesRuntime::DebugFlags flags) { + int scriptId = rand(); + LOG(INFO) << "AsyncHermesRuntime will execute script with id: " << scriptId + << ", contents: " << script; + + executor_->add([this, script, url, flags, scriptId] { + LOG(INFO) << "AsyncHermesRuntime executing script id " << scriptId + << " in background"; + + try { + runtime_->debugJavaScript(script, url, flags); + } catch (jsi::JSError &error) { + LOG(INFO) << "AsyncHermesRuntime JSError " << error.getMessage(); + thrownExceptions_.push_back(error.getMessage()); + } + + LOG(INFO) << "AsyncHermesRuntime finished executing script id " << scriptId; + }); +} + +void AsyncHermesRuntime::start() { + LOG(INFO) << "AsyncHermesRuntime: set stop flag false"; + stopFlag_.store(false); +} + +void AsyncHermesRuntime::stop() { + LOG(INFO) << "AsyncHermesRuntime: set stop flag true"; + stopFlag_.store(true); +} + +folly::Future AsyncHermesRuntime::getStoredValue() { + return storedValue_.getFuture(); +} + +jsi::Value AsyncHermesRuntime::awaitStoredValue( + std::chrono::milliseconds timeout) { + return getStoredValue().get(timeout); +} + +void AsyncHermesRuntime::wait(std::chrono::milliseconds timeout) { + LOG(INFO) << "AsyncHermesRuntime wait requested"; + auto promise = std::make_shared>(); + auto future = promise->getFuture(); + executor_->add([promise] { + LOG(INFO) << "AsyncHermesRuntime wait resolved"; + promise->setValue(true); + }); + std::move(future).get(timeout); +} + +jsi::Value AsyncHermesRuntime::shouldStop( + jsi::Runtime &runtime, + const jsi::Value &thisVal, + const jsi::Value *args, + size_t count) { + return stopFlag_.load() ? jsi::Value(true) : jsi::Value(false); +} + +jsi::Value AsyncHermesRuntime::storeValue( + jsi::Runtime &runtime, + const jsi::Value &thisVal, + const jsi::Value *args, + size_t count) { + if (count > 0) { + storedValue_.setValue(jsi::Value(runtime, args[0])); + } + return jsi::Value(); +} + +size_t AsyncHermesRuntime::getNumberOfExceptions() { + return thrownExceptions_.size(); +} + +std::string AsyncHermesRuntime::getLastThrownExceptionMessage() { + return thrownExceptions_.back(); +} + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/tests/AsyncHermesRuntime.h b/ReactCommon/hermes/inspector/chrome/tests/AsyncHermesRuntime.h new file mode 100644 index 00000000000..55dbc84e796 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/tests/AsyncHermesRuntime.h @@ -0,0 +1,109 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +/** + * AsyncHermesRuntime is a helper class that runs JS scripts in a Hermes VM on + * a separate thread. This is useful for tests that want to test running JS + * in a multithreaded environment. + */ +class AsyncHermesRuntime { + public: + AsyncHermesRuntime(); + ~AsyncHermesRuntime(); + + std::shared_ptr runtime() { + return runtime_; + } + + /** + * stop sets the stop flag on this instance. JS scripts can get the current + * value of the stop flag by calling the global shouldStop() function. + */ + void stop(); + + /** + * start unsets the stop flag on this instance. JS scripts can get the current + * value of the stop flag by calling the global shouldStop() function. + */ + void start(); + + /** + * getStoredValue returns a future that is fulfilled with the value passed in + * to storeValue() by the JS script. + */ + folly::Future getStoredValue(); + + /** + * awaitStoredValue is a helper for getStoredValue that returns the value + * synchronously rather than in a future. + */ + jsi::Value awaitStoredValue( + std::chrono::milliseconds timeout = std::chrono::milliseconds(2500)); + + /** + * executeScriptAsync evaluates JS in the underlying Hermes runtime on a + * separate thread. + * + * This method should be called at most once during the lifetime of an + * AsyncHermesRuntime instance. + */ + void executeScriptAsync( + const std::string &str, + const std::string &url = "url", + facebook::hermes::HermesRuntime::DebugFlags flags = + facebook::hermes::HermesRuntime::DebugFlags{}); + + /** + * wait blocks until all previous executeScriptAsync calls finish. + */ + void wait( + std::chrono::milliseconds timeout = std::chrono::milliseconds(2500)); + + /** + * returns the number of thrown exceptions. + */ + size_t getNumberOfExceptions(); + + /** + * returns the message of the last thrown exception. + */ + std::string getLastThrownExceptionMessage(); + + private: + jsi::Value shouldStop( + jsi::Runtime &runtime, + const jsi::Value &thisVal, + const jsi::Value *args, + size_t count); + + jsi::Value storeValue( + jsi::Runtime &runtime, + const jsi::Value &thisVal, + const jsi::Value *args, + size_t count); + + std::shared_ptr runtime_; + std::unique_ptr executor_; + std::atomic stopFlag_{}; + folly::Promise storedValue_; + std::vector thrownExceptions_; +}; + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/tests/ConnectionDemuxTests.cpp b/ReactCommon/hermes/inspector/chrome/tests/ConnectionDemuxTests.cpp new file mode 100644 index 00000000000..43ba86f918b --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/tests/ConnectionDemuxTests.cpp @@ -0,0 +1,142 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +using ::facebook::react::IInspector; +using ::facebook::react::InspectorPage; +using ::facebook::react::IRemoteConnection; + +namespace { + +std::unordered_map makePageMap( + const std::vector &pages) { + std::unordered_map pageMap; + + for (auto &page : pages) { + pageMap[page.id] = page.title; + } + + return pageMap; +} + +void expectPages( + IInspector &inspector, + const std::unordered_map &expected) { + auto pages = makePageMap(inspector.getPages()); + EXPECT_EQ(pages, expected); +} + +class TestRemoteConnection : public IRemoteConnection { + public: + class Data { + public: + void expectDisconnected() { + std::unique_lock lock(mutex_); + cv_.wait_for( + lock, std::chrono::milliseconds(2500), [&] { return !connected_; }); + EXPECT_FALSE(connected_); + } + + void setDisconnected() { + std::lock_guard lock(mutex_); + connected_ = false; + cv_.notify_one(); + } + + private: + std::mutex mutex_; + std::condition_variable cv_; + bool connected_{true}; + }; + + TestRemoteConnection() : data_(std::make_shared()) {} + ~TestRemoteConnection() {} + + void onMessage(std::string message) override {} + + void onDisconnect() override { + data_->setDisconnected(); + } + + std::shared_ptr getData() { + return data_; + } + + private: + std::shared_ptr data_; +}; + +}; // namespace + +TEST(ConnectionDemuxTests, TestEnableDisable) { + std::shared_ptr runtime1( + facebook::hermes::makeHermesRuntime()); + std::shared_ptr runtime2( + facebook::hermes::makeHermesRuntime()); + auto inspector = facebook::react::makeTestInspectorInstance(); + + ConnectionDemux demux{*inspector}; + + int id1 = demux.enableDebugging( + std::make_unique(runtime1), "page1"); + int id2 = demux.enableDebugging( + std::make_unique(runtime2), "page2"); + + expectPages(*inspector, {{id1, "page1"}, {id2, "page2"}}); + + auto remoteConn1 = std::make_unique(); + auto remoteData1 = remoteConn1->getData(); + auto localConn1 = inspector->connect(id1, std::move(remoteConn1)); + EXPECT_NE(localConn1.get(), nullptr); + + { + // If we connect to the same page id again without disconnecting, we should + // get null + auto remoteConn = std::make_unique(); + auto localConn = inspector->connect(id1, std::move(remoteConn)); + EXPECT_EQ(localConn.get(), nullptr); + } + + auto remoteConn2 = std::make_unique(); + auto remoteData2 = remoteConn2->getData(); + auto localConn2 = inspector->connect(id2, std::move(remoteConn2)); + EXPECT_NE(localConn2.get(), nullptr); + + // Disable debugging on runtime2. This should remove its page from the list + // and call onDisconnect on its remoteConn + demux.disableDebugging(*runtime2); + expectPages(*inspector, {{id1, "page1"}}); + remoteData2->expectDisconnected(); + + // Disconnect conn1. Its page should still be in the page list and + // onDisconnect should be called. + localConn1->disconnect(); + remoteData1->expectDisconnected(); + + { + // Should still be able to reconnect after disconnecting + auto remoteConn = std::make_unique(); + auto localConn = inspector->connect(id1, std::move(remoteConn)); + EXPECT_NE(localConn.get(), nullptr); + } +} + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/tests/ConnectionTests.cpp b/ReactCommon/hermes/inspector/chrome/tests/ConnectionTests.cpp new file mode 100644 index 00000000000..266b78872c9 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/tests/ConnectionTests.cpp @@ -0,0 +1,2151 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "AsyncHermesRuntime.h" +#include "SyncConnection.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +namespace m = ::facebook::hermes::inspector::chrome::message; + +using namespace std::chrono_literals; + +namespace { + +// This class mostly exists to call AsyncHermesRuntime::wait() before we +// destruct either AsyncHermesRuntime or SyncConnection. +// +// The reason for this is that we need to make sure the runtime is finished +// executing scripts before we destruct the debugger connection. Otherwise, if +// we destruct the connection while scripts are still executing, the script +// could perform an action (like hitting a breakpoint) that sends a message to +// the already-deallocated connection. +class TestContext { + public: + TestContext() : conn_(runtime_.runtime()) {} + ~TestContext() { + runtime_.wait(); + } + + AsyncHermesRuntime &runtime() { + return runtime_; + } + + SyncConnection &conn() { + return conn_; + } + + private: + AsyncHermesRuntime runtime_; + SyncConnection conn_; +}; + +template +ResponseType expectResponse(SyncConnection &conn, int id) { + ResponseType resp; + + conn.waitForResponse([id, &resp](const std::string &str) { + resp = ResponseType(folly::parseJson(str)); + EXPECT_EQ(resp.id, id); + }); + + return resp; +} + +template +NotificationType expectNotification(SyncConnection &conn) { + NotificationType note; + + conn.waitForNotification([¬e](const std::string &str) { + std::string parseError; + + try { + note = NotificationType(folly::parseJson(str)); + } catch (const std::exception &e) { + parseError = e.what(); + } + + EXPECT_EQ(parseError, ""); + }); + + return note; +} + +class UnexpectedNotificationException : public std::runtime_error { + public: + UnexpectedNotificationException() + : std::runtime_error("unexpected notification") {} +}; + +void expectNothing(SyncConnection &conn) { + auto promise = std::make_shared>(); + auto future = promise->getFuture(); + try { + conn.waitForNotification([promise](const std::string &str) { + // if we receive a value fail the promise + promise->setException(UnexpectedNotificationException()); + }); + } catch (...) { + // if no values are received it times out with an exception + // so we can say that we've succeeded at seeing nothing + promise->setValue(); + } + // timeout is 2500 milliseconds in SyncConnection::waitForNotification + // so this value is mostly a redundant safety measure + std::move(future).get(3000ms); +} + +struct FrameInfo { + FrameInfo(const std::string &functionName, int lineNumber, int scopeCount) + : functionName(functionName), + lineNumberMin(lineNumber), + lineNumberMax(lineNumber), + scopeCount(scopeCount), + columnNumber(debugger::kInvalidLocation) {} + + FrameInfo &setLineNumberMax(int lineNumberMaxParam) { + lineNumberMax = lineNumberMaxParam; + return *this; + } + + FrameInfo &setScriptId(const std::string &scriptIdParam) { + scriptId = scriptIdParam; + return *this; + } + + FrameInfo &setColumnNumber(int columnNumberParam) { + columnNumber = columnNumberParam; + return *this; + } + + std::string functionName; + int lineNumberMin; + int lineNumberMax; + int scopeCount; + int columnNumber; + std::string scriptId; +}; + +void expectCallFrames( + const std::vector &frames, + const std::vector &infos) { + EXPECT_EQ(frames.size(), infos.size()); + + int i = 0; + for (const FrameInfo &info : infos) { + m::debugger::CallFrame frame = frames[i]; + + EXPECT_EQ(frame.callFrameId, folly::to(i)); + EXPECT_EQ(frame.functionName, info.functionName); + EXPECT_GE(frame.location.lineNumber, info.lineNumberMin); + EXPECT_LE(frame.location.lineNumber, info.lineNumberMax); + + if (info.columnNumber != debugger::kInvalidLocation) { + EXPECT_EQ(frame.location.columnNumber, info.columnNumber); + } + + if (info.scriptId.size() > 0) { + EXPECT_EQ(frame.location.scriptId, info.scriptId); + } + + // TODO: make expectation more specific once Hermes gives us something other + // than kInvalidBreakpoint for the file id + EXPECT_FALSE(frame.location.scriptId.empty()); + + if (info.scopeCount > 0) { + EXPECT_EQ(frame.scopeChain.size(), info.scopeCount); + + for (int j = 0; j < info.scopeCount; j++) { + EXPECT_TRUE(frame.scopeChain[j].object.objectId.hasValue()); + } + } + + i++; + } +} + +// Helper to send a request wait for an empty response containing the req id. +template +void send(SyncConnection &conn, int id) { + RequestType req; + req.id = id; + conn.send(req.toJson()); + + expectResponse(conn, id); +} + +void sendRuntimeEvalRequest( + SyncConnection &conn, + int id, + const std::string &expression) { + m::runtime::EvaluateRequest req; + req.id = id; + req.expression = expression; + conn.send(req.toJson()); +} + +void sendEvalRequest( + SyncConnection &conn, + int id, + int callFrameId, + const std::string &expression) { + m::debugger::EvaluateOnCallFrameRequest req; + req.id = id; + req.callFrameId = folly::to(callFrameId); + req.expression = expression; + conn.send(req.toJson()); +} + +m::runtime::ExecutionContextCreatedNotification expectExecutionContextCreated( + SyncConnection &conn) { + auto note = + expectNotification(conn); + + EXPECT_EQ(note.context.id, 1); + EXPECT_EQ(note.context.origin, ""); + EXPECT_EQ(note.context.name, "hermes"); + EXPECT_EQ(note.context.isDefault, true); + EXPECT_EQ(note.context.isPageContext, true); + + return note; +} + +m::debugger::ScriptParsedNotification expectScriptParsed( + SyncConnection &conn, + const std::string &url, + const std::string &sourceMapURL) { + auto note = expectNotification(conn); + + EXPECT_EQ(note.url, url); + EXPECT_GT(note.scriptId.size(), 0); + + if (sourceMapURL.empty()) { + EXPECT_FALSE(note.sourceMapURL.hasValue()); + } else { + EXPECT_EQ(note.sourceMapURL.value(), sourceMapURL); + } + + return note; +} + +m::debugger::PausedNotification expectPaused( + SyncConnection &conn, + const std::string &reason, + const std::vector &infos) { + auto note = expectNotification(conn); + + EXPECT_EQ(note.reason, reason); + expectCallFrames(note.callFrames, infos); + // TODO: check breakpoint location for pause once hermes gives that to us + + return note; +} + +m::debugger::BreakpointId expectBreakpointResponse( + SyncConnection &conn, + int id, + int line, + int resolvedLine) { + auto resp = expectResponse(conn, id); + + EXPECT_EQ(resp.id, id); + EXPECT_FALSE(resp.breakpointId.empty()); + EXPECT_NE( + resp.breakpointId, + folly::to(facebook::hermes::debugger::kInvalidBreakpoint)); + + if (line == -1) { + EXPECT_EQ(resp.locations.size(), 0); + } else { + EXPECT_EQ(resp.locations.size(), 1); + EXPECT_EQ(resp.locations[0].lineNumber, resolvedLine); + } + + return resp.breakpointId; +} + +void expectEvalResponse( + SyncConnection &conn, + int id, + const char *expectedValue) { + auto resp = + expectResponse(conn, id); + + EXPECT_EQ(resp.id, id); + EXPECT_EQ(resp.result.type, "string"); + EXPECT_EQ(resp.result.value, expectedValue); + EXPECT_FALSE(resp.exceptionDetails.hasValue()); +} + +void expectEvalResponse(SyncConnection &conn, int id, bool expectedValue) { + auto resp = + expectResponse(conn, id); + + EXPECT_EQ(resp.id, id); + EXPECT_EQ(resp.result.type, "boolean"); + EXPECT_EQ(resp.result.value, expectedValue); + EXPECT_FALSE(resp.exceptionDetails.hasValue()); +} + +void expectEvalResponse(SyncConnection &conn, int id, int expectedValue) { + auto resp = + expectResponse(conn, id); + + EXPECT_EQ(resp.id, id); + EXPECT_EQ(resp.result.type, "number"); + EXPECT_EQ(resp.result.value, expectedValue); + EXPECT_FALSE(resp.exceptionDetails.hasValue()); +} + +void expectEvalException( + SyncConnection &conn, + int id, + const std::string &exceptionText, + const std::vector infos) { + auto resp = + expectResponse(conn, id); + + EXPECT_EQ(resp.id, id); + EXPECT_TRUE(resp.exceptionDetails.hasValue()); + + m::runtime::ExceptionDetails &details = resp.exceptionDetails.value(); + EXPECT_EQ(details.text, exceptionText); + + // TODO: Hermes doesn't seem to populate the line number for the exception? + EXPECT_EQ(details.lineNumber, 0); + + EXPECT_TRUE(details.stackTrace.hasValue()); + + m::runtime::StackTrace &stackTrace = details.stackTrace.value(); + EXPECT_EQ(stackTrace.callFrames.size(), infos.size()); + + int i = 0; + for (const FrameInfo &info : infos) { + const m::runtime::CallFrame &callFrame = stackTrace.callFrames[i]; + + EXPECT_GE(callFrame.lineNumber, info.lineNumberMin); + EXPECT_LE(callFrame.lineNumber, info.lineNumberMax); + EXPECT_EQ(callFrame.functionName, info.functionName); + + i++; + } +} + +struct PropInfo { + PropInfo(const std::string &type) : type(type) {} + + PropInfo &setSubtype(const std::string &subtypeParam) { + subtype = subtypeParam; + return *this; + } + + PropInfo &setValue(const folly::dynamic &valueParam) { + value = valueParam; + return *this; + } + + PropInfo &setUnserializableValue( + const std::string &unserializableValueParam) { + unserializableValue = unserializableValueParam; + return *this; + } + + std::string type; + folly::Optional subtype; + folly::Optional value; + folly::Optional unserializableValue; +}; + +std::unordered_map expectProps( + SyncConnection &conn, + int msgId, + const std::string &objectId, + const std::unordered_map &infos, + bool ownProperties = true) { + m::runtime::GetPropertiesRequest req; + req.id = msgId; + req.objectId = objectId; + req.ownProperties = ownProperties; + conn.send(req.toJson()); + + std::unordered_map objectIds; + auto resp = expectResponse(conn, msgId); + + EXPECT_EQ(resp.result.size(), infos.size()); + + for (int i = 0; i < resp.result.size(); i++) { + m::runtime::PropertyDescriptor &desc = resp.result[i]; + + auto infoIt = infos.find(desc.name); + EXPECT_FALSE(infoIt == infos.end()); + + if (infoIt != infos.end()) { + const PropInfo &info = infoIt->second; + + EXPECT_TRUE(desc.value.hasValue()); + + m::runtime::RemoteObject &remoteObj = desc.value.value(); + EXPECT_EQ(remoteObj.type, info.type); + + if (info.subtype.hasValue()) { + EXPECT_TRUE(remoteObj.subtype.hasValue()); + EXPECT_EQ(remoteObj.subtype.value(), info.subtype.value()); + } + + if (info.value.hasValue()) { + EXPECT_TRUE(remoteObj.value.hasValue()); + EXPECT_EQ(remoteObj.value.value(), info.value.value()); + } + + if (info.unserializableValue.hasValue()) { + EXPECT_TRUE(remoteObj.unserializableValue.hasValue()); + EXPECT_EQ( + remoteObj.unserializableValue.value(), + info.unserializableValue.value()); + } + + if ((info.type == "object" && info.subtype != "null") || + info.type == "function") { + EXPECT_TRUE(remoteObj.objectId.hasValue()); + objectIds[desc.name] = remoteObj.objectId.value(); + } + } + } + + return objectIds; +} + +void expectEvalResponse( + SyncConnection &conn, + int id, + const std::unordered_map &infos) { + auto resp = + expectResponse(conn, id); + + EXPECT_EQ(resp.id, id); + EXPECT_EQ(resp.result.type, "object"); + EXPECT_FALSE(resp.exceptionDetails.hasValue()); + + EXPECT_TRUE(resp.result.objectId.hasValue()); + expectProps(conn, id + 1, resp.result.objectId.value(), infos); +} + +} // namespace + +TEST(ConnectionTests, testRespondsOkToUnknownRequests) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + + asyncRuntime.executeScriptAsync(R"( + var a = 1 + 2; + var b = a / 2; + )"); + + send(conn, 1); + expectExecutionContextCreated(conn); + expectNotification(conn); + + conn.send(R"({"id": 2, "method": "Debugger.foo"})"); + conn.send(R"({"id": 3, "method": "Debugger.bar", "params": {"a": "b"}})"); + + expectResponse(conn, 2); + expectResponse(conn, 3); +} + +TEST(ConnectionTests, testDebuggerStatement) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var a = 1 + 2; + debugger; // [1] (line 2) hit debugger statement, resume + var b = a / 2; + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 2) hit debugger statement, resume + expectPaused(conn, "other", {{"global", 2, 1}}); + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testDebuggerStatementFromPausedWaitEnable) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var a = 1 + 2; + debugger; // [1] (line 2) hit debugger statement, resume + var b = a / 2; + )"); + + // TODO: hack that gives JS the chance to run so that we end up in the + // PausedWaitEnable state. Will move the entire test to InspectorTests once + // I get around to refactoring InspectorTests. + std::this_thread::sleep_for(250ms); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 2) hit debugger statement, resume + expectPaused(conn, "other", {{"global", 2, 1}}); + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testIsDebuggerAttached) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var a = 1 + 2; + debugger; // [1] (line 2) hit debugger statement + // [2] evaluate DebuggerInternal.isDebuggerAttached to true + var b = a / 2; + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 2) hit debugger statement + expectPaused(conn, "other", {{"global", 2, 1}}); + + // [2] evaluate DebuggerInternal.IsDebuggerAttached to true + sendEvalRequest(conn, 0, 0, R"("-> " + DebuggerInternal.isDebuggerAttached)"); + expectEvalResponse(conn, 0, "-> true"); + + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testStepOver) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var a = 1 + 2; + debugger; // [1] (line 2) hit debugger statement, step over + var b = a / 2; // [2] (line 3) step over + var c = a + b; // [3] (line 4) resume + var d = b - c; + var e = c * d; + var f = 10; + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 2): hit debugger statement, step over + expectPaused(conn, "other", {{"global", 2, 1}}); + send(conn, msgId++); + expectNotification(conn); + + // [2] (line 3): step over + expectPaused(conn, "other", {{"global", 3, 1}}); + send(conn, msgId++); + expectNotification(conn); + + // [3] (line 4): resume + expectPaused(conn, "other", {{"global", 4, 1}}); + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testStepIn) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + function addOne(val) { + return val + 1; // [3]: resume + } + + var a = 1 + 2; + debugger; // [1] (line 6) hit debugger statement, step over + var b = addOne(a); // [2] (line 7) step in + var c = a + b; + var d = b - c; + var e = c * d; + var f = 10; + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 6): hit debugger statement, step over + expectPaused(conn, "other", {{"global", 6, 1}}); + send(conn, msgId++); + expectNotification(conn); + + // [2] (line 7): step in + expectPaused(conn, "other", {{"global", 7, 1}}); + send(conn, msgId++); + expectNotification(conn); + + // [3] (line 2): resume + expectPaused(conn, "other", {{"addOne", 2, 2}, {"global", 7, 1}}); + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testStepOut) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + function addSquares(a, b) { + var a2 = a * a; + debugger; // [1] (line 3) hit debugger statement, step over + var b2 = b * b; // [2] (line 4) step out + return a2 + b2; + } + + var c = addSquares(1, 2); // [3] (line 8) resume + var d = c * c; + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 3) hit debugger statement, step over + expectPaused(conn, "other", {{"addSquares", 3, 2}, {"global", 8, 1}}); + send(conn, msgId++); + expectNotification(conn); + + // [2] (line 4) step out + expectPaused(conn, "other", {{"addSquares", 4, 2}, {"global", 8, 1}}); + send(conn, msgId++); + expectNotification(conn); + + // [3] (line 8): resume + expectPaused(conn, "other", {{"global", 8, 1}}); + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testSetBreakpoint) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var a = 1 + 2; + debugger; // [1] (line 2) hit debugger statement, + // set breakpoint on line 5 + var b = a / 2; + var c = a + b; // [2] (line 5) hit breakpoint, step over + var d = b - c; // [3] (line 6) resume + var e = c * d; + var f = 10; + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 2) hit debugger statement, set breakpoint on line 6 + expectPaused(conn, "other", {{"global", 2, 1}}); + + m::debugger::SetBreakpointByUrlRequest req; + req.id = msgId++; + req.lineNumber = 5; + req.columnNumber = 0; + conn.send(req.toJson()); + + expectBreakpointResponse(conn, req.id, 5, 5); + + send(conn, msgId++); + expectNotification(conn); + + // [2] (line 5) hit breakpoint, step over + expectPaused(conn, "other", {{"global", 5, 1}}); + send(conn, msgId++); + expectNotification(conn); + + // [3] (line 6) resume + expectPaused(conn, "other", {{"global", 6, 1}}); + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testSetLazyBreakpoint) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + facebook::hermes::HermesRuntime::DebugFlags flags{}; + flags.lazy = true; + + asyncRuntime.executeScriptAsync( + R"( + var a = 1 + 2; + debugger; // [1] (line 2) hit debugger statement, + // set breakpoint on line 5 + + function foo() { + var b = a / 2; + var c = a + b; // [2] (line 7) hit breakpoint, step over + var d = b - c; // [3] (line 8) resume + var e = c * d; + var f = 10; + } + + foo(); + )", + "url", + flags); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 2) hit debugger statement, set breakpoint on line 6 + expectPaused(conn, "other", {{"global", 2, 1}}); + + m::debugger::SetBreakpointByUrlRequest req; + req.id = msgId++; + req.lineNumber = 7; + req.columnNumber = 0; + conn.send(req.toJson()); + + auto breakpointId = expectBreakpointResponse(conn, req.id, 7, 7); + + send(conn, msgId++); + expectNotification(conn); + + // [2] (line 7) hit breakpoint, step over + expectPaused(conn, "other", {{"foo", 7, 2}, {"global", 13, 1}}); + send(conn, msgId++); + expectNotification(conn); + + // [3] (line 8) resume + expectPaused(conn, "other", {{"foo", 8, 2}, {"global", 13, 1}}); + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testSetBreakpointWhileRunning) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + while (!shouldStop()) { + var a = 1; + var b = 2; + var c = a + b; // [1] (line 4) first time: step over + // [3] second time: set stop flag, resume + var d = 10; // [2] (line 6) resume + } + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // set breakpoint on line 4: "var c = ..." + m::debugger::SetBreakpointByUrlRequest req; + req.id = msgId++; + req.lineNumber = 4; + req.columnNumber = 0; + conn.send(req.toJson()); + + expectBreakpointResponse(conn, req.id, 4, 4); + + // [1] (line 4) hit breakpoint, step over + expectPaused(conn, "other", {{"global", 4, 1}}); + send(conn, msgId++); + expectNotification(conn); + + // [2] (line 6) resume + expectPaused(conn, "other", {{"global", 6, 1}}); + send(conn, msgId++); + expectNotification(conn); + + // [3] (line 4) hit breakpoint again, set stop flag, resume + expectPaused(conn, "other", {{"global", 4, 1}}); + asyncRuntime.stop(); + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testSetBreakpointConditional) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var a = 3; + debugger; // [1] (line 2) hit debugger statement, + // set conditional breakpoint on lines 4, 5 and 6 + var b = a + 5; // [2] (line 4) skip breakpoint, condition throws + var c = b - a; // [3] (line 5) skip breakpoint, condition false + var d = b - c; // [4] (line 6) hit breakpoint, condition true + var e = c * d; + var f = 10; + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 2) hit debugger statement, + // set conditional breakpoint on lines 4, 5 and 6 + expectPaused(conn, "other", {{"global", 2, 1}}); + + m::debugger::SetBreakpointByUrlRequest req0; + req0.id = msgId++; + req0.lineNumber = 4; + req0.condition = folly::Optional("throw Error('Boom!')"); + conn.send(req0.toJson()); + + expectBreakpointResponse(conn, req0.id, 4, 4); + + m::debugger::SetBreakpointByUrlRequest req1; + req1.id = msgId++; + req1.lineNumber = 5; + req1.condition = folly::Optional("b === a"); + conn.send(req1.toJson()); + + expectBreakpointResponse(conn, req1.id, 5, 5); + + m::debugger::SetBreakpointByUrlRequest req2; + req2.id = msgId++; + req2.lineNumber = 6; + req2.condition = folly::Optional("c === 5"); + conn.send(req2.toJson()); + + expectBreakpointResponse(conn, req2.id, 6, 6); + + send(conn, msgId++); + expectNotification(conn); + + // [2] (line 4) skip breakpoint, condition throws + + // [3] (line 5) skip breakpoint, condition false + + // [4] (line 6) hit breakpoint, condition true + expectPaused(conn, "other", {{"global", 6, 1}}); + + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testRemoveBreakpoint) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + // [1] (line 2) hit debugger statement, set breakpoint on line 7 + debugger; + var a = 1; + + for (var i = 1; i <= 2; i++) { + // [1] (line 7) hit breakpoint and then remove it + a += i; + } + + storeValue(a); + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 2) hit debugger statement, set breakpoint on line 7 + expectPaused(conn, "other", {{"global", 2, 1}}); + + m::debugger::SetBreakpointByUrlRequest req; + req.id = msgId++; + req.lineNumber = 7; + conn.send(req.toJson()); + + auto breakpointId = expectBreakpointResponse(conn, req.id, 7, 7); + + send(conn, msgId++); + expectNotification(conn); + + // [1] (line 7) hit breakpoint and then remove it + expectPaused(conn, "other", {{"global", 7, 1}}); + + m::debugger::RemoveBreakpointRequest removeReq; + removeReq.id = msgId++; + removeReq.breakpointId = breakpointId; + conn.send(removeReq.toJson()); + expectResponse(conn, removeReq.id); + + send(conn, msgId++); + expectNotification(conn); + + // check final value + jsi::Value finalValue = asyncRuntime.awaitStoredValue(); + EXPECT_EQ(finalValue.asNumber(), 4); +} + +TEST(ConnectionTests, testAsyncPauseWhileRunning) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var accum = 10; + + while (!shouldStop()) { + var a = 1; + var b = 2; + var c = a + b; + + accum += c; + } // (line 9) + + var d = -accum; + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // send some number of async pauses, make sure that we always stop before + // the end of the loop on line 9 + for (int i = 0; i < 10; i++) { + send(conn, msgId++); + expectPaused( + conn, "other", {FrameInfo("global", 0, 1).setLineNumberMax(9)}); + + send(conn, msgId++); + expectNotification(conn); + } + + // break out of loop + asyncRuntime.stop(); +} + +TEST(ConnectionTests, testEvalOnCallFrame) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var globalVar = "omega"; + var booleanVar = true; + var numberVar = 42; + var objectVar = {number: 1, bool: false, str: "string"}; + + function func1(closure, f1param) { // frame 4 + var f1v1 = "alpha"; + var f1v2 = "beta"; + function func1b() { // frame 3 + var f1bv1 = "gamma"; + function func1c() { // frame 2 + var f1cv1 = 19; + closure(); + } + func1c(); + } + func1b(); + } + + function func2() { // frame 1 + var f2v1 = "baker"; + var f2v2 = "charlie"; + function func2b() { // frame 0 + var f2bv1 = "dog"; + debugger; // [1] (line 25) hit debugger statement + // [2] run evals + // [3] resume + print(globalVar); + print(f2bv1); + } + func2b(); + } + + func1(func2, "tau"); + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 25) hit debugger statement + expectPaused( + conn, + "other", + {{"func2b", 25, 3}, + {"func2", 31, 2}, + {"func1c", 13, 4}, + {"func1b", 15, 3}, + {"func1", 17, 2}, + {"global", 34, 1}}); + + // [2] run eval statements + int frame = 0; + sendEvalRequest(conn, msgId + 0, frame, R"("0: " + globalVar)"); + sendEvalRequest(conn, msgId + 1, frame, R"("1: " + f2bv1)"); + sendEvalRequest(conn, msgId + 2, frame, R"("2: " + f2v2)"); + sendEvalRequest(conn, msgId + 3, frame, R"("3: " + f2bv1 + " && " + f2v2)"); + expectEvalResponse(conn, msgId + 0, "0: omega"); + expectEvalResponse(conn, msgId + 1, "1: dog"); + expectEvalResponse(conn, msgId + 2, "2: charlie"); + expectEvalResponse(conn, msgId + 3, "3: dog && charlie"); + msgId += 4; + + frame = 1; + sendEvalRequest(conn, msgId + 0, frame, R"("4: " + f2v1)"); + sendEvalRequest(conn, msgId + 1, frame, R"("5: " + f2v2)"); + sendEvalRequest(conn, msgId + 2, frame, R"(globalVar = "mod by debugger")"); + expectEvalResponse(conn, msgId + 0, "4: baker"); + expectEvalResponse(conn, msgId + 1, "5: charlie"); + expectEvalResponse(conn, msgId + 2, "mod by debugger"); + msgId += 3; + + frame = 2; + sendEvalRequest(conn, msgId + 0, frame, R"("6: " + f1cv1 + f1bv1 + f1v1)"); + sendEvalRequest(conn, msgId + 1, frame, R"("7: " + globalVar)"); + expectEvalResponse(conn, msgId + 0, "6: 19gammaalpha"); + expectEvalResponse(conn, msgId + 1, "7: mod by debugger"); + msgId += 2; + + // [2.1] run eval statements that return non-string primitive values + frame = 0; + sendEvalRequest(conn, msgId + 0, frame, "booleanVar"); + sendEvalRequest(conn, msgId + 1, frame, "numberVar"); + expectEvalResponse(conn, msgId + 0, true); + expectEvalResponse(conn, msgId + 1, 42); + msgId += 2; + + // [2.2] run eval statement that returns object + frame = 0; + sendEvalRequest(conn, msgId + 0, frame, "objectVar"); + expectEvalResponse( + conn, + msgId + 0, + {{"number", PropInfo("number").setValue(1)}, + {"bool", PropInfo("boolean").setValue(false)}, + {"str", PropInfo("string").setValue("string")}, + {"__proto__", PropInfo("object")}}); + + // msgId is increased by 2 because expectEvalResponse will make additional + // request with expectProps. + msgId += 2; + + // [3] resume + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testRuntimeEvaluate) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var globalVar = "omega"; + var booleanVar = true; + var numberVar = 42; + var objectVar = {number: 1, bool: false, str: "string"}; + + while(!shouldStop()) { // [1] (line 6) hit infinite loop + var a = 1; // [2] run evals + a++; // [3] exit run loop + } + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 6) hit infinite loop + + // [2] run eval statements + sendRuntimeEvalRequest(conn, msgId + 0, R"("0: " + globalVar)"); + expectEvalResponse(conn, msgId + 0, "0: omega"); + + // [2.1] run eval statements that return non-string primitive values + sendRuntimeEvalRequest(conn, msgId + 1, "booleanVar"); + sendRuntimeEvalRequest(conn, msgId + 2, "numberVar"); + expectEvalResponse(conn, msgId + 1, true); + expectEvalResponse(conn, msgId + 2, 42); + + // [2.2] run eval statement that returns object + sendRuntimeEvalRequest(conn, msgId + 3, "objectVar"); + expectEvalResponse( + conn, + msgId + 3, + {{"number", PropInfo("number").setValue(1)}, + {"bool", PropInfo("boolean").setValue(false)}, + {"str", PropInfo("string").setValue("string")}, + {"__proto__", PropInfo("object")}}); + + // [3] exit run loop + asyncRuntime.stop(); +} + +TEST(ConnectionTests, testEvalOnCallFrameException) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var count = 0; + + function eventuallyThrows(x) { + if (x <= 0) + throw new Error("I frew up."); + count++; + eventuallyThrows(x-1); + } + + function callme() { + print("Hello"); + debugger; // [1] (line 12) hit debugger statement + // [2] run evals + // [3] resume + print("Goodbye"); + } + + callme(); + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 12) hit debugger statement + expectPaused(conn, "other", {{"callme", 12, 2}, {"global", 18, 1}}); + + // [2] run evals + int frame = 0; + sendEvalRequest(conn, msgId + 0, frame, "this is not valid javascript"); + sendEvalRequest(conn, msgId + 1, frame, "eventuallyThrows(5)"); + sendEvalRequest(conn, msgId + 2, frame, "count"); + + expectEvalException(conn, msgId + 0, "SyntaxError: 1:6:';' expected", {}); + expectEvalException( + conn, + msgId + 1, + "Error: I frew up.", + {{"eventuallyThrows", 5, 0}, + {"eventuallyThrows", 7, 0}, + {"eventuallyThrows", 7, 0}, + {"eventuallyThrows", 7, 0}, + {"eventuallyThrows", 7, 0}, + {"eventuallyThrows", 7, 0}, + + // TODO: unsure why these frames are here, but they're in hdb tests + // too. Ask Hermes about if they really should be there. + FrameInfo("eval", 0, 0).setLineNumberMax(19), + FrameInfo("(native)", 0, 0), + FrameInfo("global", 0, 0).setLineNumberMax(19)}); + expectEvalResponse(conn, msgId + 2, 5); + msgId += 3; + + // [3] resume + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testLoadMultipleScripts) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync( + R"( + function foo(x) { + debugger; + print(x); + } + + var a = 1 + 1; + + //# sourceMappingURL=/foo/bar/url1.js.map + )", + "url1"); + + send(conn, msgId++); + + expectExecutionContextCreated(conn); + + m::debugger::ScriptParsedNotification script1 = + expectScriptParsed(conn, "url1", "/foo/bar/url1.js.map"); + + asyncRuntime.executeScriptAsync( + R"( + var b = a + 2; + var c = b - 1; + foo(c); + + //# sourceMappingURL=/foo/bar/url2.js.map + )", + "url2"); + + m::debugger::ScriptParsedNotification script2 = + expectScriptParsed(conn, "url2", "/foo/bar/url2.js.map"); + + // [1] (line 2) hit debugger statement, resume + expectPaused( + conn, + "other", + {FrameInfo("foo", 2, 2).setScriptId(script1.scriptId), + FrameInfo("global", 3, 1).setScriptId(script2.scriptId)}); + + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testGetProperties) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + std::vector objIds; + + asyncRuntime.executeScriptAsync(R"( + function foo() { + var num = 123; + var obj = { + "depth": 0, + "value": { + "a": -1/0, + "b": 1/0, + "c": Math.sqrt(-2), + "d": -0, + "e": "e_string" + } + }; + var arr = [1, 2, 3]; + function bar() { + var num = 456; + var obj = {"depth": 1, "value": {"c": 5, "d": "d_string"}}; + debugger; + }; + bar(); + debugger; + } + + foo(); + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + auto pausedNote = expectPaused( + conn, "other", {{"bar", 17, 3}, {"foo", 19, 2}, {"global", 23, 1}}); + + auto &scopeObj = pausedNote.callFrames.at(1).scopeChain.at(0).object; + EXPECT_TRUE(scopeObj.objectId.hasValue()); + std::string scopeObjId = scopeObj.objectId.value(); + objIds.push_back(scopeObjId); + + auto scopeChildren = expectProps( + conn, + msgId++, + scopeObjId, + {{"num", PropInfo("number").setValue(123)}, + {"obj", PropInfo("object")}, + {"arr", PropInfo("object").setSubtype("array")}, + {"bar", PropInfo("function")}}); + EXPECT_EQ(scopeChildren.size(), 3); + + EXPECT_EQ(scopeChildren.count("obj"), 1); + std::string objId = scopeChildren.at("obj"); + objIds.push_back(objId); + + auto objChildren = expectProps( + conn, + msgId++, + objId, + {{"depth", PropInfo("number").setValue(0)}, + {"value", PropInfo("object")}, + {"__proto__", PropInfo("object")}}); + EXPECT_EQ(objChildren.size(), 2); + + EXPECT_EQ(objChildren.count("value"), 1); + std::string valueId = objChildren.at("value"); + objIds.push_back(valueId); + + auto valueChildren = expectProps( + conn, + msgId++, + valueId, + {{"a", PropInfo("number").setUnserializableValue("-Infinity")}, + {"b", PropInfo("number").setUnserializableValue("Infinity")}, + {"c", PropInfo("number").setUnserializableValue("NaN")}, + {"d", PropInfo("number").setUnserializableValue("-0")}, + {"e", PropInfo("string").setValue("e_string")}, + {"__proto__", PropInfo("object")}}); + EXPECT_EQ(valueChildren.size(), 1); + + send(conn, msgId++); + expectNotification(conn); + + expectPaused(conn, "other", {{"foo", 20, 2}, {"global", 23, 1}}); + + // all old object ids should be invalid after resuming + for (std::string oldObjId : objIds) { + expectProps( + conn, msgId++, oldObjId, std::unordered_map{}); + } + + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testGetPropertiesOnlyOwnProperties) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + function foo() { + var protoObject = { + "protoNum": 77 + }; + var obj = Object.create(protoObject); + obj.num = 42; + debugger; + } + foo(); + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // wait for a pause on debugger statement and get object ID from the local + // scope. + auto pausedNote = + expectPaused(conn, "other", {{"foo", 7, 2}, {"global", 9, 1}}); + auto scopeObject = pausedNote.callFrames.at(0).scopeChain.at(0).object; + auto scopeChildren = expectProps( + conn, + msgId++, + scopeObject.objectId.value(), + {{"obj", PropInfo("object")}, {"protoObject", PropInfo("object")}}); + EXPECT_EQ(scopeChildren.count("obj"), 1); + std::string objId = scopeChildren.at("obj"); + + // Check that GetProperties request for obj object only have own properties + // when onlyOwnProperties = true. + expectProps( + conn, + msgId++, + objId, + {{"num", PropInfo("number").setValue(42)}, + {"__proto__", PropInfo("object")}}, + true); + + // Check that GetProperties request for obj object only have all properties + // when onlyOwnProperties = false. + // __proto__ is not returned here because all properties from proto chain + // are already included in the result. + expectProps( + conn, + msgId++, + objId, + {{"num", PropInfo("number").setValue(42)}, + {"protoNum", PropInfo("number").setValue(77)}}, + false); + + // resume + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testDisable) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + while (!shouldStop()) { + var a = 1; + var b = 2; + var c = a + b; // [1] (line 4) disable to remove breakpoints and resume + // [2] (line 4) the breakpoint should not hit anymore + var d = 10; + } + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // set breakpoint on line 4: "var c = ..." + m::debugger::SetBreakpointByUrlRequest req; + req.id = msgId++; + req.lineNumber = 4; + conn.send(req.toJson()); + + expectBreakpointResponse(conn, req.id, 4, 4); + + // [1] (line 4) disable to remove breakpoints and resume + expectPaused(conn, "other", {{"global", 4, 1}}); + + send(conn, msgId++); + expectNotification(conn); + + // [2] (line 4) the breakpoint should not hit anymore + expectNothing(conn); + asyncRuntime.stop(); +} + +TEST(ConnectionTests, testDisableWhileRunning) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + debugger; // [1] initial pause to set the breakpoint on line 6 + while (!shouldStop()) { // [2] loop running until we receive a detach request + var a = 1; + } + while (shouldStop()) { + var c = a + 1; // [3] (line 6) the breakpoint should not hit after detach + } + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] initial pause to set the breakpoint on line 6 + expectPaused(conn, "other", {{"global", 1, 1}}); + + // set breakpoint on line 6: "var c = ..." + m::debugger::SetBreakpointByUrlRequest req; + req.id = msgId++; + req.lineNumber = 6; + conn.send(req.toJson()); + + expectBreakpointResponse(conn, req.id, 6, 6); + + // [2] loop running until we receive a detach request + send(conn, msgId++); + expectNotification(conn); + + send(conn, msgId++); + asyncRuntime.stop(); + + // [3] (line 6) the breakpoint should not hit after detach + expectNothing(conn); + asyncRuntime.start(); +} + +TEST(ConnectionTests, testSetPauseOnExceptionsAll) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + debugger; // [1] (line 1) initial pause, set throw on exceptions to 'All' + + try { + var a = 123; + throw new Error('Caught error'); // [2] line 5, pause on exception + } catch (err) { + // Do nothing. + } + + throw new Error('Uncaught exception'); // [3] line 10, pause on exception + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 1) initial pause, set throw on exceptions to 'All' + expectPaused(conn, "other", {{"global", 1, 1}}); + m::debugger::SetPauseOnExceptionsRequest allExceptionsReq; + allExceptionsReq.id = msgId++; + allExceptionsReq.state = "all"; + conn.send(allExceptionsReq.toJson()); + expectResponse(conn, allExceptionsReq.id); + + // Resume + send(conn, msgId++); + expectNotification(conn); + + // [2] line 5, pause on exception + expectPaused(conn, "exception", {{"global", 5, 1}}); + send(conn, msgId++); + expectNotification(conn); + + // [3] line 10, pause on exception + expectPaused(conn, "exception", {{"global", 10, 1}}); + + // Send resume event and check that Hermes has thrown an exception. + send(conn, msgId++); + expectNotification(conn); + asyncRuntime.wait(); + EXPECT_EQ(asyncRuntime.getNumberOfExceptions(), 1); + EXPECT_EQ(asyncRuntime.getLastThrownExceptionMessage(), "Uncaught exception"); +} + +TEST(ConnectionTests, testSetPauseOnExceptionsNone) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + debugger; // [1] (line 1) initial pause, set throw on exceptions to 'None' + + try { + var a = 123; + throw new Error('Caught error'); + } catch (err) { + // Do nothing. + } + + throw new Error('Uncaught exception'); + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 1) initial pause, set throw on exceptions to 'None' + expectPaused(conn, "other", {{"global", 1, 1}}); + m::debugger::SetPauseOnExceptionsRequest allExceptionsReq; + allExceptionsReq.id = msgId++; + allExceptionsReq.state = "none"; + conn.send(allExceptionsReq.toJson()); + expectResponse(conn, allExceptionsReq.id); + + // Resume + send(conn, msgId++); + expectNotification(conn); + + // Check that Hermes has thrown an exception (without reporting it). + expectNothing(conn); + asyncRuntime.wait(); + EXPECT_EQ(asyncRuntime.getNumberOfExceptions(), 1); + EXPECT_EQ(asyncRuntime.getLastThrownExceptionMessage(), "Uncaught exception"); +} + +TEST(ConnectionTests, testSetPauseOnExceptionsUncaught) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + debugger; // [1] (line 1) initial pause, set throw on exceptions to 'Uncaught' + + try { + var a = 123; + throw new Error('Caught error'); + } catch (err) { + // Do nothing. + } + + throw new Error('Uncaught exception'); // [3] line 10, pause on exception + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 1) initial pause, set throw on exceptions to 'Uncaught' + expectPaused(conn, "other", {{"global", 1, 1}}); + m::debugger::SetPauseOnExceptionsRequest allExceptionsReq; + allExceptionsReq.id = msgId++; + allExceptionsReq.state = "uncaught"; + conn.send(allExceptionsReq.toJson()); + expectResponse(conn, allExceptionsReq.id); + + // Resume + send(conn, msgId++); + expectNotification(conn); + + // [3] line 10, pause on exception + expectPaused(conn, "exception", {{"global", 10, 1}}); + + // Send resume event and check that Hermes has thrown an exception. + send(conn, msgId++); + expectNotification(conn); + asyncRuntime.wait(); + EXPECT_EQ(asyncRuntime.getNumberOfExceptions(), 1); + EXPECT_EQ(asyncRuntime.getLastThrownExceptionMessage(), "Uncaught exception"); +} + +TEST(ConnectionTests, testShouldPauseOnThrow) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + debugger; // [1] (line 1) initial pause, check shouldPauseOnThrow is false + // [2] set throw to 'All', check shouldPauseOnThrow is true + // [3] set throw to 'None', check shouldPauseOnThrow is false + // [4] set throw to 'Uncaught', check shouldPauseOnThrow is true + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + auto shouldPauseOnThrowEvalMsg = + R"("-> " + DebuggerInternal.shouldPauseOnThrow)"; + auto responseTrue = "-> true"; + auto responseFalse = "-> false"; + + // [1] (line 1) initial pause, check shouldPauseOnThrow is false + expectPaused(conn, "other", {{"global", 1, 1}}); + sendEvalRequest(conn, msgId + 1, 0, shouldPauseOnThrowEvalMsg); + expectEvalResponse(conn, msgId + 1, responseFalse); + + // [2] set throw to 'All', check shouldPauseOnThrow is true + m::debugger::SetPauseOnExceptionsRequest allExceptionsReq; + allExceptionsReq.id = msgId++; + allExceptionsReq.state = "all"; + conn.send(allExceptionsReq.toJson()); + expectResponse(conn, allExceptionsReq.id); + + sendEvalRequest(conn, msgId + 1, 0, shouldPauseOnThrowEvalMsg); + expectEvalResponse(conn, msgId + 1, responseTrue); + + // [3] set throw to 'None', check shouldPauseOnThrow is false + m::debugger::SetPauseOnExceptionsRequest noExceptionsReq; + noExceptionsReq.id = msgId++; + noExceptionsReq.state = "none"; + conn.send(noExceptionsReq.toJson()); + expectResponse(conn, noExceptionsReq.id); + + sendEvalRequest(conn, msgId + 1, 0, shouldPauseOnThrowEvalMsg); + expectEvalResponse(conn, msgId + 1, responseFalse); + + // [4] set throw to 'Uncaught', check shouldPauseOnThrow is true + m::debugger::SetPauseOnExceptionsRequest uncaughtExceptionsReq; + uncaughtExceptionsReq.id = msgId++; + uncaughtExceptionsReq.state = "uncaught"; + conn.send(uncaughtExceptionsReq.toJson()); + expectResponse(conn, uncaughtExceptionsReq.id); + + sendEvalRequest(conn, msgId + 1, 0, shouldPauseOnThrowEvalMsg); + expectEvalResponse(conn, msgId + 1, responseTrue); + + // Resume + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testScopeVariables) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var globalString = "global-string"; + var globalObject = {number: 1, bool: false}; + + function func() { + var localString = "local-string"; + var localObject = {number: 2, bool: true}; + debugger; // [1] (line 7) hit debugger statement + // two local vars - localString and localObject + // two global vars - globalString and globalObject + } + + func(); // line 12 + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 7) hit debugger statement + auto pausedNote = + expectPaused(conn, "other", {{"func", 7, 2}, {"global", 12, 1}}); + auto scopeChain = pausedNote.callFrames.at(0).scopeChain; + EXPECT_EQ(scopeChain.size(), 2); + + // [2] inspect local scope + EXPECT_EQ(scopeChain.at(0).name, "Scope 0"); + EXPECT_EQ(scopeChain.at(0).type, "local"); + auto localScopeObject = scopeChain.at(0).object; + auto localScopeObjectChildren = expectProps( + conn, + msgId++, + localScopeObject.objectId.value(), + {{"localString", PropInfo("string").setValue("local-string")}, + {"localObject", PropInfo("object")}}); + auto localObjectId = localScopeObjectChildren.at("localObject"); + expectProps( + conn, + msgId++, + localObjectId, + {{"number", PropInfo("number").setValue(2)}, + {"bool", PropInfo("boolean").setValue(true)}, + {"__proto__", PropInfo("object")}}); + + // [3] inspect global scope + // Global scope can contain more properties than we have defined + // in our test code and we can't use expectProps() method here. + // As a workaround we create a Map of properties and check that + // those global properties that we have defined are in the map. + EXPECT_EQ(scopeChain.at(1).name, "Global Scope"); + EXPECT_EQ(scopeChain.at(1).type, "global"); + auto globalScopeObject = scopeChain.at(1).object; + m::runtime::GetPropertiesRequest req; + req.id = msgId++; + req.objectId = globalScopeObject.objectId.value(); + conn.send(req.toJson()); + auto resp = expectResponse(conn, req.id); + std::unordered_map> + globalProperties; + for (auto propertyDescriptor : resp.result) { + globalProperties[propertyDescriptor.name] = propertyDescriptor.value; + } + EXPECT_GE(globalProperties.size(), 3); + + // globalString should be of type "string" and have value "global-string". + EXPECT_EQ(globalProperties.count("globalString"), 1); + EXPECT_TRUE(globalProperties["globalString"].hasValue()); + EXPECT_EQ(globalProperties["globalString"].value().type, "string"); + EXPECT_EQ( + globalProperties["globalString"].value().value.value(), "global-string"); + + // func should be of type "function". + EXPECT_EQ(globalProperties.count("func"), 1); + EXPECT_TRUE(globalProperties["func"].hasValue()); + EXPECT_EQ(globalProperties["func"].value().type, "function"); + + // globalObject should be of type "object" with "number" and "bool" + // properties. + EXPECT_EQ(globalProperties.count("globalObject"), 1); + EXPECT_TRUE(globalProperties["globalObject"].hasValue()); + EXPECT_EQ(globalProperties["globalObject"].value().type, "object"); + expectProps( + conn, + msgId++, + globalProperties["globalObject"].value().objectId.value(), + {{"number", PropInfo("number").setValue(1)}, + {"bool", PropInfo("boolean").setValue(false)}, + {"__proto__", PropInfo("object")}}); + + // [4] resume + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testConsoleLog) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var object1 = {number1: 1, bool1: false}; + var object2 = {number2: 2, bool2: true}; + console.warn('string value', object1, object2); + + debugger; // Hit debugger statement so that we receive console + // api notification before VM gets destroyed. + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // Two notifications (hitting debugger and console API call) can appear + // in any order. We wait for two notifications here and later check + // that both of them were hit. + bool receivedConsoleNotification = false; + bool receivedPausedNotification = false; + for (size_t i = 0; i < 2; ++i) { + conn.waitForNotification([&receivedConsoleNotification, + &receivedPausedNotification, + &conn, + &msgId](const std::string &str) { + auto parsedNote = folly::parseJson(str); + auto method = parsedNote.at("method").asString(); + if (method == "Runtime.consoleAPICalled") { + receivedConsoleNotification = true; + auto note = m::runtime::ConsoleAPICalledNotification(parsedNote); + EXPECT_EQ(note.type, "warning"); + EXPECT_EQ(note.args.size(), 3); + + EXPECT_EQ(note.args[0].type, "string"); + EXPECT_EQ(note.args[0].value, "string value"); + + EXPECT_EQ(note.args[1].type, "object"); + expectProps( + conn, + msgId++, + note.args[1].objectId.value(), + {{"number1", PropInfo("number").setValue(1)}, + {"bool1", PropInfo("boolean").setValue(false)}, + {"__proto__", PropInfo("object")}}); + + EXPECT_EQ(note.args[2].type, "object"); + expectProps( + conn, + msgId++, + note.args[2].objectId.value(), + {{"number2", PropInfo("number").setValue(2)}, + {"bool2", PropInfo("boolean").setValue(true)}, + {"__proto__", PropInfo("object")}}); + } else if (method == "Debugger.paused") { + receivedPausedNotification = true; + auto note = m::debugger::PausedNotification(parsedNote); + EXPECT_EQ(note.reason, "other"); + EXPECT_EQ(note.callFrames.size(), 1); + EXPECT_EQ(note.callFrames[0].functionName, "global"); + EXPECT_EQ(note.callFrames[0].location.lineNumber, 5); + } else { + throw UnexpectedNotificationException(); + } + }); + } + + EXPECT_TRUE(receivedConsoleNotification); + EXPECT_TRUE(receivedPausedNotification); + + // Resume and expect no further notifications + send(conn, msgId++); + expectNotification(conn); + expectNothing(conn); +} + +TEST(ConnectionTests, testThisObject) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync(R"( + var globalString = "global-string"; + + var object = { + someVar: "object var", + foo: function() { + var localString = "local-string"; + debugger; // [1] (line 7) hit debugger statement. + } + } + + object.foo(); // (line 11) + )"); + + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // [1] (line 1) hit debugger statement + auto pausedNote = + expectPaused(conn, "other", {{"foo", 7, 2}, {"global", 11, 1}}); + + // [2] inspect first call frame (foo) + auto localThisObj = pausedNote.callFrames.at(0).thisObj; + expectProps( + conn, + msgId++, + localThisObj.objectId.value(), + {{"someVar", PropInfo("string").setValue("object var")}, + {"foo", PropInfo("function")}, + {"__proto__", PropInfo("object")}}); + + // [3] inspect second call frame (global) + // Global scope can contain more properties than we have defined + // in our test code and we can't use expectProps() method here. + // As a workaround we create a Map of properties and check that + // those global properties that we have defined are in the map. + auto globalThisObj = pausedNote.callFrames.at(1).thisObj; + m::runtime::GetPropertiesRequest req; + req.id = msgId++; + req.objectId = globalThisObj.objectId.value(); + conn.send(req.toJson()); + auto resp = expectResponse(conn, req.id); + std::unordered_map> + properties; + for (auto propertyDescriptor : resp.result) { + properties[propertyDescriptor.name] = propertyDescriptor.value; + } + + // globalString should be of type "string" and have value "global-string". + EXPECT_EQ(properties.count("globalString"), 1); + EXPECT_TRUE(properties["globalString"].hasValue()); + EXPECT_EQ(properties["globalString"].value().type, "string"); + EXPECT_EQ(properties["globalString"].value().value.value(), "global-string"); + + // [4] resume + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testSetBreakpointsMultipleScripts) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + std::string url1 = "first-url"; + asyncRuntime.executeScriptAsync( + R"( + function foo1() { + var somevar1 = 111; // (line 2) hit breakpoint + var somevar2 = 222; + } + )", + url1); + send(conn, msgId++); + expectExecutionContextCreated(conn); + auto scriptParsed1 = + expectNotification(conn); + + std::string url2 = "second-url"; + asyncRuntime.executeScriptAsync( + R"( + function foo2() { + var somevar3 = 333; + var somevar4 = 444; // (line 3) hit breakpoint + } + )", + url2); + auto scriptParsed2 = + expectNotification(conn); + + // In the third script we will set breakpoint (on debugger statement) + // and call both functions (script url doesn't matter). + asyncRuntime.executeScriptAsync(R"( + debugger; // [1] (line 1) set breakpoints in both files + foo1(); + foo2(); + )"); + auto scriptParsed3 = + expectNotification(conn); + + // [1] hit debugger statement + expectPaused(conn, "other", {{"global", 1, 1}}); + + // Set breakpoint on line 2 in the first script and line 3 in the second + // script. + m::debugger::SetBreakpointByUrlRequest req1; + req1.id = msgId++; + req1.lineNumber = 2; + req1.url = url1; + conn.send(req1.toJson()); + + expectBreakpointResponse(conn, req1.id, 2, 2); + + m::debugger::SetBreakpointByUrlRequest req2; + req2.id = msgId++; + req2.lineNumber = 3; + req2.url = url2; + conn.send(req2.toJson()); + + expectBreakpointResponse(conn, req2.id, 3, 3); + + // Resume and check that we hit correct breakpoints. + send(conn, msgId++); + expectNotification(conn); + + // First we should stop on line 2 of the first script. + expectPaused( + conn, + "other", + {FrameInfo("foo1", 2, 2).setScriptId(scriptParsed1.scriptId), + FrameInfo("global", 2, 1).setScriptId(scriptParsed3.scriptId)}); + send(conn, msgId++); + expectNotification(conn); + + // Next we should stop on line 3 of the second script. + expectPaused( + conn, + "other", + {FrameInfo("foo2", 3, 2).setScriptId(scriptParsed2.scriptId), + FrameInfo("global", 3, 1).setScriptId(scriptParsed3.scriptId)}); + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testSetBreakpointByUrlRegex) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + std::string url1 = "https://www.example.com/123456"; + asyncRuntime.executeScriptAsync( + R"( + function foo1() { + var somevar1 = 111; // (line 2) hit breakpoint + } + )", + url1); + send(conn, msgId++); + expectExecutionContextCreated(conn); + auto scriptParsed1 = + expectNotification(conn); + + std::string url2 = "https://www.example.com/abcdefg"; + asyncRuntime.executeScriptAsync( + R"( + function foo2() { + var aaa = 'bbb'; + var somevar2 = 222; // (line 3) hit breakpoint + } + )", + url2); + auto scriptParsed2 = + expectNotification(conn); + + // In the third script we will set breakpoint (on debugger statement) + // and call both functions (script url doesn't matter). + asyncRuntime.executeScriptAsync(R"( + debugger; // [1] (line 1) set breakpoints in both files + foo1(); + foo2(); + )"); + auto scriptParsed3 = + expectNotification(conn); + + // [1] hit debugger statement + expectPaused(conn, "other", {{"global", 1, 1}}); + + // Set breakpoint on line 2 of URL matching "www\.example\.com\/[\d]+" + // (should match url1). + m::debugger::SetBreakpointByUrlRequest req1; + req1.id = msgId++; + req1.lineNumber = 2; + req1.urlRegex = R"(https://www\.example\.com\/[\d]+)"; + conn.send(req1.toJson()); + + expectBreakpointResponse(conn, req1.id, 2, 2); + + // Set breakpoint on line 3 of URL matching "www\.example\.com\/[a-zA-z]+" + // (should match url2). + m::debugger::SetBreakpointByUrlRequest req2; + req2.id = msgId++; + req2.lineNumber = 3; + req2.urlRegex = R"(https://www\.example\.com\/[a-zA-z]+)"; + conn.send(req2.toJson()); + + expectBreakpointResponse(conn, req2.id, 3, 3); + + // Resume and check that we hit correct breakpoints. + send(conn, msgId++); + expectNotification(conn); + + // First we should stop on line 2 of the first script. + expectPaused( + conn, + "other", + {FrameInfo("foo1", 2, 2).setScriptId(scriptParsed1.scriptId), + FrameInfo("global", 2, 1).setScriptId(scriptParsed3.scriptId)}); + send(conn, msgId++); + expectNotification(conn); + + // Next we should stop on line 3 of the second script. + expectPaused( + conn, + "other", + {FrameInfo("foo2", 3, 2).setScriptId(scriptParsed2.scriptId), + FrameInfo("global", 3, 1).setScriptId(scriptParsed3.scriptId)}); + send(conn, msgId++); + expectNotification(conn); +} + +TEST(ConnectionTests, testColumnBreakpoint) { + TestContext context; + AsyncHermesRuntime &asyncRuntime = context.runtime(); + SyncConnection &conn = context.conn(); + int msgId = 1; + + asyncRuntime.executeScriptAsync( + R"( +function foo(){x=1}debugger;foo(); +)", + "url"); + send(conn, msgId++); + expectExecutionContextCreated(conn); + expectNotification(conn); + + // Hit debugger statement. + expectPaused(conn, "other", {{"global", 1, 1}}); + + // Set breakpoint on position 1:16 (x=1). + m::debugger::SetBreakpointByUrlRequest req; + req.id = msgId++; + req.lineNumber = 1; + req.columnNumber = 16; + req.url = "url"; + conn.send(req.toJson()); + + expectBreakpointResponse(conn, req.id, 1, 1); + + // Resume and except to pause on a breakpoint. + send(conn, msgId++); + expectNotification(conn); + expectPaused( + conn, + "other", + {FrameInfo("foo", 1, 2).setColumnNumber(16), FrameInfo("global", 1, 1)}); + + // Resume execution + send(conn, msgId++); + expectNotification(conn); +} + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/tests/MessageTests.cpp b/ReactCommon/hermes/inspector/chrome/tests/MessageTests.cpp new file mode 100644 index 00000000000..cf2d9278703 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/tests/MessageTests.cpp @@ -0,0 +1,439 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include + +#include + +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { +namespace message { + +using folly::dynamic; + +TEST(MessageTests, testSerializeSomeFieldsInRequest) { + debugger::SetBreakpointByUrlRequest req; + // req.id should default to 0 + req.lineNumber = 2; + req.url = "http://example.com/example.js"; + + dynamic result = req.toDynamic(); + dynamic expected = folly::parseJson(R"({ + "id": 0, + "method": "Debugger.setBreakpointByUrl", + "params": { + "lineNumber": 2, + "url": "http://example.com/example.js" + } + })"); + EXPECT_EQ(result, expected); +} + +TEST(MessageTests, testDeserializeSomeFieldsInRequest) { + dynamic message = folly::parseJson(R"( + { + "id": 10, + "method": "Debugger.setBreakpointByUrl", + "params": { + "lineNumber": 42, + "url": "http://example.com" + } + } + )"); + debugger::SetBreakpointByUrlRequest req(message); + + EXPECT_EQ(req.id, 10); + EXPECT_EQ(req.method, "Debugger.setBreakpointByUrl"); + EXPECT_EQ(req.lineNumber, 42); + EXPECT_FALSE(req.columnNumber.hasValue()); + EXPECT_FALSE(req.condition.hasValue()); + EXPECT_EQ(req.url, "http://example.com"); + EXPECT_FALSE(req.urlRegex.hasValue()); +} + +TEST(MessageTests, testSerializeAllFieldsInRequest) { + debugger::SetBreakpointByUrlRequest req; + req.id = 1; + req.lineNumber = 2; + req.columnNumber = 3; + req.condition = "foo == 42"; + req.url = "http://example.com/example.js"; + req.urlRegex = "http://example.com/.*"; + + dynamic result = req.toDynamic(); + dynamic expected = folly::parseJson(R"({ + "id": 1, + "method": "Debugger.setBreakpointByUrl", + "params": { + "lineNumber": 2, + "columnNumber": 3, + "condition": "foo == 42", + "url": "http://example.com/example.js", + "urlRegex": "http://example.com/.*" + } + })"); + EXPECT_EQ(result, expected); +} + +TEST(MessageTests, testDeserializeAllFieldsInRequest) { + dynamic message = folly::parseJson(R"({ + "id": 1, + "method": "Debugger.setBreakpointByUrl", + "params": { + "lineNumber": 2, + "columnNumber": 3, + "condition": "foo == 42", + "url": "http://example.com/example.js", + "urlRegex": "http://example.com/.*" + } + })"); + debugger::SetBreakpointByUrlRequest req(message); + + EXPECT_EQ(req.id, 1); + EXPECT_EQ(req.method, "Debugger.setBreakpointByUrl"); + EXPECT_EQ(req.lineNumber, 2); + EXPECT_EQ(req.columnNumber, 3); + EXPECT_EQ(req.condition, "foo == 42"); + EXPECT_EQ(req.url, "http://example.com/example.js"); + EXPECT_EQ(req.urlRegex, "http://example.com/.*"); +} + +TEST(MessageTests, testSerializeResponse) { + debugger::Location location; + location.scriptId = "myScriptId"; + location.lineNumber = 2; + location.columnNumber = 3; + + debugger::SetBreakpointByUrlResponse resp; + resp.id = 1; + resp.breakpointId = "myBreakpointId"; + resp.locations = {location}; + + dynamic result = resp.toDynamic(); + dynamic expected = folly::parseJson(R"({ + "id": 1, + "result": { + "breakpointId": "myBreakpointId", + "locations": [ + { + "lineNumber": 2, + "columnNumber": 3, + "scriptId": "myScriptId" + } + ] + } + })"); + EXPECT_EQ(result, expected); +} + +TEST(MessageTests, testDeserializeResponse) { + dynamic message = folly::parseJson(R"({ + "id": 1, + "result": { + "breakpointId": "myBreakpointId", + "locations": [ + { + "lineNumber": 2, + "columnNumber": 3, + "scriptId": "myScriptId" + } + ] + } + })"); + debugger::SetBreakpointByUrlResponse resp(message); + + EXPECT_EQ(resp.id, 1); + EXPECT_EQ(resp.breakpointId, "myBreakpointId"); + EXPECT_EQ(resp.locations.size(), 1); + EXPECT_EQ(resp.locations[0].lineNumber, 2); + EXPECT_EQ(resp.locations[0].columnNumber, 3); + EXPECT_EQ(resp.locations[0].scriptId, "myScriptId"); +} + +TEST(MessageTests, testSerializeNotification) { + debugger::Location startLocation; + startLocation.lineNumber = 1; + startLocation.scriptId = "script1"; + + debugger::Location endLocation; + endLocation.lineNumber = 2; + endLocation.scriptId = "script2"; + + debugger::Scope scope; + scope.type = "closure"; + scope.object.type = "object"; + scope.object.subtype = "regexp"; + scope.object.className = "RegExp"; + scope.object.value = dynamic::object("foo", "bar"); + scope.object.unserializableValue = "nope"; + scope.object.description = "myDesc"; + scope.object.objectId = "id1"; + scope.name = "myScope"; + scope.startLocation = startLocation; + scope.endLocation = endLocation; + + debugger::CallFrame frame; + frame.callFrameId = "callFrame1"; + frame.functionName = "foo1"; + frame.location.scriptId = "script1"; + frame.location.lineNumber = 3; + frame.location.columnNumber = 4; + frame.url = "foo.js"; + frame.scopeChain = std::vector{scope}; + frame.thisObj.type = "function"; + + debugger::PausedNotification note; + note.callFrames = std::vector{frame}; + note.reason = "debugCommand"; + note.data = dynamic::object("foo", "bar"); + note.hitBreakpoints = std::vector{"a", "b"}; + + dynamic result = note.toDynamic(); + dynamic expected = folly::parseJson(R"({ + "method": "Debugger.paused", + "params": { + "callFrames": [ + { + "callFrameId": "callFrame1", + "functionName": "foo1", + "location": { + "scriptId": "script1", + "lineNumber": 3, + "columnNumber": 4 + }, + "url": "foo.js", + "scopeChain": [ + { + "type": "closure", + "object": { + "type": "object", + "subtype": "regexp", + "className": "RegExp", + "value": { "foo": "bar" }, + "unserializableValue": "nope", + "description": "myDesc", + "objectId": "id1" + }, + "name": "myScope", + "startLocation": { + "lineNumber": 1, + "scriptId": "script1" + }, + "endLocation": { + "lineNumber": 2, + "scriptId": "script2" + } + } + ], + "this": { "type": "function" } + } + ], + "reason": "debugCommand", + "data": { + "foo": "bar" + }, + "hitBreakpoints": [ "a", "b" ] + } + })"); + EXPECT_EQ(result, expected); +} + +TEST(MessageTests, testDeserializeNotification) { + dynamic message = folly::parseJson(R"({ + "method": "Debugger.paused", + "params": { + "callFrames": [ + { + "callFrameId": "callFrame1", + "functionName": "foo1", + "location": { + "scriptId": "script1", + "lineNumber": 3, + "columnNumber": 4 + }, + "url": "foo.js", + "scopeChain": [ + { + "type": "closure", + "object": { + "type": "object", + "subtype": "regexp", + "className": "RegExp", + "value": { "foo": "bar" }, + "unserializableValue": "nope", + "description": "myDesc", + "objectId": "id1" + }, + "name": "myScope", + "startLocation": { + "lineNumber": 1, + "scriptId": "script1" + }, + "endLocation": { + "lineNumber": 2, + "scriptId": "script2" + } + } + ], + "this": { "type": "function" } + } + ], + "reason": "debugCommand", + "data": { + "foo": "bar" + }, + "hitBreakpoints": [ "a", "b" ] + } + })"); + debugger::PausedNotification note(message); + + EXPECT_EQ(note.method, "Debugger.paused"); + EXPECT_EQ(note.callFrames.size(), 1); + EXPECT_EQ(note.reason, "debugCommand"); + EXPECT_EQ(note.data, static_cast(dynamic::object("foo", "bar"))); + auto expectedHitBreakpoints = std::vector{"a", "b"}; + EXPECT_EQ(note.hitBreakpoints, expectedHitBreakpoints); + + debugger::CallFrame &callFrame = note.callFrames[0]; + EXPECT_EQ(callFrame.callFrameId, "callFrame1"); + EXPECT_EQ(callFrame.functionName, "foo1"); + EXPECT_EQ(callFrame.location.scriptId, "script1"); + EXPECT_EQ(callFrame.location.lineNumber, 3); + EXPECT_EQ(callFrame.location.columnNumber, 4); + EXPECT_EQ(callFrame.url, "foo.js"); + EXPECT_EQ(callFrame.scopeChain.size(), 1); + EXPECT_EQ(callFrame.thisObj.type, "function"); + + debugger::Scope &scope = callFrame.scopeChain[0]; + EXPECT_EQ(scope.type, "closure"); + EXPECT_EQ(scope.object.type, "object"); + EXPECT_EQ(scope.object.subtype, "regexp"); + EXPECT_EQ(scope.object.className, "RegExp"); + EXPECT_EQ( + scope.object.value, static_cast(dynamic::object("foo", "bar"))); + EXPECT_EQ(scope.object.unserializableValue, "nope"); + EXPECT_EQ(scope.object.description, "myDesc"); + EXPECT_EQ(scope.object.objectId, "id1"); + EXPECT_EQ(scope.name, "myScope"); + + debugger::Location &startLocation = scope.startLocation.value(); + EXPECT_EQ(startLocation.lineNumber, 1); + EXPECT_FALSE(startLocation.columnNumber.hasValue()); + EXPECT_EQ(startLocation.scriptId, "script1"); + + debugger::Location &endLocation = scope.endLocation.value(); + EXPECT_EQ(endLocation.lineNumber, 2); + EXPECT_FALSE(endLocation.columnNumber.hasValue()); + EXPECT_EQ(endLocation.scriptId, "script2"); +} + +TEST(MessageTests, TestSerializeAsyncStackTrace) { + runtime::StackTrace stack; + stack.description = "childStack"; + stack.parent = std::make_unique(); + stack.parent->description = "parentStack"; + + dynamic result = stack.toDynamic(); + dynamic expected = folly::parseJson(R"({ + "description": "childStack", + "callFrames": [], + "parent": { + "description": "parentStack", + "callFrames": [] + } + })"); + EXPECT_EQ(result, expected); +} + +TEST(MessageTests, TestDeserializeAsyncStackTrace) { + dynamic message = folly::parseJson(R"({ + "description": "childStack", + "callFrames": [], + "parent": { + "description": "parentStack", + "callFrames": [] + } + })"); + runtime::StackTrace stack(message); + + EXPECT_EQ(stack.description, "childStack"); + EXPECT_EQ(stack.callFrames.size(), 0); + EXPECT_EQ(stack.parent->description, "parentStack"); + EXPECT_EQ(stack.parent->callFrames.size(), 0); +} + +TEST(MessageTests, TestRequestFromJson) { + std::unique_ptr baseReq1 = Request::fromJsonThrowOnError(R"({ + "id": 1, + "method": "Debugger.enable" + })"); + auto req1 = static_cast(baseReq1.get()); + EXPECT_EQ(req1->id, 1); + EXPECT_EQ(req1->method, "Debugger.enable"); + + std::unique_ptr baseReq2 = Request::fromJsonThrowOnError(R"({ + "id": 2, + "method": "Debugger.removeBreakpoint", + "params": { + "breakpointId": "foobar" + } + })"); + auto req2 = static_cast(baseReq2.get()); + EXPECT_EQ(req2->id, 2); + EXPECT_EQ(req2->method, "Debugger.removeBreakpoint"); + EXPECT_EQ(req2->breakpointId, "foobar"); + + folly::Try> invalidReq = + Request::fromJson("invalid"); + EXPECT_TRUE(invalidReq.hasException()); +} + +struct MyHandler : public NoopRequestHandler { + void handle(const debugger::EnableRequest &req) override { + enableReq = req; + } + + void handle(const debugger::RemoveBreakpointRequest &req) override { + removeReq = req; + } + + debugger::EnableRequest enableReq; + debugger::RemoveBreakpointRequest removeReq; +}; + +TEST(MessageTests, TestRequestHandler) { + MyHandler handler; + + std::unique_ptr enableReq = Request::fromJsonThrowOnError(R"({ + "id": 1, + "method": "Debugger.enable" + })"); + enableReq->accept(handler); + + EXPECT_EQ(handler.enableReq.id, 1); + EXPECT_EQ(handler.enableReq.method, "Debugger.enable"); + + std::unique_ptr removeReq = Request::fromJsonThrowOnError(R"({ + "id": 2, + "method": "Debugger.removeBreakpoint", + "params": { + "breakpointId": "foobar" + } + })"); + removeReq->accept(handler); + + EXPECT_EQ(handler.removeReq.id, 2); + EXPECT_EQ(handler.removeReq.method, "Debugger.removeBreakpoint"); + EXPECT_EQ(handler.removeReq.breakpointId, "foobar"); +} + +} // namespace message +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/tests/RemoteObjectsTableTest.cpp b/ReactCommon/hermes/inspector/chrome/tests/RemoteObjectsTableTest.cpp new file mode 100644 index 00000000000..6ce59547f2f --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/tests/RemoteObjectsTableTest.cpp @@ -0,0 +1,106 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include + +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +namespace { + +struct TestContext { + TestContext() { + scope1 = table.addScope(std::make_pair(1, 1), BacktraceObjectGroup); + scope2 = table.addScope(std::make_pair(2, 1), ConsoleObjectGroup); + scope3 = table.addScope(std::make_pair(3, 1), ""); + value1 = table.addValue(jsi::Value(1.5), BacktraceObjectGroup); + value2 = table.addValue(jsi::Value(2.5), BacktraceObjectGroup); + value3 = table.addValue(jsi::Value(3.5), ""); + } + + RemoteObjectsTable table; + std::string scope1; + std::string scope2; + std::string scope3; + std::string value1; + std::string value2; + std::string value3; +}; + +} // namespace + +TEST(RemoteObjectsTableTest, TestGetScope) { + TestContext ctx; + + EXPECT_EQ(ctx.table.getScope(ctx.scope1)->first, 1); + EXPECT_EQ(ctx.table.getScope(ctx.scope2)->first, 2); + EXPECT_EQ(ctx.table.getScope(ctx.scope3)->first, 3); + EXPECT_TRUE(ctx.table.getScope(ctx.value1) == nullptr); + EXPECT_TRUE(ctx.table.getScope(ctx.value2) == nullptr); + EXPECT_TRUE(ctx.table.getScope(ctx.value3) == nullptr); +} + +TEST(RemoteObjectsTableTest, TestGetValue) { + TestContext ctx; + + EXPECT_TRUE(ctx.table.getValue(ctx.scope1) == nullptr); + EXPECT_TRUE(ctx.table.getValue(ctx.scope2) == nullptr); + EXPECT_TRUE(ctx.table.getValue(ctx.scope3) == nullptr); + EXPECT_EQ(ctx.table.getValue(ctx.value1)->asNumber(), 1.5); + EXPECT_EQ(ctx.table.getValue(ctx.value2)->asNumber(), 2.5); + EXPECT_EQ(ctx.table.getValue(ctx.value3)->asNumber(), 3.5); +} + +TEST(RemoteObjectsTableTest, TestGetObjectGroup) { + TestContext ctx; + + EXPECT_EQ(ctx.table.getObjectGroup(ctx.scope1), BacktraceObjectGroup); + EXPECT_EQ(ctx.table.getObjectGroup(ctx.scope2), ConsoleObjectGroup); + EXPECT_EQ(ctx.table.getObjectGroup(ctx.scope3), ""); + EXPECT_EQ(ctx.table.getObjectGroup(ctx.value1), BacktraceObjectGroup); + EXPECT_EQ(ctx.table.getObjectGroup(ctx.value2), BacktraceObjectGroup); + EXPECT_EQ(ctx.table.getObjectGroup(ctx.value3), ""); +} + +TEST(RemoteObjectsTableTest, TestReleaseObject) { + TestContext ctx; + + ctx.table.releaseObject(ctx.scope1); + ctx.table.releaseObject(ctx.value3); + std::string scope4 = ctx.table.addScope(std::make_pair(4, 1), ""); + std::string value4 = ctx.table.addValue(jsi::Value(4.5), ""); + + EXPECT_EQ(ctx.table.getScope(ctx.scope1), nullptr); + EXPECT_EQ(ctx.table.getScope(ctx.scope2)->first, 2); + EXPECT_EQ(ctx.table.getScope(ctx.scope3)->first, 3); + EXPECT_EQ(ctx.table.getScope(scope4)->first, 4); + EXPECT_EQ(ctx.table.getValue(ctx.value1)->asNumber(), 1.5); + EXPECT_EQ(ctx.table.getValue(ctx.value2)->asNumber(), 2.5); + EXPECT_EQ(ctx.table.getValue(ctx.value3), nullptr); + EXPECT_EQ(ctx.table.getValue(value4)->asNumber(), 4.5); +} + +TEST(RemoteObjectsTableTest, TestReleaseObjectGroup) { + TestContext ctx; + + ctx.table.releaseObjectGroup(BacktraceObjectGroup); + std::string scope4 = ctx.table.addScope(std::make_pair(4, 1), ""); + std::string value4 = ctx.table.addValue(jsi::Value(4.5), ""); + + EXPECT_EQ(ctx.table.getScope(ctx.scope1), nullptr); + EXPECT_EQ(ctx.table.getScope(ctx.scope2)->first, 2); + EXPECT_EQ(ctx.table.getScope(ctx.scope3)->first, 3); + EXPECT_EQ(ctx.table.getScope(scope4)->first, 4); + EXPECT_EQ(ctx.table.getValue(ctx.value1), nullptr); + EXPECT_EQ(ctx.table.getValue(ctx.value2), nullptr); + EXPECT_EQ(ctx.table.getValue(ctx.value3)->asNumber(), 3.5); + EXPECT_EQ(ctx.table.getValue(value4)->asNumber(), 4.5); +} + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/tests/SyncConnection.cpp b/ReactCommon/hermes/inspector/chrome/tests/SyncConnection.cpp new file mode 100644 index 00000000000..3fd78a93eb0 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/tests/SyncConnection.cpp @@ -0,0 +1,123 @@ +#include "SyncConnection.h" + +#include +#include + +#include +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +using namespace std::placeholders; +using ::facebook::react::IRemoteConnection; + +namespace { + +std::string prettify(const std::string &str) { + try { + folly::dynamic obj = folly::parseJson(str); + return folly::toPrettyJson(obj); + } catch (...) { + // pass + } + + return str; +} + +} // namespace + +class SyncConnection::RemoteConnnection : public IRemoteConnection { + public: + RemoteConnnection(SyncConnection &conn) : conn_(conn) {} + + void onMessage(std::string message) override { + conn_.onReply(message); + } + + void onDisconnect() override {} + + private: + SyncConnection &conn_; +}; + +SyncConnection::SyncConnection(std::shared_ptr runtime) + : connection_( + std::make_unique(std::move(runtime)), + "testConn") { + connection_.connect(std::make_unique(*this)); +} + +void SyncConnection::send(const std::string &str) { + LOG(INFO) << "SyncConnection::send sending " << str; + + connection_.sendMessage(str); +} + +void SyncConnection::waitForResponse( + folly::Function handler, + std::chrono::milliseconds timeout) { + std::string reply; + + { + std::unique_lock lock(mutex_); + + bool success = hasReply_.wait_for( + lock, timeout, [this]() -> bool { return !replies_.empty(); }); + + if (!success) { + throw std::runtime_error("timed out waiting for reply"); + } + + reply = std::move(replies_.front()); + replies_.pop(); + } + + handler(reply); +} + +void SyncConnection::waitForNotification( + folly::Function handler, + std::chrono::milliseconds timeout) { + std::string notification; + + { + std::unique_lock lock(mutex_); + + bool success = hasNotification_.wait_for( + lock, timeout, [this]() -> bool { return !notifications_.empty(); }); + + if (!success) { + throw std::runtime_error("timed out waiting for notification"); + } + + notification = std::move(notifications_.front()); + notifications_.pop(); + } + + handler(notification); +} + +void SyncConnection::onReply(const std::string &message) { + LOG(INFO) << "SyncConnection::onReply got message: " << prettify(message); + + std::lock_guard lock(mutex_); + + folly::dynamic obj = folly::parseJson(message); + if (obj.count("id")) { + replies_.push(message); + hasReply_.notify_one(); + } else { + notifications_.push(message); + hasNotification_.notify_one(); + } +} + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/chrome/tests/SyncConnection.h b/ReactCommon/hermes/inspector/chrome/tests/SyncConnection.h new file mode 100644 index 00000000000..25589432c51 --- /dev/null +++ b/ReactCommon/hermes/inspector/chrome/tests/SyncConnection.h @@ -0,0 +1,62 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include +#include +#include + +#include +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace chrome { + +/** + * SyncConnection provides a synchronous interface over Connection that is + * useful in tests. + */ +class SyncConnection { + public: + SyncConnection(std::shared_ptr runtime); + ~SyncConnection() = default; + + /// sends a message to the debugger + void send(const std::string &str); + + /// waits for the next response from the debugger. handler is called with the + /// response. throws on timeout. + void waitForResponse( + folly::Function handler, + std::chrono::milliseconds timeout = std::chrono::milliseconds(2500)); + + /// waits for the next notification from the debugger. handler is called with + /// the notification. throws on timeout. + void waitForNotification( + folly::Function handler, + std::chrono::milliseconds timeout = std::chrono::milliseconds(2500)); + + private: + class RemoteConnnection; + friend class RemoteConnnection; + + void onReply(const std::string &message); + + Connection connection_; + + std::mutex mutex_; + std::condition_variable hasReply_; + std::queue replies_; + std::condition_variable hasNotification_; + std::queue notifications_; +}; + +} // namespace chrome +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/detail/SerialExecutor.cpp b/ReactCommon/hermes/inspector/detail/SerialExecutor.cpp new file mode 100644 index 00000000000..77d16f1c122 --- /dev/null +++ b/ReactCommon/hermes/inspector/detail/SerialExecutor.cpp @@ -0,0 +1,57 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include "SerialExecutor.h" + +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace detail { + +SerialExecutor::SerialExecutor(const std::string &name) + : finish_(false), thread_(name, [this]() { runLoop(); }) {} + +SerialExecutor::~SerialExecutor() { + { + std::lock_guard lock(mutex_); + finish_ = true; + wakeup_.notify_one(); + } + + thread_.join(); +} + +void SerialExecutor::add(folly::Func func) { + std::lock_guard lock(mutex_); + funcs_.push(std::move(func)); + wakeup_.notify_one(); +} + +void SerialExecutor::runLoop() { + bool shouldExit = false; + while (!shouldExit) { + folly::Func func; + + { + std::unique_lock lock(mutex_); + wakeup_.wait(lock, [this] { return finish_ || !funcs_.empty(); }); + + if (!funcs_.empty()) { + func = std::move(funcs_.front()); + funcs_.pop(); + } + + shouldExit = funcs_.empty() && finish_; + } + + if (func) { + func(); + } + } +} + +} // namespace detail +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/detail/SerialExecutor.h b/ReactCommon/hermes/inspector/detail/SerialExecutor.h new file mode 100644 index 00000000000..f094e0409f7 --- /dev/null +++ b/ReactCommon/hermes/inspector/detail/SerialExecutor.h @@ -0,0 +1,52 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include +#include +#include + +#include + +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace detail { + +/// SerialExecutor is a simple implementation of folly::Executor that processes +/// work items serially on a worker thread. It exists for two reasons: +/// +/// 1. Currently Hermes builds for the host as well as in fbandroid and +/// fbobjc, so we need an implementation of a serial executor that doesn't +/// use the SerialAsyncExecutorFactory from fbandroid or fbobjc. +/// 2. None of folly's Executor factories are included in the stripped-down +/// version of folly in xplat. +/// +/// TODO: create a factory that uses SerialAsyncExecutorFactory if we're +/// building for fbandroid or fbobjc, and otherwise creates an instance of this +/// class. +class SerialExecutor : public folly::Executor { + public: + SerialExecutor(const std::string &name); + ~SerialExecutor(); + + void add(folly::Func) override; + + private: + void runLoop(); + + std::mutex mutex_; + std::queue funcs_; + std::condition_variable wakeup_; + bool finish_; + + Thread thread_; +}; + +} // namespace detail +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/detail/Thread.cpp b/ReactCommon/hermes/inspector/detail/Thread.cpp new file mode 100644 index 00000000000..ec68bfd39fd --- /dev/null +++ b/ReactCommon/hermes/inspector/detail/Thread.cpp @@ -0,0 +1,34 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#ifdef __ANDROID__ +#include "Thread.h" + +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace detail { + +struct Thread::Impl { + facebook::jni::global_ref thread_; +}; + +Thread::Thread(std::string, std::function runnable) + : impl_(std::make_unique(Impl{facebook::jni::make_global( + facebook::jni::JThread::create(std::move(runnable)))})) { + impl_->thread_->start(); +} + +Thread::~Thread() {} + +void Thread::join() { + impl_->thread_->join(); +} + +} // namespace detail +} // namespace inspector +} // namespace hermes +} // namespace facebook + +#endif diff --git a/ReactCommon/hermes/inspector/detail/Thread.h b/ReactCommon/hermes/inspector/detail/Thread.h new file mode 100644 index 00000000000..7f4b6ba252e --- /dev/null +++ b/ReactCommon/hermes/inspector/detail/Thread.h @@ -0,0 +1,78 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#pragma once + +#include +#include + +#ifndef __ANDROID__ +#include +#include +#endif + +namespace facebook { +namespace hermes { +namespace inspector { +namespace detail { + +#ifdef __ANDROID__ + +/// Android version of Thread that uses JThread, which is a java.lang.Thread. +/// This is desirable because real Java threads have access to the app's +/// classloader, which allows us to call in to Java from C++. +/// +/// The implementation is private to the .cpp file to avoid leaking +/// the fbjni dependencies into code which creates Threads. + +class Thread { + public: + Thread(std::string name, std::function runnable); + ~Thread(); + + void detach() { + // Java threads don't need to be explicitly detached + } + + void join(); + + private: + struct Impl; + std::unique_ptr impl_; +}; + +#else + +class Thread { + public: + Thread(std::string name, std::function runnable) + : thread_(run, name, runnable) {} + + void detach() { + thread_.detach(); + } + + void join() { + thread_.join(); + } + + private: + static void run(std::string name, std::function runnable) { +#if defined(_GNU_SOURCE) + pthread_setname_np(pthread_self(), name.c_str()); +#elif defined(__APPLE__) + pthread_setname_np(name.c_str()); +#endif + + runnable(); + } + + std::thread thread_; +}; + +#endif + +}; // namespace detail + +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/detail/tests/SerialExecutorTests.cpp b/ReactCommon/hermes/inspector/detail/tests/SerialExecutorTests.cpp new file mode 100644 index 00000000000..4967b5bca4a --- /dev/null +++ b/ReactCommon/hermes/inspector/detail/tests/SerialExecutorTests.cpp @@ -0,0 +1,36 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include + +#include +#include + +#include + +namespace facebook { +namespace hermes { +namespace inspector { +namespace detail { + +TEST(SerialExecutorTests, testProcessesItems) { + std::array values{}; + + { + SerialExecutor executor("TestExecutor"); + + for (int i = 0; i < values.size(); i++) { + executor.add([=, &values]() { values[i] = i; }); + } + } + + // By this time the serial executor destructor should have exited and waited + // for all work items to complete. + for (int i = 0; i < values.size(); i++) { + EXPECT_EQ(values[i], i); + } +} + +} // namespace detail +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/docs/GenerateInspectorFSM.sh b/ReactCommon/hermes/inspector/docs/GenerateInspectorFSM.sh new file mode 100755 index 00000000000..5abeec66586 --- /dev/null +++ b/ReactCommon/hermes/inspector/docs/GenerateInspectorFSM.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +dot -Tpdf InspectorFSM.gv -o InspectorFSM.pdf diff --git a/ReactCommon/hermes/inspector/docs/InspectorFSM.gv b/ReactCommon/hermes/inspector/docs/InspectorFSM.gv new file mode 100644 index 00000000000..7b537f8638a --- /dev/null +++ b/ReactCommon/hermes/inspector/docs/InspectorFSM.gv @@ -0,0 +1,39 @@ +digraph InspectorFSM { + node [shape = point]; + init1; + init2; + + node [shape = circle]; + init1 -> RWE [ label = " pauseOnFirstStmt " ] + init2 -> RD [ label = " !pauseOnFirstStmt " ] + RD -> RD [ label = " didPause" ]; + RD -> PWE [ label = " debuggerStmt " ]; + RWE -> PWE [ label = " didPause " ]; + RWP -> P [label = " didPause " ]; + RD -> R [ label = " enable " ]; + PWE -> P [label = " enable " ]; + RWE -> RWP [ label = " enable" ]; + R -> P [ label = " !implicitPause " ]; + R -> R [ label = " implicitPause "]; + P -> R [ label = " receivedCommand " ]; + P -> RD [ label = " disable "]; + R -> RD [ label = " disable "]; + + { rank = same; RD RWE } + { rank = same; R P } + + label = < + + + + +
+ + + + + + +
AbbrevState
RWERunningWaitEnable
RWPRunningWaitPause
RDRunningDetached
PWEPausedWaitEnable
PPaused
RRunning
>; + labelloc = "b"; +} diff --git a/ReactCommon/hermes/inspector/docs/InspectorFSM.pdf b/ReactCommon/hermes/inspector/docs/InspectorFSM.pdf new file mode 100644 index 00000000000..f2daf5a4fd0 Binary files /dev/null and b/ReactCommon/hermes/inspector/docs/InspectorFSM.pdf differ diff --git a/ReactCommon/hermes/inspector/tests/InspectorTests.cpp b/ReactCommon/hermes/inspector/tests/InspectorTests.cpp new file mode 100644 index 00000000000..4bebd645042 --- /dev/null +++ b/ReactCommon/hermes/inspector/tests/InspectorTests.cpp @@ -0,0 +1,405 @@ +// Copyright 2004-present Facebook. All Rights Reserved. + +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace facebook { +namespace hermes { +namespace inspector { + +namespace debugger = facebook::hermes::debugger; +using namespace std::chrono_literals; +using Unit = folly::Unit; + +static auto constexpr kDefaultTimeout = 5000ms; + +namespace { + +int getCurrentLine(const debugger::ProgramState &state) { + return state.getStackTrace().callFrameForIndex(0).location.line; +} + +debugger::SourceLocation locationForLine(int line) { + debugger::SourceLocation loc; + loc.line = line; + return loc; +} + +} // namespace + +/* + * LambdaInspectorObserver is useful for sequencing calls to the debugger based + * on the number of onPause() callbacks. + */ + +using OnPauseFunction = + std::function; + +class LambdaInspectorObserver : public InspectorObserver { + public: + LambdaInspectorObserver(OnPauseFunction func) + : onPauseFunc_(func), pauseCount_(0) {} + ~LambdaInspectorObserver() = default; + + void onBreakpointResolved( + Inspector &inspector, + const debugger::BreakpointInfo &info) override {} + + void onContextCreated(Inspector &inspector) override {} + + void onPause(Inspector &inspector, const debugger::ProgramState &state) + override { + pauseCount_++; + onPauseFunc_(inspector, state, pauseCount_); + } + + void onResume(Inspector &inspector) override {} + + void onScriptParsed(Inspector &inspector, const ScriptInfo &info) override {} + + void onMessageAdded(Inspector &inspector, const ConsoleMessageInfo &info) + override{}; + + int getPauseCount() { + return pauseCount_; + } + + private: + OnPauseFunction onPauseFunc_; + int pauseCount_; +}; + +/* + * Helpers for running JS in a separate thread. + */ + +struct HermesDebugContext { + HermesDebugContext( + InspectorObserver &observer, + folly::Future &&finished) + : runtime(makeHermesRuntime()), + inspector( + std::make_shared(runtime), + observer, + false), + stopFlag(false), + finished(std::move(finished)) { + runtime->global().setProperty( + *runtime, + "shouldStop", + jsi::Function::createFromHostFunction( + *runtime, + jsi::PropNameID::forAscii(*runtime, "shouldStop"), + 0, + [this]( + jsi::Runtime &, + const jsi::Value &, + const jsi::Value *args, + size_t count) { + return stopFlag.load() ? jsi::Value(true) : jsi::Value(false); + })); + } + ~HermesDebugContext() = default; + + void setStopFlag() { + stopFlag.store(true); + } + + void wait(std::chrono::milliseconds timeout = kDefaultTimeout) { + std::move(finished).get(timeout); + } + + std::shared_ptr runtime; + Inspector inspector; + std::atomic stopFlag{}; + folly::Future finished; +}; + +static std::shared_ptr runScriptAsync( + InspectorObserver &observer, + const std::string &script) { + auto promise = std::make_shared>(); + auto future = promise->getFuture(); + auto context = + std::make_shared(observer, std::move(future)); + + std::thread t([=]() { + HermesRuntime::DebugFlags flags{}; + context->runtime->debugJavaScript(script, "url", flags); + promise->setValue(); + }); + t.detach(); + + return context; +} + +/* + * Tests + */ + +TEST(InspectorTests, testStepOver) { + std::string script = R"( + var a = 1 + 2; + debugger; + var b = a / 2; + var c = a + b; + var d = b - c; + var e = c * d; + var f = 10; + )"; + + // TODO: move this vector into lambdaInspectorObserver + std::vector> futures; + + OnPauseFunction onPauseFunc = [&futures]( + Inspector &inspector, + const debugger::ProgramState &state, + int pauseCount) { + switch (pauseCount) { + case 1: { + EXPECT_EQ( + state.getPauseReason(), debugger::PauseReason::DebuggerStatement); + EXPECT_EQ(getCurrentLine(state), 3); + + futures.emplace_back(inspector.stepOver()); + + break; + } + case 2: { + EXPECT_EQ(state.getPauseReason(), debugger::PauseReason::StepFinish); + EXPECT_EQ(getCurrentLine(state), 4); + + futures.emplace_back(inspector.stepOver()); + + break; + } + case 3: { + EXPECT_EQ(state.getPauseReason(), debugger::PauseReason::StepFinish); + EXPECT_EQ(getCurrentLine(state), 5); + + futures.emplace_back(inspector.resume()); + + break; + } + } + }; + + LambdaInspectorObserver observer(onPauseFunc); + std::shared_ptr context = + runScriptAsync(observer, script); + + // TODO: temporarily do this to ensure i hit failure case + std::this_thread::sleep_for(1000ms); + + futures.emplace_back(context->inspector.enable()); + + context->wait(); + folly::collectAll(futures).get(kDefaultTimeout); + + EXPECT_EQ(observer.getPauseCount(), 3); +} + +TEST(InspectorTests, testSetBreakpoint) { + std::string script = R"( + var a = 1 + 2; + debugger; + var b = a / 2; + var c = a + b; + var d = b - c; + var e = c * d; + var f = 10; + )"; + + std::vector> futures; + + OnPauseFunction onPauseFunc = [&futures]( + Inspector &inspector, + const debugger::ProgramState &state, + int pauseCount) { + switch (pauseCount) { + case 1: { + EXPECT_EQ( + state.getPauseReason(), debugger::PauseReason::DebuggerStatement); + EXPECT_EQ(getCurrentLine(state), 3); + + auto stepFuture = inspector.stepOver(); + futures.emplace_back(std::move(stepFuture)); + + break; + } + case 2: { + EXPECT_EQ(state.getPauseReason(), debugger::PauseReason::StepFinish); + EXPECT_EQ(getCurrentLine(state), 4); + + auto breakpointFuture = inspector.setBreakpoint(locationForLine(6)); + futures.emplace_back(std::move(breakpointFuture) + .thenValue([](debugger::BreakpointInfo info) { + EXPECT_EQ(info.resolvedLocation.line, 6); + })); + + auto resumeFuture = inspector.resume(); + futures.emplace_back(std::move(resumeFuture)); + + break; + } + case 3: { + EXPECT_EQ(state.getPauseReason(), debugger::PauseReason::Breakpoint); + EXPECT_EQ(getCurrentLine(state), 6); + + auto resumeFuture = inspector.resume(); + futures.emplace_back(std::move(resumeFuture)); + + break; + } + } + }; + + LambdaInspectorObserver observer(onPauseFunc); + std::shared_ptr context = + runScriptAsync(observer, script); + + auto enablePromise = context->inspector.enable(); + futures.emplace_back(std::move(enablePromise)); + + context->wait(); + folly::collectAll(futures).get(kDefaultTimeout); + + EXPECT_EQ(observer.getPauseCount(), 3); +} + +TEST(InspectorTests, testAsyncSetBreakpoint) { + std::string script = R"( + while (!shouldStop()) { + var a = 1; + var b = 2; + var c = a + b; + var d = 10; + } + )"; + + std::vector> futures; + folly::Func stopFunc; + + OnPauseFunction onPauseFunc = [&futures, &stopFunc]( + Inspector &inspector, + const debugger::ProgramState &state, + int pauseCount) { + switch (pauseCount) { + case 1: { + EXPECT_EQ(state.getPauseReason(), debugger::PauseReason::Breakpoint); + EXPECT_EQ(getCurrentLine(state), 4); + + auto stepFuture = inspector.stepOver(); + futures.emplace_back(std::move(stepFuture)); + + break; + } + case 2: { + EXPECT_EQ(state.getPauseReason(), debugger::PauseReason::StepFinish); + EXPECT_EQ(getCurrentLine(state), 5); + + stopFunc(); + + auto resumeFuture = inspector.resume(); + futures.emplace_back(std::move(resumeFuture)); + + break; + } + } + }; + + LambdaInspectorObserver observer(onPauseFunc); + std::shared_ptr context = + runScriptAsync(observer, script); + + stopFunc = [context]() { context->setStopFlag(); }; + + context->inspector.enable(); + + auto breakpointPromise = context->inspector.setBreakpoint(locationForLine(4)) + .thenValue([](debugger::BreakpointInfo info) { + EXPECT_EQ(info.resolvedLocation.line, 4); + }); + + context->wait(); + + futures.emplace_back(std::move(breakpointPromise)); + folly::collectAll(futures).get(kDefaultTimeout); + + EXPECT_EQ(observer.getPauseCount(), 2); +} + +TEST(InspectorTests, testDisable) { + std::string script = R"( + var a = 1 + 2; + debugger; + var b = a / 2; + var c = a + b; + var d = b - c; + var e = c * d; + var f = 10; + )"; + + std::vector> futures; + + OnPauseFunction onPauseFunc = [&futures]( + Inspector &inspector, + const debugger::ProgramState &state, + int pauseCount) { + switch (pauseCount) { + case 1: { + EXPECT_EQ( + state.getPauseReason(), debugger::PauseReason::DebuggerStatement); + EXPECT_EQ(getCurrentLine(state), 3); + + auto stepFuture = inspector.stepOver(); + futures.emplace_back(std::move(stepFuture)); + + break; + } + case 2: { + EXPECT_EQ(state.getPauseReason(), debugger::PauseReason::StepFinish); + EXPECT_EQ(getCurrentLine(state), 4); + + futures.emplace_back(inspector.setBreakpoint(locationForLine(6)) + .thenValue([](debugger::BreakpointInfo info) { + EXPECT_EQ(info.resolvedLocation.line, 6); + })); + futures.emplace_back(inspector.setBreakpoint(locationForLine(7)) + .thenValue([](debugger::BreakpointInfo info) { + EXPECT_EQ(info.resolvedLocation.line, 7); + })); + + auto detachFuture = inspector.disable(); + futures.emplace_back(std::move(detachFuture)); + + break; + } + } + }; + + LambdaInspectorObserver observer(onPauseFunc); + std::shared_ptr context = + runScriptAsync(observer, script); + + auto enablePromise = context->inspector.enable(); + futures.emplace_back(std::move(enablePromise)); + + context->wait(); + folly::collectAll(futures).get(kDefaultTimeout); + + EXPECT_EQ(observer.getPauseCount(), 2); +} + +} // namespace inspector +} // namespace hermes +} // namespace facebook diff --git a/ReactCommon/hermes/inspector/tools/format b/ReactCommon/hermes/inspector/tools/format new file mode 100755 index 00000000000..1db414780a0 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/format @@ -0,0 +1,10 @@ +#!/bin/sh + +DIR="$(dirname "${BASH_SOURCE[0]}")" +cd "$DIR" + +FBSOURCE="$(hg root)" +CLANG_FORMAT="$FBSOURCE/tools/third-party/clang-format/clang-format" +SRC="$FBSOURCE/xplat/hermes-inspector" + +find "$SRC" '(' -name '*.h' -or -name '*.cpp' ')' -exec "$CLANG_FORMAT" -i -style=file '{}' ';' diff --git a/ReactCommon/hermes/inspector/tools/message_types.txt b/ReactCommon/hermes/inspector/tools/message_types.txt new file mode 100644 index 00000000000..04b943765a3 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/message_types.txt @@ -0,0 +1,19 @@ +Debugger.breakpointResolved +Debugger.disable +Debugger.enable +Debugger.evaluateOnCallFrame +Debugger.pause +Debugger.paused +Debugger.removeBreakpoint +Debugger.resume +Debugger.resumed +Debugger.scriptParsed +Debugger.setBreakpointByUrl +Debugger.setPauseOnExceptions +Debugger.stepInto +Debugger.stepOut +Debugger.stepOver +Runtime.consoleAPICalled +Runtime.evaluate +Runtime.executionContextCreated +Runtime.getProperties diff --git a/ReactCommon/hermes/inspector/tools/msggen/.babelrc b/ReactCommon/hermes/inspector/tools/msggen/.babelrc new file mode 100644 index 00000000000..0a0f3cbf901 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/.babelrc @@ -0,0 +1,9 @@ +{ + "presets": [ "flow", ["env", { + "targets": { + "node": "current" + } + }] + ], + "plugins": ["idx"] +} diff --git a/ReactCommon/hermes/inspector/tools/msggen/.flowconfig b/ReactCommon/hermes/inspector/tools/msggen/.flowconfig new file mode 100644 index 00000000000..15700903b7d --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/.flowconfig @@ -0,0 +1,16 @@ +[ignore] +.*/node_modules/* +.*/bin/.* + +[include] + +[libs] + +[options] +suppress_comment= \\(.\\|\n\\)*\\$FlowFixMe +esproposal.class_static_fields=enable +esproposal.class_instance_fields=enable +unsafe.enable_getters_and_setters=true + +[version] +^0.56.0 diff --git a/ReactCommon/hermes/inspector/tools/msggen/.gitignore b/ReactCommon/hermes/inspector/tools/msggen/.gitignore new file mode 100644 index 00000000000..050ba480f8f --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/.gitignore @@ -0,0 +1,3 @@ +.DS_Store +bin/ +node_modules/ diff --git a/ReactCommon/hermes/inspector/tools/msggen/__tests__/CommandTest.js b/ReactCommon/hermes/inspector/tools/msggen/__tests__/CommandTest.js new file mode 100644 index 00000000000..225f3168005 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/__tests__/CommandTest.js @@ -0,0 +1,65 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +'use strict'; + +import { Command } from '../src/Command.js'; + +test('parses simple command', () => { + let obj = { + 'name': 'setBreakpointsActive', + 'parameters': [ + { 'name': 'active', 'type': 'boolean', 'description': 'New value for breakpoints active state.' }, + ], + 'description': 'Activates / deactivates all breakpoints on the page.', + }; + let command = Command.create('Debugger', obj, false); + + expect(command.domain).toBe('Debugger'); + expect(command.name).toBe('setBreakpointsActive'); + expect(command.description).toBe('Activates / deactivates all breakpoints on the page.'); + expect(command.parameters.map(p => p.name)).toEqual(['active']); + expect(command.returns.length).toBe(0); + + expect(command.getDebuggerName()).toBe('Debugger.setBreakpointsActive'); + expect(command.getCppNamespace()).toBe('debugger'); + expect(command.getRequestCppType()).toBe('SetBreakpointsActiveRequest'); + expect(command.getResponseCppType()).toBeUndefined(); + expect(command.getForwardDecls()).toEqual(['struct SetBreakpointsActiveRequest;']); +}); + +test('parses command with return', () => { + let obj = { + 'name': 'setBreakpoint', + 'parameters': [ + { 'name': 'location', '$ref': 'Location', 'description': 'Location to set breakpoint in.' }, + { 'name': 'condition', 'type': 'string', 'optional': true, 'description': 'Expression to use as a breakpoint condition. When specified, debugger will only stop on the breakpoint if this expression evaluates to true.' }, + ], + 'returns': [ + { 'name': 'breakpointId', '$ref': 'BreakpointId', 'description': 'Id of the created breakpoint for further reference.' }, + { 'name': 'actualLocation', '$ref': 'Location', 'description': 'Location this breakpoint resolved into.' }, + ], + 'description': 'Sets JavaScript breakpoint at a given location.', + }; + let command = Command.create('Debugger', obj, false); + + expect(command.domain).toBe('Debugger'); + expect(command.name).toBe('setBreakpoint'); + expect(command.description).toBe('Sets JavaScript breakpoint at a given location.'); + expect(command.parameters.map(p => p.name)).toEqual(['location', 'condition']); + expect(command.returns.map(p => p.name)).toEqual(['breakpointId', 'actualLocation']); + + expect(command.getDebuggerName()).toBe('Debugger.setBreakpoint'); + expect(command.getCppNamespace()).toBe('debugger'); + expect(command.getRequestCppType()).toBe('SetBreakpointRequest'); + expect(command.getResponseCppType()).toBe('SetBreakpointResponse'); + expect(command.getForwardDecls()).toEqual([ + 'struct SetBreakpointRequest;', + 'struct SetBreakpointResponse;', + ]); +}); diff --git a/ReactCommon/hermes/inspector/tools/msggen/__tests__/EventTest.js b/ReactCommon/hermes/inspector/tools/msggen/__tests__/EventTest.js new file mode 100644 index 00000000000..edaae1226cc --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/__tests__/EventTest.js @@ -0,0 +1,50 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +'use strict'; + +import { Event } from '../src/Event.js'; + +test('parses simple event', () => { + let obj = { + 'name': 'resumed', + 'description': 'Fired when the virtual machine resumed execution.', + }; + let event = Event.create('Debugger', obj, false); + + expect(event.domain).toBe('Debugger'); + expect(event.name).toBe('resumed'); + expect(event.description).toBe('Fired when the virtual machine resumed execution.'); + + expect(event.getDebuggerName()).toBe('Debugger.resumed'); + expect(event.getCppNamespace()).toBe('debugger'); + expect(event.getCppType()).toBe('ResumedNotification'); + expect(event.getForwardDecls()).toEqual(['struct ResumedNotification;']); +}); + +test('parses event with params', () => { + let obj = { + 'name': 'breakpointResolved', + 'parameters': [ + { 'name': 'breakpointId', '$ref': 'BreakpointId', 'description': 'Breakpoint unique identifier.' }, + { 'name': 'location', '$ref': 'Location', 'description': 'Actual breakpoint location.' }, + ], + 'description': 'Fired when breakpoint is resolved to an actual script and location.', + }; + let event = Event.create('Debugger', obj, false); + + expect(event.domain).toBe('Debugger'); + expect(event.name).toBe('breakpointResolved'); + expect(event.description).toBe('Fired when breakpoint is resolved to an actual script and location.'); + expect(event.parameters.map(p => p.name)).toEqual(['breakpointId', 'location']); + + expect(event.getDebuggerName()).toBe('Debugger.breakpointResolved'); + expect(event.getCppNamespace()).toBe('debugger'); + expect(event.getCppType()).toBe('BreakpointResolvedNotification'); + expect(event.getForwardDecls()).toEqual(['struct BreakpointResolvedNotification;']); +}); diff --git a/ReactCommon/hermes/inspector/tools/msggen/__tests__/GraphTest.js b/ReactCommon/hermes/inspector/tools/msggen/__tests__/GraphTest.js new file mode 100644 index 00000000000..799eac32505 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/__tests__/GraphTest.js @@ -0,0 +1,81 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +'use strict'; + +import { Graph } from '../src/Graph.js'; + +// graph looks like this before test: https://pxl.cl/9k8t +let graph = null; + +beforeEach(() => { + graph = new Graph(); + graph.addEdge('A1', 'B1'); + graph.addEdge('A2', 'B1'); + graph.addEdge('A2', 'B2'); + graph.addEdge('A3', 'B2'); + graph.addEdge('A3', 'C3'); + graph.addEdge('B1', 'C1'); + graph.addEdge('B1', 'C2'); + graph.addEdge('B1', 'C3'); + graph.addEdge('B2', 'C2'); +}); + +// checks id1 occurs after id2 in arr +function expectOccursAfter(arr, id1, id2) { + let idx1 = arr.indexOf(id1); + let idx2 = arr.indexOf(id2); + + expect(idx1).not.toBe(-1); + expect(idx2).not.toBe(-1); + expect(idx1).toBeGreaterThan(idx2); +} + +test('detects cycle', () => { + graph.addEdge('C2', 'A1'); + expect(() => graph.traverse(['A2'])).toThrow(/^Not a DAG/); +}); + +test('checks for presence of root', () => { + expect(() => graph.traverse(['A1', 'NX'])).toThrow(/^No node/); +}); + +test('traverses partial graph', () => { + let ids = graph.traverse(['B1', 'A3']); + + // Check that expected nodes are there + let sortedIds = ids.slice().sort(); + expect(sortedIds).toEqual(['A3', 'B1', 'B2', 'C1', 'C2', 'C3']); + + // Check that the result is topologically sorted + expectOccursAfter(ids, 'A3', 'B2'); + expectOccursAfter(ids, 'A3', 'C3'); + expectOccursAfter(ids, 'B1', 'C1'); + expectOccursAfter(ids, 'B1', 'C2'); + expectOccursAfter(ids, 'B1', 'C3'); + expectOccursAfter(ids, 'B2', 'C2'); +}); + +test('traverses complete graph', () => { + let ids = graph.traverse(['A1', 'A2', 'A3']); + + // Check that expected nodes are there + let sortedIds = ids.slice().sort(); + expect(sortedIds).toEqual(['A1', 'A2', 'A3', 'B1', 'B2', 'C1', 'C2', 'C3']); + + // Check that the result is topologically sorted + expectOccursAfter(ids, 'A1', 'B1'); + expectOccursAfter(ids, 'A2', 'B1'); + expectOccursAfter(ids, 'A2', 'B2'); + expectOccursAfter(ids, 'A3', 'B2'); + expectOccursAfter(ids, 'A3', 'C3'); + expectOccursAfter(ids, 'B1', 'C1'); + expectOccursAfter(ids, 'B1', 'C2'); + expectOccursAfter(ids, 'B1', 'C3'); + expectOccursAfter(ids, 'B2', 'C2'); +}); diff --git a/ReactCommon/hermes/inspector/tools/msggen/__tests__/HeaderWriterTest.js b/ReactCommon/hermes/inspector/tools/msggen/__tests__/HeaderWriterTest.js new file mode 100644 index 00000000000..75188e22b7f --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/__tests__/HeaderWriterTest.js @@ -0,0 +1,131 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +'use strict'; + +import { expectCodeIsEqual, FakeWritable } from '../src/TestHelpers'; +import { + emitNotificationDecl, + emitRequestDecl, + emitResponseDecl, + emitTypeDecl, +} from '../src/HeaderWriter'; +import { Event } from '../src/Event'; +import { Command } from '../src/Command'; +import { Type } from '../src/Type'; + +let stream = null; + +beforeEach(() => { + stream = new FakeWritable(); +}); + +test('emits type decl', () => { + let obj = { + 'id': 'Location', + 'type': 'object', + 'properties': [ + { 'name': 'scriptId', '$ref': 'Runtime.ScriptId', 'description': 'Script identifier as reported in the Debugger.scriptParsed.' }, + { 'name': 'lineNumber', 'type': 'integer', 'description': 'Line number in the script (0-based).' }, + { 'name': 'columnNumber', 'type': 'integer', 'optional': true, 'description': 'Column number in the script (0-based).' }, + ], + 'description': 'Location in the source code.', + }; + let type = Type.create('Debugger', obj); + + emitTypeDecl(stream, type); + + expectCodeIsEqual(stream.get(), ` + struct debugger::Location : public Serializable { + Location() = default; + explicit Location(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + runtime::ScriptId scriptId{}; + int lineNumber{}; + folly::Optional columnNumber; + }; + `); +}); + +test('emits request decl', () => { + let obj = { + 'name': 'getScriptSource', + 'parameters': [ + { 'name': 'scriptId', '$ref': 'Runtime.ScriptId', 'description': 'Id of the script to get source for.' }, + ], + 'returns': [ + { 'name': 'scriptSource', 'type': 'string', 'description': 'Script source.' }, + ], + 'description': 'Returns source for the script with given id.', + }; + let command = Command.create('Debugger', obj); + + emitRequestDecl(stream, command); + + expectCodeIsEqual(stream.get(), ` + struct debugger::GetScriptSourceRequest : public Request { + GetScriptSourceRequest(); + explicit GetScriptSourceRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; + + runtime::ScriptId scriptId{}; + }; + `); +}); + +test('emits response decl', () => { + let obj = { + 'name': 'getScriptSource', + 'parameters': [ + { 'name': 'scriptId', '$ref': 'Runtime.ScriptId', 'description': 'Id of the script to get source for.' }, + ], + 'returns': [ + { 'name': 'scriptSource', 'type': 'string', 'description': 'Script source.' }, + ], + 'description': 'Returns source for the script with given id.', + }; + let command = Command.create('Debugger', obj); + + emitResponseDecl(stream, command); + + expectCodeIsEqual(stream.get(), ` + struct debugger::GetScriptSourceResponse : public Response { + GetScriptSourceResponse() = default; + explicit GetScriptSourceResponse(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + std::string scriptSource; + }; + `); +}); + +test('emits notification decl', () => { + let obj = { + 'name': 'messageAdded', + 'parameters': [ + { 'name': 'message', '$ref': 'ConsoleMessage', 'description': 'Console message that has been added.' }, + ], + 'description': 'Issued when new console message is added.', + }; + let event = Event.create('Console', obj); + + emitNotificationDecl(stream, event); + + expectCodeIsEqual(stream.get(), ` + struct console::MessageAddedNotification : public Notification { + MessageAddedNotification(); + explicit MessageAddedNotification(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + console::ConsoleMessage message{}; + }; + `); +}); diff --git a/ReactCommon/hermes/inspector/tools/msggen/__tests__/ImplementationWriterTest.js b/ReactCommon/hermes/inspector/tools/msggen/__tests__/ImplementationWriterTest.js new file mode 100644 index 00000000000..fea2fdb4b97 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/__tests__/ImplementationWriterTest.js @@ -0,0 +1,174 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +'use strict'; + +import { expectCodeIsEqual, FakeWritable } from '../src/TestHelpers'; +import { + emitNotificationDef, + emitRequestDef, + emitResponseDef, + emitTypeDef, +} from '../src/ImplementationWriter'; +import { Event } from '../src/Event'; +import { Command } from '../src/Command'; +import { Type } from '../src/Type'; + +let stream = null; + +beforeEach(() => { + stream = new FakeWritable(); +}); + +test('emits type def', () => { + let obj = { + 'id': 'Location', + 'type': 'object', + 'properties': [ + { 'name': 'scriptId', '$ref': 'Runtime.ScriptId', 'description': 'Script identifier as reported in the Debugger.scriptParsed.' }, + { 'name': 'lineNumber', 'type': 'integer', 'description': 'Line number in the script (0-based).' }, + { 'name': 'columnNumber', 'type': 'integer', 'optional': true, 'description': 'Column number in the script (0-based).' }, + ], + 'description': 'Location in the source code.', + }; + let type = Type.create('Debugger', obj); + + emitTypeDef(stream, type); + + expectCodeIsEqual(stream.get(), ` + debugger::Location::Location(const dynamic &obj) { + assign(scriptId, obj, "scriptId"); + assign(lineNumber, obj, "lineNumber"); + assign(columnNumber, obj, "columnNumber"); + } + + dynamic debugger::Location::toDynamic() const { + dynamic obj = dynamic::object; + put(obj, "scriptId", scriptId); + put(obj, "lineNumber", lineNumber); + put(obj, "columnNumber", columnNumber); + return obj; + } + `); +}); + +test('emits request def', () => { + let obj = { + 'name': 'getScriptSource', + 'parameters': [ + { 'name': 'scriptId', '$ref': 'Runtime.ScriptId', 'description': 'Id of the script to get source for.' }, + ], + 'returns': [ + { 'name': 'scriptSource', 'type': 'string', 'description': 'Script source.' }, + ], + 'description': 'Returns source for the script with given id.', + }; + let command = Command.create('Debugger', obj); + + emitRequestDef(stream, command); + + expectCodeIsEqual(stream.get(), ` + debugger::GetScriptSourceRequest::GetScriptSourceRequest() + : Request("Debugger.getScriptSource") {} + + debugger::GetScriptSourceRequest::GetScriptSourceRequest(const dynamic &obj) + : Request("Debugger.getScriptSource") { + assign(id, obj, "id"); + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(scriptId, params, "scriptId"); + } + + dynamic debugger::GetScriptSourceRequest::toDynamic() const { + dynamic params = dynamic::object; + put(params, "scriptId", scriptId); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; + } + + void debugger::GetScriptSourceRequest::accept(RequestHandler &handler) const { + handler.handle(*this); + } + `); +}); + +test('emits response def', () => { + let obj = { + 'name': 'getScriptSource', + 'parameters': [ + { 'name': 'scriptId', '$ref': 'Runtime.ScriptId', 'description': 'Id of the script to get source for.' }, + ], + 'returns': [ + { 'name': 'scriptSource', 'type': 'string', 'description': 'Script source.' }, + ], + 'description': 'Returns source for the script with given id.', + }; + let command = Command.create('Debugger', obj); + + emitResponseDef(stream, command); + + expectCodeIsEqual(stream.get(), ` + debugger::GetScriptSourceResponse::GetScriptSourceResponse(const dynamic &obj) { + assign(id, obj, "id"); + + dynamic res = obj.at("result"); + assign(scriptSource, res, "scriptSource"); + } + + dynamic debugger::GetScriptSourceResponse::toDynamic() const { + dynamic res = dynamic::object; + put(res, "scriptSource", scriptSource); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "result", std::move(res)); + return obj; + } + `); +}); + +test('emits notification def', () => { + let obj = { + 'name': 'messageAdded', + 'parameters': [ + { 'name': 'message', '$ref': 'ConsoleMessage', 'description': 'Console message that has been added.' }, + ], + 'description': 'Issued when new console message is added.', + }; + let event = Event.create('Console', obj); + + emitNotificationDef(stream, event); + + expectCodeIsEqual(stream.get(), ` + console::MessageAddedNotification::MessageAddedNotification() + : Notification("Console.messageAdded") {} + + console::MessageAddedNotification::MessageAddedNotification(const dynamic &obj) + : Notification("Console.messageAdded") { + assign(method, obj, "method"); + + dynamic params = obj.at("params"); + assign(message, params, "message"); + } + + dynamic console::MessageAddedNotification::toDynamic() const { + dynamic params = dynamic::object; + put(params, "message", message); + + dynamic obj = dynamic::object; + put(obj, "method", method); + put(obj, "params", std::move(params)); + return obj; + } + `); +}); diff --git a/ReactCommon/hermes/inspector/tools/msggen/__tests__/PropertyTest.js b/ReactCommon/hermes/inspector/tools/msggen/__tests__/PropertyTest.js new file mode 100644 index 00000000000..5811e460f73 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/__tests__/PropertyTest.js @@ -0,0 +1,134 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +'use strict'; + +import { Property } from '../src/Property.js'; + +test('parses required primitive prop', () => { + let obj = { + 'name': 'lineNumber', + 'type': 'integer', + 'description': 'Line number in the script (0-based).', + }; + let prop = Property.create('Debugger', obj); + + expect(prop.domain).toBe('Debugger'); + expect(prop.name).toBe('lineNumber'); + expect(prop.type).toBe('integer'); + expect(prop.optional).toBeUndefined(); + expect(prop.description).toBe('Line number in the script (0-based).'); + + expect(prop.getFullCppType()).toBe('int'); + expect(prop.getCppIdentifier()).toBe('lineNumber'); + expect(prop.getInitializer()).toBe('{}'); +}); + +test('parses optional primitive prop', () => { + let obj = { + 'name': 'samplingInterval', + 'type': 'number', + 'optional': true, + 'description': 'Average sample interval in bytes.', + }; + let prop = Property.create('HeapProfiler', obj); + + expect(prop.domain).toBe('HeapProfiler'); + expect(prop.name).toBe('samplingInterval'); + expect(prop.type).toBe('number'); + expect(prop.optional).toBe(true); + expect(prop.description).toBe('Average sample interval in bytes.'); + + expect(prop.getFullCppType()).toBe('folly::Optional'); + expect(prop.getCppIdentifier()).toBe('samplingInterval'); + expect(prop.getInitializer()).toBe(''); +}); + +test('parses optional ref prop', () => { + let obj = { + 'name': 'exceptionDetails', + 'optional': true, + '$ref': 'Runtime.ExceptionDetails', + 'description': 'Exception details if any.', + }; + let prop = Property.create('Debugger', obj); + + expect(prop.domain).toBe('Debugger'); + expect(prop.name).toBe('exceptionDetails'); + expect(prop.optional).toBe(true); + expect(prop.$ref).toBe('Runtime.ExceptionDetails'); + expect(prop.description).toBe('Exception details if any.'); + + expect(prop.getFullCppType()).toBe('folly::Optional'); + expect(prop.getCppIdentifier()).toBe('exceptionDetails'); + expect(prop.getInitializer()).toBe(''); +}); + +test('parses recursive ref prop', () => { + let obj = { + 'name': 'parent', + '$ref': 'StackTrace', + 'optional': true, + 'recursive': true, + 'description': 'Asynchronous JavaScript stack trace...', + }; + let prop = Property.create('Runtime', obj); + + expect(prop.domain).toBe('Runtime'); + expect(prop.name).toBe('parent'); + expect(prop.optional).toBe(true); + expect(prop.recursive).toBe(true); + expect(prop.$ref).toBe('StackTrace'); + expect(prop.description).toBe('Asynchronous JavaScript stack trace...'); + + expect(prop.getFullCppType()).toBe('std::unique_ptr'); + expect(prop.getCppIdentifier()).toBe('parent'); + expect(prop.getInitializer()).toBe(''); +}); + +test('parses optional array items prop', () => { + let obj = { + 'name': 'hitBreakpoints', + 'type': 'array', + 'optional': true, + 'items': { 'type': 'string' }, + 'description': 'Hit breakpoints IDs', + }; + let prop = Property.create('Debugger', obj); + + expect(prop.domain).toBe('Debugger'); + expect(prop.name).toBe('hitBreakpoints'); + expect(prop.type).toBe('array'); + expect(prop.optional).toBe(true); + expect(prop.items).toEqual({ 'type': 'string' }); + expect(prop.description).toBe('Hit breakpoints IDs'); + + expect(prop.getFullCppType()).toBe('folly::Optional>'); + expect(prop.getCppIdentifier()).toBe('hitBreakpoints'); + expect(prop.getInitializer()).toBe(''); +}); + +test('parses array ref prop', () => { + let obj = { + 'name': 'domains', + 'type': 'array', + 'items': { '$ref': 'Domain' }, + 'description': 'List of supported domains.', + }; + let prop = Property.create('Schema', obj); + + expect(prop.domain).toBe('Schema'); + expect(prop.name).toBe('domains'); + expect(prop.type).toBe('array'); + expect(prop.items).toEqual({ $ref: 'Domain' }); + expect(prop.description).toBe('List of supported domains.'); + + expect(prop.getFullCppType()).toBe('std::vector'); + expect(prop.getCppIdentifier()).toBe('domains'); + expect(prop.getInitializer()).toBe(''); +}); diff --git a/ReactCommon/hermes/inspector/tools/msggen/__tests__/TypeTest.js b/ReactCommon/hermes/inspector/tools/msggen/__tests__/TypeTest.js new file mode 100644 index 00000000000..840a1507250 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/__tests__/TypeTest.js @@ -0,0 +1,53 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + +'use strict'; + +import { Type } from '../src/Type.js'; + +test('parses primitive type', () => { + let obj = { + 'id': 'Timestamp', + 'type': 'number', + 'description': 'Number of milliseconds since epoch.', + }; + let type = Type.create('Runtime', obj, false); + + expect(type.domain).toBe('Runtime'); + expect(type.id).toBe('Timestamp'); + expect(type.type).toBe('number'); + expect(type.description).toBe('Number of milliseconds since epoch.'); + + expect(type.getCppNamespace()).toBe('runtime'); + expect(type.getCppType()).toBe('Timestamp'); + expect(type.getForwardDecls()).toEqual(['using Timestamp = double;']); +}); + +test('parses object type', () => { + let obj = { + 'id': 'Location', + 'type': 'object', + 'properties': [ + { 'name': 'scriptId', '$ref': 'Runtime.ScriptId', 'description': 'Script identifier as reported in the Debugger.scriptParsed.' }, + { 'name': 'lineNumber', 'type': 'integer', 'description': 'Line number in the script (0-based).' }, + { 'name': 'columnNumber', 'type': 'integer', 'optional': true, 'description': 'Column number in the script (0-based).' }, + ], + 'description': 'Location in the source code.', + }; + let type = Type.create('Debugger', obj, false); + + expect(type.domain).toBe('Debugger'); + expect(type.id).toBe('Location'); + expect(type.type).toBe('object'); + expect(type.properties.map(p => p.name)).toEqual(['scriptId', 'lineNumber', 'columnNumber']); + expect(type.description).toBe('Location in the source code.'); + + expect(type.getCppNamespace()).toBe('debugger'); + expect(type.getCppType()).toBe('Location'); + expect(type.getForwardDecls()).toEqual(['struct Location;']); +}); diff --git a/ReactCommon/hermes/inspector/tools/msggen/package.json b/ReactCommon/hermes/inspector/tools/msggen/package.json new file mode 100644 index 00000000000..9b7884a3daa --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/package.json @@ -0,0 +1,34 @@ +{ + "name": "hermes-inspector-msggen", + "version": "1.0.0", + "bin": { + "msggen": "./bin/index.js" + }, + "scripts": { + "flow": "flow", + "build": "babel src --out-dir bin --source-maps", + "watch": "babel src --out-dir bin --source-maps --watch", + "test": "jest" + }, + "devDependencies": { + "babel-cli": "^6.26.0", + "babel-core": "^6.26.0", + "babel-loader": "^7.1.2", + "babel-plugin-idx": "^2.0.0", + "babel-plugin-syntax-flow": "^6.18.0", + "babel-plugin-transform-flow-strip-types": "^6.22.0", + "babel-preset-env": "^1.6.0", + "babel-preset-flow": "^6.23.0", + "jest": "^21.2.1", + "webpack": "^3.6.0" + }, + "jest": { + "transform": { + ".*": "/node_modules/babel-jest" + } + }, + "dependencies": { + "idx": "^2.1.0", + "yargs": "^9.0.1" + } +} diff --git a/ReactCommon/hermes/inspector/tools/msggen/src/Command.js b/ReactCommon/hermes/inspector/tools/msggen/src/Command.js new file mode 100644 index 00000000000..a53901b0939 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/src/Command.js @@ -0,0 +1,80 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ +'use strict'; + +import {Property} from './Property'; +import {toCppNamespace, toCppType} from './Converters'; + +export class Command { + domain: string; + name: string; + description: ?string; + experimental: ?boolean; + parameters: Array; + returns: Array; + + static create( + domain: string, + obj: any, + ignoreExperimental: boolean, + ): ?Command { + return ignoreExperimental && obj.experimental + ? null + : new Command(domain, obj, ignoreExperimental); + } + + constructor(domain: string, obj: any, ignoreExperimental: boolean) { + this.domain = domain; + this.name = obj.name; + this.description = obj.description; + this.experimental = obj.experimental; + this.parameters = Property.createArray( + domain, + obj.parameters || [], + ignoreExperimental, + ); + this.returns = Property.createArray( + domain, + obj.returns || [], + ignoreExperimental, + ); + } + + getDebuggerName(): string { + return `${this.domain}.${this.name}`; + } + + getCppNamespace(): string { + return toCppNamespace(this.domain); + } + + getRequestCppType(): string { + return toCppType(this.name + 'Request'); + } + + getResponseCppType(): ?string { + if (this.returns && this.returns.length > 0) { + return toCppType(this.name + 'Response'); + } + } + + getForwardDecls(): Array { + const decls = [`struct ${this.getRequestCppType()};`]; + const respCppType = this.getResponseCppType(); + if (respCppType) { + decls.push(`struct ${respCppType};`); + } + return decls; + } + + getForwardDeclSortKey(): string { + return this.getRequestCppType(); + } +} diff --git a/ReactCommon/hermes/inspector/tools/msggen/src/Converters.js b/ReactCommon/hermes/inspector/tools/msggen/src/Converters.js new file mode 100644 index 00000000000..f8dd5f8c047 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/src/Converters.js @@ -0,0 +1,36 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ +'use strict'; + +export function toCppNamespace(domain: string) { + return domain.substr(0, 1).toLowerCase() + domain.substr(1); +} + +export function toCppType(type: string) { + return type.substr(0, 1).toUpperCase() + type.substr(1); +} + +const jsTypeMappings: {[key: string]: string} = { + any: 'folly::dynamic', + array: 'folly::dynamic', + boolean: 'bool', + integer: 'int', + number: 'double', + object: 'folly::dynamic', + string: 'std::string', +}; + +export function jsTypeToCppType(jsTypeStr: string): string { + const cppType = jsTypeMappings[jsTypeStr]; + if (!cppType) { + throw new TypeError(`${jsTypeStr} is not an expected JS type string`); + } + return cppType; +} diff --git a/ReactCommon/hermes/inspector/tools/msggen/src/Event.js b/ReactCommon/hermes/inspector/tools/msggen/src/Event.js new file mode 100644 index 00000000000..3be22108d4f --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/src/Event.js @@ -0,0 +1,58 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ +'use strict'; + +import {Property} from './Property'; +import {toCppNamespace, toCppType} from './Converters'; + +export class Event { + domain: string; + name: string; + description: ?string; + experimental: ?boolean; + parameters: Array; + + static create(domain: string, obj: any, ignoreExperimental: boolean): ?Event { + return ignoreExperimental && obj.experimental + ? null + : new Event(domain, obj, ignoreExperimental); + } + + constructor(domain: string, obj: any, ignoreExperimental: boolean) { + this.domain = domain; + this.name = obj.name; + this.description = obj.description; + this.parameters = Property.createArray( + domain, + obj.parameters || [], + ignoreExperimental, + ); + } + + getDebuggerName(): string { + return `${this.domain}.${this.name}`; + } + + getCppNamespace(): string { + return toCppNamespace(this.domain); + } + + getCppType(): string { + return toCppType(this.name + 'Notification'); + } + + getForwardDecls(): Array { + return [`struct ${this.getCppType()};`]; + } + + getForwardDeclSortKey(): string { + return this.getCppType(); + } +} diff --git a/ReactCommon/hermes/inspector/tools/msggen/src/GeneratedHeader.js b/ReactCommon/hermes/inspector/tools/msggen/src/GeneratedHeader.js new file mode 100644 index 00000000000..775d459ee65 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/src/GeneratedHeader.js @@ -0,0 +1,15 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ +'use strict'; + +// placeholder token that will be replaced by signedsource script +export const GeneratedHeader = + '// Copyright 2004-present Facebook. All Rights Reserved.\n' + + '// @generated <>'; diff --git a/ReactCommon/hermes/inspector/tools/msggen/src/Graph.js b/ReactCommon/hermes/inspector/tools/msggen/src/Graph.js new file mode 100644 index 00000000000..96b5ced8090 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/src/Graph.js @@ -0,0 +1,91 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ +'use strict'; + +import invariant from 'assert'; + +type NodeId = string; + +class Node { + id: NodeId; + children: Set; + state: 'none' | 'visiting' | 'visited'; + + constructor(id: NodeId) { + this.id = id; + this.children = new Set(); + this.state = 'none'; + } +} + +export class Graph { + nodes: Map; + + constructor() { + this.nodes = new Map(); + } + + addNode(nodeId: NodeId): Node { + let node = this.nodes.get(nodeId); + if (!node) { + node = new Node(nodeId); + this.nodes.set(nodeId, node); + } + return node; + } + + addEdge(srcId: NodeId, dstId: NodeId) { + const src = this.addNode(srcId); + const dst = this.addNode(dstId); + src.children.add(dst); + } + + // traverse returns all nodes in the graph reachable from the given rootIds. + // the returned nodes are topologically sorted, with the deepest nodes + // returned first. + traverse(rootIds: Array): Array { + // clear marks + for (const node of this.nodes.values()) { + node.state = 'none'; + } + + // make a fake root node that points to all the provided rootIds + const root = new Node('root'); + for (const id of rootIds) { + const node = this.nodes.get(id); + invariant(node != null, `No node ${id} in graph`); + root.children.add(node); + } + + const output = []; + postorder(root, output); + + // remove fake root node + output.splice(-1); + + return output; + } +} + +function postorder(node: Node, output: Array) { + if (node.state === 'visited') { + return; + } + + invariant(node.state !== 'visiting', `Not a DAG: cycle involving ${node.id}`); + + node.state = 'visiting'; + for (const child of node.children) { + postorder(child, output); + } + + node.state = 'visited'; + output.push(node.id); +} diff --git a/ReactCommon/hermes/inspector/tools/msggen/src/HeaderWriter.js b/ReactCommon/hermes/inspector/tools/msggen/src/HeaderWriter.js new file mode 100644 index 00000000000..74ce79afeb8 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/src/HeaderWriter.js @@ -0,0 +1,324 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ +'use strict'; + +import {Writable} from 'stream'; + +import {GeneratedHeader} from './GeneratedHeader'; +import {Property} from './Property'; +import {PropsType, Type} from './Type'; +import {Command} from './Command'; +import {Event} from './Event'; +import {toCppNamespace} from './Converters'; + +export class HeaderWriter { + stream: Writable; + types: Array; + commands: Array; + events: Array; + + constructor( + stream: Writable, + types: Array, + commands: Array, + events: Array, + ) { + this.stream = stream; + this.types = types; + this.commands = commands; + this.events = events; + } + + write() { + this.writePrologue(); + this.writeForwardDecls(); + this.writeRequestHandlerDecls(); + this.writeTypeDecls(); + this.writeRequestDecls(); + this.writeResponseDecls(); + this.writeNotificationDecls(); + this.writeEpilogue(); + } + + writePrologue() { + this.stream.write(`${GeneratedHeader} + + #pragma once + + #include + + #include + + #include + + namespace facebook { + namespace hermes { + namespace inspector { + namespace chrome { + namespace message { + + `); + } + + writeForwardDecls() { + this.stream.write('struct UnknownRequest;\n\n'); + + const namespaceMap: Map> = new Map(); + const addToMap = function(type) { + const domain = type.domain; + let types = namespaceMap.get(domain); + if (!types) { + types = []; + namespaceMap.set(domain, types); + } + types.push(type); + }; + + this.types.forEach(addToMap); + this.commands.forEach(addToMap); + this.events.forEach(addToMap); + + for (const [domain, types] of namespaceMap) { + types.sort((a, b) => { + const nameA = a.getForwardDeclSortKey(); + const nameB = b.getForwardDeclSortKey(); + return nameA < nameB ? -1 : nameA > nameB ? 1 : 0; + }); + + const ns = toCppNamespace(domain); + this.stream.write(`namespace ${ns} {\n`); + + for (const type of types) { + for (const decl of type.getForwardDecls()) { + this.stream.write(`${decl}\n`); + } + } + + this.stream.write(`} // namespace ${ns}\n\n`); + } + } + + writeRequestHandlerDecls() { + this.stream.write( + '\n/// RequestHandler handles requests via the visitor pattern.\n', + ); + emitRequestHandlerDecl(this.stream, this.commands); + + this.stream.write( + '\n/// NoopRequestHandler can be subclassed to only handle some requests.\n', + ); + emitNoopRequestHandlerDecl(this.stream, this.commands); + } + + writeTypeDecls() { + this.stream.write('\n/// Types\n'); + + for (const type of this.types) { + if (type instanceof PropsType) { + emitTypeDecl(this.stream, type); + } + } + } + + writeRequestDecls() { + this.stream.write('\n/// Requests\n'); + + emitUnknownRequestDecl(this.stream); + + for (const command of this.commands) { + emitRequestDecl(this.stream, command); + } + } + + writeResponseDecls() { + this.stream.write('\n/// Responses\n'); + + emitErrorResponseDecl(this.stream); + emitOkResponseDecl(this.stream); + + for (const command of this.commands) { + emitResponseDecl(this.stream, command); + } + } + + writeNotificationDecls() { + this.stream.write('\n/// Notifications\n'); + + for (const event of this.events) { + emitNotificationDecl(this.stream, event); + } + } + + writeEpilogue() { + this.stream.write(` + } // namespace message + } // namespace chrome + } // namespace inspector + } // namespace hermes + } // namespace facebook + `); + } +} + +function emitRequestHandlerDecl(stream: Writable, commands: Array) { + stream.write(`struct RequestHandler { + virtual ~RequestHandler() = default; + + virtual void handle(const UnknownRequest &req) = 0; + `); + + for (const command of commands) { + const cppNs = command.getCppNamespace(); + const cppType = command.getRequestCppType(); + + stream.write(`virtual void handle(const ${cppNs}::${cppType} &req) = 0;`); + } + + stream.write('};\n'); +} + +function emitNoopRequestHandlerDecl( + stream: Writable, + commands: Array, +) { + stream.write(`struct NoopRequestHandler : public RequestHandler { + void handle(const UnknownRequest &req) override {} + `); + + for (const command of commands) { + const cppNs = command.getCppNamespace(); + const cppType = command.getRequestCppType(); + + stream.write(`void handle(const ${cppNs}::${cppType} &req) override {}`); + } + + stream.write('};\n'); +} + +function emitProps(stream: Writable, props: ?Array) { + if (!props || props.length === 0) { + return; + } + + stream.write('\n'); + + for (const prop of props) { + const fullCppType = prop.getFullCppType(); + const cppId = prop.getCppIdentifier(); + const init = prop.getInitializer(); + + stream.write(` ${fullCppType} ${cppId}${init};\n`); + } +} + +export function emitTypeDecl(stream: Writable, type: PropsType) { + const cppNs = type.getCppNamespace(); + const cppType = type.getCppType(); + + stream.write(`struct ${cppNs}::${cppType} : public Serializable { + ${cppType}() = default; + explicit ${cppType}(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + `); + + if (type instanceof PropsType) { + emitProps(stream, type.properties); + } + + stream.write('};\n\n'); +} + +function emitUnknownRequestDecl(stream: Writable) { + stream.write(`struct UnknownRequest : public Request { + UnknownRequest(); + explicit UnknownRequest(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; + + folly::Optional params; + }; + + `); +} + +export function emitRequestDecl(stream: Writable, command: Command) { + const cppNs = command.getCppNamespace(); + const cppType = command.getRequestCppType(); + + stream.write(`struct ${cppNs}::${cppType} : public Request { + ${cppType}(); + explicit ${cppType}(const folly::dynamic &obj); + + folly::dynamic toDynamic() const override; + void accept(RequestHandler &handler) const override; + `); + + emitProps(stream, command.parameters); + + stream.write('};\n\n'); +} + +function emitErrorResponseDecl(stream: Writable) { + stream.write(`struct ErrorResponse : public Response { + ErrorResponse() = default; + explicit ErrorResponse(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + + int code; + std::string message; + folly::Optional data; + }; + + `); +} + +function emitOkResponseDecl(stream: Writable) { + stream.write(`struct OkResponse : public Response { + OkResponse() = default; + explicit OkResponse(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + }; + + `); +} + +export function emitResponseDecl(stream: Writable, command: Command) { + const cppNs = command.getCppNamespace(); + const cppType = command.getResponseCppType(); + if (!cppType) { + return; + } + + stream.write(`struct ${cppNs}::${cppType} : public Response { + ${cppType}() = default; + explicit ${cppType}(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + `); + + emitProps(stream, command.returns); + + stream.write('};\n\n'); +} + +export function emitNotificationDecl(stream: Writable, event: Event) { + const cppNs = event.getCppNamespace(); + const cppType = event.getCppType(); + + stream.write(`struct ${cppNs}::${cppType} : public Notification { + ${cppType}(); + explicit ${cppType}(const folly::dynamic &obj); + folly::dynamic toDynamic() const override; + `); + + emitProps(stream, event.parameters); + + stream.write('};\n\n'); +} diff --git a/ReactCommon/hermes/inspector/tools/msggen/src/ImplementationWriter.js b/ReactCommon/hermes/inspector/tools/msggen/src/ImplementationWriter.js new file mode 100644 index 00000000000..b4c6a6ac0b4 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/src/ImplementationWriter.js @@ -0,0 +1,409 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ +'use strict'; + +import {Writable} from 'stream'; + +import {GeneratedHeader} from './GeneratedHeader'; +import {PropsType, Type} from './Type'; +import {Command} from './Command'; +import {Event} from './Event'; + +export class ImplementationWriter { + stream: Writable; + types: Array; + commands: Array; + events: Array; + + constructor( + stream: Writable, + types: Array, + commands: Array, + events: Array, + ) { + this.stream = stream; + this.types = types; + this.commands = commands; + this.events = events; + } + + write() { + this.writePrologue(); + this.writeRequestParser(); + this.writeTypeDefs(); + this.writeRequestDefs(); + this.writeResponseDefs(); + this.writeNotificationDefs(); + this.writeEpilogue(); + } + + writePrologue() { + this.stream.write(`${GeneratedHeader} + + #include "MessageTypes.h" + + #include "MessageTypesInlines.h" + + namespace facebook { + namespace hermes { + namespace inspector { + namespace chrome { + namespace message { + + `); + } + + writeRequestParser() { + emitRequestParser(this.stream, this.commands); + } + + writeTypeDefs() { + this.stream.write('\n/// Types\n'); + + for (const type of this.types) { + if (type instanceof PropsType) { + emitTypeDef(this.stream, type); + } + } + } + + writeRequestDefs() { + this.stream.write('\n/// Requests\n'); + + emitUnknownRequestDef(this.stream); + + for (const command of this.commands) { + emitRequestDef(this.stream, command); + } + } + + writeResponseDefs() { + this.stream.write('\n/// Responses\n'); + + emitErrorResponseDef(this.stream); + emitOkResponseDef(this.stream); + + for (const command of this.commands) { + emitResponseDef(this.stream, command); + } + } + + writeNotificationDefs() { + this.stream.write('\n/// Notifications\n'); + + for (const event of this.events) { + emitNotificationDef(this.stream, event); + } + } + + writeEpilogue() { + this.stream.write(` + } // namespace message + } // namespace chrome + } // namespace inspector + } // namespace hermes + } // namespace facebook + `); + } +} + +function emitRequestParser(stream: Writable, commands: Array) { + stream.write(` + using RequestBuilder = std::unique_ptr (*)(const dynamic &); + + namespace { + + template + std::unique_ptr makeUnique(const dynamic &obj) { + return std::make_unique(obj); + } + + } // namespace + + std::unique_ptr Request::fromJsonThrowOnError(const std::string &str) { + static std::unordered_map builders = { + `); + + for (const command of commands) { + const cppNs = command.getCppNamespace(); + const cppType = command.getRequestCppType(); + const dbgName = command.getDebuggerName(); + + stream.write(`{"${dbgName}", makeUnique<${cppNs}::${cppType}>},\n`); + } + + stream.write(`}; + + dynamic obj = folly::parseJson(str); + std::string method = obj.at("method").asString(); + + auto it = builders.find(method); + if (it == builders.end()) { + return std::make_unique(obj); + } + + auto builder = it->second; + return builder(obj); + } + + folly::Try> Request::fromJson(const std::string &str) { + return folly::makeTryWith( + [&str] { return Request::fromJsonThrowOnError(str); }); + }\n\n`); + + stream.write('\n'); +} + +export function emitTypeDef(stream: Writable, type: PropsType) { + const cppNs = type.getCppNamespace(); + const cppType = type.getCppType(); + const props = type.properties || []; + + // From-dynamic constructor + stream.write(`${cppNs}::${cppType}::${cppType}(const dynamic &obj) {\n`); + + for (const prop of props) { + const id = prop.getCppIdentifier(); + const name = prop.name; + stream.write(`assign(${id}, obj, "${name}");\n`); + } + + stream.write('}\n\n'); + + // toDynamic + stream.write(`dynamic ${cppNs}::${cppType}::toDynamic() const { + dynamic obj = dynamic::object;\n\n`); + + for (const prop of props) { + const id = prop.getCppIdentifier(); + const name = prop.name; + stream.write(`put(obj, "${name}", ${id});\n`); + } + + stream.write('return obj;\n}\n\n'); +} + +function emitErrorResponseDef(stream: Writable) { + stream.write(`ErrorResponse::ErrorResponse(const dynamic &obj) { + assign(id, obj, "id"); + + dynamic error = obj.at("error"); + assign(code, error, "code"); + assign(message, error, "message"); + assign(data, error, "data"); + } + + dynamic ErrorResponse::toDynamic() const { + dynamic error = dynamic::object; + put(error, "code", code); + put(error, "message", message); + put(error, "data", data); + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "error", std::move(error)); + return obj; + }\n\n`); +} + +function emitOkResponseDef(stream: Writable) { + stream.write(`OkResponse::OkResponse(const dynamic &obj) { + assign(id, obj, "id"); + } + + dynamic OkResponse::toDynamic() const { + dynamic result = dynamic::object; + + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "result", std::move(result)); + return obj; + }\n\n`); +} + +function emitUnknownRequestDef(stream: Writable) { + stream.write(`UnknownRequest::UnknownRequest() {} + +UnknownRequest::UnknownRequest(const dynamic &obj) { + assign(id, obj, "id"); + assign(method, obj, "method"); + assign(params, obj, "params"); +} + +dynamic UnknownRequest::toDynamic() const { + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + put(obj, "params", params); + return obj; +} + +void UnknownRequest::accept(RequestHandler &handler) const { + handler.handle(*this); +}\n\n`); +} + +export function emitRequestDef(stream: Writable, command: Command) { + const cppNs = command.getCppNamespace(); + const cppType = command.getRequestCppType(); + const dbgName = command.getDebuggerName(); + const props = command.parameters || []; + + // Default constructor + stream.write(`${cppNs}::${cppType}::${cppType}() + : Request("${dbgName}") {}\n\n`); + + // From-dynamic constructor + stream.write(`${cppNs}::${cppType}::${cppType}(const dynamic &obj) + : Request("${dbgName}") { + assign(id, obj, "id"); + assign(method, obj, "method");\n\n`); + + if (props.length > 0) { + stream.write('dynamic params = obj.at("params");\n'); + + for (const prop of props) { + const id = prop.getCppIdentifier(); + const name = prop.name; + stream.write(`assign(${id}, params, "${name}");\n`); + } + } + + stream.write('}\n\n'); + + // toDynamic + stream.write(`dynamic ${cppNs}::${cppType}::toDynamic() const {\n`); + + if (props.length > 0) { + stream.write('dynamic params = dynamic::object;\n'); + + for (const prop of props) { + const id = prop.getCppIdentifier(); + const name = prop.name; + stream.write(`put(params, "${name}", ${id});\n`); + } + } + + stream.write(` + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "method", method); + `); + + if (props.length > 0) { + stream.write('put(obj, "params", std::move(params));\n'); + } + + stream.write(`return obj; + }\n\n`); + + // visitor + stream.write(`void ${cppNs}::${cppType}::accept(RequestHandler &handler) const { + handler.handle(*this); + }\n\n`); +} + +export function emitResponseDef(stream: Writable, command: Command) { + const cppNs = command.getCppNamespace(); + const cppType = command.getResponseCppType(); + if (!cppType) { + return; + } + + // From-dynamic constructor + stream.write(`${cppNs}::${cppType}::${cppType}(const dynamic &obj) { + assign(id, obj, "id");\n\n`); + + const props = command.returns || []; + if (props.length > 0) { + stream.write('dynamic res = obj.at("result");\n'); + + for (const prop of props) { + const id = prop.getCppIdentifier(); + const name = prop.name; + stream.write(`assign(${id}, res, "${name}");\n`); + } + } + + stream.write('}\n\n'); + + // toDynamic + stream.write(`dynamic ${cppNs}::${cppType}::toDynamic() const {\n`); + + if (props.length > 0) { + stream.write('dynamic res = dynamic::object;\n'); + + for (const prop of props) { + const id = prop.getCppIdentifier(); + const name = prop.name; + stream.write(`put(res, "${name}", ${id});\n`); + } + } + + stream.write(` + dynamic obj = dynamic::object; + put(obj, "id", id); + put(obj, "result", std::move(res)); + return obj; + }\n\n`); +} + +export function emitNotificationDef(stream: Writable, event: Event) { + const cppNs = event.getCppNamespace(); + const cppType = event.getCppType(); + const dbgName = event.getDebuggerName(); + const props = event.parameters || []; + + // Default constructor + stream.write(`${cppNs}::${cppType}::${cppType}() + : Notification("${dbgName}") {}\n\n`); + + // From-dynamic constructor + stream.write(`${cppNs}::${cppType}::${cppType}(const dynamic &obj) + : Notification("${dbgName}") { + assign(method, obj, "method");\n\n`); + + if (props.length > 0) { + stream.write('dynamic params = obj.at("params");\n'); + + for (const prop of props) { + const id = prop.getCppIdentifier(); + const name = prop.name; + stream.write(`assign(${id}, params, "${name}");\n`); + } + } + + stream.write('}\n\n'); + + // toDynamic + stream.write(`dynamic ${cppNs}::${cppType}::toDynamic() const {\n`); + + if (props.length > 0) { + stream.write('dynamic params = dynamic::object;\n'); + + for (const prop of props) { + const id = prop.getCppIdentifier(); + const name = prop.name; + stream.write(`put(params, "${name}", ${id});\n`); + } + } + + stream.write(` + dynamic obj = dynamic::object; + put(obj, "method", method); + `); + + if (props.length > 0) { + stream.write('put(obj, "params", std::move(params));\n'); + } + + stream.write(`return obj; + }\n\n`); +} diff --git a/ReactCommon/hermes/inspector/tools/msggen/src/Property.js b/ReactCommon/hermes/inspector/tools/msggen/src/Property.js new file mode 100644 index 00000000000..0dc7ab742be --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/src/Property.js @@ -0,0 +1,228 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ +'use strict'; + +import {jsTypeToCppType, toCppNamespace, toCppType} from './Converters'; + +export class Property { + domain: string; + name: string; + description: ?string; + exported: ?boolean; + experimental: ?boolean; + optional: ?boolean; + + static create(domain: string, obj: any): Property { + if (obj.$ref) { + return new RefProperty(domain, obj); + } else if (obj.type === 'array') { + return new ArrayProperty(domain, obj); + } + return new PrimitiveProperty(domain, obj); + } + + static createArray( + domain: string, + elements: Array, + ignoreExperimental: boolean, + ): Array { + let props = elements.map(elem => Property.create(domain, elem)); + if (ignoreExperimental) { + props = props.filter(prop => !prop.experimental); + } + return props; + } + + constructor(domain: string, obj: any) { + this.domain = domain; + this.name = obj.name; + this.description = obj.description; + this.exported = obj.exported; + this.experimental = obj.experimental; + this.optional = obj.optional; + } + + getRefDebuggerName(): ?string { + throw new Error('subclass must implement'); + } + + getFullCppType(): string { + throw new Error('subclass must implement'); + } + + getCppIdentifier(): string { + // need to munge identifier if it matches a C++ keyword like "this" + if (this.name === 'this') { + return 'thisObj'; + } + return this.name; + } + + getInitializer(): string { + throw new Error('subclass must implement'); + } +} + +function maybeWrapOptional( + type: string, + optional: ?boolean, + recursive: ?boolean, +) { + if (optional) { + return recursive ? `std::unique_ptr<${type}>` : `folly::Optional<${type}>`; + } + return type; +} + +function toDomainAndId( + curDomain: string, + absOrRelRef: string, +): [string, string] { + let [domain, id] = ['', '']; + + // absOrRelRef can be: + // 1) absolute ref with a "." referencing a type from another namespace, like + // "Runtime.ExceptionDetails" + // 2) relative ref without a "." referencing a type in current domain, like + // "Domain" + const i = absOrRelRef.indexOf('.'); + if (i === -1) { + domain = curDomain; + id = absOrRelRef; + } else { + domain = absOrRelRef.substr(0, i); + id = absOrRelRef.substr(i + 1); + } + + return [domain, id]; +} + +function toFullCppType(curDomain: string, absOrRelRef: string) { + const [domain, id] = toDomainAndId(curDomain, absOrRelRef); + return `${toCppNamespace(domain)}::${toCppType(id)}`; +} + +type JsTypeString = + | 'any' + | 'boolean' + | 'integer' + | 'number' + | 'object' + | 'string'; + +class PrimitiveProperty extends Property { + type: JsTypeString; + + constructor(domain: string, obj: any) { + super(domain, obj); + this.type = obj.type; + } + + getRefDebuggerName(): ?string { + return undefined; + } + + getFullCppType(): string { + return maybeWrapOptional(jsTypeToCppType(this.type), this.optional); + } + + getInitializer(): string { + // folly::Optional doesn't need to be explicitly zero-init + if (this.optional) { + return ''; + } + + // we want to explicitly zero-init bool, int, and double + const type = this.type; + if (type === 'boolean' || type === 'integer' || type === 'number') { + return '{}'; + } + + // everything else (folly::dynamic and std::string) has sensible default + // constructor, no need to explicitly zero-init + return ''; + } +} + +class RefProperty extends Property { + $ref: string; + recursive: ?boolean; + + constructor(domain: string, obj: any) { + super(domain, obj); + this.$ref = obj.$ref; + this.recursive = obj.recursive; + } + + getRefDebuggerName(): ?string { + // recursive props cause cycles--just ignore them + if (this.recursive) { + return null; + } + + const [domain, id] = toDomainAndId(this.domain, this.$ref); + return `${domain}.${id}`; + } + + getFullCppType(): string { + const fullCppType = toFullCppType(this.domain, this.$ref); + return maybeWrapOptional(`${fullCppType}`, this.optional, this.recursive); + } + + getInitializer(): string { + // must zero-init non-optional ref props since the ref could just be an + // alias to a C++ primitive type like int which we always want to zero-init + return this.optional ? '' : '{}'; + } +} + +class ArrayProperty extends Property { + type: 'array'; + items: + | {|type: JsTypeString, recursive: false|} + | {|$ref: string, recursive: ?boolean|}; + + constructor(domain: string, obj: any) { + super(domain, obj); + this.type = obj.type; + this.items = obj.items; + } + + getRefDebuggerName(): ?string { + if (this.items && this.items.$ref && !this.items.recursive) { + const [domain, id] = toDomainAndId(this.domain, this.items.$ref); + return `${domain}.${id}`; + } + } + + getFullCppType(): string { + let elemType: string = 'folly::dynamic'; + let recursive = false; + + if (this.items) { + if (this.items.type) { + elemType = jsTypeToCppType(this.items.type); + } else if (this.items.$ref) { + elemType = toFullCppType(this.domain, this.items.$ref); + recursive = this.items.recursive; + } + } + + return maybeWrapOptional( + `std::vector<${elemType}>`, + this.optional, + recursive, + ); + } + + getInitializer(): string { + return ''; + } +} diff --git a/ReactCommon/hermes/inspector/tools/msggen/src/TestHelpers.js b/ReactCommon/hermes/inspector/tools/msggen/src/TestHelpers.js new file mode 100644 index 00000000000..d301de287f1 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/src/TestHelpers.js @@ -0,0 +1,42 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + */ + /*global expect*/ + +'use strict'; + +// munges string so that it's nice to look at in a test diff +function strip(str) { + // Trim leading and trailing WS + str = str.replace(/^\s+/, ''); + str = str.replace(/\s+$/, ''); + + // Collapse all repeating newlines (possibly with spaces in between) into a + // single newline + str = str.replace(/\n(\s*)/g, '\n'); + + // Collapse all non-newline whitespace into a single space + return str.replace(/[^\S\n]+/g, ' '); +} + +export function expectCodeIsEqual(actual, expected) { + expect(strip(actual)).toBe(strip(expected)); +} + +export class FakeWritable { + constructor() { + this.result = ''; + } + + write(str) { + this.result += str; + } + + get() { + return this.result; + } +} diff --git a/ReactCommon/hermes/inspector/tools/msggen/src/Type.js b/ReactCommon/hermes/inspector/tools/msggen/src/Type.js new file mode 100644 index 00000000000..ca265ec5417 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/src/Type.js @@ -0,0 +1,99 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ +'use strict'; + +import {Property} from './Property'; +import {jsTypeToCppType, toCppNamespace, toCppType} from './Converters'; + +export class Type { + domain: string; + id: string; + description: ?string; + exported: ?boolean; + experimental: ?boolean; + + static create(domain: string, obj: any, ignoreExperimental: boolean): ?Type { + let type = null; + + if (obj.type === 'object' && obj.properties) { + type = new PropsType(domain, obj, ignoreExperimental); + } else if (obj.type) { + type = new PrimitiveType(domain, obj, ignoreExperimental); + } else { + throw new TypeError('Type requires `type` property.'); + } + + if (ignoreExperimental && type.experimental) { + type = null; + } + + return type; + } + + constructor(domain: string, obj: any) { + this.domain = domain; + this.id = obj.id; + this.description = obj.description; + this.exported = obj.exported; + this.experimental = obj.experimental; + } + + getDebuggerName(): string { + return `${this.domain}.${this.id}`; + } + + getCppNamespace(): string { + return toCppNamespace(this.domain); + } + + getCppType(): string { + return toCppType(this.id); + } + + getForwardDecls(): Array { + throw new Error('subclass must implement'); + } + + getForwardDeclSortKey(): string { + return this.getCppType(); + } +} + +export class PrimitiveType extends Type { + type: 'integer' | 'number' | 'object' | 'string'; + + constructor(domain: string, obj: any, ignoreExperimental: boolean) { + super(domain, obj); + this.type = obj.type; + } + + getForwardDecls(): Array { + return [`using ${this.getCppType()} = ${jsTypeToCppType(this.type)};`]; + } +} + +export class PropsType extends Type { + type: 'object'; + properties: Array; + + constructor(domain: string, obj: any, ignoreExperimental: boolean) { + super(domain, obj); + this.type = obj.type; + this.properties = Property.createArray( + domain, + obj.properties || [], + ignoreExperimental, + ); + } + + getForwardDecls(): Array { + return [`struct ${this.getCppType()};`]; + } +} diff --git a/ReactCommon/hermes/inspector/tools/msggen/src/index.js b/ReactCommon/hermes/inspector/tools/msggen/src/index.js new file mode 100644 index 00000000000..a0955329d7f --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/src/index.js @@ -0,0 +1,228 @@ +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @flow + * @format + */ +'use strict'; + +import fs from 'fs'; + +// $FlowFixMe: flow doesn't know about yargs +import yargs from 'yargs'; + +import {Command} from './Command'; +import {Event} from './Event'; +import {Graph} from './Graph'; +import {Property} from './Property'; +import {PropsType, Type} from './Type'; + +import {HeaderWriter} from './HeaderWriter'; +import {ImplementationWriter} from './ImplementationWriter'; + +type Descriptor = {| + types: Array, + commands: Array, + events: Array, +|}; + +function parseDomains( + domainObjs: Array, + ignoreExperimental: boolean, +): Descriptor { + const desc = { + types: [], + commands: [], + events: [], + }; + + for (const obj of domainObjs) { + const domain = obj.domain; + + for (const typeObj of obj.types || []) { + const type = Type.create(domain, typeObj, ignoreExperimental); + if (type) { + desc.types.push(type); + } + } + + for (const commandObj of obj.commands || []) { + const command = Command.create(domain, commandObj, ignoreExperimental); + if (command) { + desc.commands.push(command); + } + } + + for (const eventObj of obj.events || []) { + const event = Event.create(domain, eventObj, ignoreExperimental); + if (event) { + desc.events.push(event); + } + } + } + + return desc; +} + +function buildGraph(desc: Descriptor): Graph { + const graph = new Graph(); + + const types = desc.types; + const commands = desc.commands; + const events = desc.events; + + const maybeAddPropEdges = function(nodeId: string, props: ?Array) { + if (props) { + for (const prop of props) { + const refId = prop.getRefDebuggerName(); + if (refId) { + graph.addEdge(nodeId, refId); + } + } + } + }; + + for (const type of types) { + graph.addNode(type.getDebuggerName()); + + if (type instanceof PropsType) { + maybeAddPropEdges(type.getDebuggerName(), type.properties); + } + } + + for (const command of commands) { + graph.addNode(command.getDebuggerName()); + + maybeAddPropEdges(command.getDebuggerName(), command.parameters); + maybeAddPropEdges(command.getDebuggerName(), command.returns); + } + + for (const event of events) { + graph.addNode(event.getDebuggerName()); + + maybeAddPropEdges(event.getDebuggerName(), event.parameters); + } + + return graph; +} + +function parseRoots(desc: Descriptor, rootsPath: ?string): Array { + const roots = []; + + if (rootsPath) { + const buf = fs.readFileSync(rootsPath); + for (let line of buf.toString().split('\n')) { + line = line.trim(); + + // ignore comments and blank lines + if (!line.match(/\s*#/) && line.length > 0) { + roots.push(line); + } + } + } else { + for (const type of desc.types) { + roots.push(type.getDebuggerName()); + } + for (const command of desc.commands) { + roots.push(command.getDebuggerName()); + } + for (const event of desc.events) { + roots.push(event.getDebuggerName()); + } + } + + return roots; +} + +// only include types, commands, events that can be reached from the given +// root messages +function filterReachableFromRoots( + desc: Descriptor, + graph: Graph, + roots: Array, +): Descriptor { + const topoSortedIds = graph.traverse(roots); + + // Types can include other types by value, so they need to be topologically + // sorted in the header. + const typeMap: Map = new Map(); + for (const type of desc.types) { + typeMap.set(type.getDebuggerName(), type); + } + + const types = []; + for (const id of topoSortedIds) { + const type = typeMap.get(id); + if (type) { + types.push(type); + } + } + + // Commands and events don't depend on each other, so just emit them in the + // order we got them from the JSON file. + const ids = new Set(topoSortedIds); + const commands = desc.commands.filter(cmd => ids.has(cmd.getDebuggerName())); + const events = desc.events.filter(event => ids.has(event.getDebuggerName())); + + // Sort commands and events so the code is easier to read. Types have to be + // topologically sorted as explained above. + const comparator = (a, b) => { + const id1 = a.getDebuggerName(); + const id2 = b.getDebuggerName(); + return id1 < id2 ? -1 : id1 > id2 ? 1 : 0; + }; + commands.sort(comparator); + events.sort(comparator); + + return {types, commands, events}; +} + +function main() { + const args = yargs + .usage('Usage: msggen ') + .alias('h', 'help') + .help('h') + .boolean('e') + .alias('e', 'ignore-experimental') + .describe('e', 'ignore experimental commands, props, and types') + .alias('r', 'roots') + .describe('r', 'path to a file listing root types, events, and commands') + .nargs('r', 1) + .demandCommand(3, 3).argv; + + const ignoreExperimental = !!args.e; + const [protoJsonPath, headerPath, implPath] = args._; + + const headerStream = fs.createWriteStream(headerPath); + const implStream = fs.createWriteStream(implPath); + + const protoJsonBuf = fs.readFileSync(protoJsonPath); + const proto = JSON.parse(protoJsonBuf.toString()); + + const desc = parseDomains(proto.domains, ignoreExperimental); + const graph = buildGraph(desc); + const roots = parseRoots(desc, String(args.roots)); + + const reachable = filterReachableFromRoots(desc, graph, roots); + + const hw = new HeaderWriter( + headerStream, + reachable.types, + reachable.commands, + reachable.events, + ); + hw.write(); + + const iw = new ImplementationWriter( + implStream, + reachable.types, + reachable.commands, + reachable.events, + ); + iw.write(); +} + +main(); diff --git a/ReactCommon/hermes/inspector/tools/msggen/yarn.lock b/ReactCommon/hermes/inspector/tools/msggen/yarn.lock new file mode 100644 index 00000000000..3bf115e2a8f --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/msggen/yarn.lock @@ -0,0 +1,3700 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +abab@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/abab/-/abab-1.0.4.tgz#5faad9c2c07f60dd76770f71cf025b62a63cfd4e" + +abbrev@1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.1.tgz#f8f2c887ad10bf67f634f005b6987fed3179aac8" + +acorn-dynamic-import@^2.0.0: + version "2.0.2" + resolved "https://registry.yarnpkg.com/acorn-dynamic-import/-/acorn-dynamic-import-2.0.2.tgz#c752bd210bef679501b6c6cb7fc84f8f47158cc4" + dependencies: + acorn "^4.0.3" + +acorn-globals@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/acorn-globals/-/acorn-globals-3.1.0.tgz#fd8270f71fbb4996b004fa880ee5d46573a731bf" + dependencies: + acorn "^4.0.4" + +acorn@^4.0.3, acorn@^4.0.4: + version "4.0.13" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-4.0.13.tgz#105495ae5361d697bd195c825192e1ad7f253787" + +acorn@^5.0.0: + version "5.1.2" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-5.1.2.tgz#911cb53e036807cf0fa778dc5d370fbd864246d7" + +ajv-keywords@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-2.1.0.tgz#a296e17f7bfae7c1ce4f7e0de53d29cb32162df0" + +ajv@^4.9.1: + version "4.11.8" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-4.11.8.tgz#82ffb02b29e662ae53bdc20af15947706739c536" + dependencies: + co "^4.6.0" + json-stable-stringify "^1.0.1" + +ajv@^5.1.0, ajv@^5.1.5: + version "5.2.3" + resolved "https://registry.yarnpkg.com/ajv/-/ajv-5.2.3.tgz#c06f598778c44c6b161abafe3466b81ad1814ed2" + dependencies: + co "^4.6.0" + fast-deep-equal "^1.0.0" + json-schema-traverse "^0.3.0" + json-stable-stringify "^1.0.1" + +align-text@^0.1.1, align-text@^0.1.3: + version "0.1.4" + resolved "https://registry.yarnpkg.com/align-text/-/align-text-0.1.4.tgz#0cd90a561093f35d0a99256c22b7069433fad117" + dependencies: + kind-of "^3.0.2" + longest "^1.0.1" + repeat-string "^1.5.2" + +amdefine@>=0.0.4: + version "1.0.1" + resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5" + +ansi-escapes@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/ansi-escapes/-/ansi-escapes-3.0.0.tgz#ec3e8b4e9f8064fc02c3ac9b65f1c275bda8ef92" + +ansi-regex@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-2.1.1.tgz#c3b33ab5ee360d86e0e628f0468ae7ef27d654df" + +ansi-regex@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/ansi-regex/-/ansi-regex-3.0.0.tgz#ed0317c322064f79466c02966bddb605ab37d998" + +ansi-styles@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-2.2.1.tgz#b432dd3358b634cf75e1e4664368240533c1ddbe" + +ansi-styles@^3.1.0, ansi-styles@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/ansi-styles/-/ansi-styles-3.2.0.tgz#c159b8d5be0f9e5a6f346dab94f16ce022161b88" + dependencies: + color-convert "^1.9.0" + +anymatch@^1.3.0: + version "1.3.2" + resolved "https://registry.yarnpkg.com/anymatch/-/anymatch-1.3.2.tgz#553dcb8f91e3c889845dfdba34c77721b90b9d7a" + dependencies: + micromatch "^2.1.5" + normalize-path "^2.0.0" + +append-transform@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/append-transform/-/append-transform-0.4.0.tgz#d76ebf8ca94d276e247a36bad44a4b74ab611991" + dependencies: + default-require-extensions "^1.0.0" + +aproba@^1.0.3: + version "1.2.0" + resolved "https://registry.yarnpkg.com/aproba/-/aproba-1.2.0.tgz#6802e6264efd18c790a1b0d517f0f2627bf2c94a" + +are-we-there-yet@~1.1.2: + version "1.1.4" + resolved "https://registry.yarnpkg.com/are-we-there-yet/-/are-we-there-yet-1.1.4.tgz#bb5dca382bb94f05e15194373d16fd3ba1ca110d" + dependencies: + delegates "^1.0.0" + readable-stream "^2.0.6" + +argparse@^1.0.7: + version "1.0.9" + resolved "https://registry.yarnpkg.com/argparse/-/argparse-1.0.9.tgz#73d83bc263f86e97f8cc4f6bae1b0e90a7d22c86" + dependencies: + sprintf-js "~1.0.2" + +arr-diff@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/arr-diff/-/arr-diff-2.0.0.tgz#8f3b827f955a8bd669697e4a4256ac3ceae356cf" + dependencies: + arr-flatten "^1.0.1" + +arr-flatten@^1.0.1: + version "1.1.0" + resolved "https://registry.yarnpkg.com/arr-flatten/-/arr-flatten-1.1.0.tgz#36048bbff4e7b47e136644316c99669ea5ae91f1" + +array-equal@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/array-equal/-/array-equal-1.0.0.tgz#8c2a5ef2472fd9ea742b04c77a75093ba2757c93" + +array-unique@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/array-unique/-/array-unique-0.2.1.tgz#a1d97ccafcbc2625cc70fadceb36a50c58b01a53" + +arrify@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/arrify/-/arrify-1.0.1.tgz#898508da2226f380df904728456849c1501a4b0d" + +asn1.js@^4.0.0: + version "4.9.1" + resolved "https://registry.yarnpkg.com/asn1.js/-/asn1.js-4.9.1.tgz#48ba240b45a9280e94748990ba597d216617fd40" + dependencies: + bn.js "^4.0.0" + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + +asn1@~0.2.3: + version "0.2.3" + resolved "https://registry.yarnpkg.com/asn1/-/asn1-0.2.3.tgz#dac8787713c9966849fc8180777ebe9c1ddf3b86" + +assert-plus@1.0.0, assert-plus@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-1.0.0.tgz#f12e0f3c5d77b0b1cdd9146942e4e96c1e4dd525" + +assert-plus@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/assert-plus/-/assert-plus-0.2.0.tgz#d74e1b87e7affc0db8aadb7021f3fe48101ab234" + +assert@^1.1.1: + version "1.4.1" + resolved "https://registry.yarnpkg.com/assert/-/assert-1.4.1.tgz#99912d591836b5a6f5b345c0f07eefc08fc65d91" + dependencies: + util "0.10.3" + +astral-regex@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/astral-regex/-/astral-regex-1.0.0.tgz#6c8c3fb827dd43ee3918f27b82782ab7658a6fd9" + +async-each@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/async-each/-/async-each-1.0.1.tgz#19d386a1d9edc6e7c1c85d388aedbcc56d33602d" + +async@^1.4.0: + version "1.5.2" + resolved "https://registry.yarnpkg.com/async/-/async-1.5.2.tgz#ec6a61ae56480c0c3cb241c95618e20892f9672a" + +async@^2.1.2, async@^2.1.4: + version "2.5.0" + resolved "https://registry.yarnpkg.com/async/-/async-2.5.0.tgz#843190fd6b7357a0b9e1c956edddd5ec8462b54d" + dependencies: + lodash "^4.14.0" + +asynckit@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/asynckit/-/asynckit-0.4.0.tgz#c79ed97f7f34cb8f2ba1bc9790bcc366474b4b79" + +aws-sign2@~0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.6.0.tgz#14342dd38dbcc94d0e5b87d763cd63612c0e794f" + +aws-sign2@~0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/aws-sign2/-/aws-sign2-0.7.0.tgz#b46e890934a9591f2d2f6f86d7e6a9f1b3fe76a8" + +aws4@^1.2.1, aws4@^1.6.0: + version "1.6.0" + resolved "https://registry.yarnpkg.com/aws4/-/aws4-1.6.0.tgz#83ef5ca860b2b32e4a0deedee8c771b9db57471e" + +babel-cli@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-cli/-/babel-cli-6.26.0.tgz#502ab54874d7db88ad00b887a06383ce03d002f1" + dependencies: + babel-core "^6.26.0" + babel-polyfill "^6.26.0" + babel-register "^6.26.0" + babel-runtime "^6.26.0" + commander "^2.11.0" + convert-source-map "^1.5.0" + fs-readdir-recursive "^1.0.0" + glob "^7.1.2" + lodash "^4.17.4" + output-file-sync "^1.1.2" + path-is-absolute "^1.0.1" + slash "^1.0.0" + source-map "^0.5.6" + v8flags "^2.1.1" + optionalDependencies: + chokidar "^1.6.1" + +babel-code-frame@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-code-frame/-/babel-code-frame-6.26.0.tgz#63fd43f7dc1e3bb7ce35947db8fe369a3f58c74b" + dependencies: + chalk "^1.1.3" + esutils "^2.0.2" + js-tokens "^3.0.2" + +babel-core@^6.0.0, babel-core@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-core/-/babel-core-6.26.0.tgz#af32f78b31a6fcef119c87b0fd8d9753f03a0bb8" + dependencies: + babel-code-frame "^6.26.0" + babel-generator "^6.26.0" + babel-helpers "^6.24.1" + babel-messages "^6.23.0" + babel-register "^6.26.0" + babel-runtime "^6.26.0" + babel-template "^6.26.0" + babel-traverse "^6.26.0" + babel-types "^6.26.0" + babylon "^6.18.0" + convert-source-map "^1.5.0" + debug "^2.6.8" + json5 "^0.5.1" + lodash "^4.17.4" + minimatch "^3.0.4" + path-is-absolute "^1.0.1" + private "^0.1.7" + slash "^1.0.0" + source-map "^0.5.6" + +babel-generator@^6.18.0, babel-generator@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-generator/-/babel-generator-6.26.0.tgz#ac1ae20070b79f6e3ca1d3269613053774f20dc5" + dependencies: + babel-messages "^6.23.0" + babel-runtime "^6.26.0" + babel-types "^6.26.0" + detect-indent "^4.0.0" + jsesc "^1.3.0" + lodash "^4.17.4" + source-map "^0.5.6" + trim-right "^1.0.1" + +babel-helper-builder-binary-assignment-operator-visitor@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-helper-builder-binary-assignment-operator-visitor/-/babel-helper-builder-binary-assignment-operator-visitor-6.24.1.tgz#cce4517ada356f4220bcae8a02c2b346f9a56664" + dependencies: + babel-helper-explode-assignable-expression "^6.24.1" + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-helper-call-delegate@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-helper-call-delegate/-/babel-helper-call-delegate-6.24.1.tgz#ece6aacddc76e41c3461f88bfc575bd0daa2df8d" + dependencies: + babel-helper-hoist-variables "^6.24.1" + babel-runtime "^6.22.0" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helper-define-map@^6.24.1: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-helper-define-map/-/babel-helper-define-map-6.26.0.tgz#a5f56dab41a25f97ecb498c7ebaca9819f95be5f" + dependencies: + babel-helper-function-name "^6.24.1" + babel-runtime "^6.26.0" + babel-types "^6.26.0" + lodash "^4.17.4" + +babel-helper-explode-assignable-expression@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-helper-explode-assignable-expression/-/babel-helper-explode-assignable-expression-6.24.1.tgz#f25b82cf7dc10433c55f70592d5746400ac22caa" + dependencies: + babel-runtime "^6.22.0" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helper-function-name@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-helper-function-name/-/babel-helper-function-name-6.24.1.tgz#d3475b8c03ed98242a25b48351ab18399d3580a9" + dependencies: + babel-helper-get-function-arity "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helper-get-function-arity@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-helper-get-function-arity/-/babel-helper-get-function-arity-6.24.1.tgz#8f7782aa93407c41d3aa50908f89b031b1b6853d" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-helper-hoist-variables@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-helper-hoist-variables/-/babel-helper-hoist-variables-6.24.1.tgz#1ecb27689c9d25513eadbc9914a73f5408be7a76" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-helper-optimise-call-expression@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-helper-optimise-call-expression/-/babel-helper-optimise-call-expression-6.24.1.tgz#f7a13427ba9f73f8f4fa993c54a97882d1244257" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-helper-regex@^6.24.1: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-helper-regex/-/babel-helper-regex-6.26.0.tgz#325c59f902f82f24b74faceed0363954f6495e72" + dependencies: + babel-runtime "^6.26.0" + babel-types "^6.26.0" + lodash "^4.17.4" + +babel-helper-remap-async-to-generator@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-helper-remap-async-to-generator/-/babel-helper-remap-async-to-generator-6.24.1.tgz#5ec581827ad723fecdd381f1c928390676e4551b" + dependencies: + babel-helper-function-name "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helper-replace-supers@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-helper-replace-supers/-/babel-helper-replace-supers-6.24.1.tgz#bf6dbfe43938d17369a213ca8a8bf74b6a90ab1a" + dependencies: + babel-helper-optimise-call-expression "^6.24.1" + babel-messages "^6.23.0" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-helpers@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-helpers/-/babel-helpers-6.24.1.tgz#3471de9caec388e5c850e597e58a26ddf37602b2" + dependencies: + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-jest@^21.2.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-21.2.0.tgz#2ce059519a9374a2c46f2455b6fbef5ad75d863e" + dependencies: + babel-plugin-istanbul "^4.0.0" + babel-preset-jest "^21.2.0" + +babel-loader@^7.1.2: + version "7.1.2" + resolved "https://registry.yarnpkg.com/babel-loader/-/babel-loader-7.1.2.tgz#f6cbe122710f1aa2af4d881c6d5b54358ca24126" + dependencies: + find-cache-dir "^1.0.0" + loader-utils "^1.0.2" + mkdirp "^0.5.1" + +babel-messages@^6.23.0: + version "6.23.0" + resolved "https://registry.yarnpkg.com/babel-messages/-/babel-messages-6.23.0.tgz#f3cdf4703858035b2a2951c6ec5edf6c62f2630e" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-check-es2015-constants@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-check-es2015-constants/-/babel-plugin-check-es2015-constants-6.22.0.tgz#35157b101426fd2ffd3da3f75c7d1e91835bbf8a" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-idx@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/babel-plugin-idx/-/babel-plugin-idx-2.0.0.tgz#a852e416f5e58f8eb0764cc09189ae5dad00c2c2" + +babel-plugin-istanbul@^4.0.0: + version "4.1.5" + resolved "https://registry.yarnpkg.com/babel-plugin-istanbul/-/babel-plugin-istanbul-4.1.5.tgz#6760cdd977f411d3e175bb064f2bc327d99b2b6e" + dependencies: + find-up "^2.1.0" + istanbul-lib-instrument "^1.7.5" + test-exclude "^4.1.1" + +babel-plugin-jest-hoist@^21.2.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/babel-plugin-jest-hoist/-/babel-plugin-jest-hoist-21.2.0.tgz#2cef637259bd4b628a6cace039de5fcd14dbb006" + +babel-plugin-syntax-async-functions@^6.8.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-async-functions/-/babel-plugin-syntax-async-functions-6.13.0.tgz#cad9cad1191b5ad634bf30ae0872391e0647be95" + +babel-plugin-syntax-exponentiation-operator@^6.8.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-exponentiation-operator/-/babel-plugin-syntax-exponentiation-operator-6.13.0.tgz#9ee7e8337290da95288201a6a57f4170317830de" + +babel-plugin-syntax-flow@^6.18.0: + version "6.18.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-flow/-/babel-plugin-syntax-flow-6.18.0.tgz#4c3ab20a2af26aa20cd25995c398c4eb70310c8d" + +babel-plugin-syntax-object-rest-spread@^6.13.0: + version "6.13.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-object-rest-spread/-/babel-plugin-syntax-object-rest-spread-6.13.0.tgz#fd6536f2bce13836ffa3a5458c4903a597bb3bf5" + +babel-plugin-syntax-trailing-function-commas@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-6.22.0.tgz#ba0360937f8d06e40180a43fe0d5616fff532cf3" + +babel-plugin-transform-async-to-generator@^6.22.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-async-to-generator/-/babel-plugin-transform-async-to-generator-6.24.1.tgz#6536e378aff6cb1d5517ac0e40eb3e9fc8d08761" + dependencies: + babel-helper-remap-async-to-generator "^6.24.1" + babel-plugin-syntax-async-functions "^6.8.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-arrow-functions@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-arrow-functions/-/babel-plugin-transform-es2015-arrow-functions-6.22.0.tgz#452692cb711d5f79dc7f85e440ce41b9f244d221" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-block-scoped-functions@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoped-functions/-/babel-plugin-transform-es2015-block-scoped-functions-6.22.0.tgz#bbc51b49f964d70cb8d8e0b94e820246ce3a6141" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-block-scoping@^6.23.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-block-scoping/-/babel-plugin-transform-es2015-block-scoping-6.26.0.tgz#d70f5299c1308d05c12f463813b0a09e73b1895f" + dependencies: + babel-runtime "^6.26.0" + babel-template "^6.26.0" + babel-traverse "^6.26.0" + babel-types "^6.26.0" + lodash "^4.17.4" + +babel-plugin-transform-es2015-classes@^6.23.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-classes/-/babel-plugin-transform-es2015-classes-6.24.1.tgz#5a4c58a50c9c9461e564b4b2a3bfabc97a2584db" + dependencies: + babel-helper-define-map "^6.24.1" + babel-helper-function-name "^6.24.1" + babel-helper-optimise-call-expression "^6.24.1" + babel-helper-replace-supers "^6.24.1" + babel-messages "^6.23.0" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-computed-properties@^6.22.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-computed-properties/-/babel-plugin-transform-es2015-computed-properties-6.24.1.tgz#6fe2a8d16895d5634f4cd999b6d3480a308159b3" + dependencies: + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-plugin-transform-es2015-destructuring@^6.23.0: + version "6.23.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-destructuring/-/babel-plugin-transform-es2015-destructuring-6.23.0.tgz#997bb1f1ab967f682d2b0876fe358d60e765c56d" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-duplicate-keys@^6.22.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-duplicate-keys/-/babel-plugin-transform-es2015-duplicate-keys-6.24.1.tgz#73eb3d310ca969e3ef9ec91c53741a6f1576423e" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-for-of@^6.23.0: + version "6.23.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-for-of/-/babel-plugin-transform-es2015-for-of-6.23.0.tgz#f47c95b2b613df1d3ecc2fdb7573623c75248691" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-function-name@^6.22.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-function-name/-/babel-plugin-transform-es2015-function-name-6.24.1.tgz#834c89853bc36b1af0f3a4c5dbaa94fd8eacaa8b" + dependencies: + babel-helper-function-name "^6.24.1" + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-literals@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-literals/-/babel-plugin-transform-es2015-literals-6.22.0.tgz#4f54a02d6cd66cf915280019a31d31925377ca2e" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-modules-amd@^6.22.0, babel-plugin-transform-es2015-modules-amd@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-amd/-/babel-plugin-transform-es2015-modules-amd-6.24.1.tgz#3b3e54017239842d6d19c3011c4bd2f00a00d154" + dependencies: + babel-plugin-transform-es2015-modules-commonjs "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-plugin-transform-es2015-modules-commonjs@^6.23.0, babel-plugin-transform-es2015-modules-commonjs@^6.24.1: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-commonjs/-/babel-plugin-transform-es2015-modules-commonjs-6.26.0.tgz#0d8394029b7dc6abe1a97ef181e00758dd2e5d8a" + dependencies: + babel-plugin-transform-strict-mode "^6.24.1" + babel-runtime "^6.26.0" + babel-template "^6.26.0" + babel-types "^6.26.0" + +babel-plugin-transform-es2015-modules-systemjs@^6.23.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-systemjs/-/babel-plugin-transform-es2015-modules-systemjs-6.24.1.tgz#ff89a142b9119a906195f5f106ecf305d9407d23" + dependencies: + babel-helper-hoist-variables "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-plugin-transform-es2015-modules-umd@^6.23.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-modules-umd/-/babel-plugin-transform-es2015-modules-umd-6.24.1.tgz#ac997e6285cd18ed6176adb607d602344ad38468" + dependencies: + babel-plugin-transform-es2015-modules-amd "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + +babel-plugin-transform-es2015-object-super@^6.22.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-object-super/-/babel-plugin-transform-es2015-object-super-6.24.1.tgz#24cef69ae21cb83a7f8603dad021f572eb278f8d" + dependencies: + babel-helper-replace-supers "^6.24.1" + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-parameters@^6.23.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-parameters/-/babel-plugin-transform-es2015-parameters-6.24.1.tgz#57ac351ab49caf14a97cd13b09f66fdf0a625f2b" + dependencies: + babel-helper-call-delegate "^6.24.1" + babel-helper-get-function-arity "^6.24.1" + babel-runtime "^6.22.0" + babel-template "^6.24.1" + babel-traverse "^6.24.1" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-shorthand-properties@^6.22.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-shorthand-properties/-/babel-plugin-transform-es2015-shorthand-properties-6.24.1.tgz#24f875d6721c87661bbd99a4622e51f14de38aa0" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-spread@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-spread/-/babel-plugin-transform-es2015-spread-6.22.0.tgz#d6d68a99f89aedc4536c81a542e8dd9f1746f8d1" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-sticky-regex@^6.22.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-sticky-regex/-/babel-plugin-transform-es2015-sticky-regex-6.24.1.tgz#00c1cdb1aca71112cdf0cf6126c2ed6b457ccdbc" + dependencies: + babel-helper-regex "^6.24.1" + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-plugin-transform-es2015-template-literals@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-template-literals/-/babel-plugin-transform-es2015-template-literals-6.22.0.tgz#a84b3450f7e9f8f1f6839d6d687da84bb1236d8d" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-typeof-symbol@^6.23.0: + version "6.23.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-typeof-symbol/-/babel-plugin-transform-es2015-typeof-symbol-6.23.0.tgz#dec09f1cddff94b52ac73d505c84df59dcceb372" + dependencies: + babel-runtime "^6.22.0" + +babel-plugin-transform-es2015-unicode-regex@^6.22.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-es2015-unicode-regex/-/babel-plugin-transform-es2015-unicode-regex-6.24.1.tgz#d38b12f42ea7323f729387f18a7c5ae1faeb35e9" + dependencies: + babel-helper-regex "^6.24.1" + babel-runtime "^6.22.0" + regexpu-core "^2.0.0" + +babel-plugin-transform-exponentiation-operator@^6.22.0: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-exponentiation-operator/-/babel-plugin-transform-exponentiation-operator-6.24.1.tgz#2ab0c9c7f3098fa48907772bb813fe41e8de3a0e" + dependencies: + babel-helper-builder-binary-assignment-operator-visitor "^6.24.1" + babel-plugin-syntax-exponentiation-operator "^6.8.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-flow-strip-types@^6.22.0: + version "6.22.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-flow-strip-types/-/babel-plugin-transform-flow-strip-types-6.22.0.tgz#84cb672935d43714fdc32bce84568d87441cf7cf" + dependencies: + babel-plugin-syntax-flow "^6.18.0" + babel-runtime "^6.22.0" + +babel-plugin-transform-regenerator@^6.22.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-regenerator/-/babel-plugin-transform-regenerator-6.26.0.tgz#e0703696fbde27f0a3efcacf8b4dca2f7b3a8f2f" + dependencies: + regenerator-transform "^0.10.0" + +babel-plugin-transform-strict-mode@^6.24.1: + version "6.24.1" + resolved "https://registry.yarnpkg.com/babel-plugin-transform-strict-mode/-/babel-plugin-transform-strict-mode-6.24.1.tgz#d5faf7aa578a65bbe591cf5edae04a0c67020758" + dependencies: + babel-runtime "^6.22.0" + babel-types "^6.24.1" + +babel-polyfill@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-polyfill/-/babel-polyfill-6.26.0.tgz#379937abc67d7895970adc621f284cd966cf2153" + dependencies: + babel-runtime "^6.26.0" + core-js "^2.5.0" + regenerator-runtime "^0.10.5" + +babel-preset-env@^1.6.0: + version "1.6.1" + resolved "https://registry.yarnpkg.com/babel-preset-env/-/babel-preset-env-1.6.1.tgz#a18b564cc9b9afdf4aae57ae3c1b0d99188e6f48" + dependencies: + babel-plugin-check-es2015-constants "^6.22.0" + babel-plugin-syntax-trailing-function-commas "^6.22.0" + babel-plugin-transform-async-to-generator "^6.22.0" + babel-plugin-transform-es2015-arrow-functions "^6.22.0" + babel-plugin-transform-es2015-block-scoped-functions "^6.22.0" + babel-plugin-transform-es2015-block-scoping "^6.23.0" + babel-plugin-transform-es2015-classes "^6.23.0" + babel-plugin-transform-es2015-computed-properties "^6.22.0" + babel-plugin-transform-es2015-destructuring "^6.23.0" + babel-plugin-transform-es2015-duplicate-keys "^6.22.0" + babel-plugin-transform-es2015-for-of "^6.23.0" + babel-plugin-transform-es2015-function-name "^6.22.0" + babel-plugin-transform-es2015-literals "^6.22.0" + babel-plugin-transform-es2015-modules-amd "^6.22.0" + babel-plugin-transform-es2015-modules-commonjs "^6.23.0" + babel-plugin-transform-es2015-modules-systemjs "^6.23.0" + babel-plugin-transform-es2015-modules-umd "^6.23.0" + babel-plugin-transform-es2015-object-super "^6.22.0" + babel-plugin-transform-es2015-parameters "^6.23.0" + babel-plugin-transform-es2015-shorthand-properties "^6.22.0" + babel-plugin-transform-es2015-spread "^6.22.0" + babel-plugin-transform-es2015-sticky-regex "^6.22.0" + babel-plugin-transform-es2015-template-literals "^6.22.0" + babel-plugin-transform-es2015-typeof-symbol "^6.23.0" + babel-plugin-transform-es2015-unicode-regex "^6.22.0" + babel-plugin-transform-exponentiation-operator "^6.22.0" + babel-plugin-transform-regenerator "^6.22.0" + browserslist "^2.1.2" + invariant "^2.2.2" + semver "^5.3.0" + +babel-preset-flow@^6.23.0: + version "6.23.0" + resolved "https://registry.yarnpkg.com/babel-preset-flow/-/babel-preset-flow-6.23.0.tgz#e71218887085ae9a24b5be4169affb599816c49d" + dependencies: + babel-plugin-transform-flow-strip-types "^6.22.0" + +babel-preset-jest@^21.2.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/babel-preset-jest/-/babel-preset-jest-21.2.0.tgz#ff9d2bce08abd98e8a36d9a8a5189b9173b85638" + dependencies: + babel-plugin-jest-hoist "^21.2.0" + babel-plugin-syntax-object-rest-spread "^6.13.0" + +babel-register@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-register/-/babel-register-6.26.0.tgz#6ed021173e2fcb486d7acb45c6009a856f647071" + dependencies: + babel-core "^6.26.0" + babel-runtime "^6.26.0" + core-js "^2.5.0" + home-or-tmp "^2.0.0" + lodash "^4.17.4" + mkdirp "^0.5.1" + source-map-support "^0.4.15" + +babel-runtime@^6.18.0, babel-runtime@^6.22.0, babel-runtime@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-runtime/-/babel-runtime-6.26.0.tgz#965c7058668e82b55d7bfe04ff2337bc8b5647fe" + dependencies: + core-js "^2.4.0" + regenerator-runtime "^0.11.0" + +babel-template@^6.16.0, babel-template@^6.24.1, babel-template@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-template/-/babel-template-6.26.0.tgz#de03e2d16396b069f46dd9fff8521fb1a0e35e02" + dependencies: + babel-runtime "^6.26.0" + babel-traverse "^6.26.0" + babel-types "^6.26.0" + babylon "^6.18.0" + lodash "^4.17.4" + +babel-traverse@^6.18.0, babel-traverse@^6.24.1, babel-traverse@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-traverse/-/babel-traverse-6.26.0.tgz#46a9cbd7edcc62c8e5c064e2d2d8d0f4035766ee" + dependencies: + babel-code-frame "^6.26.0" + babel-messages "^6.23.0" + babel-runtime "^6.26.0" + babel-types "^6.26.0" + babylon "^6.18.0" + debug "^2.6.8" + globals "^9.18.0" + invariant "^2.2.2" + lodash "^4.17.4" + +babel-types@^6.18.0, babel-types@^6.19.0, babel-types@^6.24.1, babel-types@^6.26.0: + version "6.26.0" + resolved "https://registry.yarnpkg.com/babel-types/-/babel-types-6.26.0.tgz#a3b073f94ab49eb6fa55cd65227a334380632497" + dependencies: + babel-runtime "^6.26.0" + esutils "^2.0.2" + lodash "^4.17.4" + to-fast-properties "^1.0.3" + +babylon@^6.18.0: + version "6.18.0" + resolved "https://registry.yarnpkg.com/babylon/-/babylon-6.18.0.tgz#af2f3b88fa6f5c1e4c634d1a0f8eac4f55b395e3" + +balanced-match@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" + +base64-js@^1.0.2: + version "1.2.1" + resolved "https://registry.yarnpkg.com/base64-js/-/base64-js-1.2.1.tgz#a91947da1f4a516ea38e5b4ec0ec3773675e0886" + +bcrypt-pbkdf@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz#63bc5dcb61331b92bc05fd528953c33462a06f8d" + dependencies: + tweetnacl "^0.14.3" + +big.js@^3.1.3: + version "3.2.0" + resolved "https://registry.yarnpkg.com/big.js/-/big.js-3.2.0.tgz#a5fc298b81b9e0dca2e458824784b65c52ba588e" + +binary-extensions@^1.0.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/binary-extensions/-/binary-extensions-1.10.0.tgz#9aeb9a6c5e88638aad171e167f5900abe24835d0" + +block-stream@*: + version "0.0.9" + resolved "https://registry.yarnpkg.com/block-stream/-/block-stream-0.0.9.tgz#13ebfe778a03205cfe03751481ebb4b3300c126a" + dependencies: + inherits "~2.0.0" + +bn.js@^4.0.0, bn.js@^4.1.0, bn.js@^4.1.1, bn.js@^4.4.0: + version "4.11.8" + resolved "https://registry.yarnpkg.com/bn.js/-/bn.js-4.11.8.tgz#2cde09eb5ee341f484746bb0309b3253b1b1442f" + +boom@2.x.x: + version "2.10.1" + resolved "https://registry.yarnpkg.com/boom/-/boom-2.10.1.tgz#39c8918ceff5799f83f9492a848f625add0c766f" + dependencies: + hoek "2.x.x" + +boom@4.x.x: + version "4.3.1" + resolved "https://registry.yarnpkg.com/boom/-/boom-4.3.1.tgz#4f8a3005cb4a7e3889f749030fd25b96e01d2e31" + dependencies: + hoek "4.x.x" + +boom@5.x.x: + version "5.2.0" + resolved "https://registry.yarnpkg.com/boom/-/boom-5.2.0.tgz#5dd9da6ee3a5f302077436290cb717d3f4a54e02" + dependencies: + hoek "4.x.x" + +brace-expansion@^1.1.7: + version "1.1.8" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.8.tgz#c07b211c7c952ec1f8efd51a77ef0d1d3990a292" + dependencies: + balanced-match "^1.0.0" + concat-map "0.0.1" + +braces@^1.8.2: + version "1.8.5" + resolved "https://registry.yarnpkg.com/braces/-/braces-1.8.5.tgz#ba77962e12dff969d6b76711e914b737857bf6a7" + dependencies: + expand-range "^1.8.1" + preserve "^0.2.0" + repeat-element "^1.1.2" + +brorand@^1.0.1: + version "1.1.0" + resolved "https://registry.yarnpkg.com/brorand/-/brorand-1.1.0.tgz#12c25efe40a45e3c323eb8675a0a0ce57b22371f" + +browser-resolve@^1.11.2: + version "1.11.2" + resolved "https://registry.yarnpkg.com/browser-resolve/-/browser-resolve-1.11.2.tgz#8ff09b0a2c421718a1051c260b32e48f442938ce" + dependencies: + resolve "1.1.7" + +browserify-aes@^1.0.0, browserify-aes@^1.0.4: + version "1.1.0" + resolved "https://registry.yarnpkg.com/browserify-aes/-/browserify-aes-1.1.0.tgz#1d2ad62a8b479f23f0ab631c1be86a82dbccbe48" + dependencies: + buffer-xor "^1.0.3" + cipher-base "^1.0.0" + create-hash "^1.1.0" + evp_bytestokey "^1.0.3" + inherits "^2.0.1" + safe-buffer "^5.0.1" + +browserify-cipher@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/browserify-cipher/-/browserify-cipher-1.0.0.tgz#9988244874bf5ed4e28da95666dcd66ac8fc363a" + dependencies: + browserify-aes "^1.0.4" + browserify-des "^1.0.0" + evp_bytestokey "^1.0.0" + +browserify-des@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/browserify-des/-/browserify-des-1.0.0.tgz#daa277717470922ed2fe18594118a175439721dd" + dependencies: + cipher-base "^1.0.1" + des.js "^1.0.0" + inherits "^2.0.1" + +browserify-rsa@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/browserify-rsa/-/browserify-rsa-4.0.1.tgz#21e0abfaf6f2029cf2fafb133567a701d4135524" + dependencies: + bn.js "^4.1.0" + randombytes "^2.0.1" + +browserify-sign@^4.0.0: + version "4.0.4" + resolved "https://registry.yarnpkg.com/browserify-sign/-/browserify-sign-4.0.4.tgz#aa4eb68e5d7b658baa6bf6a57e630cbd7a93d298" + dependencies: + bn.js "^4.1.1" + browserify-rsa "^4.0.0" + create-hash "^1.1.0" + create-hmac "^1.1.2" + elliptic "^6.0.0" + inherits "^2.0.1" + parse-asn1 "^5.0.0" + +browserify-zlib@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/browserify-zlib/-/browserify-zlib-0.1.4.tgz#bb35f8a519f600e0fa6b8485241c979d0141fb2d" + dependencies: + pako "~0.2.0" + +browserslist@^2.1.2: + version "2.5.1" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-2.5.1.tgz#68e4bc536bbcc6086d62843a2ffccea8396821c6" + dependencies: + caniuse-lite "^1.0.30000744" + electron-to-chromium "^1.3.24" + +bser@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/bser/-/bser-2.0.0.tgz#9ac78d3ed5d915804fd87acb158bc797147a1719" + dependencies: + node-int64 "^0.4.0" + +buffer-xor@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/buffer-xor/-/buffer-xor-1.0.3.tgz#26e61ed1422fb70dd42e6e36729ed51d855fe8d9" + +buffer@^4.3.0: + version "4.9.1" + resolved "https://registry.yarnpkg.com/buffer/-/buffer-4.9.1.tgz#6d1bb601b07a4efced97094132093027c95bc298" + dependencies: + base64-js "^1.0.2" + ieee754 "^1.1.4" + isarray "^1.0.0" + +builtin-modules@^1.0.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-1.1.1.tgz#270f076c5a72c02f5b65a47df94c5fe3a278892f" + +builtin-status-codes@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8" + +callsites@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/callsites/-/callsites-2.0.0.tgz#06eb84f00eea413da86affefacbffb36093b3c50" + +camelcase@^1.0.2: + version "1.2.1" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-1.2.1.tgz#9bb5304d2e0b56698b2c758b08a3eaa9daa58a39" + +camelcase@^4.1.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/camelcase/-/camelcase-4.1.0.tgz#d545635be1e33c542649c69173e5de6acfae34dd" + +caniuse-lite@^1.0.30000744: + version "1.0.30000746" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30000746.tgz#c64f95a3925cfd30207a308ed76c1ae96ea09ea0" + +caseless@~0.12.0: + version "0.12.0" + resolved "https://registry.yarnpkg.com/caseless/-/caseless-0.12.0.tgz#1b681c21ff84033c826543090689420d187151dc" + +center-align@^0.1.1: + version "0.1.3" + resolved "https://registry.yarnpkg.com/center-align/-/center-align-0.1.3.tgz#aa0d32629b6ee972200411cbd4461c907bc2b7ad" + dependencies: + align-text "^0.1.3" + lazy-cache "^1.0.3" + +chalk@^1.1.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-1.1.3.tgz#a8115c55e4a702fe4d150abd3872822a7e09fc98" + dependencies: + ansi-styles "^2.2.1" + escape-string-regexp "^1.0.2" + has-ansi "^2.0.0" + strip-ansi "^3.0.0" + supports-color "^2.0.0" + +chalk@^2.0.1: + version "2.1.0" + resolved "https://registry.yarnpkg.com/chalk/-/chalk-2.1.0.tgz#ac5becf14fa21b99c6c92ca7a7d7cfd5b17e743e" + dependencies: + ansi-styles "^3.1.0" + escape-string-regexp "^1.0.5" + supports-color "^4.0.0" + +chokidar@^1.6.1, chokidar@^1.7.0: + version "1.7.0" + resolved "https://registry.yarnpkg.com/chokidar/-/chokidar-1.7.0.tgz#798e689778151c8076b4b360e5edd28cda2bb468" + dependencies: + anymatch "^1.3.0" + async-each "^1.0.0" + glob-parent "^2.0.0" + inherits "^2.0.1" + is-binary-path "^1.0.0" + is-glob "^2.0.0" + path-is-absolute "^1.0.0" + readdirp "^2.0.0" + optionalDependencies: + fsevents "^1.0.0" + +ci-info@^1.0.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/ci-info/-/ci-info-1.1.1.tgz#47b44df118c48d2597b56d342e7e25791060171a" + +cipher-base@^1.0.0, cipher-base@^1.0.1, cipher-base@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/cipher-base/-/cipher-base-1.0.4.tgz#8760e4ecc272f4c363532f926d874aae2c1397de" + dependencies: + inherits "^2.0.1" + safe-buffer "^5.0.1" + +cliui@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-2.1.0.tgz#4b475760ff80264c762c3a1719032e91c7fea0d1" + dependencies: + center-align "^0.1.1" + right-align "^0.1.1" + wordwrap "0.0.2" + +cliui@^3.2.0: + version "3.2.0" + resolved "https://registry.yarnpkg.com/cliui/-/cliui-3.2.0.tgz#120601537a916d29940f934da3b48d585a39213d" + dependencies: + string-width "^1.0.1" + strip-ansi "^3.0.1" + wrap-ansi "^2.0.0" + +co@^4.6.0: + version "4.6.0" + resolved "https://registry.yarnpkg.com/co/-/co-4.6.0.tgz#6ea6bdf3d853ae54ccb8e47bfa0bf3f9031fb184" + +code-point-at@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/code-point-at/-/code-point-at-1.1.0.tgz#0d070b4d043a5bea33a2f1a40e2edb3d9a4ccf77" + +color-convert@^1.9.0: + version "1.9.0" + resolved "https://registry.yarnpkg.com/color-convert/-/color-convert-1.9.0.tgz#1accf97dd739b983bf994d56fec8f95853641b7a" + dependencies: + color-name "^1.1.1" + +color-name@^1.1.1: + version "1.1.3" + resolved "https://registry.yarnpkg.com/color-name/-/color-name-1.1.3.tgz#a7d0558bd89c42f795dd42328f740831ca53bc25" + +combined-stream@^1.0.5, combined-stream@~1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.5.tgz#938370a57b4a51dea2c77c15d5c5fdf895164009" + dependencies: + delayed-stream "~1.0.0" + +commander@^2.11.0: + version "2.14.1" + resolved "https://registry.yarnpkg.com/commander/-/commander-2.14.1.tgz#2235123e37af8ca3c65df45b026dbd357b01b9aa" + +commondir@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/commondir/-/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b" + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + +console-browserify@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/console-browserify/-/console-browserify-1.1.0.tgz#f0241c45730a9fc6323b206dbf38edc741d0bb10" + dependencies: + date-now "^0.1.4" + +console-control-strings@^1.0.0, console-control-strings@~1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/console-control-strings/-/console-control-strings-1.1.0.tgz#3d7cf4464db6446ea644bf4b39507f9851008e8e" + +constants-browserify@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/constants-browserify/-/constants-browserify-1.0.0.tgz#c20b96d8c617748aaf1c16021760cd27fcb8cb75" + +content-type-parser@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/content-type-parser/-/content-type-parser-1.0.1.tgz#c3e56988c53c65127fb46d4032a3a900246fdc94" + +convert-source-map@^1.4.0, convert-source-map@^1.5.0: + version "1.5.0" + resolved "https://registry.yarnpkg.com/convert-source-map/-/convert-source-map-1.5.0.tgz#9acd70851c6d5dfdd93d9282e5edf94a03ff46b5" + +core-js@^2.4.0, core-js@^2.5.0: + version "2.5.1" + resolved "https://registry.yarnpkg.com/core-js/-/core-js-2.5.1.tgz#ae6874dc66937789b80754ff5428df66819ca50b" + +core-util-is@1.0.2, core-util-is@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/core-util-is/-/core-util-is-1.0.2.tgz#b5fd54220aa2bc5ab57aab7140c940754503c1a7" + +create-ecdh@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/create-ecdh/-/create-ecdh-4.0.0.tgz#888c723596cdf7612f6498233eebd7a35301737d" + dependencies: + bn.js "^4.1.0" + elliptic "^6.0.0" + +create-hash@^1.1.0, create-hash@^1.1.2: + version "1.1.3" + resolved "https://registry.yarnpkg.com/create-hash/-/create-hash-1.1.3.tgz#606042ac8b9262750f483caddab0f5819172d8fd" + dependencies: + cipher-base "^1.0.1" + inherits "^2.0.1" + ripemd160 "^2.0.0" + sha.js "^2.4.0" + +create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4: + version "1.1.6" + resolved "https://registry.yarnpkg.com/create-hmac/-/create-hmac-1.1.6.tgz#acb9e221a4e17bdb076e90657c42b93e3726cf06" + dependencies: + cipher-base "^1.0.3" + create-hash "^1.1.0" + inherits "^2.0.1" + ripemd160 "^2.0.0" + safe-buffer "^5.0.1" + sha.js "^2.4.8" + +cross-spawn@^5.0.1: + version "5.1.0" + resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-5.1.0.tgz#e8bd0efee58fcff6f8f94510a0a554bbfa235449" + dependencies: + lru-cache "^4.0.1" + shebang-command "^1.2.0" + which "^1.2.9" + +cryptiles@2.x.x: + version "2.0.5" + resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-2.0.5.tgz#3bdfecdc608147c1c67202fa291e7dca59eaa3b8" + dependencies: + boom "2.x.x" + +cryptiles@3.x.x: + version "3.1.2" + resolved "https://registry.yarnpkg.com/cryptiles/-/cryptiles-3.1.2.tgz#a89fbb220f5ce25ec56e8c4aa8a4fd7b5b0d29fe" + dependencies: + boom "5.x.x" + +crypto-browserify@^3.11.0: + version "3.11.1" + resolved "https://registry.yarnpkg.com/crypto-browserify/-/crypto-browserify-3.11.1.tgz#948945efc6757a400d6e5e5af47194d10064279f" + dependencies: + browserify-cipher "^1.0.0" + browserify-sign "^4.0.0" + create-ecdh "^4.0.0" + create-hash "^1.1.0" + create-hmac "^1.1.0" + diffie-hellman "^5.0.0" + inherits "^2.0.1" + pbkdf2 "^3.0.3" + public-encrypt "^4.0.0" + randombytes "^2.0.0" + +cssom@0.3.x, "cssom@>= 0.3.2 < 0.4.0": + version "0.3.2" + resolved "https://registry.yarnpkg.com/cssom/-/cssom-0.3.2.tgz#b8036170c79f07a90ff2f16e22284027a243848b" + +"cssstyle@>= 0.2.37 < 0.3.0": + version "0.2.37" + resolved "https://registry.yarnpkg.com/cssstyle/-/cssstyle-0.2.37.tgz#541097234cb2513c83ceed3acddc27ff27987d54" + dependencies: + cssom "0.3.x" + +d@1: + version "1.0.0" + resolved "https://registry.yarnpkg.com/d/-/d-1.0.0.tgz#754bb5bfe55451da69a58b94d45f4c5b0462d58f" + dependencies: + es5-ext "^0.10.9" + +dashdash@^1.12.0: + version "1.14.1" + resolved "https://registry.yarnpkg.com/dashdash/-/dashdash-1.14.1.tgz#853cfa0f7cbe2fed5de20326b8dd581035f6e2f0" + dependencies: + assert-plus "^1.0.0" + +date-now@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/date-now/-/date-now-0.1.4.tgz#eaf439fd4d4848ad74e5cc7dbef200672b9e345b" + +debug@^2.2.0, debug@^2.6.3, debug@^2.6.8: + version "2.6.9" + resolved "https://registry.yarnpkg.com/debug/-/debug-2.6.9.tgz#5d128515df134ff327e90a4c93f4e077a536341f" + dependencies: + ms "2.0.0" + +decamelize@^1.0.0, decamelize@^1.1.1: + version "1.2.0" + resolved "https://registry.yarnpkg.com/decamelize/-/decamelize-1.2.0.tgz#f6534d15148269b20352e7bee26f501f9a191290" + +deep-extend@~0.4.0: + version "0.4.2" + resolved "https://registry.yarnpkg.com/deep-extend/-/deep-extend-0.4.2.tgz#48b699c27e334bf89f10892be432f6e4c7d34a7f" + +deep-is@~0.1.3: + version "0.1.3" + resolved "https://registry.yarnpkg.com/deep-is/-/deep-is-0.1.3.tgz#b369d6fb5dbc13eecf524f91b070feedc357cf34" + +default-require-extensions@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/default-require-extensions/-/default-require-extensions-1.0.0.tgz#f37ea15d3e13ffd9b437d33e1a75b5fb97874cb8" + dependencies: + strip-bom "^2.0.0" + +delayed-stream@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delayed-stream/-/delayed-stream-1.0.0.tgz#df3ae199acadfb7d440aaae0b29e2272b24ec619" + +delegates@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/delegates/-/delegates-1.0.0.tgz#84c6e159b81904fdca59a0ef44cd870d31250f9a" + +des.js@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.0.0.tgz#c074d2e2aa6a8a9a07dbd61f9a15c2cd83ec8ecc" + dependencies: + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + +detect-indent@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-4.0.0.tgz#f76d064352cdf43a1cb6ce619c4ee3a9475de208" + dependencies: + repeating "^2.0.0" + +diff@^3.2.0: + version "3.4.0" + resolved "https://registry.yarnpkg.com/diff/-/diff-3.4.0.tgz#b1d85507daf3964828de54b37d0d73ba67dda56c" + +diffie-hellman@^5.0.0: + version "5.0.2" + resolved "https://registry.yarnpkg.com/diffie-hellman/-/diffie-hellman-5.0.2.tgz#b5835739270cfe26acf632099fded2a07f209e5e" + dependencies: + bn.js "^4.1.0" + miller-rabin "^4.0.0" + randombytes "^2.0.0" + +domain-browser@^1.1.1: + version "1.1.7" + resolved "https://registry.yarnpkg.com/domain-browser/-/domain-browser-1.1.7.tgz#867aa4b093faa05f1de08c06f4d7b21fdf8698bc" + +ecc-jsbn@~0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/ecc-jsbn/-/ecc-jsbn-0.1.1.tgz#0fc73a9ed5f0d53c38193398523ef7e543777505" + dependencies: + jsbn "~0.1.0" + +electron-to-chromium@^1.3.24: + version "1.3.26" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.26.tgz#996427294861a74d9c7c82b9260ea301e8c02d66" + +elliptic@^6.0.0: + version "6.4.0" + resolved "https://registry.yarnpkg.com/elliptic/-/elliptic-6.4.0.tgz#cac9af8762c85836187003c8dfe193e5e2eae5df" + dependencies: + bn.js "^4.4.0" + brorand "^1.0.1" + hash.js "^1.0.0" + hmac-drbg "^1.0.0" + inherits "^2.0.1" + minimalistic-assert "^1.0.0" + minimalistic-crypto-utils "^1.0.0" + +emojis-list@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/emojis-list/-/emojis-list-2.1.0.tgz#4daa4d9db00f9819880c79fa457ae5b09a1fd389" + +enhanced-resolve@^3.4.0: + version "3.4.1" + resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-3.4.1.tgz#0421e339fd71419b3da13d129b3979040230476e" + dependencies: + graceful-fs "^4.1.2" + memory-fs "^0.4.0" + object-assign "^4.0.1" + tapable "^0.2.7" + +errno@^0.1.3, errno@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/errno/-/errno-0.1.4.tgz#b896e23a9e5e8ba33871fc996abd3635fc9a1c7d" + dependencies: + prr "~0.0.0" + +error-ex@^1.2.0: + version "1.3.1" + resolved "https://registry.yarnpkg.com/error-ex/-/error-ex-1.3.1.tgz#f855a86ce61adc4e8621c3cda21e7a7612c3a8dc" + dependencies: + is-arrayish "^0.2.1" + +es5-ext@^0.10.14, es5-ext@^0.10.35, es5-ext@^0.10.9, es5-ext@~0.10.14: + version "0.10.35" + resolved "https://registry.yarnpkg.com/es5-ext/-/es5-ext-0.10.35.tgz#18ee858ce6a3c45c7d79e91c15fcca9ec568494f" + dependencies: + es6-iterator "~2.0.1" + es6-symbol "~3.1.1" + +es6-iterator@^2.0.1, es6-iterator@~2.0.1: + version "2.0.3" + resolved "https://registry.yarnpkg.com/es6-iterator/-/es6-iterator-2.0.3.tgz#a7de889141a05a94b0854403b2d0a0fbfa98f3b7" + dependencies: + d "1" + es5-ext "^0.10.35" + es6-symbol "^3.1.1" + +es6-map@^0.1.3: + version "0.1.5" + resolved "https://registry.yarnpkg.com/es6-map/-/es6-map-0.1.5.tgz#9136e0503dcc06a301690f0bb14ff4e364e949f0" + dependencies: + d "1" + es5-ext "~0.10.14" + es6-iterator "~2.0.1" + es6-set "~0.1.5" + es6-symbol "~3.1.1" + event-emitter "~0.3.5" + +es6-set@~0.1.5: + version "0.1.5" + resolved "https://registry.yarnpkg.com/es6-set/-/es6-set-0.1.5.tgz#d2b3ec5d4d800ced818db538d28974db0a73ccb1" + dependencies: + d "1" + es5-ext "~0.10.14" + es6-iterator "~2.0.1" + es6-symbol "3.1.1" + event-emitter "~0.3.5" + +es6-symbol@3.1.1, es6-symbol@^3.1.1, es6-symbol@~3.1.1: + version "3.1.1" + resolved "https://registry.yarnpkg.com/es6-symbol/-/es6-symbol-3.1.1.tgz#bf00ef4fdab6ba1b46ecb7b629b4c7ed5715cc77" + dependencies: + d "1" + es5-ext "~0.10.14" + +es6-weak-map@^2.0.1: + version "2.0.2" + resolved "https://registry.yarnpkg.com/es6-weak-map/-/es6-weak-map-2.0.2.tgz#5e3ab32251ffd1538a1f8e5ffa1357772f92d96f" + dependencies: + d "1" + es5-ext "^0.10.14" + es6-iterator "^2.0.1" + es6-symbol "^3.1.1" + +escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" + +escodegen@^1.6.1: + version "1.9.0" + resolved "https://registry.yarnpkg.com/escodegen/-/escodegen-1.9.0.tgz#9811a2f265dc1cd3894420ee3717064b632b8852" + dependencies: + esprima "^3.1.3" + estraverse "^4.2.0" + esutils "^2.0.2" + optionator "^0.8.1" + optionalDependencies: + source-map "~0.5.6" + +escope@^3.6.0: + version "3.6.0" + resolved "https://registry.yarnpkg.com/escope/-/escope-3.6.0.tgz#e01975e812781a163a6dadfdd80398dc64c889c3" + dependencies: + es6-map "^0.1.3" + es6-weak-map "^2.0.1" + esrecurse "^4.1.0" + estraverse "^4.1.1" + +esprima@^3.1.3: + version "3.1.3" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-3.1.3.tgz#fdca51cee6133895e3c88d535ce49dbff62a4633" + +esprima@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/esprima/-/esprima-4.0.0.tgz#4499eddcd1110e0b218bacf2fa7f7f59f55ca804" + +esrecurse@^4.1.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/esrecurse/-/esrecurse-4.2.0.tgz#fa9568d98d3823f9a41d91e902dcab9ea6e5b163" + dependencies: + estraverse "^4.1.0" + object-assign "^4.0.1" + +estraverse@^4.1.0, estraverse@^4.1.1, estraverse@^4.2.0: + version "4.2.0" + resolved "https://registry.yarnpkg.com/estraverse/-/estraverse-4.2.0.tgz#0dee3fed31fcd469618ce7342099fc1afa0bdb13" + +esutils@^2.0.2: + version "2.0.2" + resolved "https://registry.yarnpkg.com/esutils/-/esutils-2.0.2.tgz#0abf4f1caa5bcb1f7a9d8acc6dea4faaa04bac9b" + +event-emitter@~0.3.5: + version "0.3.5" + resolved "https://registry.yarnpkg.com/event-emitter/-/event-emitter-0.3.5.tgz#df8c69eef1647923c7157b9ce83840610b02cc39" + dependencies: + d "1" + es5-ext "~0.10.14" + +events@^1.0.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/events/-/events-1.1.1.tgz#9ebdb7635ad099c70dcc4c2a1f5004288e8bd924" + +evp_bytestokey@^1.0.0, evp_bytestokey@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/evp_bytestokey/-/evp_bytestokey-1.0.3.tgz#7fcbdb198dc71959432efe13842684e0525acb02" + dependencies: + md5.js "^1.3.4" + safe-buffer "^5.1.1" + +exec-sh@^0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/exec-sh/-/exec-sh-0.2.1.tgz#163b98a6e89e6b65b47c2a28d215bc1f63989c38" + dependencies: + merge "^1.1.3" + +execa@^0.7.0: + version "0.7.0" + resolved "https://registry.yarnpkg.com/execa/-/execa-0.7.0.tgz#944becd34cc41ee32a63a9faf27ad5a65fc59777" + dependencies: + cross-spawn "^5.0.1" + get-stream "^3.0.0" + is-stream "^1.1.0" + npm-run-path "^2.0.0" + p-finally "^1.0.0" + signal-exit "^3.0.0" + strip-eof "^1.0.0" + +expand-brackets@^0.1.4: + version "0.1.5" + resolved "https://registry.yarnpkg.com/expand-brackets/-/expand-brackets-0.1.5.tgz#df07284e342a807cd733ac5af72411e581d1177b" + dependencies: + is-posix-bracket "^0.1.0" + +expand-range@^1.8.1: + version "1.8.2" + resolved "https://registry.yarnpkg.com/expand-range/-/expand-range-1.8.2.tgz#a299effd335fe2721ebae8e257ec79644fc85337" + dependencies: + fill-range "^2.1.0" + +expect@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/expect/-/expect-21.2.1.tgz#003ac2ac7005c3c29e73b38a272d4afadd6d1d7b" + dependencies: + ansi-styles "^3.2.0" + jest-diff "^21.2.1" + jest-get-type "^21.2.0" + jest-matcher-utils "^21.2.1" + jest-message-util "^21.2.1" + jest-regex-util "^21.2.0" + +extend@~3.0.0, extend@~3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/extend/-/extend-3.0.1.tgz#a755ea7bc1adfcc5a31ce7e762dbaadc5e636444" + +extglob@^0.3.1: + version "0.3.2" + resolved "https://registry.yarnpkg.com/extglob/-/extglob-0.3.2.tgz#2e18ff3d2f49ab2765cec9023f011daa8d8349a1" + dependencies: + is-extglob "^1.0.0" + +extsprintf@1.3.0, extsprintf@^1.2.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/extsprintf/-/extsprintf-1.3.0.tgz#96918440e3041a7a414f8c52e3c574eb3c3e1e05" + +fast-deep-equal@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-1.0.0.tgz#96256a3bc975595eb36d82e9929d060d893439ff" + +fast-levenshtein@~2.0.4: + version "2.0.6" + resolved "https://registry.yarnpkg.com/fast-levenshtein/-/fast-levenshtein-2.0.6.tgz#3d8a5c66883a16a30ca8643e851f19baa7797917" + +fb-watchman@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/fb-watchman/-/fb-watchman-2.0.0.tgz#54e9abf7dfa2f26cd9b1636c588c1afc05de5d58" + dependencies: + bser "^2.0.0" + +filename-regex@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/filename-regex/-/filename-regex-2.0.1.tgz#c1c4b9bee3e09725ddb106b75c1e301fe2f18b26" + +fileset@^2.0.2: + version "2.0.3" + resolved "https://registry.yarnpkg.com/fileset/-/fileset-2.0.3.tgz#8e7548a96d3cc2327ee5e674168723a333bba2a0" + dependencies: + glob "^7.0.3" + minimatch "^3.0.3" + +fill-range@^2.1.0: + version "2.2.3" + resolved "https://registry.yarnpkg.com/fill-range/-/fill-range-2.2.3.tgz#50b77dfd7e469bc7492470963699fe7a8485a723" + dependencies: + is-number "^2.1.0" + isobject "^2.0.0" + randomatic "^1.1.3" + repeat-element "^1.1.2" + repeat-string "^1.5.2" + +find-cache-dir@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/find-cache-dir/-/find-cache-dir-1.0.0.tgz#9288e3e9e3cc3748717d39eade17cf71fc30ee6f" + dependencies: + commondir "^1.0.1" + make-dir "^1.0.0" + pkg-dir "^2.0.0" + +find-up@^1.0.0: + version "1.1.2" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-1.1.2.tgz#6b2e9822b1a2ce0a60ab64d610eccad53cb24d0f" + dependencies: + path-exists "^2.0.0" + pinkie-promise "^2.0.0" + +find-up@^2.0.0, find-up@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/find-up/-/find-up-2.1.0.tgz#45d1b7e506c717ddd482775a2b77920a3c0c57a7" + dependencies: + locate-path "^2.0.0" + +for-in@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/for-in/-/for-in-1.0.2.tgz#81068d295a8142ec0ac726c6e2200c30fb6d5e80" + +for-own@^0.1.4: + version "0.1.5" + resolved "https://registry.yarnpkg.com/for-own/-/for-own-0.1.5.tgz#5265c681a4f294dabbf17c9509b6763aa84510ce" + dependencies: + for-in "^1.0.1" + +forever-agent@~0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91" + +form-data@~2.1.1: + version "2.1.4" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.1.4.tgz#33c183acf193276ecaa98143a69e94bfee1750d1" + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.5" + mime-types "^2.1.12" + +form-data@~2.3.1: + version "2.3.1" + resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.3.1.tgz#6fb94fbd71885306d73d15cc497fe4cc4ecd44bf" + dependencies: + asynckit "^0.4.0" + combined-stream "^1.0.5" + mime-types "^2.1.12" + +fs-readdir-recursive@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/fs-readdir-recursive/-/fs-readdir-recursive-1.1.0.tgz#e32fc030a2ccee44a6b5371308da54be0b397d27" + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + +fsevents@^1.0.0, fsevents@^1.1.1: + version "1.1.2" + resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-1.1.2.tgz#3282b713fb3ad80ede0e9fcf4611b5aa6fc033f4" + dependencies: + nan "^2.3.0" + node-pre-gyp "^0.6.36" + +fstream-ignore@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/fstream-ignore/-/fstream-ignore-1.0.5.tgz#9c31dae34767018fe1d249b24dada67d092da105" + dependencies: + fstream "^1.0.0" + inherits "2" + minimatch "^3.0.0" + +fstream@^1.0.0, fstream@^1.0.10, fstream@^1.0.2: + version "1.0.11" + resolved "https://registry.yarnpkg.com/fstream/-/fstream-1.0.11.tgz#5c1fb1f117477114f0632a0eb4b71b3cb0fd3171" + dependencies: + graceful-fs "^4.1.2" + inherits "~2.0.0" + mkdirp ">=0.5 0" + rimraf "2" + +gauge@~2.7.3: + version "2.7.4" + resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7" + dependencies: + aproba "^1.0.3" + console-control-strings "^1.0.0" + has-unicode "^2.0.0" + object-assign "^4.1.0" + signal-exit "^3.0.0" + string-width "^1.0.1" + strip-ansi "^3.0.1" + wide-align "^1.1.0" + +get-caller-file@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/get-caller-file/-/get-caller-file-1.0.2.tgz#f702e63127e7e231c160a80c1554acb70d5047e5" + +get-stream@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" + +getpass@^0.1.1: + version "0.1.7" + resolved "https://registry.yarnpkg.com/getpass/-/getpass-0.1.7.tgz#5eff8e3e684d569ae4cb2b1282604e8ba62149fa" + dependencies: + assert-plus "^1.0.0" + +glob-base@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/glob-base/-/glob-base-0.3.0.tgz#dbb164f6221b1c0b1ccf82aea328b497df0ea3c4" + dependencies: + glob-parent "^2.0.0" + is-glob "^2.0.0" + +glob-parent@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/glob-parent/-/glob-parent-2.0.0.tgz#81383d72db054fcccf5336daa902f182f6edbb28" + dependencies: + is-glob "^2.0.0" + +glob@^7.0.3, glob@^7.0.5, glob@^7.1.1, glob@^7.1.2: + version "7.1.2" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.2.tgz#c19c9df9a028702d678612384a6552404c636d15" + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + +globals@^9.18.0: + version "9.18.0" + resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" + +graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.4: + version "4.1.11" + resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" + +growly@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/growly/-/growly-1.3.0.tgz#f10748cbe76af964b7c96c93c6bcc28af120c081" + +handlebars@^4.0.3: + version "4.0.11" + resolved "https://registry.yarnpkg.com/handlebars/-/handlebars-4.0.11.tgz#630a35dfe0294bc281edae6ffc5d329fc7982dcc" + dependencies: + async "^1.4.0" + optimist "^0.6.1" + source-map "^0.4.4" + optionalDependencies: + uglify-js "^2.6" + +har-schema@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-1.0.5.tgz#d263135f43307c02c602afc8fe95970c0151369e" + +har-schema@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/har-schema/-/har-schema-2.0.0.tgz#a94c2224ebcac04782a0d9035521f24735b7ec92" + +har-validator@~4.2.1: + version "4.2.1" + resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-4.2.1.tgz#33481d0f1bbff600dd203d75812a6a5fba002e2a" + dependencies: + ajv "^4.9.1" + har-schema "^1.0.5" + +har-validator@~5.0.3: + version "5.0.3" + resolved "https://registry.yarnpkg.com/har-validator/-/har-validator-5.0.3.tgz#ba402c266194f15956ef15e0fcf242993f6a7dfd" + dependencies: + ajv "^5.1.0" + har-schema "^2.0.0" + +has-ansi@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/has-ansi/-/has-ansi-2.0.0.tgz#34f5049ce1ecdf2b0649af3ef24e45ed35416d91" + dependencies: + ansi-regex "^2.0.0" + +has-flag@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-1.0.0.tgz#9d9e793165ce017a00f00418c43f942a7b1d11fa" + +has-flag@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/has-flag/-/has-flag-2.0.0.tgz#e8207af1cc7b30d446cc70b734b5e8be18f88d51" + +has-unicode@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/has-unicode/-/has-unicode-2.0.1.tgz#e0e6fe6a28cf51138855e086d1691e771de2a8b9" + +hash-base@^2.0.0: + version "2.0.2" + resolved "https://registry.yarnpkg.com/hash-base/-/hash-base-2.0.2.tgz#66ea1d856db4e8a5470cadf6fce23ae5244ef2e1" + dependencies: + inherits "^2.0.1" + +hash-base@^3.0.0: + version "3.0.4" + resolved "https://registry.yarnpkg.com/hash-base/-/hash-base-3.0.4.tgz#5fc8686847ecd73499403319a6b0a3f3f6ae4918" + dependencies: + inherits "^2.0.1" + safe-buffer "^5.0.1" + +hash.js@^1.0.0, hash.js@^1.0.3: + version "1.1.3" + resolved "https://registry.yarnpkg.com/hash.js/-/hash.js-1.1.3.tgz#340dedbe6290187151c1ea1d777a3448935df846" + dependencies: + inherits "^2.0.3" + minimalistic-assert "^1.0.0" + +hawk@3.1.3, hawk@~3.1.3: + version "3.1.3" + resolved "https://registry.yarnpkg.com/hawk/-/hawk-3.1.3.tgz#078444bd7c1640b0fe540d2c9b73d59678e8e1c4" + dependencies: + boom "2.x.x" + cryptiles "2.x.x" + hoek "2.x.x" + sntp "1.x.x" + +hawk@~6.0.2: + version "6.0.2" + resolved "https://registry.yarnpkg.com/hawk/-/hawk-6.0.2.tgz#af4d914eb065f9b5ce4d9d11c1cb2126eecc3038" + dependencies: + boom "4.x.x" + cryptiles "3.x.x" + hoek "4.x.x" + sntp "2.x.x" + +hmac-drbg@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/hmac-drbg/-/hmac-drbg-1.0.1.tgz#d2745701025a6c775a6c545793ed502fc0c649a1" + dependencies: + hash.js "^1.0.3" + minimalistic-assert "^1.0.0" + minimalistic-crypto-utils "^1.0.1" + +hoek@2.x.x: + version "2.16.3" + resolved "https://registry.yarnpkg.com/hoek/-/hoek-2.16.3.tgz#20bb7403d3cea398e91dc4710a8ff1b8274a25ed" + +hoek@4.x.x: + version "4.2.0" + resolved "https://registry.yarnpkg.com/hoek/-/hoek-4.2.0.tgz#72d9d0754f7fe25ca2d01ad8f8f9a9449a89526d" + +home-or-tmp@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-2.0.0.tgz#e36c3f2d2cae7d746a857e38d18d5f32a7882db8" + dependencies: + os-homedir "^1.0.0" + os-tmpdir "^1.0.1" + +hosted-git-info@^2.1.4: + version "2.5.0" + resolved "https://registry.yarnpkg.com/hosted-git-info/-/hosted-git-info-2.5.0.tgz#6d60e34b3abbc8313062c3b798ef8d901a07af3c" + +html-encoding-sniffer@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/html-encoding-sniffer/-/html-encoding-sniffer-1.0.1.tgz#79bf7a785ea495fe66165e734153f363ff5437da" + dependencies: + whatwg-encoding "^1.0.1" + +http-signature@~1.1.0: + version "1.1.1" + resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.1.1.tgz#df72e267066cd0ac67fb76adf8e134a8fbcf91bf" + dependencies: + assert-plus "^0.2.0" + jsprim "^1.2.2" + sshpk "^1.7.0" + +http-signature@~1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/http-signature/-/http-signature-1.2.0.tgz#9aecd925114772f3d95b65a60abb8f7c18fbace1" + dependencies: + assert-plus "^1.0.0" + jsprim "^1.2.2" + sshpk "^1.7.0" + +https-browserify@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/https-browserify/-/https-browserify-0.0.1.tgz#3f91365cabe60b77ed0ebba24b454e3e09d95a82" + +iconv-lite@0.4.13: + version "0.4.13" + resolved "https://registry.yarnpkg.com/iconv-lite/-/iconv-lite-0.4.13.tgz#1f88aba4ab0b1508e8312acc39345f36e992e2f2" + +idx@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/idx/-/idx-2.1.0.tgz#e0c96663ff1bb2778a362bea988531f13889ffba" + +ieee754@^1.1.4: + version "1.1.8" + resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.1.8.tgz#be33d40ac10ef1926701f6f08a2d86fbfd1ad3e4" + +imurmurhash@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/imurmurhash/-/imurmurhash-0.1.4.tgz#9218b9b2b928a238b13dc4fb6b6d576f231453ea" + +indexof@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/indexof/-/indexof-0.0.1.tgz#82dc336d232b9062179d05ab3293a66059fd435d" + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2, inherits@^2.0.1, inherits@^2.0.3, inherits@~2.0.0, inherits@~2.0.1, inherits@~2.0.3: + version "2.0.3" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.3.tgz#633c2c83e3da42a502f52466022480f4208261de" + +inherits@2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.1.tgz#b17d08d326b4423e568eff719f91b0b1cbdf69f1" + +ini@~1.3.0: + version "1.3.4" + resolved "https://registry.yarnpkg.com/ini/-/ini-1.3.4.tgz#0537cb79daf59b59a1a517dff706c86ec039162e" + +interpret@^1.0.0: + version "1.0.4" + resolved "https://registry.yarnpkg.com/interpret/-/interpret-1.0.4.tgz#820cdd588b868ffb191a809506d6c9c8f212b1b0" + +invariant@^2.2.2: + version "2.2.2" + resolved "https://registry.yarnpkg.com/invariant/-/invariant-2.2.2.tgz#9e1f56ac0acdb6bf303306f338be3b204ae60360" + dependencies: + loose-envify "^1.0.0" + +invert-kv@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6" + +is-arrayish@^0.2.1: + version "0.2.1" + resolved "https://registry.yarnpkg.com/is-arrayish/-/is-arrayish-0.2.1.tgz#77c99840527aa8ecb1a8ba697b80645a7a926a9d" + +is-binary-path@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/is-binary-path/-/is-binary-path-1.0.1.tgz#75f16642b480f187a711c814161fd3a4a7655898" + dependencies: + binary-extensions "^1.0.0" + +is-buffer@^1.1.5: + version "1.1.5" + resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.5.tgz#1f3b26ef613b214b88cbca23cc6c01d87961eecc" + +is-builtin-module@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-builtin-module/-/is-builtin-module-1.0.0.tgz#540572d34f7ac3119f8f76c30cbc1b1e037affbe" + dependencies: + builtin-modules "^1.0.0" + +is-ci@^1.0.10: + version "1.0.10" + resolved "https://registry.yarnpkg.com/is-ci/-/is-ci-1.0.10.tgz#f739336b2632365061a9d48270cd56ae3369318e" + dependencies: + ci-info "^1.0.0" + +is-dotfile@^1.0.0: + version "1.0.3" + resolved "https://registry.yarnpkg.com/is-dotfile/-/is-dotfile-1.0.3.tgz#a6a2f32ffd2dfb04f5ca25ecd0f6b83cf798a1e1" + +is-equal-shallow@^0.1.3: + version "0.1.3" + resolved "https://registry.yarnpkg.com/is-equal-shallow/-/is-equal-shallow-0.1.3.tgz#2238098fc221de0bcfa5d9eac4c45d638aa1c534" + dependencies: + is-primitive "^2.0.0" + +is-extendable@^0.1.1: + version "0.1.1" + resolved "https://registry.yarnpkg.com/is-extendable/-/is-extendable-0.1.1.tgz#62b110e289a471418e3ec36a617d472e301dfc89" + +is-extglob@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-extglob/-/is-extglob-1.0.0.tgz#ac468177c4943405a092fc8f29760c6ffc6206c0" + +is-finite@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/is-finite/-/is-finite-1.0.2.tgz#cc6677695602be550ef11e8b4aa6305342b6d0aa" + dependencies: + number-is-nan "^1.0.0" + +is-fullwidth-code-point@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-1.0.0.tgz#ef9e31386f031a7f0d643af82fde50c457ef00cb" + dependencies: + number-is-nan "^1.0.0" + +is-fullwidth-code-point@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz#a3b30a5c4f199183167aaab93beefae3ddfb654f" + +is-glob@^2.0.0, is-glob@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/is-glob/-/is-glob-2.0.1.tgz#d096f926a3ded5600f3fdfd91198cb0888c2d863" + dependencies: + is-extglob "^1.0.0" + +is-number@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/is-number/-/is-number-2.1.0.tgz#01fcbbb393463a548f2f466cce16dece49db908f" + dependencies: + kind-of "^3.0.2" + +is-number@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195" + dependencies: + kind-of "^3.0.2" + +is-posix-bracket@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/is-posix-bracket/-/is-posix-bracket-0.1.1.tgz#3334dc79774368e92f016e6fbc0a88f5cd6e6bc4" + +is-primitive@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/is-primitive/-/is-primitive-2.0.0.tgz#207bab91638499c07b2adf240a41a87210034575" + +is-stream@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/is-stream/-/is-stream-1.1.0.tgz#12d4a3dd4e68e0b79ceb8dbc84173ae80d91ca44" + +is-typedarray@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/is-typedarray/-/is-typedarray-1.0.0.tgz#e479c80858df0c1b11ddda6940f96011fcda4a9a" + +is-utf8@^0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72" + +isarray@1.0.0, isarray@^1.0.0, isarray@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/isarray/-/isarray-1.0.0.tgz#bb935d48582cba168c06834957a54a3e07124f11" + +isexe@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10" + +isobject@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/isobject/-/isobject-2.1.0.tgz#f065561096a3f1da2ef46272f815c840d87e0c89" + dependencies: + isarray "1.0.0" + +isstream@~0.1.2: + version "0.1.2" + resolved "https://registry.yarnpkg.com/isstream/-/isstream-0.1.2.tgz#47e63f7af55afa6f92e1500e690eb8b8529c099a" + +istanbul-api@^1.1.1: + version "1.1.14" + resolved "https://registry.yarnpkg.com/istanbul-api/-/istanbul-api-1.1.14.tgz#25bc5701f7c680c0ffff913de46e3619a3a6e680" + dependencies: + async "^2.1.4" + fileset "^2.0.2" + istanbul-lib-coverage "^1.1.1" + istanbul-lib-hook "^1.0.7" + istanbul-lib-instrument "^1.8.0" + istanbul-lib-report "^1.1.1" + istanbul-lib-source-maps "^1.2.1" + istanbul-reports "^1.1.2" + js-yaml "^3.7.0" + mkdirp "^0.5.1" + once "^1.4.0" + +istanbul-lib-coverage@^1.0.1, istanbul-lib-coverage@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/istanbul-lib-coverage/-/istanbul-lib-coverage-1.1.1.tgz#73bfb998885299415c93d38a3e9adf784a77a9da" + +istanbul-lib-hook@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/istanbul-lib-hook/-/istanbul-lib-hook-1.0.7.tgz#dd6607f03076578fe7d6f2a630cf143b49bacddc" + dependencies: + append-transform "^0.4.0" + +istanbul-lib-instrument@^1.4.2, istanbul-lib-instrument@^1.7.5, istanbul-lib-instrument@^1.8.0: + version "1.8.0" + resolved "https://registry.yarnpkg.com/istanbul-lib-instrument/-/istanbul-lib-instrument-1.8.0.tgz#66f6c9421cc9ec4704f76f2db084ba9078a2b532" + dependencies: + babel-generator "^6.18.0" + babel-template "^6.16.0" + babel-traverse "^6.18.0" + babel-types "^6.18.0" + babylon "^6.18.0" + istanbul-lib-coverage "^1.1.1" + semver "^5.3.0" + +istanbul-lib-report@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/istanbul-lib-report/-/istanbul-lib-report-1.1.1.tgz#f0e55f56655ffa34222080b7a0cd4760e1405fc9" + dependencies: + istanbul-lib-coverage "^1.1.1" + mkdirp "^0.5.1" + path-parse "^1.0.5" + supports-color "^3.1.2" + +istanbul-lib-source-maps@^1.1.0, istanbul-lib-source-maps@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/istanbul-lib-source-maps/-/istanbul-lib-source-maps-1.2.1.tgz#a6fe1acba8ce08eebc638e572e294d267008aa0c" + dependencies: + debug "^2.6.3" + istanbul-lib-coverage "^1.1.1" + mkdirp "^0.5.1" + rimraf "^2.6.1" + source-map "^0.5.3" + +istanbul-reports@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/istanbul-reports/-/istanbul-reports-1.1.2.tgz#0fb2e3f6aa9922bd3ce45d05d8ab4d5e8e07bd4f" + dependencies: + handlebars "^4.0.3" + +jest-changed-files@^21.2.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/jest-changed-files/-/jest-changed-files-21.2.0.tgz#5dbeecad42f5d88b482334902ce1cba6d9798d29" + dependencies: + throat "^4.0.0" + +jest-cli@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-cli/-/jest-cli-21.2.1.tgz#9c528b6629d651911138d228bdb033c157ec8c00" + dependencies: + ansi-escapes "^3.0.0" + chalk "^2.0.1" + glob "^7.1.2" + graceful-fs "^4.1.11" + is-ci "^1.0.10" + istanbul-api "^1.1.1" + istanbul-lib-coverage "^1.0.1" + istanbul-lib-instrument "^1.4.2" + istanbul-lib-source-maps "^1.1.0" + jest-changed-files "^21.2.0" + jest-config "^21.2.1" + jest-environment-jsdom "^21.2.1" + jest-haste-map "^21.2.0" + jest-message-util "^21.2.1" + jest-regex-util "^21.2.0" + jest-resolve-dependencies "^21.2.0" + jest-runner "^21.2.1" + jest-runtime "^21.2.1" + jest-snapshot "^21.2.1" + jest-util "^21.2.1" + micromatch "^2.3.11" + node-notifier "^5.0.2" + pify "^3.0.0" + slash "^1.0.0" + string-length "^2.0.0" + strip-ansi "^4.0.0" + which "^1.2.12" + worker-farm "^1.3.1" + yargs "^9.0.0" + +jest-config@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-config/-/jest-config-21.2.1.tgz#c7586c79ead0bcc1f38c401e55f964f13bf2a480" + dependencies: + chalk "^2.0.1" + glob "^7.1.1" + jest-environment-jsdom "^21.2.1" + jest-environment-node "^21.2.1" + jest-get-type "^21.2.0" + jest-jasmine2 "^21.2.1" + jest-regex-util "^21.2.0" + jest-resolve "^21.2.0" + jest-util "^21.2.1" + jest-validate "^21.2.1" + pretty-format "^21.2.1" + +jest-diff@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-21.2.1.tgz#46cccb6cab2d02ce98bc314011764bb95b065b4f" + dependencies: + chalk "^2.0.1" + diff "^3.2.0" + jest-get-type "^21.2.0" + pretty-format "^21.2.1" + +jest-docblock@^21.2.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.2.0.tgz#51529c3b30d5fd159da60c27ceedc195faf8d414" + +jest-environment-jsdom@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-environment-jsdom/-/jest-environment-jsdom-21.2.1.tgz#38d9980c8259b2a608ec232deee6289a60d9d5b4" + dependencies: + jest-mock "^21.2.0" + jest-util "^21.2.1" + jsdom "^9.12.0" + +jest-environment-node@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-environment-node/-/jest-environment-node-21.2.1.tgz#98c67df5663c7fbe20f6e792ac2272c740d3b8c8" + dependencies: + jest-mock "^21.2.0" + jest-util "^21.2.1" + +jest-get-type@^21.2.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-21.2.0.tgz#f6376ab9db4b60d81e39f30749c6c466f40d4a23" + +jest-haste-map@^21.2.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/jest-haste-map/-/jest-haste-map-21.2.0.tgz#1363f0a8bb4338f24f001806571eff7a4b2ff3d8" + dependencies: + fb-watchman "^2.0.0" + graceful-fs "^4.1.11" + jest-docblock "^21.2.0" + micromatch "^2.3.11" + sane "^2.0.0" + worker-farm "^1.3.1" + +jest-jasmine2@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-jasmine2/-/jest-jasmine2-21.2.1.tgz#9cc6fc108accfa97efebce10c4308548a4ea7592" + dependencies: + chalk "^2.0.1" + expect "^21.2.1" + graceful-fs "^4.1.11" + jest-diff "^21.2.1" + jest-matcher-utils "^21.2.1" + jest-message-util "^21.2.1" + jest-snapshot "^21.2.1" + p-cancelable "^0.3.0" + +jest-matcher-utils@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-21.2.1.tgz#72c826eaba41a093ac2b4565f865eb8475de0f64" + dependencies: + chalk "^2.0.1" + jest-get-type "^21.2.0" + pretty-format "^21.2.1" + +jest-message-util@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-message-util/-/jest-message-util-21.2.1.tgz#bfe5d4692c84c827d1dcf41823795558f0a1acbe" + dependencies: + chalk "^2.0.1" + micromatch "^2.3.11" + slash "^1.0.0" + +jest-mock@^21.2.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/jest-mock/-/jest-mock-21.2.0.tgz#7eb0770e7317968165f61ea2a7281131534b3c0f" + +jest-regex-util@^21.2.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/jest-regex-util/-/jest-regex-util-21.2.0.tgz#1b1e33e63143babc3e0f2e6c9b5ba1eb34b2d530" + +jest-resolve-dependencies@^21.2.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/jest-resolve-dependencies/-/jest-resolve-dependencies-21.2.0.tgz#9e231e371e1a736a1ad4e4b9a843bc72bfe03d09" + dependencies: + jest-regex-util "^21.2.0" + +jest-resolve@^21.2.0: + version "21.2.0" + resolved "https://registry.yarnpkg.com/jest-resolve/-/jest-resolve-21.2.0.tgz#068913ad2ba6a20218e5fd32471f3874005de3a6" + dependencies: + browser-resolve "^1.11.2" + chalk "^2.0.1" + is-builtin-module "^1.0.0" + +jest-runner@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-runner/-/jest-runner-21.2.1.tgz#194732e3e518bfb3d7cbfc0fd5871246c7e1a467" + dependencies: + jest-config "^21.2.1" + jest-docblock "^21.2.0" + jest-haste-map "^21.2.0" + jest-jasmine2 "^21.2.1" + jest-message-util "^21.2.1" + jest-runtime "^21.2.1" + jest-util "^21.2.1" + pify "^3.0.0" + throat "^4.0.0" + worker-farm "^1.3.1" + +jest-runtime@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-runtime/-/jest-runtime-21.2.1.tgz#99dce15309c670442eee2ebe1ff53a3cbdbbb73e" + dependencies: + babel-core "^6.0.0" + babel-jest "^21.2.0" + babel-plugin-istanbul "^4.0.0" + chalk "^2.0.1" + convert-source-map "^1.4.0" + graceful-fs "^4.1.11" + jest-config "^21.2.1" + jest-haste-map "^21.2.0" + jest-regex-util "^21.2.0" + jest-resolve "^21.2.0" + jest-util "^21.2.1" + json-stable-stringify "^1.0.1" + micromatch "^2.3.11" + slash "^1.0.0" + strip-bom "3.0.0" + write-file-atomic "^2.1.0" + yargs "^9.0.0" + +jest-snapshot@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-snapshot/-/jest-snapshot-21.2.1.tgz#29e49f16202416e47343e757e5eff948c07fd7b0" + dependencies: + chalk "^2.0.1" + jest-diff "^21.2.1" + jest-matcher-utils "^21.2.1" + mkdirp "^0.5.1" + natural-compare "^1.4.0" + pretty-format "^21.2.1" + +jest-util@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-util/-/jest-util-21.2.1.tgz#a274b2f726b0897494d694a6c3d6a61ab819bb78" + dependencies: + callsites "^2.0.0" + chalk "^2.0.1" + graceful-fs "^4.1.11" + jest-message-util "^21.2.1" + jest-mock "^21.2.0" + jest-validate "^21.2.1" + mkdirp "^0.5.1" + +jest-validate@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest-validate/-/jest-validate-21.2.1.tgz#cc0cbca653cd54937ba4f2a111796774530dd3c7" + dependencies: + chalk "^2.0.1" + jest-get-type "^21.2.0" + leven "^2.1.0" + pretty-format "^21.2.1" + +jest@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/jest/-/jest-21.2.1.tgz#c964e0b47383768a1438e3ccf3c3d470327604e1" + dependencies: + jest-cli "^21.2.1" + +js-tokens@^3.0.0, js-tokens@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-3.0.2.tgz#9866df395102130e38f7f996bceb65443209c25b" + +js-yaml@^3.7.0: + version "3.10.0" + resolved "https://registry.yarnpkg.com/js-yaml/-/js-yaml-3.10.0.tgz#2e78441646bd4682e963f22b6e92823c309c62dc" + dependencies: + argparse "^1.0.7" + esprima "^4.0.0" + +jsbn@~0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/jsbn/-/jsbn-0.1.1.tgz#a5e654c2e5a2deb5f201d96cefbca80c0ef2f513" + +jsdom@^9.12.0: + version "9.12.0" + resolved "https://registry.yarnpkg.com/jsdom/-/jsdom-9.12.0.tgz#e8c546fffcb06c00d4833ca84410fed7f8a097d4" + dependencies: + abab "^1.0.3" + acorn "^4.0.4" + acorn-globals "^3.1.0" + array-equal "^1.0.0" + content-type-parser "^1.0.1" + cssom ">= 0.3.2 < 0.4.0" + cssstyle ">= 0.2.37 < 0.3.0" + escodegen "^1.6.1" + html-encoding-sniffer "^1.0.1" + nwmatcher ">= 1.3.9 < 2.0.0" + parse5 "^1.5.1" + request "^2.79.0" + sax "^1.2.1" + symbol-tree "^3.2.1" + tough-cookie "^2.3.2" + webidl-conversions "^4.0.0" + whatwg-encoding "^1.0.1" + whatwg-url "^4.3.0" + xml-name-validator "^2.0.1" + +jsesc@^1.3.0: + version "1.3.0" + resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-1.3.0.tgz#46c3fec8c1892b12b0833db9bc7622176dbab34b" + +jsesc@~0.5.0: + version "0.5.0" + resolved "https://registry.yarnpkg.com/jsesc/-/jsesc-0.5.0.tgz#e7dee66e35d6fc16f710fe91d5cf69f70f08911d" + +json-loader@^0.5.4: + version "0.5.7" + resolved "https://registry.yarnpkg.com/json-loader/-/json-loader-0.5.7.tgz#dca14a70235ff82f0ac9a3abeb60d337a365185d" + +json-schema-traverse@^0.3.0: + version "0.3.1" + resolved "https://registry.yarnpkg.com/json-schema-traverse/-/json-schema-traverse-0.3.1.tgz#349a6d44c53a51de89b40805c5d5e59b417d3340" + +json-schema@0.2.3: + version "0.2.3" + resolved "https://registry.yarnpkg.com/json-schema/-/json-schema-0.2.3.tgz#b480c892e59a2f05954ce727bd3f2a4e882f9e13" + +json-stable-stringify@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/json-stable-stringify/-/json-stable-stringify-1.0.1.tgz#9a759d39c5f2ff503fd5300646ed445f88c4f9af" + dependencies: + jsonify "~0.0.0" + +json-stringify-safe@~5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" + +json5@^0.5.0, json5@^0.5.1: + version "0.5.1" + resolved "https://registry.yarnpkg.com/json5/-/json5-0.5.1.tgz#1eade7acc012034ad84e2396767ead9fa5495821" + +jsonify@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/jsonify/-/jsonify-0.0.0.tgz#2c74b6ee41d93ca51b7b5aaee8f503631d252a73" + +jsprim@^1.2.2: + version "1.4.1" + resolved "https://registry.yarnpkg.com/jsprim/-/jsprim-1.4.1.tgz#313e66bc1e5cc06e438bc1b7499c2e5c56acb6a2" + dependencies: + assert-plus "1.0.0" + extsprintf "1.3.0" + json-schema "0.2.3" + verror "1.10.0" + +kind-of@^3.0.2: + version "3.2.2" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-3.2.2.tgz#31ea21a734bab9bbb0f32466d893aea51e4a3c64" + dependencies: + is-buffer "^1.1.5" + +kind-of@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/kind-of/-/kind-of-4.0.0.tgz#20813df3d712928b207378691a45066fae72dd57" + dependencies: + is-buffer "^1.1.5" + +lazy-cache@^1.0.3: + version "1.0.4" + resolved "https://registry.yarnpkg.com/lazy-cache/-/lazy-cache-1.0.4.tgz#a1d78fc3a50474cb80845d3b3b6e1da49a446e8e" + +lcid@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/lcid/-/lcid-1.0.0.tgz#308accafa0bc483a3867b4b6f2b9506251d1b835" + dependencies: + invert-kv "^1.0.0" + +leven@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/leven/-/leven-2.1.0.tgz#c2e7a9f772094dee9d34202ae8acce4687875580" + +levn@~0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/levn/-/levn-0.3.0.tgz#3b09924edf9f083c0490fdd4c0bc4421e04764ee" + dependencies: + prelude-ls "~1.1.2" + type-check "~0.3.2" + +load-json-file@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-1.1.0.tgz#956905708d58b4bab4c2261b04f59f31c99374c0" + dependencies: + graceful-fs "^4.1.2" + parse-json "^2.2.0" + pify "^2.0.0" + pinkie-promise "^2.0.0" + strip-bom "^2.0.0" + +load-json-file@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-2.0.0.tgz#7947e42149af80d696cbf797bcaabcfe1fe29ca8" + dependencies: + graceful-fs "^4.1.2" + parse-json "^2.2.0" + pify "^2.0.0" + strip-bom "^3.0.0" + +loader-runner@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/loader-runner/-/loader-runner-2.3.0.tgz#f482aea82d543e07921700d5a46ef26fdac6b8a2" + +loader-utils@^1.0.2, loader-utils@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.1.0.tgz#c98aef488bcceda2ffb5e2de646d6a754429f5cd" + dependencies: + big.js "^3.1.3" + emojis-list "^2.0.0" + json5 "^0.5.0" + +locate-path@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/locate-path/-/locate-path-2.0.0.tgz#2b568b265eec944c6d9c0de9c3dbbbca0354cd8e" + dependencies: + p-locate "^2.0.0" + path-exists "^3.0.0" + +lodash@^4.14.0, lodash@^4.17.4: + version "4.17.4" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.4.tgz#78203a4d1c328ae1d86dca6460e369b57f4055ae" + +longest@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/longest/-/longest-1.0.1.tgz#30a0b2da38f73770e8294a0d22e6625ed77d0097" + +loose-envify@^1.0.0: + version "1.3.1" + resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.3.1.tgz#d1a8ad33fa9ce0e713d65fdd0ac8b748d478c848" + dependencies: + js-tokens "^3.0.0" + +lru-cache@^4.0.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/lru-cache/-/lru-cache-4.1.1.tgz#622e32e82488b49279114a4f9ecf45e7cd6bba55" + dependencies: + pseudomap "^1.0.2" + yallist "^2.1.2" + +make-dir@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.0.0.tgz#97a011751e91dd87cfadef58832ebb04936de978" + dependencies: + pify "^2.3.0" + +makeerror@1.0.x: + version "1.0.11" + resolved "https://registry.yarnpkg.com/makeerror/-/makeerror-1.0.11.tgz#e01a5c9109f2af79660e4e8b9587790184f5a96c" + dependencies: + tmpl "1.0.x" + +md5.js@^1.3.4: + version "1.3.4" + resolved "https://registry.yarnpkg.com/md5.js/-/md5.js-1.3.4.tgz#e9bdbde94a20a5ac18b04340fc5764d5b09d901d" + dependencies: + hash-base "^3.0.0" + inherits "^2.0.1" + +mem@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/mem/-/mem-1.1.0.tgz#5edd52b485ca1d900fe64895505399a0dfa45f76" + dependencies: + mimic-fn "^1.0.0" + +memory-fs@^0.4.0, memory-fs@~0.4.1: + version "0.4.1" + resolved "https://registry.yarnpkg.com/memory-fs/-/memory-fs-0.4.1.tgz#3a9a20b8462523e447cfbc7e8bb80ed667bfc552" + dependencies: + errno "^0.1.3" + readable-stream "^2.0.1" + +merge@^1.1.3: + version "1.2.0" + resolved "https://registry.yarnpkg.com/merge/-/merge-1.2.0.tgz#7531e39d4949c281a66b8c5a6e0265e8b05894da" + +micromatch@^2.1.5, micromatch@^2.3.11: + version "2.3.11" + resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-2.3.11.tgz#86677c97d1720b363431d04d0d15293bd38c1565" + dependencies: + arr-diff "^2.0.0" + array-unique "^0.2.1" + braces "^1.8.2" + expand-brackets "^0.1.4" + extglob "^0.3.1" + filename-regex "^2.0.0" + is-extglob "^1.0.0" + is-glob "^2.0.1" + kind-of "^3.0.2" + normalize-path "^2.0.1" + object.omit "^2.0.0" + parse-glob "^3.0.4" + regex-cache "^0.4.2" + +miller-rabin@^4.0.0: + version "4.0.1" + resolved "https://registry.yarnpkg.com/miller-rabin/-/miller-rabin-4.0.1.tgz#f080351c865b0dc562a8462966daa53543c78a4d" + dependencies: + bn.js "^4.0.0" + brorand "^1.0.1" + +mime-db@~1.30.0: + version "1.30.0" + resolved "https://registry.yarnpkg.com/mime-db/-/mime-db-1.30.0.tgz#74c643da2dd9d6a45399963465b26d5ca7d71f01" + +mime-types@^2.1.12, mime-types@~2.1.17, mime-types@~2.1.7: + version "2.1.17" + resolved "https://registry.yarnpkg.com/mime-types/-/mime-types-2.1.17.tgz#09d7a393f03e995a79f8af857b70a9e0ab16557a" + dependencies: + mime-db "~1.30.0" + +mimic-fn@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/mimic-fn/-/mimic-fn-1.1.0.tgz#e667783d92e89dbd342818b5230b9d62a672ad18" + +minimalistic-assert@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/minimalistic-assert/-/minimalistic-assert-1.0.0.tgz#702be2dda6b37f4836bcb3f5db56641b64a1d3d3" + +minimalistic-crypto-utils@^1.0.0, minimalistic-crypto-utils@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/minimalistic-crypto-utils/-/minimalistic-crypto-utils-1.0.1.tgz#f6c00c1c0b082246e5c4d99dfb8c7c083b2b582a" + +minimatch@^3.0.0, minimatch@^3.0.2, minimatch@^3.0.3, minimatch@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" + dependencies: + brace-expansion "^1.1.7" + +minimist@0.0.8: + version "0.0.8" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" + +minimist@^1.1.1, minimist@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.0.tgz#a35008b20f41383eec1fb914f4cd5df79a264284" + +minimist@~0.0.1: + version "0.0.10" + resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.10.tgz#de3f98543dbf96082be48ad1a0c7cda836301dcf" + +"mkdirp@>=0.5 0", mkdirp@^0.5.1, mkdirp@~0.5.0: + version "0.5.1" + resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-0.5.1.tgz#30057438eac6cf7f8c4767f38648d6697d75c903" + dependencies: + minimist "0.0.8" + +ms@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/ms/-/ms-2.0.0.tgz#5608aeadfc00be6c2901df5f9861788de0d597c8" + +nan@^2.3.0: + version "2.7.0" + resolved "https://registry.yarnpkg.com/nan/-/nan-2.7.0.tgz#d95bf721ec877e08db276ed3fc6eb78f9083ad46" + +natural-compare@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/natural-compare/-/natural-compare-1.4.0.tgz#4abebfeed7541f2c27acfb29bdbbd15c8d5ba4f7" + +node-int64@^0.4.0: + version "0.4.0" + resolved "https://registry.yarnpkg.com/node-int64/-/node-int64-0.4.0.tgz#87a9065cdb355d3182d8f94ce11188b825c68a3b" + +node-libs-browser@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/node-libs-browser/-/node-libs-browser-2.0.0.tgz#a3a59ec97024985b46e958379646f96c4b616646" + dependencies: + assert "^1.1.1" + browserify-zlib "^0.1.4" + buffer "^4.3.0" + console-browserify "^1.1.0" + constants-browserify "^1.0.0" + crypto-browserify "^3.11.0" + domain-browser "^1.1.1" + events "^1.0.0" + https-browserify "0.0.1" + os-browserify "^0.2.0" + path-browserify "0.0.0" + process "^0.11.0" + punycode "^1.2.4" + querystring-es3 "^0.2.0" + readable-stream "^2.0.5" + stream-browserify "^2.0.1" + stream-http "^2.3.1" + string_decoder "^0.10.25" + timers-browserify "^2.0.2" + tty-browserify "0.0.0" + url "^0.11.0" + util "^0.10.3" + vm-browserify "0.0.4" + +node-notifier@^5.0.2: + version "5.1.2" + resolved "https://registry.yarnpkg.com/node-notifier/-/node-notifier-5.1.2.tgz#2fa9e12605fa10009d44549d6fcd8a63dde0e4ff" + dependencies: + growly "^1.3.0" + semver "^5.3.0" + shellwords "^0.1.0" + which "^1.2.12" + +node-pre-gyp@^0.6.36: + version "0.6.38" + resolved "https://registry.yarnpkg.com/node-pre-gyp/-/node-pre-gyp-0.6.38.tgz#e92a20f83416415bb4086f6d1fb78b3da73d113d" + dependencies: + hawk "3.1.3" + mkdirp "^0.5.1" + nopt "^4.0.1" + npmlog "^4.0.2" + rc "^1.1.7" + request "2.81.0" + rimraf "^2.6.1" + semver "^5.3.0" + tar "^2.2.1" + tar-pack "^3.4.0" + +nopt@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/nopt/-/nopt-4.0.1.tgz#d0d4685afd5415193c8c7505602d0d17cd64474d" + dependencies: + abbrev "1" + osenv "^0.1.4" + +normalize-package-data@^2.3.2: + version "2.4.0" + resolved "https://registry.yarnpkg.com/normalize-package-data/-/normalize-package-data-2.4.0.tgz#12f95a307d58352075a04907b84ac8be98ac012f" + dependencies: + hosted-git-info "^2.1.4" + is-builtin-module "^1.0.0" + semver "2 || 3 || 4 || 5" + validate-npm-package-license "^3.0.1" + +normalize-path@^2.0.0, normalize-path@^2.0.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/normalize-path/-/normalize-path-2.1.1.tgz#1ab28b556e198363a8c1a6f7e6fa20137fe6aed9" + dependencies: + remove-trailing-separator "^1.0.1" + +npm-run-path@^2.0.0: + version "2.0.2" + resolved "https://registry.yarnpkg.com/npm-run-path/-/npm-run-path-2.0.2.tgz#35a9232dfa35d7067b4cb2ddf2357b1871536c5f" + dependencies: + path-key "^2.0.0" + +npmlog@^4.0.2: + version "4.1.2" + resolved "https://registry.yarnpkg.com/npmlog/-/npmlog-4.1.2.tgz#08a7f2a8bf734604779a9efa4ad5cc717abb954b" + dependencies: + are-we-there-yet "~1.1.2" + console-control-strings "~1.1.0" + gauge "~2.7.3" + set-blocking "~2.0.0" + +number-is-nan@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/number-is-nan/-/number-is-nan-1.0.1.tgz#097b602b53422a522c1afb8790318336941a011d" + +"nwmatcher@>= 1.3.9 < 2.0.0": + version "1.4.3" + resolved "https://registry.yarnpkg.com/nwmatcher/-/nwmatcher-1.4.3.tgz#64348e3b3d80f035b40ac11563d278f8b72db89c" + +oauth-sign@~0.8.1, oauth-sign@~0.8.2: + version "0.8.2" + resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43" + +object-assign@^4.0.1, object-assign@^4.1.0: + version "4.1.1" + resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" + +object.omit@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/object.omit/-/object.omit-2.0.1.tgz#1a9c744829f39dbb858c76ca3579ae2a54ebd1fa" + dependencies: + for-own "^0.1.4" + is-extendable "^0.1.1" + +once@^1.3.0, once@^1.3.3, once@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + dependencies: + wrappy "1" + +optimist@^0.6.1: + version "0.6.1" + resolved "https://registry.yarnpkg.com/optimist/-/optimist-0.6.1.tgz#da3ea74686fa21a19a111c326e90eb15a0196686" + dependencies: + minimist "~0.0.1" + wordwrap "~0.0.2" + +optionator@^0.8.1: + version "0.8.2" + resolved "https://registry.yarnpkg.com/optionator/-/optionator-0.8.2.tgz#364c5e409d3f4d6301d6c0b4c05bba50180aeb64" + dependencies: + deep-is "~0.1.3" + fast-levenshtein "~2.0.4" + levn "~0.3.0" + prelude-ls "~1.1.2" + type-check "~0.3.2" + wordwrap "~1.0.0" + +os-browserify@^0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/os-browserify/-/os-browserify-0.2.1.tgz#63fc4ccee5d2d7763d26bbf8601078e6c2e0044f" + +os-homedir@^1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" + +os-locale@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/os-locale/-/os-locale-2.1.0.tgz#42bc2900a6b5b8bd17376c8e882b65afccf24bf2" + dependencies: + execa "^0.7.0" + lcid "^1.0.0" + mem "^1.1.0" + +os-tmpdir@^1.0.0, os-tmpdir@^1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" + +osenv@^0.1.4: + version "0.1.4" + resolved "https://registry.yarnpkg.com/osenv/-/osenv-0.1.4.tgz#42fe6d5953df06c8064be6f176c3d05aaaa34644" + dependencies: + os-homedir "^1.0.0" + os-tmpdir "^1.0.0" + +output-file-sync@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/output-file-sync/-/output-file-sync-1.1.2.tgz#d0a33eefe61a205facb90092e826598d5245ce76" + dependencies: + graceful-fs "^4.1.4" + mkdirp "^0.5.1" + object-assign "^4.1.0" + +p-cancelable@^0.3.0: + version "0.3.0" + resolved "https://registry.yarnpkg.com/p-cancelable/-/p-cancelable-0.3.0.tgz#b9e123800bcebb7ac13a479be195b507b98d30fa" + +p-finally@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/p-finally/-/p-finally-1.0.0.tgz#3fbcfb15b899a44123b34b6dcc18b724336a2cae" + +p-limit@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/p-limit/-/p-limit-1.1.0.tgz#b07ff2d9a5d88bec806035895a2bab66a27988bc" + +p-locate@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/p-locate/-/p-locate-2.0.0.tgz#20a0103b222a70c8fd39cc2e580680f3dde5ec43" + dependencies: + p-limit "^1.1.0" + +pako@~0.2.0: + version "0.2.9" + resolved "https://registry.yarnpkg.com/pako/-/pako-0.2.9.tgz#f3f7522f4ef782348da8161bad9ecfd51bf83a75" + +parse-asn1@^5.0.0: + version "5.1.0" + resolved "https://registry.yarnpkg.com/parse-asn1/-/parse-asn1-5.1.0.tgz#37c4f9b7ed3ab65c74817b5f2480937fbf97c712" + dependencies: + asn1.js "^4.0.0" + browserify-aes "^1.0.0" + create-hash "^1.1.0" + evp_bytestokey "^1.0.0" + pbkdf2 "^3.0.3" + +parse-glob@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/parse-glob/-/parse-glob-3.0.4.tgz#b2c376cfb11f35513badd173ef0bb6e3a388391c" + dependencies: + glob-base "^0.3.0" + is-dotfile "^1.0.0" + is-extglob "^1.0.0" + is-glob "^2.0.0" + +parse-json@^2.2.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/parse-json/-/parse-json-2.2.0.tgz#f480f40434ef80741f8469099f8dea18f55a4dc9" + dependencies: + error-ex "^1.2.0" + +parse5@^1.5.1: + version "1.5.1" + resolved "https://registry.yarnpkg.com/parse5/-/parse5-1.5.1.tgz#9b7f3b0de32be78dc2401b17573ccaf0f6f59d94" + +path-browserify@0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/path-browserify/-/path-browserify-0.0.0.tgz#a0b870729aae214005b7d5032ec2cbbb0fb4451a" + +path-exists@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-2.1.0.tgz#0feb6c64f0fc518d9a754dd5efb62c7022761f4b" + dependencies: + pinkie-promise "^2.0.0" + +path-exists@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/path-exists/-/path-exists-3.0.0.tgz#ce0ebeaa5f78cb18925ea7d810d7b59b010fd515" + +path-is-absolute@^1.0.0, path-is-absolute@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + +path-key@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/path-key/-/path-key-2.0.1.tgz#411cadb574c5a140d3a4b1910d40d80cc9f40b40" + +path-parse@^1.0.5: + version "1.0.5" + resolved "https://registry.yarnpkg.com/path-parse/-/path-parse-1.0.5.tgz#3c1adf871ea9cd6c9431b6ea2bd74a0ff055c4c1" + +path-type@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/path-type/-/path-type-1.1.0.tgz#59c44f7ee491da704da415da5a4070ba4f8fe441" + dependencies: + graceful-fs "^4.1.2" + pify "^2.0.0" + pinkie-promise "^2.0.0" + +path-type@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/path-type/-/path-type-2.0.0.tgz#f012ccb8415b7096fc2daa1054c3d72389594c73" + dependencies: + pify "^2.0.0" + +pbkdf2@^3.0.3: + version "3.0.14" + resolved "https://registry.yarnpkg.com/pbkdf2/-/pbkdf2-3.0.14.tgz#a35e13c64799b06ce15320f459c230e68e73bade" + dependencies: + create-hash "^1.1.2" + create-hmac "^1.1.4" + ripemd160 "^2.0.1" + safe-buffer "^5.0.1" + sha.js "^2.4.8" + +performance-now@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-0.2.0.tgz#33ef30c5c77d4ea21c5a53869d91b56d8f2555e5" + +performance-now@^2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/performance-now/-/performance-now-2.1.0.tgz#6309f4e0e5fa913ec1c69307ae364b4b377c9e7b" + +pify@^2.0.0, pify@^2.3.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/pify/-/pify-2.3.0.tgz#ed141a6ac043a849ea588498e7dca8b15330e90c" + +pify@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/pify/-/pify-3.0.0.tgz#e5a4acd2c101fdf3d9a4d07f0dbc4db49dd28176" + +pinkie-promise@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/pinkie-promise/-/pinkie-promise-2.0.1.tgz#2135d6dfa7a358c069ac9b178776288228450ffa" + dependencies: + pinkie "^2.0.0" + +pinkie@^2.0.0: + version "2.0.4" + resolved "https://registry.yarnpkg.com/pinkie/-/pinkie-2.0.4.tgz#72556b80cfa0d48a974e80e77248e80ed4f7f870" + +pkg-dir@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-2.0.0.tgz#f6d5d1109e19d63edf428e0bd57e12777615334b" + dependencies: + find-up "^2.1.0" + +prelude-ls@~1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" + +preserve@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" + +pretty-format@^21.2.1: + version "21.2.1" + resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-21.2.1.tgz#ae5407f3cf21066cd011aa1ba5fce7b6a2eddb36" + dependencies: + ansi-regex "^3.0.0" + ansi-styles "^3.2.0" + +private@^0.1.6, private@^0.1.7: + version "0.1.8" + resolved "https://registry.yarnpkg.com/private/-/private-0.1.8.tgz#2381edb3689f7a53d653190060fcf822d2f368ff" + +process-nextick-args@~1.0.6: + version "1.0.7" + resolved "https://registry.yarnpkg.com/process-nextick-args/-/process-nextick-args-1.0.7.tgz#150e20b756590ad3f91093f25a4f2ad8bff30ba3" + +process@^0.11.0: + version "0.11.10" + resolved "https://registry.yarnpkg.com/process/-/process-0.11.10.tgz#7332300e840161bda3e69a1d1d91a7d4bc16f182" + +prr@~0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/prr/-/prr-0.0.0.tgz#1a84b85908325501411853d0081ee3fa86e2926a" + +pseudomap@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/pseudomap/-/pseudomap-1.0.2.tgz#f052a28da70e618917ef0a8ac34c1ae5a68286b3" + +public-encrypt@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/public-encrypt/-/public-encrypt-4.0.0.tgz#39f699f3a46560dd5ebacbca693caf7c65c18cc6" + dependencies: + bn.js "^4.1.0" + browserify-rsa "^4.0.0" + create-hash "^1.1.0" + parse-asn1 "^5.0.0" + randombytes "^2.0.1" + +punycode@1.3.2: + version "1.3.2" + resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.3.2.tgz#9653a036fb7c1ee42342f2325cceefea3926c48d" + +punycode@^1.2.4, punycode@^1.4.1: + version "1.4.1" + resolved "https://registry.yarnpkg.com/punycode/-/punycode-1.4.1.tgz#c0d5a63b2718800ad8e1eb0fa5269c84dd41845e" + +qs@~6.4.0: + version "6.4.0" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.4.0.tgz#13e26d28ad6b0ffaa91312cd3bf708ed351e7233" + +qs@~6.5.1: + version "6.5.1" + resolved "https://registry.yarnpkg.com/qs/-/qs-6.5.1.tgz#349cdf6eef89ec45c12d7d5eb3fc0c870343a6d8" + +querystring-es3@^0.2.0: + version "0.2.1" + resolved "https://registry.yarnpkg.com/querystring-es3/-/querystring-es3-0.2.1.tgz#9ec61f79049875707d69414596fd907a4d711e73" + +querystring@0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/querystring/-/querystring-0.2.0.tgz#b209849203bb25df820da756e747005878521620" + +randomatic@^1.1.3: + version "1.1.7" + resolved "https://registry.yarnpkg.com/randomatic/-/randomatic-1.1.7.tgz#c7abe9cc8b87c0baa876b19fde83fd464797e38c" + dependencies: + is-number "^3.0.0" + kind-of "^4.0.0" + +randombytes@^2.0.0, randombytes@^2.0.1: + version "2.0.5" + resolved "https://registry.yarnpkg.com/randombytes/-/randombytes-2.0.5.tgz#dc009a246b8d09a177b4b7a0ae77bc570f4b1b79" + dependencies: + safe-buffer "^5.1.0" + +rc@^1.1.7: + version "1.2.2" + resolved "https://registry.yarnpkg.com/rc/-/rc-1.2.2.tgz#d8ce9cb57e8d64d9c7badd9876c7c34cbe3c7077" + dependencies: + deep-extend "~0.4.0" + ini "~1.3.0" + minimist "^1.2.0" + strip-json-comments "~2.0.1" + +read-pkg-up@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-1.0.1.tgz#9d63c13276c065918d57f002a57f40a1b643fb02" + dependencies: + find-up "^1.0.0" + read-pkg "^1.0.0" + +read-pkg-up@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/read-pkg-up/-/read-pkg-up-2.0.0.tgz#6b72a8048984e0c41e79510fd5e9fa99b3b549be" + dependencies: + find-up "^2.0.0" + read-pkg "^2.0.0" + +read-pkg@^1.0.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-1.1.0.tgz#f5ffaa5ecd29cb31c0474bca7d756b6bb29e3f28" + dependencies: + load-json-file "^1.0.0" + normalize-package-data "^2.3.2" + path-type "^1.0.0" + +read-pkg@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/read-pkg/-/read-pkg-2.0.0.tgz#8ef1c0623c6a6db0dc6713c4bfac46332b2368f8" + dependencies: + load-json-file "^2.0.0" + normalize-package-data "^2.3.2" + path-type "^2.0.0" + +readable-stream@^2.0.1, readable-stream@^2.0.2, readable-stream@^2.0.5, readable-stream@^2.0.6, readable-stream@^2.1.4, readable-stream@^2.2.6: + version "2.3.3" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.3.tgz#368f2512d79f9d46fdfc71349ae7878bbc1eb95c" + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.3" + isarray "~1.0.0" + process-nextick-args "~1.0.6" + safe-buffer "~5.1.1" + string_decoder "~1.0.3" + util-deprecate "~1.0.1" + +readdirp@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/readdirp/-/readdirp-2.1.0.tgz#4ed0ad060df3073300c48440373f72d1cc642d78" + dependencies: + graceful-fs "^4.1.2" + minimatch "^3.0.2" + readable-stream "^2.0.2" + set-immediate-shim "^1.0.1" + +regenerate@^1.2.1: + version "1.3.3" + resolved "https://registry.yarnpkg.com/regenerate/-/regenerate-1.3.3.tgz#0c336d3980553d755c39b586ae3b20aa49c82b7f" + +regenerator-runtime@^0.10.5: + version "0.10.5" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.10.5.tgz#336c3efc1220adcedda2c9fab67b5a7955a33658" + +regenerator-runtime@^0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/regenerator-runtime/-/regenerator-runtime-0.11.0.tgz#7e54fe5b5ccd5d6624ea6255c3473be090b802e1" + +regenerator-transform@^0.10.0: + version "0.10.1" + resolved "https://registry.yarnpkg.com/regenerator-transform/-/regenerator-transform-0.10.1.tgz#1e4996837231da8b7f3cf4114d71b5691a0680dd" + dependencies: + babel-runtime "^6.18.0" + babel-types "^6.19.0" + private "^0.1.6" + +regex-cache@^0.4.2: + version "0.4.4" + resolved "https://registry.yarnpkg.com/regex-cache/-/regex-cache-0.4.4.tgz#75bdc58a2a1496cec48a12835bc54c8d562336dd" + dependencies: + is-equal-shallow "^0.1.3" + +regexpu-core@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/regexpu-core/-/regexpu-core-2.0.0.tgz#49d038837b8dcf8bfa5b9a42139938e6ea2ae240" + dependencies: + regenerate "^1.2.1" + regjsgen "^0.2.0" + regjsparser "^0.1.4" + +regjsgen@^0.2.0: + version "0.2.0" + resolved "https://registry.yarnpkg.com/regjsgen/-/regjsgen-0.2.0.tgz#6c016adeac554f75823fe37ac05b92d5a4edb1f7" + +regjsparser@^0.1.4: + version "0.1.5" + resolved "https://registry.yarnpkg.com/regjsparser/-/regjsparser-0.1.5.tgz#7ee8f84dc6fa792d3fd0ae228d24bd949ead205c" + dependencies: + jsesc "~0.5.0" + +remove-trailing-separator@^1.0.1: + version "1.1.0" + resolved "https://registry.yarnpkg.com/remove-trailing-separator/-/remove-trailing-separator-1.1.0.tgz#c24bce2a283adad5bc3f58e0d48249b92379d8ef" + +repeat-element@^1.1.2: + version "1.1.2" + resolved "https://registry.yarnpkg.com/repeat-element/-/repeat-element-1.1.2.tgz#ef089a178d1483baae4d93eb98b4f9e4e11d990a" + +repeat-string@^1.5.2: + version "1.6.1" + resolved "https://registry.yarnpkg.com/repeat-string/-/repeat-string-1.6.1.tgz#8dcae470e1c88abc2d600fff4a776286da75e637" + +repeating@^2.0.0: + version "2.0.1" + resolved "https://registry.yarnpkg.com/repeating/-/repeating-2.0.1.tgz#5214c53a926d3552707527fbab415dbc08d06dda" + dependencies: + is-finite "^1.0.0" + +request@2.81.0: + version "2.81.0" + resolved "https://registry.yarnpkg.com/request/-/request-2.81.0.tgz#c6928946a0e06c5f8d6f8a9333469ffda46298a0" + dependencies: + aws-sign2 "~0.6.0" + aws4 "^1.2.1" + caseless "~0.12.0" + combined-stream "~1.0.5" + extend "~3.0.0" + forever-agent "~0.6.1" + form-data "~2.1.1" + har-validator "~4.2.1" + hawk "~3.1.3" + http-signature "~1.1.0" + is-typedarray "~1.0.0" + isstream "~0.1.2" + json-stringify-safe "~5.0.1" + mime-types "~2.1.7" + oauth-sign "~0.8.1" + performance-now "^0.2.0" + qs "~6.4.0" + safe-buffer "^5.0.1" + stringstream "~0.0.4" + tough-cookie "~2.3.0" + tunnel-agent "^0.6.0" + uuid "^3.0.0" + +request@^2.79.0: + version "2.83.0" + resolved "https://registry.yarnpkg.com/request/-/request-2.83.0.tgz#ca0b65da02ed62935887808e6f510381034e3356" + dependencies: + aws-sign2 "~0.7.0" + aws4 "^1.6.0" + caseless "~0.12.0" + combined-stream "~1.0.5" + extend "~3.0.1" + forever-agent "~0.6.1" + form-data "~2.3.1" + har-validator "~5.0.3" + hawk "~6.0.2" + http-signature "~1.2.0" + is-typedarray "~1.0.0" + isstream "~0.1.2" + json-stringify-safe "~5.0.1" + mime-types "~2.1.17" + oauth-sign "~0.8.2" + performance-now "^2.1.0" + qs "~6.5.1" + safe-buffer "^5.1.1" + stringstream "~0.0.5" + tough-cookie "~2.3.3" + tunnel-agent "^0.6.0" + uuid "^3.1.0" + +require-directory@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/require-directory/-/require-directory-2.1.1.tgz#8c64ad5fd30dab1c976e2344ffe7f792a6a6df42" + +require-main-filename@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/require-main-filename/-/require-main-filename-1.0.1.tgz#97f717b69d48784f5f526a6c5aa8ffdda055a4d1" + +resolve@1.1.7: + version "1.1.7" + resolved "https://registry.yarnpkg.com/resolve/-/resolve-1.1.7.tgz#203114d82ad2c5ed9e8e0411b3932875e889e97b" + +right-align@^0.1.1: + version "0.1.3" + resolved "https://registry.yarnpkg.com/right-align/-/right-align-0.1.3.tgz#61339b722fe6a3515689210d24e14c96148613ef" + dependencies: + align-text "^0.1.1" + +rimraf@2, rimraf@^2.5.1, rimraf@^2.6.1: + version "2.6.2" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.2.tgz#2ed8150d24a16ea8651e6d6ef0f47c4158ce7a36" + dependencies: + glob "^7.0.5" + +ripemd160@^2.0.0, ripemd160@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/ripemd160/-/ripemd160-2.0.1.tgz#0f4584295c53a3628af7e6d79aca21ce57d1c6e7" + dependencies: + hash-base "^2.0.0" + inherits "^2.0.1" + +safe-buffer@^5.0.1, safe-buffer@^5.1.0, safe-buffer@^5.1.1, safe-buffer@~5.1.0, safe-buffer@~5.1.1: + version "5.1.1" + resolved "https://registry.yarnpkg.com/safe-buffer/-/safe-buffer-5.1.1.tgz#893312af69b2123def71f57889001671eeb2c853" + +sane@^2.0.0: + version "2.2.0" + resolved "https://registry.yarnpkg.com/sane/-/sane-2.2.0.tgz#d6d2e2fcab00e3d283c93b912b7c3a20846f1d56" + dependencies: + anymatch "^1.3.0" + exec-sh "^0.2.0" + fb-watchman "^2.0.0" + minimatch "^3.0.2" + minimist "^1.1.1" + walker "~1.0.5" + watch "~0.18.0" + optionalDependencies: + fsevents "^1.1.1" + +sax@^1.2.1: + version "1.2.4" + resolved "https://registry.yarnpkg.com/sax/-/sax-1.2.4.tgz#2816234e2378bddc4e5354fab5caa895df7100d9" + +"semver@2 || 3 || 4 || 5", semver@^5.3.0: + version "5.4.1" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.4.1.tgz#e059c09d8571f0540823733433505d3a2f00b18e" + +set-blocking@^2.0.0, set-blocking@~2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/set-blocking/-/set-blocking-2.0.0.tgz#045f9782d011ae9a6803ddd382b24392b3d890f7" + +set-immediate-shim@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/set-immediate-shim/-/set-immediate-shim-1.0.1.tgz#4b2b1b27eb808a9f8dcc481a58e5e56f599f3f61" + +setimmediate@^1.0.4: + version "1.0.5" + resolved "https://registry.yarnpkg.com/setimmediate/-/setimmediate-1.0.5.tgz#290cbb232e306942d7d7ea9b83732ab7856f8285" + +sha.js@^2.4.0, sha.js@^2.4.8: + version "2.4.9" + resolved "https://registry.yarnpkg.com/sha.js/-/sha.js-2.4.9.tgz#98f64880474b74f4a38b8da9d3c0f2d104633e7d" + dependencies: + inherits "^2.0.1" + safe-buffer "^5.0.1" + +shebang-command@^1.2.0: + version "1.2.0" + resolved "https://registry.yarnpkg.com/shebang-command/-/shebang-command-1.2.0.tgz#44aac65b695b03398968c39f363fee5deafdf1ea" + dependencies: + shebang-regex "^1.0.0" + +shebang-regex@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/shebang-regex/-/shebang-regex-1.0.0.tgz#da42f49740c0b42db2ca9728571cb190c98efea3" + +shellwords@^0.1.0: + version "0.1.1" + resolved "https://registry.yarnpkg.com/shellwords/-/shellwords-0.1.1.tgz#d6b9181c1a48d397324c84871efbcfc73fc0654b" + +signal-exit@^3.0.0, signal-exit@^3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/signal-exit/-/signal-exit-3.0.2.tgz#b5fdc08f1287ea1178628e415e25132b73646c6d" + +slash@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/slash/-/slash-1.0.0.tgz#c41f2f6c39fc16d1cd17ad4b5d896114ae470d55" + +sntp@1.x.x: + version "1.0.9" + resolved "https://registry.yarnpkg.com/sntp/-/sntp-1.0.9.tgz#6541184cc90aeea6c6e7b35e2659082443c66198" + dependencies: + hoek "2.x.x" + +sntp@2.x.x: + version "2.0.2" + resolved "https://registry.yarnpkg.com/sntp/-/sntp-2.0.2.tgz#5064110f0af85f7cfdb7d6b67a40028ce52b4b2b" + dependencies: + hoek "4.x.x" + +source-list-map@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/source-list-map/-/source-list-map-2.0.0.tgz#aaa47403f7b245a92fbc97ea08f250d6087ed085" + +source-map-support@^0.4.15: + version "0.4.18" + resolved "https://registry.yarnpkg.com/source-map-support/-/source-map-support-0.4.18.tgz#0286a6de8be42641338594e97ccea75f0a2c585f" + dependencies: + source-map "^0.5.6" + +source-map@^0.4.4: + version "0.4.4" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.4.4.tgz#eba4f5da9c0dc999de68032d8b4f76173652036b" + dependencies: + amdefine ">=0.0.4" + +source-map@^0.5.3, source-map@^0.5.6, source-map@~0.5.1, source-map@~0.5.3, source-map@~0.5.6: + version "0.5.7" + resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.5.7.tgz#8a039d2d1021d22d1ea14c80d8ea468ba2ef3fcc" + +spdx-correct@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/spdx-correct/-/spdx-correct-1.0.2.tgz#4b3073d933ff51f3912f03ac5519498a4150db40" + dependencies: + spdx-license-ids "^1.0.2" + +spdx-expression-parse@~1.0.0: + version "1.0.4" + resolved "https://registry.yarnpkg.com/spdx-expression-parse/-/spdx-expression-parse-1.0.4.tgz#9bdf2f20e1f40ed447fbe273266191fced51626c" + +spdx-license-ids@^1.0.2: + version "1.2.2" + resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-1.2.2.tgz#c9df7a3424594ade6bd11900d596696dc06bac57" + +sprintf-js@~1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c" + +sshpk@^1.7.0: + version "1.13.1" + resolved "https://registry.yarnpkg.com/sshpk/-/sshpk-1.13.1.tgz#512df6da6287144316dc4c18fe1cf1d940739be3" + dependencies: + asn1 "~0.2.3" + assert-plus "^1.0.0" + dashdash "^1.12.0" + getpass "^0.1.1" + optionalDependencies: + bcrypt-pbkdf "^1.0.0" + ecc-jsbn "~0.1.1" + jsbn "~0.1.0" + tweetnacl "~0.14.0" + +stream-browserify@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/stream-browserify/-/stream-browserify-2.0.1.tgz#66266ee5f9bdb9940a4e4514cafb43bb71e5c9db" + dependencies: + inherits "~2.0.1" + readable-stream "^2.0.2" + +stream-http@^2.3.1: + version "2.7.2" + resolved "https://registry.yarnpkg.com/stream-http/-/stream-http-2.7.2.tgz#40a050ec8dc3b53b33d9909415c02c0bf1abfbad" + dependencies: + builtin-status-codes "^3.0.0" + inherits "^2.0.1" + readable-stream "^2.2.6" + to-arraybuffer "^1.0.0" + xtend "^4.0.0" + +string-length@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/string-length/-/string-length-2.0.0.tgz#d40dbb686a3ace960c1cffca562bf2c45f8363ed" + dependencies: + astral-regex "^1.0.0" + strip-ansi "^4.0.0" + +string-width@^1.0.1, string-width@^1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-1.0.2.tgz#118bdf5b8cdc51a2a7e70d211e07e2b0b9b107d3" + dependencies: + code-point-at "^1.0.0" + is-fullwidth-code-point "^1.0.0" + strip-ansi "^3.0.0" + +string-width@^2.0.0: + version "2.1.1" + resolved "https://registry.yarnpkg.com/string-width/-/string-width-2.1.1.tgz#ab93f27a8dc13d28cac815c462143a6d9012ae9e" + dependencies: + is-fullwidth-code-point "^2.0.0" + strip-ansi "^4.0.0" + +string_decoder@^0.10.25: + version "0.10.31" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-0.10.31.tgz#62e203bc41766c6c28c9fc84301dab1c5310fa94" + +string_decoder@~1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/string_decoder/-/string_decoder-1.0.3.tgz#0fc67d7c141825de94282dd536bec6b9bce860ab" + dependencies: + safe-buffer "~5.1.0" + +stringstream@~0.0.4, stringstream@~0.0.5: + version "0.0.5" + resolved "https://registry.yarnpkg.com/stringstream/-/stringstream-0.0.5.tgz#4e484cd4de5a0bbbee18e46307710a8a81621878" + +strip-ansi@^3.0.0, strip-ansi@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-3.0.1.tgz#6a385fb8853d952d5ff05d0e8aaf94278dc63dcf" + dependencies: + ansi-regex "^2.0.0" + +strip-ansi@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-4.0.0.tgz#a8479022eb1ac368a871389b635262c505ee368f" + dependencies: + ansi-regex "^3.0.0" + +strip-bom@3.0.0, strip-bom@^3.0.0: + version "3.0.0" + resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-3.0.0.tgz#2334c18e9c759f7bdd56fdef7e9ae3d588e68ed3" + +strip-bom@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/strip-bom/-/strip-bom-2.0.0.tgz#6219a85616520491f35788bdbf1447a99c7e6b0e" + dependencies: + is-utf8 "^0.2.0" + +strip-eof@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/strip-eof/-/strip-eof-1.0.0.tgz#bb43ff5598a6eb05d89b59fcd129c983313606bf" + +strip-json-comments@~2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/strip-json-comments/-/strip-json-comments-2.0.1.tgz#3c531942e908c2697c0ec344858c286c7ca0a60a" + +supports-color@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7" + +supports-color@^3.1.2: + version "3.2.3" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-3.2.3.tgz#65ac0504b3954171d8a64946b2ae3cbb8a5f54f6" + dependencies: + has-flag "^1.0.0" + +supports-color@^4.0.0, supports-color@^4.2.1: + version "4.4.0" + resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-4.4.0.tgz#883f7ddabc165142b2a61427f3352ded195d1a3e" + dependencies: + has-flag "^2.0.0" + +symbol-tree@^3.2.1: + version "3.2.2" + resolved "https://registry.yarnpkg.com/symbol-tree/-/symbol-tree-3.2.2.tgz#ae27db38f660a7ae2e1c3b7d1bc290819b8519e6" + +tapable@^0.2.7: + version "0.2.8" + resolved "https://registry.yarnpkg.com/tapable/-/tapable-0.2.8.tgz#99372a5c999bf2df160afc0d74bed4f47948cd22" + +tar-pack@^3.4.0: + version "3.4.0" + resolved "https://registry.yarnpkg.com/tar-pack/-/tar-pack-3.4.0.tgz#23be2d7f671a8339376cbdb0b8fe3fdebf317984" + dependencies: + debug "^2.2.0" + fstream "^1.0.10" + fstream-ignore "^1.0.5" + once "^1.3.3" + readable-stream "^2.1.4" + rimraf "^2.5.1" + tar "^2.2.1" + uid-number "^0.0.6" + +tar@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/tar/-/tar-2.2.1.tgz#8e4d2a256c0e2185c6b18ad694aec968b83cb1d1" + dependencies: + block-stream "*" + fstream "^1.0.2" + inherits "2" + +test-exclude@^4.1.1: + version "4.1.1" + resolved "https://registry.yarnpkg.com/test-exclude/-/test-exclude-4.1.1.tgz#4d84964b0966b0087ecc334a2ce002d3d9341e26" + dependencies: + arrify "^1.0.1" + micromatch "^2.3.11" + object-assign "^4.1.0" + read-pkg-up "^1.0.1" + require-main-filename "^1.0.1" + +throat@^4.0.0: + version "4.1.0" + resolved "https://registry.yarnpkg.com/throat/-/throat-4.1.0.tgz#89037cbc92c56ab18926e6ba4cbb200e15672a6a" + +timers-browserify@^2.0.2: + version "2.0.4" + resolved "https://registry.yarnpkg.com/timers-browserify/-/timers-browserify-2.0.4.tgz#96ca53f4b794a5e7c0e1bd7cc88a372298fa01e6" + dependencies: + setimmediate "^1.0.4" + +tmpl@1.0.x: + version "1.0.4" + resolved "https://registry.yarnpkg.com/tmpl/-/tmpl-1.0.4.tgz#23640dd7b42d00433911140820e5cf440e521dd1" + +to-arraybuffer@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/to-arraybuffer/-/to-arraybuffer-1.0.1.tgz#7d229b1fcc637e466ca081180836a7aabff83f43" + +to-fast-properties@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/to-fast-properties/-/to-fast-properties-1.0.3.tgz#b83571fa4d8c25b82e231b06e3a3055de4ca1a47" + +tough-cookie@^2.3.2, tough-cookie@~2.3.0, tough-cookie@~2.3.3: + version "2.3.3" + resolved "https://registry.yarnpkg.com/tough-cookie/-/tough-cookie-2.3.3.tgz#0b618a5565b6dea90bf3425d04d55edc475a7561" + dependencies: + punycode "^1.4.1" + +tr46@~0.0.3: + version "0.0.3" + resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a" + +trim-right@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/trim-right/-/trim-right-1.0.1.tgz#cb2e1203067e0c8de1f614094b9fe45704ea6003" + +tty-browserify@0.0.0: + version "0.0.0" + resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6" + +tunnel-agent@^0.6.0: + version "0.6.0" + resolved "https://registry.yarnpkg.com/tunnel-agent/-/tunnel-agent-0.6.0.tgz#27a5dea06b36b04a0a9966774b290868f0fc40fd" + dependencies: + safe-buffer "^5.0.1" + +tweetnacl@^0.14.3, tweetnacl@~0.14.0: + version "0.14.5" + resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-0.14.5.tgz#5ae68177f192d4456269d108afa93ff8743f4f64" + +type-check@~0.3.2: + version "0.3.2" + resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.3.2.tgz#5884cab512cf1d355e3fb784f30804b2b520db72" + dependencies: + prelude-ls "~1.1.2" + +uglify-js@^2.6, uglify-js@^2.8.29: + version "2.8.29" + resolved "https://registry.yarnpkg.com/uglify-js/-/uglify-js-2.8.29.tgz#29c5733148057bb4e1f75df35b7a9cb72e6a59dd" + dependencies: + source-map "~0.5.1" + yargs "~3.10.0" + optionalDependencies: + uglify-to-browserify "~1.0.0" + +uglify-to-browserify@~1.0.0: + version "1.0.2" + resolved "https://registry.yarnpkg.com/uglify-to-browserify/-/uglify-to-browserify-1.0.2.tgz#6e0924d6bda6b5afe349e39a6d632850a0f882b7" + +uglifyjs-webpack-plugin@^0.4.6: + version "0.4.6" + resolved "https://registry.yarnpkg.com/uglifyjs-webpack-plugin/-/uglifyjs-webpack-plugin-0.4.6.tgz#b951f4abb6bd617e66f63eb891498e391763e309" + dependencies: + source-map "^0.5.6" + uglify-js "^2.8.29" + webpack-sources "^1.0.1" + +uid-number@^0.0.6: + version "0.0.6" + resolved "https://registry.yarnpkg.com/uid-number/-/uid-number-0.0.6.tgz#0ea10e8035e8eb5b8e4449f06da1c730663baa81" + +url@^0.11.0: + version "0.11.0" + resolved "https://registry.yarnpkg.com/url/-/url-0.11.0.tgz#3838e97cfc60521eb73c525a8e55bfdd9e2e28f1" + dependencies: + punycode "1.3.2" + querystring "0.2.0" + +user-home@^1.1.1: + version "1.1.1" + resolved "https://registry.yarnpkg.com/user-home/-/user-home-1.1.1.tgz#2b5be23a32b63a7c9deb8d0f28d485724a3df190" + +util-deprecate@~1.0.1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/util-deprecate/-/util-deprecate-1.0.2.tgz#450d4dc9fa70de732762fbd2d4a28981419a0ccf" + +util@0.10.3, util@^0.10.3: + version "0.10.3" + resolved "https://registry.yarnpkg.com/util/-/util-0.10.3.tgz#7afb1afe50805246489e3db7fe0ed379336ac0f9" + dependencies: + inherits "2.0.1" + +uuid@^3.0.0, uuid@^3.1.0: + version "3.1.0" + resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.1.0.tgz#3dd3d3e790abc24d7b0d3a034ffababe28ebbc04" + +v8flags@^2.1.1: + version "2.1.1" + resolved "https://registry.yarnpkg.com/v8flags/-/v8flags-2.1.1.tgz#aab1a1fa30d45f88dd321148875ac02c0b55e5b4" + dependencies: + user-home "^1.1.1" + +validate-npm-package-license@^3.0.1: + version "3.0.1" + resolved "https://registry.yarnpkg.com/validate-npm-package-license/-/validate-npm-package-license-3.0.1.tgz#2804babe712ad3379459acfbe24746ab2c303fbc" + dependencies: + spdx-correct "~1.0.0" + spdx-expression-parse "~1.0.0" + +verror@1.10.0: + version "1.10.0" + resolved "https://registry.yarnpkg.com/verror/-/verror-1.10.0.tgz#3a105ca17053af55d6e270c1f8288682e18da400" + dependencies: + assert-plus "^1.0.0" + core-util-is "1.0.2" + extsprintf "^1.2.0" + +vm-browserify@0.0.4: + version "0.0.4" + resolved "https://registry.yarnpkg.com/vm-browserify/-/vm-browserify-0.0.4.tgz#5d7ea45bbef9e4a6ff65f95438e0a87c357d5a73" + dependencies: + indexof "0.0.1" + +walker@~1.0.5: + version "1.0.7" + resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.7.tgz#2f7f9b8fd10d677262b18a884e28d19618e028fb" + dependencies: + makeerror "1.0.x" + +watch@~0.18.0: + version "0.18.0" + resolved "https://registry.yarnpkg.com/watch/-/watch-0.18.0.tgz#28095476c6df7c90c963138990c0a5423eb4b986" + dependencies: + exec-sh "^0.2.0" + minimist "^1.2.0" + +watchpack@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-1.4.0.tgz#4a1472bcbb952bd0a9bb4036801f954dfb39faac" + dependencies: + async "^2.1.2" + chokidar "^1.7.0" + graceful-fs "^4.1.2" + +webidl-conversions@^3.0.0: + version "3.0.1" + resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871" + +webidl-conversions@^4.0.0: + version "4.0.2" + resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad" + +webpack-sources@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/webpack-sources/-/webpack-sources-1.0.1.tgz#c7356436a4d13123be2e2426a05d1dad9cbe65cf" + dependencies: + source-list-map "^2.0.0" + source-map "~0.5.3" + +webpack@^3.6.0: + version "3.8.1" + resolved "https://registry.yarnpkg.com/webpack/-/webpack-3.8.1.tgz#b16968a81100abe61608b0153c9159ef8bb2bd83" + dependencies: + acorn "^5.0.0" + acorn-dynamic-import "^2.0.0" + ajv "^5.1.5" + ajv-keywords "^2.0.0" + async "^2.1.2" + enhanced-resolve "^3.4.0" + escope "^3.6.0" + interpret "^1.0.0" + json-loader "^0.5.4" + json5 "^0.5.1" + loader-runner "^2.3.0" + loader-utils "^1.1.0" + memory-fs "~0.4.1" + mkdirp "~0.5.0" + node-libs-browser "^2.0.0" + source-map "^0.5.3" + supports-color "^4.2.1" + tapable "^0.2.7" + uglifyjs-webpack-plugin "^0.4.6" + watchpack "^1.4.0" + webpack-sources "^1.0.1" + yargs "^8.0.2" + +whatwg-encoding@^1.0.1: + version "1.0.1" + resolved "https://registry.yarnpkg.com/whatwg-encoding/-/whatwg-encoding-1.0.1.tgz#3c6c451a198ee7aec55b1ec61d0920c67801a5f4" + dependencies: + iconv-lite "0.4.13" + +whatwg-url@^4.3.0: + version "4.8.0" + resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-4.8.0.tgz#d2981aa9148c1e00a41c5a6131166ab4683bbcc0" + dependencies: + tr46 "~0.0.3" + webidl-conversions "^3.0.0" + +which-module@^2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/which-module/-/which-module-2.0.0.tgz#d9ef07dce77b9902b8a3a8fa4b31c3e3f7e6e87a" + +which@^1.2.12, which@^1.2.9: + version "1.3.0" + resolved "https://registry.yarnpkg.com/which/-/which-1.3.0.tgz#ff04bdfc010ee547d780bec38e1ac1c2777d253a" + dependencies: + isexe "^2.0.0" + +wide-align@^1.1.0: + version "1.1.2" + resolved "https://registry.yarnpkg.com/wide-align/-/wide-align-1.1.2.tgz#571e0f1b0604636ebc0dfc21b0339bbe31341710" + dependencies: + string-width "^1.0.2" + +window-size@0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/window-size/-/window-size-0.1.0.tgz#5438cd2ea93b202efa3a19fe8887aee7c94f9c9d" + +wordwrap@0.0.2: + version "0.0.2" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.2.tgz#b79669bb42ecb409f83d583cad52ca17eaa1643f" + +wordwrap@~0.0.2: + version "0.0.3" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-0.0.3.tgz#a3d5da6cd5c0bc0008d37234bbaf1bed63059107" + +wordwrap@~1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb" + +worker-farm@^1.3.1: + version "1.5.0" + resolved "https://registry.yarnpkg.com/worker-farm/-/worker-farm-1.5.0.tgz#adfdf0cd40581465ed0a1f648f9735722afd5c8d" + dependencies: + errno "^0.1.4" + xtend "^4.0.1" + +wrap-ansi@^2.0.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-2.1.0.tgz#d8fc3d284dd05794fe84973caecdd1cf824fdd85" + dependencies: + string-width "^1.0.1" + strip-ansi "^3.0.1" + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + +write-file-atomic@^2.1.0: + version "2.3.0" + resolved "https://registry.yarnpkg.com/write-file-atomic/-/write-file-atomic-2.3.0.tgz#1ff61575c2e2a4e8e510d6fa4e243cce183999ab" + dependencies: + graceful-fs "^4.1.11" + imurmurhash "^0.1.4" + signal-exit "^3.0.2" + +xml-name-validator@^2.0.1: + version "2.0.1" + resolved "https://registry.yarnpkg.com/xml-name-validator/-/xml-name-validator-2.0.1.tgz#4d8b8f1eccd3419aa362061becef515e1e559635" + +xtend@^4.0.0, xtend@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/xtend/-/xtend-4.0.1.tgz#a5c6d532be656e23db820efb943a1f04998d63af" + +y18n@^3.2.1: + version "3.2.1" + resolved "https://registry.yarnpkg.com/y18n/-/y18n-3.2.1.tgz#6d15fba884c08679c0d77e88e7759e811e07fa41" + +yallist@^2.1.2: + version "2.1.2" + resolved "https://registry.yarnpkg.com/yallist/-/yallist-2.1.2.tgz#1c11f9218f076089a47dd512f93c6699a6a81d52" + +yargs-parser@^7.0.0: + version "7.0.0" + resolved "https://registry.yarnpkg.com/yargs-parser/-/yargs-parser-7.0.0.tgz#8d0ac42f16ea55debd332caf4c4038b3e3f5dfd9" + dependencies: + camelcase "^4.1.0" + +yargs@^8.0.2: + version "8.0.2" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-8.0.2.tgz#6299a9055b1cefc969ff7e79c1d918dceb22c360" + dependencies: + camelcase "^4.1.0" + cliui "^3.2.0" + decamelize "^1.1.1" + get-caller-file "^1.0.1" + os-locale "^2.0.0" + read-pkg-up "^2.0.0" + require-directory "^2.1.1" + require-main-filename "^1.0.1" + set-blocking "^2.0.0" + string-width "^2.0.0" + which-module "^2.0.0" + y18n "^3.2.1" + yargs-parser "^7.0.0" + +yargs@^9.0.0, yargs@^9.0.1: + version "9.0.1" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-9.0.1.tgz#52acc23feecac34042078ee78c0c007f5085db4c" + dependencies: + camelcase "^4.1.0" + cliui "^3.2.0" + decamelize "^1.1.1" + get-caller-file "^1.0.1" + os-locale "^2.0.0" + read-pkg-up "^2.0.0" + require-directory "^2.1.1" + require-main-filename "^1.0.1" + set-blocking "^2.0.0" + string-width "^2.0.0" + which-module "^2.0.0" + y18n "^3.2.1" + yargs-parser "^7.0.0" + +yargs@~3.10.0: + version "3.10.0" + resolved "https://registry.yarnpkg.com/yargs/-/yargs-3.10.0.tgz#f7ee7bd857dd7c1d2d38c0e74efbd681d1431fd1" + dependencies: + camelcase "^1.0.2" + cliui "^2.1.0" + decamelize "^1.0.0" + window-size "0.1.0" diff --git a/ReactCommon/hermes/inspector/tools/run_msggen b/ReactCommon/hermes/inspector/tools/run_msggen new file mode 100755 index 00000000000..a3056f86491 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/run_msggen @@ -0,0 +1,26 @@ +#!/bin/bash + +set -e + +DIR=$(dirname "${BASH_SOURCE[0]}") +cd "${DIR}/msggen" + +yarn install +yarn build + +FBSOURCE=$(hg root) +MSGTYPES_PATH="${FBSOURCE}/xplat/hermes-inspector/tools/message_types.txt" +PROTO_PATH="${FBSOURCE}/xplat/third-party/chrome-devtools-protocol/json/js_protocol.json" +HEADER_PATH="${FBSOURCE}/xplat/hermes-inspector/chrome/MessageTypes.h" +CPP_PATH="${FBSOURCE}/xplat/hermes-inspector/chrome/MessageTypes.cpp" + +node bin/index.js \ + --ignore-experimental \ + --roots "$MSGTYPES_PATH" \ + "$PROTO_PATH" "$HEADER_PATH" "$CPP_PATH" + +clang-format -i --style=file "$HEADER_PATH" +clang-format -i --style=file "$CPP_PATH" + +"${FBSOURCE}/tools/signedsource" sign "$HEADER_PATH" +"${FBSOURCE}/tools/signedsource" sign "$CPP_PATH" diff --git a/ReactCommon/hermes/inspector/tools/sandcastle/build_and_test.sh b/ReactCommon/hermes/inspector/tools/sandcastle/build_and_test.sh new file mode 100755 index 00000000000..86433016db4 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/sandcastle/build_and_test.sh @@ -0,0 +1,9 @@ +#!/bin/bash + +THIS_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +source "$THIS_DIR/setup.sh" + +buck test fbsource//xplat/hermes-inspector:chrome && + buck test fbsource//xplat/hermes-inspector:detail && + buck test fbsource//xplat/hermes-inspector:inspectorlib && + buck build fbsource//xplat/hermes-inspector:hermes-chrome-debug-server diff --git a/ReactCommon/hermes/inspector/tools/sandcastle/setup.sh b/ReactCommon/hermes/inspector/tools/sandcastle/setup.sh new file mode 100755 index 00000000000..df06457aae0 --- /dev/null +++ b/ReactCommon/hermes/inspector/tools/sandcastle/setup.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# Basic setup for xplat testing in sandcastle. Based on +# xplat/hermes/facebook/sandcastle/setup.sh. + +set -x +set -e +set -o pipefail + +THIS_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) +ROOT_DIR=$(cd "$THIS_DIR" && hg root) + +# Buck by default uses clang-3.6 from /opt/local/bin. +# Override it to use system clang. +export PATH="/usr/bin:$PATH" + +# Enter xplat +cd "$ROOT_DIR"/xplat || exit 1 + +# Setup env +export TITLE +TITLE=$(hg log -l 1 --template "{desc|strip|firstline}") +export REV +REV=$(hg log -l 1 --template "{node}") +export AUTHOR +AUTHOR=$(hg log -l 1 --template "{author|emailuser}") + +if [ -n "$SANDCASTLE" ]; then + source automation/setup_buck.sh +fi diff --git a/package.json b/package.json index 68c66f8d842..993fe913d55 100644 --- a/package.json +++ b/package.json @@ -22,13 +22,14 @@ "cli.js", "flow", "init.sh", + "scripts/compose-source-maps.js", "scripts/ios-configure-glog.sh", "scripts/ios-install-third-party.sh", "scripts/launchPackager.bat", "scripts/launchPackager.command", + "scripts/node-binary.sh", "scripts/packager.sh", "scripts/react-native-xcode.sh", - "scripts/node-binary.sh", "jest-preset.js", "jest", "lib", @@ -96,10 +97,12 @@ "event-target-shim": "^5.0.1", "fbjs": "^1.0.0", "fbjs-scripts": "^1.1.0", + "hermesvm": "^0.1.0", "invariant": "^2.2.4", "jsc-android": "^245459.0.0", "metro-babel-register": "0.54.1", "metro-react-native-babel-transformer": "0.54.1", + "metro-source-map": "^0.55.0", "nullthrows": "^1.1.0", "pretty-format": "^24.7.0", "promise": "^7.1.1", diff --git a/react.gradle b/react.gradle index 1b8e303c4d4..0140355fa7e 100644 --- a/react.gradle +++ b/react.gradle @@ -8,12 +8,15 @@ import org.apache.tools.ant.taskdefs.condition.Os def config = project.hasProperty("react") ? project.react : []; def cliPath = config.cliPath ?: "node_modules/react-native/cli.js" +def composeSourceMapsPath = config.composeSourceMapsPath ?: "node_modules/react-native/scripts/compose-source-maps.js" def bundleAssetName = config.bundleAssetName ?: "index.android.bundle" def entryFile = config.entryFile ?: "index.android.js" def bundleCommand = config.bundleCommand ?: "bundle" def reactRoot = file(config.root ?: "../../") def inputExcludes = config.inputExcludes ?: ["android/**", "ios/**"] def bundleConfig = config.bundleConfig ? "${reactRoot}/${config.bundleConfig}" : null ; +def enableVmCleanup = config.enableVmCleanup == null ? true : config.enableVmCleanup +def hermesCommand = config.hermesCommand ?: "../../node_modules/hermesvm/%OS-BIN%/hermes" def reactNativeDevServerPort() { def value = project.getProperties().get("reactNativeDevServerPort") @@ -25,6 +28,34 @@ def reactNativeInspectorProxyPort() { return value != null ? value : reactNativeDevServerPort() } +def getHermesOSBin() { + if (Os.isFamily(Os.FAMILY_WINDOWS)) return "win64-bin"; + if (Os.isFamily(Os.FAMILY_MAC)) return "osx-bin"; + if (Os.isOs(null, "linux", "amd64", null)) return "linux64-bin"; + throw new Exception("OS not recognized. Please set project.ext.react.hermesCommand " + + "to the path of a working Hermes compiler."); +} + +// Make sure not to inspect the Hermes config unless we need it, +// to avoid breaking any JSC-only setups. +def getHermesCommand = { + // If the project specifies a Hermes command, don't second guess it. + if (!hermesCommand.contains("%OS-BIN%")) { + return hermesCommand + } + + // Execution on Windows fails with / as separator + return hermesCommand + .replaceAll("%OS-BIN%", getHermesOSBin()) + .replace('/' as char, File.separatorChar); +} + +// Set enableHermesForVariant to a function to configure per variant, +// or set `enableHermes` to True/False to set all of them +def enableHermesForVariant = config.enableHermesForVariant ?: { + def variant -> config.enableHermes ?: false +} + android { buildTypes.all { resValue "integer", "react_native_dev_server_port", reactNativeDevServerPort() @@ -45,11 +76,18 @@ afterEvaluate { def resourcesDir = file("$buildDir/generated/res/react/${targetPath}") def jsBundleFile = file("$jsBundleDir/$bundleAssetName") + def jsSourceMapsDir = file("$buildDir/generated/sourcemaps/react/${targetPath}") + def jsIntermediateSourceMapsDir = file("$buildDir/intermediates/sourcemaps/react/${targetPath}") + def jsPackagerSourceMapFile = file("$jsIntermediateSourceMapsDir/${bundleAssetName}.packager.map") + def jsCompilerSourceMapFile = file("$jsIntermediateSourceMapsDir/${bundleAssetName}.compiler.map") + def jsOutputSourceMapFile = file("$jsSourceMapsDir/${bundleAssetName}.map") // Additional node and packager commandline arguments def nodeExecutableAndArgs = config.nodeExecutableAndArgs ?: ["node"] def extraPackagerArgs = config.extraPackagerArgs ?: [] + def enableHermes = enableHermesForVariant(variant) + def currentBundleTask = tasks.create( name: "bundle${targetName}JsAndAssets", type: Exec) { @@ -62,6 +100,10 @@ afterEvaluate { jsBundleDir.mkdirs() resourcesDir.deleteDir() resourcesDir.mkdirs() + jsIntermediateSourceMapsDir.deleteDir() + jsIntermediateSourceMapsDir.mkdirs() + jsSourceMapsDir.deleteDir() + jsSourceMapsDir.mkdirs() } // Set up inputs and outputs so gradle can cache the result @@ -86,10 +128,52 @@ afterEvaluate { if (Os.isFamily(Os.FAMILY_WINDOWS)) { commandLine("cmd", "/c", *nodeExecutableAndArgs, cliPath, bundleCommand, "--platform", "android", "--dev", "${devEnabled}", - "--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir, *extraArgs) + "--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir, + "--sourcemap-output", enableHermes ? jsPackagerSourceMapFile : jsOutputSourceMapFile, *extraArgs) } else { commandLine(*nodeExecutableAndArgs, cliPath, bundleCommand, "--platform", "android", "--dev", "${devEnabled}", - "--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir, *extraArgs) + "--reset-cache", "--entry-file", entryFile, "--bundle-output", jsBundleFile, "--assets-dest", resourcesDir, + "--sourcemap-output", enableHermes ? jsPackagerSourceMapFile : jsOutputSourceMapFile, *extraArgs) + } + + if (enableHermes) { + doLast { + def hermesFlags; + def hbcTempFile = file("${jsBundleFile}.hbc") + exec { + if (targetName.toLowerCase().contains("release")) { + // Can't use ?: since that will also substitute valid empty lists + hermesFlags = config.hermesFlagsRelease + if (hermesFlags == null) hermesFlags = ["-O", "-output-source-map"] + } else { + hermesFlags = config.hermesFlagsDebug + if (hermesFlags == null) hermesFlags = [] + } + commandLine(getHermesCommand(), "-emit-binary", "-out", hbcTempFile, jsBundleFile, *hermesFlags) + } + ant.move( + file: hbcTempFile, + toFile: jsBundleFile + ); + if (hermesFlags.contains("-output-source-map")) { + ant.move( + // Hermes will generate a source map with this exact name + file: "${jsBundleFile}.hbc.map", + tofile: jsCompilerSourceMapFile + ); + exec { + // TODO: set task dependencies for caching + + // Set up the call to the compose-source-maps script + workingDir(reactRoot) + if (Os.isFamily(Os.FAMILY_WINDOWS)) { + commandLine("cmd", "/c", *nodeExecutableAndArgs, composeSourceMapsPath, jsPackagerSourceMapFile, jsCompilerSourceMapFile, "-o", jsOutputSourceMapFile) + } else { + commandLine(*nodeExecutableAndArgs, composeSourceMapsPath, jsPackagerSourceMapFile, jsCompilerSourceMapFile, "-o", jsOutputSourceMapFile) + } + } + } + } } enabled config."bundleIn${targetName}" != null @@ -181,5 +265,46 @@ afterEvaluate { if (buildPreBundleTask != null) { buildPreBundleTask.dependsOn(currentAssetsCopyTask) } + + // Delete the VM related libraries that this build doesn't need. + // The application can manage this manually by setting 'enableVmCleanup: false' + // + // This should really be done by packaging all Hermes releated libs into + // two separate HermesDebug and HermesRelease AARs, but until then we'll + // kludge it by deleting the .so files out of the /transforms/ directory. + def isRelease = targetName.toLowerCase().contains("release") + def libDir = "$buildDir/intermediates/transforms/" + def vmSelectionAction = { + fileTree(libDir).matching { + if (enableHermes) { + // For Hermes, delete all the libjsc* files + include "**/libjsc*.so" + + if (isRelease) { + // Reduce size by deleting the debugger/inspector + include '**/libhermes-inspector.so' + include '**/libhermes-executor-debug.so' + } else { + // Release libs take precedence and must be removed + // to allow debugging + include '**/libhermes-executor-release.so' + } + } else { + // For JSC, delete all the libhermes* files + include "**/libhermes*.so" + } + }.visit { details -> + def targetVariant = ".*/transforms/[^/]*/${targetPath}/.*" + def path = details.file.getAbsolutePath().replace(File.separatorChar, '/' as char) + if (path.matches(targetVariant) && details.file.isFile()) { + details.file.delete() + } + } + } + + if (enableVmCleanup) { + def task = tasks.findByName("package${targetName}") + task.doFirst(vmSelectionAction) + } } } diff --git a/scripts/compose-source-maps.js b/scripts/compose-source-maps.js new file mode 100755 index 00000000000..fc1bb56fd1b --- /dev/null +++ b/scripts/compose-source-maps.js @@ -0,0 +1,61 @@ +#!/usr/bin/env node +/** + * Copyright (c) Facebook, Inc. and its affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + * + * @format + */ +'use strict'; + +const {composeSourceMaps} = require('metro-source-map'); +const fs = require('fs'); + +const argv = process.argv.slice(2); +let outputPath; +for (let i = 0; i < argv.length;) { + if (argv[i] === '-o') { + outputPath = argv[i + 1]; + argv.splice(i, 2); + continue; + } + ++i; +} +if (!argv.length) { + process.stderr.write( + 'Usage: node compose-source-maps.js [-o output_file]\n' + ); + process.exitCode = -1; +} else { + const [packagerSourcemapPath, compilerSourcemapPath] = argv.splice(0, 2); + const packagerSourcemap = JSON.parse(fs.readFileSync(packagerSourcemapPath, 'utf8')); + const compilerSourcemap = JSON.parse( + fs.readFileSync(compilerSourcemapPath, 'utf8'), + ); + + if ( + packagerSourcemap.x_facebook_offsets != null || + compilerSourcemap.x_facebook_offsets != null + ) { + throw new Error( + 'Random Access Bundle (RAM) format is not supported by this tool; ' + + 'it cannot process the `x_facebook_offsets` field provided ' + + 'in the base and/or target source map(s)', + ); + } + + if (compilerSourcemap.x_facebook_segments != null) { + throw new Error( + 'This tool cannot process the `x_facebook_segments` field provided ' + + 'in the target source map.', + ); + } + + const composedMapJSON = JSON.stringify(composeSourceMaps([packagerSourcemap, compilerSourcemap])); + if (outputPath) { + fs.writeFileSync(outputPath, composedMapJSON, 'utf8'); + } else { + process.stdout.write(); + } +} diff --git a/scripts/test-manual-e2e.sh b/scripts/test-manual-e2e.sh index 7a1aab22636..f021398f0c0 100755 --- a/scripts/test-manual-e2e.sh +++ b/scripts/test-manual-e2e.sh @@ -51,7 +51,7 @@ info "and then press any key." info "" read -n 1 -./gradlew :RNTester:android:app:installDebug || error "Couldn't build RNTester Android" +./gradlew :RNTester:android:app:installJscDebug || error "Couldn't build RNTester Android" info "Press any key to run RNTester in an already running Android emulator/device" info "" diff --git a/template/App.js b/template/App.js index fee529a8f21..a0076ec35bf 100644 --- a/template/App.js +++ b/template/App.js @@ -33,6 +33,11 @@ const App = () => { contentInsetAdjustmentBehavior="automatic" style={styles.scrollView}>

+ {global.HermesInternal == null ? null : ( + + Engine: Hermes + + )} Step One @@ -71,6 +76,10 @@ const styles = StyleSheet.create({ scrollView: { backgroundColor: Colors.lighter, }, + engine: { + position: 'absolute', + right: 0, + }, body: { backgroundColor: Colors.white, }, @@ -92,6 +101,14 @@ const styles = StyleSheet.create({ highlight: { fontWeight: '700', }, + footer: { + color: Colors.dark, + fontSize: 12, + fontWeight: '600', + padding: 4, + paddingRight: 12, + textAlign: 'right', + }, }); export default App; diff --git a/template/android/app/build.gradle b/template/android/app/build.gradle index 33fc17752a4..7898e7bd0a5 100644 --- a/template/android/app/build.gradle +++ b/template/android/app/build.gradle @@ -76,7 +76,8 @@ import com.android.build.OutputFile */ project.ext.react = [ - entryFile: "index.js" + entryFile: "index.js", + enableHermes: false, // clean and rebuild if changing ] apply from: "../../node_modules/react-native/react.gradle" @@ -97,13 +98,26 @@ def enableSeparateBuildPerCPUArchitecture = false def enableProguardInReleaseBuilds = false /** - * Use international variant JavaScriptCore - * International variant includes ICU i18n library and necessary data allowing to use - * e.g. Date.toLocaleString and String.localeCompare that give correct results - * when using with locales other than en-US. - * Note that this variant is about 6MiB larger per architecture than default. + * The preferred build flavor of JavaScriptCore. + * + * For example, to use the international variant, you can use: + * `def jscFlavor = 'org.webkit:android-jsc-intl:+'` + * + * The international variant includes ICU i18n library and necessary data + * allowing to use e.g. `Date.toLocaleString` and `String.localeCompare` that + * give correct results when using with locales other than en-US. Note that + * this variant is about 6MiB larger per architecture than default. */ -def useIntlJsc = false +def jscFlavor = 'org.webkit:android-jsc:+' + +/** + * Whether to enable the Hermes VM. + * + * This should be set on project.ext.react and mirrored here. If it is not set + * on project.ext.react, JavaScript will not be compiled to Hermes Bytecode + * and the benefits of using Hermes will therefore be sharply reduced. + */ +def enableHermes = project.ext.react.get("enableHermes", false); android { compileSdkVersion rootProject.ext.compileSdkVersion @@ -159,19 +173,30 @@ android { output.versionCodeOverride = versionCodes.get(abi) * 1048576 + defaultConfig.versionCode } + } } + + packagingOptions { + pickFirst '**/armeabi-v7a/libc++_shared.so' + pickFirst '**/x86/libc++_shared.so' + pickFirst '**/arm64-v8a/libc++_shared.so' + pickFirst '**/x86_64/libc++_shared.so' + pickFirst '**/x86/libjsc.so' + pickFirst '**/armeabi-v7a/libjsc.so' + } } dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation "com.facebook.react:react-native:+" // From node_modules - // JSC from node_modules - if (useIntlJsc) { - implementation 'org.webkit:android-jsc-intl:+' + if (enableHermes) { + def hermesPath = "../../node_modules/hermesvm/android/"; + debugImplementation files(hermesPath + "hermes-debug.aar") + releaseImplementation files(hermesPath + "hermes-release.aar") } else { - implementation 'org.webkit:android-jsc:+' + implementation jscFlavor } } diff --git a/yarn.lock b/yarn.lock index a0a3e05b71a..36b0f3ba0fd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -885,29 +885,40 @@ "@hapi/address@2.x.x": version "2.0.0" - resolved "https://registry.yarnpkg.com/@hapi/address/-/address-2.0.0.tgz#9f05469c88cb2fd3dcd624776b54ee95c312126a" + resolved "https://registry.npmjs.org/@hapi/address/-/address-2.0.0.tgz#9f05469c88cb2fd3dcd624776b54ee95c312126a" integrity sha512-mV6T0IYqb0xL1UALPFplXYQmR0twnXG0M6jUswpquqT2sD12BOiCiLy3EvMp/Fy7s3DZElC4/aPjEjo2jeZpvw== "@hapi/hoek@6.x.x": - version "6.2.1" - resolved "https://registry.yarnpkg.com/@hapi/hoek/-/hoek-6.2.1.tgz#d3a66329159af879bfdf0b0cff2229c43c5a3451" - integrity sha512-+ryw4GU9pjr1uT6lBuErHJg3NYqzwJTvZ75nKuJijEzpd00Uqi6oiawTGDDf5Hl0zWmI7qHfOtaqB0kpQZJQzA== + version "6.2.4" + resolved "https://registry.npmjs.org/@hapi/hoek/-/hoek-6.2.4.tgz#4b95fbaccbfba90185690890bdf1a2fbbda10595" + integrity sha512-HOJ20Kc93DkDVvjwHyHawPwPkX44sIrbXazAUDiUXaY2R9JwQGo2PhFfnQtdrsIe4igjG2fPgMra7NYw7qhy0A== + +"@hapi/hoek@8.x.x": + version "8.0.2" + resolved "https://registry.npmjs.org/@hapi/hoek/-/hoek-8.0.2.tgz#f63a5ff00e891a4e7aa98f11119f9515c6672032" + integrity sha512-O6o6mrV4P65vVccxymuruucb+GhP2zl9NLCG8OdoFRS8BEGw3vwpPp20wpAtpbQQxz1CEUtmxJGgWhjq1XA3qw== "@hapi/joi@^15.0.3": - version "15.0.3" - resolved "https://registry.yarnpkg.com/@hapi/joi/-/joi-15.0.3.tgz#e94568fd859e5e945126d5675e7dd218484638a7" - integrity sha512-z6CesJ2YBwgVCi+ci8SI8zixoj8bGFn/vZb9MBPbSyoxsS2PnWYjHcyTM17VLK6tx64YVK38SDIh10hJypB+ig== + version "15.1.0" + resolved "https://registry.npmjs.org/@hapi/joi/-/joi-15.1.0.tgz#940cb749b5c55c26ab3b34ce362e82b6162c8e7a" + integrity sha512-n6kaRQO8S+kepUTbXL9O/UOL788Odqs38/VOfoCrATDtTvyfiO3fgjlSRaNkHabpTLgM7qru9ifqXlXbXk8SeQ== dependencies: "@hapi/address" "2.x.x" "@hapi/hoek" "6.x.x" + "@hapi/marker" "1.x.x" "@hapi/topo" "3.x.x" +"@hapi/marker@1.x.x": + version "1.0.0" + resolved "https://registry.yarnpkg.com/@hapi/marker/-/marker-1.0.0.tgz#65b0b2b01d1be06304886ce9b4b77b1bfb21a769" + integrity sha512-JOfdekTXnJexfE8PyhZFyHvHjt81rBFSAbTIRAhF2vv/2Y1JzoKsGqxH/GpZJoF7aEfYok8JVcAHmSz1gkBieA== + "@hapi/topo@3.x.x": - version "3.1.0" - resolved "https://registry.yarnpkg.com/@hapi/topo/-/topo-3.1.0.tgz#5c47cd9637c2953db185aa957a27bcb2a8b7a6f8" - integrity sha512-gZDI/eXOIk8kP2PkUKjWu9RW8GGVd2Hkgjxyr/S7Z+JF+0mr7bAlbw+DkTRxnD580o8Kqxlnba9wvqp5aOHBww== + version "3.1.2" + resolved "https://registry.npmjs.org/@hapi/topo/-/topo-3.1.2.tgz#57cc1317be1a8c5f47c124f9b0e3c49cd78424d2" + integrity sha512-r+aumOqJ5QbD6aLPJWqVjMAPsx5pZKz+F5yPqXZ/WWG9JTtHbQqlzrJoknJ0iJxLj9vlXtmpSdjlkszseeG8OA== dependencies: - "@hapi/hoek" "6.x.x" + "@hapi/hoek" "8.x.x" "@jest/console@^24.7.1": version "24.7.1" @@ -3499,6 +3510,11 @@ has@^1.0.1, has@^1.0.3: dependencies: function-bind "^1.1.1" +hermesvm@^0.1.0: + version "0.1.0" + resolved "https://registry.yarnpkg.com/hermesvm/-/hermesvm-0.1.0.tgz#4bfaf4ac682a2fd407b862ab641eb8deb232de83" + integrity sha512-GbP6dKaVW/V2QpB+DZPxcmhBhJVFa9cHS/xRX7FD1MGfa6Z1aHHD83VDCwo3SgcqNj5yHlVbe9UgrK1PFGCXpw== + home-or-tmp@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/home-or-tmp/-/home-or-tmp-3.0.0.tgz#57a8fe24cf33cdd524860a15821ddc25c86671fb" @@ -3833,7 +3849,7 @@ is-windows@^1.0.2: is-wsl@^1.1.0: version "1.1.0" - resolved "https://registry.yarnpkg.com/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d" + resolved "https://registry.npmjs.org/is-wsl/-/is-wsl-1.1.0.tgz#1f16e4aa22b04d1336b66188a66af3c600c3a66d" integrity sha1-HxbkqiKwTRM2tmGIpmrzxgDDpm0= isarray@1.0.0, isarray@~1.0.0: @@ -4796,7 +4812,7 @@ merge-stream@^1.0.1: metro-babel-register@0.54.1: version "0.54.1" - resolved "https://registry.yarnpkg.com/metro-babel-register/-/metro-babel-register-0.54.1.tgz#7d2bfe444b1ccef8de99aedc7d9330891d806076" + resolved "https://registry.npmjs.org/metro-babel-register/-/metro-babel-register-0.54.1.tgz#7d2bfe444b1ccef8de99aedc7d9330891d806076" integrity sha512-j3VydgncUG8HP6AZala6GTIt3V01nptodnnOke3JMYLqgk8EJ1LOVOdotK9pXi80o7EmmNKFs/LyyH8z+uAJzQ== dependencies: "@babel/core" "^7.0.0" @@ -4814,21 +4830,21 @@ metro-babel-register@0.54.1: metro-babel-transformer@0.54.1: version "0.54.1" - resolved "https://registry.yarnpkg.com/metro-babel-transformer/-/metro-babel-transformer-0.54.1.tgz#371ffa2d1118b22cc9e40b3c3ea6738c49dae9dc" + resolved "https://registry.npmjs.org/metro-babel-transformer/-/metro-babel-transformer-0.54.1.tgz#371ffa2d1118b22cc9e40b3c3ea6738c49dae9dc" integrity sha512-2aiAnuYBdcLV1VINb8ENAA4keIaJIepHgR9+iRvIde+9GSjKnexqx4nNmJN392285gRDp1fVZ7uY0uQawK/A5g== dependencies: "@babel/core" "^7.0.0" metro-babel7-plugin-react-transform@0.54.1: version "0.54.1" - resolved "https://registry.yarnpkg.com/metro-babel7-plugin-react-transform/-/metro-babel7-plugin-react-transform-0.54.1.tgz#5335b810284789724886dc483d5bde9c149a1996" + resolved "https://registry.npmjs.org/metro-babel7-plugin-react-transform/-/metro-babel7-plugin-react-transform-0.54.1.tgz#5335b810284789724886dc483d5bde9c149a1996" integrity sha512-jWm5myuMoZAOhoPsa8ItfDxdTcOzKhTTzzhFlbZnRamE7i9qybeMdrZt8KHQpF7i2p/mKzE9Yhf4ouOz5K/jHg== dependencies: "@babel/helper-module-imports" "^7.0.0" metro-cache@0.54.1: version "0.54.1" - resolved "https://registry.yarnpkg.com/metro-cache/-/metro-cache-0.54.1.tgz#2e9017cbd11106837b8c385c9eb8c8175469a8c1" + resolved "https://registry.npmjs.org/metro-cache/-/metro-cache-0.54.1.tgz#2e9017cbd11106837b8c385c9eb8c8175469a8c1" integrity sha512-RxCFoNcANHXZYi4MIQNnqh68gUnC3bMpzCFJY5pBoqqdrkkn8ibYglBweA0/DW7hx1OZTJWelwS1Dp8xxmE2CA== dependencies: jest-serializer "^24.4.0" @@ -4838,7 +4854,7 @@ metro-cache@0.54.1: metro-config@0.54.1, metro-config@^0.54.1: version "0.54.1" - resolved "https://registry.yarnpkg.com/metro-config/-/metro-config-0.54.1.tgz#808b4e17625d9f4e9afa34232778fdf8e63cc8dd" + resolved "https://registry.npmjs.org/metro-config/-/metro-config-0.54.1.tgz#808b4e17625d9f4e9afa34232778fdf8e63cc8dd" integrity sha512-FpxrA+63rGkPGvGI653dvuSreJzU+eOTILItVnnhmqwn2SAK5V00N/qGTOIJe2YIuWEFXwCzw9lXmANrXbwuGg== dependencies: cosmiconfig "^5.0.5" @@ -4850,7 +4866,7 @@ metro-config@0.54.1, metro-config@^0.54.1: metro-core@0.54.1, metro-core@^0.54.1: version "0.54.1" - resolved "https://registry.yarnpkg.com/metro-core/-/metro-core-0.54.1.tgz#17f6ecc167918da8819d4af5726349e55714954b" + resolved "https://registry.npmjs.org/metro-core/-/metro-core-0.54.1.tgz#17f6ecc167918da8819d4af5726349e55714954b" integrity sha512-8oz3Ck7QFBzW9dG9tKFhrXHKPu2Ajx3R7eatf61Gl6Jf/tF7PNouv3wHxPsJW3oXDFiwKLszd89+OgleTGkB5g== dependencies: jest-haste-map "^24.7.1" @@ -4878,7 +4894,7 @@ metro-minify-uglify@0.54.1: metro-react-native-babel-preset@0.54.1: version "0.54.1" - resolved "https://registry.yarnpkg.com/metro-react-native-babel-preset/-/metro-react-native-babel-preset-0.54.1.tgz#b8f03865c381841d7f8912e7ba46804ea3a928b8" + resolved "https://registry.npmjs.org/metro-react-native-babel-preset/-/metro-react-native-babel-preset-0.54.1.tgz#b8f03865c381841d7f8912e7ba46804ea3a928b8" integrity sha512-Hfr32+u5yYl3qhYQJU8NQ26g4kQlc3yFMg7keVR/3H8rwBIbFqXgsKt8oe0dOrv7WvrMqBHhDtVdU9ls3sSq8g== dependencies: "@babel/plugin-proposal-class-properties" "^7.0.0" @@ -4920,7 +4936,7 @@ metro-react-native-babel-preset@0.54.1: metro-react-native-babel-transformer@0.54.1, metro-react-native-babel-transformer@^0.54.1: version "0.54.1" - resolved "https://registry.yarnpkg.com/metro-react-native-babel-transformer/-/metro-react-native-babel-transformer-0.54.1.tgz#45b56db004421134e10e739f69e8de50775fef17" + resolved "https://registry.npmjs.org/metro-react-native-babel-transformer/-/metro-react-native-babel-transformer-0.54.1.tgz#45b56db004421134e10e739f69e8de50775fef17" integrity sha512-ECw7xG91t8dk/PHdiyoC5SP1s9OQzfmJzG5m0YOZaKtHMe534qTDbncxaKfTI3CP99yti2maXFBRVj+xyvph/g== dependencies: "@babel/core" "^7.0.0" @@ -4930,7 +4946,7 @@ metro-react-native-babel-transformer@0.54.1, metro-react-native-babel-transforme metro-resolver@0.54.1: version "0.54.1" - resolved "https://registry.yarnpkg.com/metro-resolver/-/metro-resolver-0.54.1.tgz#0295b38624b678b88b16bf11d47288845132b087" + resolved "https://registry.npmjs.org/metro-resolver/-/metro-resolver-0.54.1.tgz#0295b38624b678b88b16bf11d47288845132b087" integrity sha512-Byv1LIawYAASy9CFRwzrncYnqaFGLe8vpw178EtzStqP05Hu6hXSqkNTrfoXa+3V9bPFGCrVzFx2NY3gFp2btg== dependencies: absolute-path "^0.0.0" @@ -4944,6 +4960,29 @@ metro-source-map@0.54.1: "@babel/types" "^7.0.0" source-map "^0.5.6" +metro-source-map@0.55.0, metro-source-map@^0.55.0: + version "0.55.0" + resolved "https://registry.npmjs.org/metro-source-map/-/metro-source-map-0.55.0.tgz#1f6289905f08277c398f2b9b9c13e7e0e5a6f540" + integrity sha512-HZODA0KPl5onJNGIztfTHHWurR2nL6Je/X8wwj+bL4ZBB/hSMVeDk7rWReCAvO3twVz7Ztp8Si0jfMmmH4Ruuw== + dependencies: + "@babel/traverse" "^7.0.0" + "@babel/types" "^7.0.0" + invariant "^2.2.4" + metro-symbolicate "0.55.0" + ob1 "0.55.0" + source-map "^0.5.6" + vlq "^1.0.0" + +metro-symbolicate@0.55.0: + version "0.55.0" + resolved "https://registry.npmjs.org/metro-symbolicate/-/metro-symbolicate-0.55.0.tgz#4086a2adae54b5e44a4911ca572d8a7b03c71fa1" + integrity sha512-3r3Gpv5L4U7rBGpIqw5S1nun5MelfUMLRiScJsPRGZVTX3WY1w+zpaQKlWBi5yuHf5dMQ+ZUVbhb02IdrfJ2Fg== + dependencies: + metro-source-map "0.55.0" + source-map "^0.5.6" + through2 "^2.0.1" + vlq "^1.0.0" + metro@0.54.1, metro@^0.54.1: version "0.54.1" resolved "https://registry.yarnpkg.com/metro/-/metro-0.54.1.tgz#a629be00abee5a450a25a8f71c24745f70cc9b44" @@ -5052,9 +5091,9 @@ mime@1.4.1: integrity sha512-KI1+qOZu5DcW6wayYHSzR/tXKCDC5Om4s1z2QJjDULzLcmf3DvzS7oluY4HCTrc+9FiKmWUgeNLg7W3uIQvxtQ== mime@^2.4.1: - version "2.4.3" - resolved "https://registry.yarnpkg.com/mime/-/mime-2.4.3.tgz#229687331e86f68924e6cb59e1cdd937f18275fe" - integrity sha512-QgrPRJfE+riq5TPZMcHZOtm8c6K/yYrMbKIoRfapfiGLxS8OTeIfRhUGW5LU7MlRa52KOAGCfUNruqLrIBvWZw== + version "2.4.4" + resolved "https://registry.npmjs.org/mime/-/mime-2.4.4.tgz#bd7b91135fc6b01cde3e9bae33d659b63d8857e5" + integrity sha512-LRxmNwziLPT828z+4YkNzloCFC2YM4wrB99k+AV5ZbEyfGNWfG8SO1FUXLmLDBSo89NrJZ4DIWeLjy1CHGhMGA== mimic-fn@^1.0.0: version "1.2.0" @@ -5238,7 +5277,7 @@ node-fetch@^2.2.0: node-fetch@^2.5.0: version "2.6.0" - resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" + resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz#e633456386d4aa55863f676a7ab0daa8fdecb0fd" integrity sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA== node-int64@^0.4.0: @@ -5364,6 +5403,11 @@ oauth-sign@~0.9.0: resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.9.0.tgz#47a7b016baa68b5fa0ecf3dee08a85c679ac6455" integrity sha512-fexhUFFPTGV8ybAtSIGbV6gOkSv8UtRbDBnAyLQw4QPKkgNlsH2ByPGtMUqdWkos6YCRmAqViwgZrJc/mRDzZQ== +ob1@0.55.0: + version "0.55.0" + resolved "https://registry.npmjs.org/ob1/-/ob1-0.55.0.tgz#e393b4ae786ef442b3ef2a298ab70d6ec353dbdd" + integrity sha512-pfyiMVsUItl8WiRKMT15eCi662pCRAuYTq2+V3UpE+PpFErJI/TvRh/M/l/9TaLlbFr7krJ7gdl+FXJNcybmvw== + object-assign@^4.0.1, object-assign@^4.1.0, object-assign@^4.1.1: version "4.1.1" resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863" @@ -5442,9 +5486,9 @@ onetime@^2.0.0: mimic-fn "^1.0.0" open@^6.2.0: - version "6.3.0" - resolved "https://registry.yarnpkg.com/open/-/open-6.3.0.tgz#60d0b845ee38fae0631f5d739a21bd40e3d2a527" - integrity sha512-6AHdrJxPvAXIowO/aIaeHZ8CeMdDf7qCyRNq8NwJpinmCdXhz+NZR7ie1Too94lpciCDsG+qHGO9Mt0svA4OqA== + version "6.4.0" + resolved "https://registry.npmjs.org/open/-/open-6.4.0.tgz#5c13e96d0dc894686164f18965ecfe889ecfc8a9" + integrity sha512-IFenVPgF70fSm1keSd2iDBIDIBZkroLeuffXq+wKTzTJlBpesFWojV9lb8mzOfaAzM1sr7HQHuO0vtV0zYekGg== dependencies: is-wsl "^1.1.0" @@ -5761,7 +5805,7 @@ prelude-ls@~1.1.2: prettier@1.17.0: version "1.17.0" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.17.0.tgz#53b303676eed22cc14a9f0cec09b477b3026c008" + resolved "https://registry.npmjs.org/prettier/-/prettier-1.17.0.tgz#53b303676eed22cc14a9f0cec09b477b3026c008" integrity sha512-sXe5lSt2WQlCbydGETgfm1YBShgOX4HxQkFPvbxkcwgDvGDeqVau8h+12+lmSVlP3rHPz0oavfddSZg/q+Szjw== pretty-format@^24.0.0: @@ -5915,7 +5959,7 @@ react-is@^16.8.1, react-is@^16.8.4: react-is@^16.8.6: version "16.8.6" - resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16" + resolved "https://registry.npmjs.org/react-is/-/react-is-16.8.6.tgz#5bbc1e2d29141c9fbdfed456343fe2bc430a6a16" integrity sha512-aUk3bHfZ2bRSVFFbbeVS4i+lNPZr3/WM5jT2J5omUVV1zzcs1nAaf3l51ctA5FFvCRbhrH0bdAsRRQddFJZPtA== react-proxy@^1.1.7: @@ -5933,7 +5977,7 @@ react-refresh@^0.3.0: react-test-renderer@16.8.6: version "16.8.6" - resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.8.6.tgz#188d8029b8c39c786f998aa3efd3ffe7642d5ba1" + resolved "https://registry.npmjs.org/react-test-renderer/-/react-test-renderer-16.8.6.tgz#188d8029b8c39c786f998aa3efd3ffe7642d5ba1" integrity sha512-H2srzU5IWYT6cZXof6AhUcx/wEyJddQ8l7cLM/F7gDXYyPr4oq+vCIxJYXVGhId1J706sqziAjuOEjyNkfgoEw== dependencies: object-assign "^4.1.1" @@ -5951,7 +5995,7 @@ react-transform-hmr@^1.0.4: react@16.8.6: version "16.8.6" - resolved "https://registry.yarnpkg.com/react/-/react-16.8.6.tgz#ad6c3a9614fd3a4e9ef51117f54d888da01f2bbe" + resolved "https://registry.npmjs.org/react/-/react-16.8.6.tgz#ad6c3a9614fd3a4e9ef51117f54d888da01f2bbe" integrity sha512-pC0uMkhLaHm11ZSJULfOBqV4tIZkx87ZLvbbQYunNixAAvjnC+snJCg0XQXn9VIsttVsbZP/H/ewzgsd5fxKXw== dependencies: loose-envify "^1.1.0" @@ -5993,7 +6037,7 @@ read-pkg@^3.0.0: normalize-package-data "^2.3.2" path-type "^3.0.0" -readable-stream@^2.0.1, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2: +readable-stream@^2.0.1, readable-stream@^2.0.6, readable-stream@^2.1.5, readable-stream@^2.2.2, readable-stream@~2.3.6: version "2.3.6" resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-2.3.6.tgz#b11c27d88b8ff1fbe070643cf94b0c79ae1b0aaf" integrity sha512-tQtKA9WIAhBF3+VLAseyMqZeBjW0AHJoxOtYqSUZNJxauErmLbVm2FW1y+J/YA9dUrAC39ITejlZWhVIwawkKw== @@ -6355,7 +6399,7 @@ sax@~1.1.1: scheduler@0.14.0: version "0.14.0" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.14.0.tgz#b392c23c9c14bfa2933d4740ad5603cc0d59ea5b" + resolved "https://registry.npmjs.org/scheduler/-/scheduler-0.14.0.tgz#b392c23c9c14bfa2933d4740ad5603cc0d59ea5b" integrity sha512-9CgbS06Kki2f4R9FjLSITjZo5BZxPsryiRNyL3LpvrM9WxcVmhlqAOc9E+KQbeI2nqej4JIIbOsfdL51cNb4Iw== dependencies: loose-envify "^1.1.0" @@ -6363,7 +6407,7 @@ scheduler@0.14.0: scheduler@^0.13.6: version "0.13.6" - resolved "https://registry.yarnpkg.com/scheduler/-/scheduler-0.13.6.tgz#466a4ec332467b31a91b9bf74e5347072e4cd889" + resolved "https://registry.npmjs.org/scheduler/-/scheduler-0.13.6.tgz#466a4ec332467b31a91b9bf74e5347072e4cd889" integrity sha512-IWnObHt413ucAYKsD9J1QShUKkbKLQQHdxRyw73sw4FN26iWr3DY/H34xGPe4nmL1DwXyWmSWmMrA9TfQbE/XQ== dependencies: loose-envify "^1.1.0" @@ -6901,6 +6945,14 @@ through2@^2.0.0: readable-stream "^2.1.5" xtend "~4.0.1" +through2@^2.0.1: + version "2.0.5" + resolved "https://registry.npmjs.org/through2/-/through2-2.0.5.tgz#01c1e39eb31d07cb7d03a96a70823260b23132cd" + integrity sha512-/mrRod8xqpA+IHSLyGCQ2s8SPHiCDEeQJSep1jqLYeEUClOFG2Qsh+4FU6G9VeqpZnGW/Su8LQGc4YKni5rYSQ== + dependencies: + readable-stream "~2.3.6" + xtend "~4.0.1" + through@^2.3.6: version "2.3.8" resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5" @@ -7158,6 +7210,11 @@ vlq@^0.2.1: resolved "https://registry.yarnpkg.com/vlq/-/vlq-0.2.3.tgz#8f3e4328cf63b1540c0d67e1b2778386f8975b26" integrity sha512-DRibZL6DsNhIgYQ+wNdWDL2SL3bKPlVrRiBqV5yuMm++op8W4kGFtaQfCs4KEJn0wBZcHVHJ3eoywX8983k1ow== +vlq@^1.0.0: + version "1.0.1" + resolved "https://registry.npmjs.org/vlq/-/vlq-1.0.1.tgz#c003f6e7c0b4c1edd623fd6ee50bbc0d6a1de468" + integrity sha512-gQpnTgkubC6hQgdIcRdYGDSDc+SaujOdyesZQMv6JlfQee/9Mp0Qhnys6WxDWvQnL5WZdT7o2Ul187aSt0Rq+w== + w3c-hr-time@^1.0.1: version "1.0.1" resolved "https://registry.yarnpkg.com/w3c-hr-time/-/w3c-hr-time-1.0.1.tgz#82ac2bff63d950ea9e3189a58a65625fedf19045"