IncludeJS  0.0.1
Build your own JavaScript runtime
engine.h
1 #ifndef INCLUDEJS_ENGINE_H_
2 #define INCLUDEJS_ENGINE_H_
3 
6 
7 #include "engine_export.h"
8 
9 #include <includejs/engine_context.h>
10 #include <includejs/engine_error.h>
11 #include <includejs/engine_function.h>
12 #include <includejs/engine_value.h>
13 
14 #include <filesystem> // std::filesystem::path
15 #include <initializer_list> // std::initializer_list
16 #include <ios> // std::ios_base
17 #include <istream> // std::ifstream
18 #include <memory> // std::unique_ptr
19 #include <sstream> // std::ostringstream
20 #include <string> // std::string
21 #include <vector> // std::vector
22 
23 namespace includejs {
24 
26 class INCLUDEJS_ENGINE_EXPORT Engine {
27 public:
28  Engine();
29  ~Engine();
30 
31  auto evaluate(const std::filesystem::path &path) -> Value;
32  auto evaluate(const std::string &code,
33  const std::filesystem::path &path) -> Value;
34  auto evaluate(std::ifstream &stream,
35  const std::filesystem::path &path) -> Value;
36 
37  // TODO(RaisinTen): Add support for bind_function() to the V8 backend.
38 #if !defined(INCLUDEJS_ENGINE_V8)
39  auto bind_function(std::initializer_list<std::string> location,
40  Function function) -> void;
41 #endif
42  auto bind_global(std::initializer_list<std::string> location,
43  Value value) -> void;
44  auto bind_global(std::initializer_list<std::string> location,
45  bool value) -> void;
46  auto bind_global(std::initializer_list<std::string> location,
47  int value) -> void;
48  auto bind_global(std::initializer_list<std::string> location,
49  std::initializer_list<Value> values) -> void;
50 
51  auto context() -> Context &;
52 
53 private:
54  struct Internal;
55  std::unique_ptr<Internal> internal;
56  auto on_error(const Value &exception) -> void;
57 };
58 
59 } // namespace includejs
60 
61 #endif
Definition: engine_context.h:15
Definition: engine.h:26
Definition: engine_value.h:30