GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/node_native_module.h Lines: 2 2 100.0 %
Date: 2019-09-13 22:28:55 Branches: 0 0 - %

Line Branch Exec Source
1
#ifndef SRC_NODE_NATIVE_MODULE_H_
2
#define SRC_NODE_NATIVE_MODULE_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include <map>
7
#include <memory>
8
#include <set>
9
#include <string>
10
#include "node_mutex.h"
11
#include "node_union_bytes.h"
12
#include "v8.h"
13
14
// Forward declare test fixture for `friend` declaration.
15
class PerProcessTest;
16
17
namespace node {
18
namespace native_module {
19
20
using NativeModuleRecordMap = std::map<std::string, UnionBytes>;
21
using NativeModuleCacheMap =
22
    std::unordered_map<std::string,
23
                       std::unique_ptr<v8::ScriptCompiler::CachedData>>;
24
25
// The native (C++) side of the NativeModule in JS land, which
26
// handles compilation and caching of builtin modules (NativeModule)
27
// and bootstrappers, whose source are bundled into the binary
28
// as static data.
29
// This class should not depend on any Environment, or depend on access to
30
// the its own singleton - that should be encapsulated in NativeModuleEnv
31
// instead.
32
5031
class NativeModuleLoader {
33
 public:
34
  NativeModuleLoader(const NativeModuleLoader&) = delete;
35
  NativeModuleLoader& operator=(const NativeModuleLoader&) = delete;
36
37
 private:
38
  // Only allow access from friends.
39
  friend class NativeModuleEnv;
40
  friend class CodeCacheBuilder;
41
42
  NativeModuleLoader();
43
  static NativeModuleLoader* GetInstance();
44
45
  // Generated by tools/js2c.py as node_javascript.cc
46
  void LoadJavaScriptSource();  // Loads data into source_
47
  UnionBytes GetConfig();       // Return data for config.gypi
48
49
  bool Exists(const char* id);
50
  v8::Local<v8::Object> GetSourceObject(v8::Local<v8::Context> context);
51
  v8::Local<v8::String> GetConfigString(v8::Isolate* isolate);
52
  std::vector<std::string> GetModuleIds();
53
54
10062
  struct ModuleCategories {
55
    bool is_initialized = false;
56
    std::set<std::string> can_be_required;
57
    std::set<std::string> cannot_be_required;
58
  };
59
  void InitializeModuleCategories();
60
  const std::set<std::string>& GetCannotBeRequired();
61
  const std::set<std::string>& GetCanBeRequired();
62
63
  bool CanBeRequired(const char* id);
64
  bool CannotBeRequired(const char* id);
65
66
  NativeModuleCacheMap* code_cache();
67
  v8::ScriptCompiler::CachedData* GetCodeCache(const char* id) const;
68
  enum class Result { kWithCache, kWithoutCache };
69
  // If an exception is encountered (e.g. source code contains
70
  // syntax error), the returned value is empty.
71
  v8::MaybeLocal<v8::Function> LookupAndCompile(
72
      v8::Local<v8::Context> context,
73
      const char* id,
74
      std::vector<v8::Local<v8::String>>* parameters,
75
      Result* result);
76
  v8::MaybeLocal<v8::Function> CompileAsModule(v8::Local<v8::Context> context,
77
                                               const char* id,
78
                                               Result* result);
79
80
  static NativeModuleLoader instance_;
81
  ModuleCategories module_categories_;
82
  NativeModuleRecordMap source_;
83
  NativeModuleCacheMap code_cache_;
84
  UnionBytes config_;
85
86
  // Used to synchronize access to the code cache map
87
  Mutex code_cache_mutex_;
88
89
  friend class ::PerProcessTest;
90
};
91
}  // namespace native_module
92
93
}  // namespace node
94
95
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
96
97
#endif  // SRC_NODE_NATIVE_MODULE_H_