node_util.h 1001 B

123456789101112131415161718192021222324252627282930313233343536
  1. // Copyright (c) 2019 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #ifndef SHELL_COMMON_NODE_UTIL_H_
  5. #define SHELL_COMMON_NODE_UTIL_H_
  6. #include <vector>
  7. #include "v8/include/v8.h"
  8. namespace node {
  9. class Environment;
  10. } // namespace node
  11. namespace electron {
  12. namespace util {
  13. // Run a script with JS source bundled inside the binary as if it's wrapped
  14. // in a function called with a null receiver and arguments specified in C++.
  15. // The returned value is empty if an exception is encountered.
  16. // JS code run with this method can assume that their top-level
  17. // declarations won't affect the global scope.
  18. v8::MaybeLocal<v8::Value> CompileAndCall(
  19. v8::Local<v8::Context> context,
  20. const char* id,
  21. std::vector<v8::Local<v8::String>>* parameters,
  22. std::vector<v8::Local<v8::Value>>* arguments,
  23. node::Environment* optional_env);
  24. } // namespace util
  25. } // namespace electron
  26. #endif // SHELL_COMMON_NODE_UTIL_H_