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