#include "shell/common/node_natives_code_cache.h"
#include "shell/browser/javascript_environment.h"
#include "shell/common/node_includes.h"
#include "shell/common/node_natives_code_cache_internal.h"
#include "shell/common/process_util.h"
#include "third_party/electron_node/src/node_snapshot_builder.h"
namespace electron {
Js2cCacheFlavor CurrentProcessJs2cCacheFlavor(bool has_node_env) {
if (IsBrowserProcess() || IsUtilityProcess()) {
if (JavascriptEnvironment::NodeSnapshot())
return Js2cCacheFlavor::kBrowser;
const bool build_embeds_node_snapshot =
node::SnapshotBuilder::GetEmbeddedSnapshotData() != nullptr;
return IsUtilityProcess() || build_embeds_node_snapshot
? Js2cCacheFlavor::kUtility
: Js2cCacheFlavor::kBrowser;
}
if (IsRendererProcess()) {
return has_node_env ? Js2cCacheFlavor::kRenderer
: Js2cCacheFlavor::kSandbox;
}
return Js2cCacheFlavor::kWorker;
}
const std::vector<node::builtins::CodeCacheInfo>& GetNativesCodeCache(
Js2cCacheFlavor flavor) {
switch (flavor) {
case Js2cCacheFlavor::kSandbox:
return internal::Js2cCacheSandbox();
case Js2cCacheFlavor::kRenderer:
return internal::Js2cCacheRenderer();
case Js2cCacheFlavor::kBrowser:
return internal::Js2cCacheBrowser();
case Js2cCacheFlavor::kUtility:
return internal::Js2cCacheUtility();
case Js2cCacheFlavor::kWorker:
return internal::Js2cCacheWorker();
}
}
}