node_util.h 1013 B

123456789101112131415161718192021222324252627282930313233
  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 ELECTRON_SHELL_COMMON_NODE_UTIL_H_
  5. #define ELECTRON_SHELL_COMMON_NODE_UTIL_H_
  6. #include <vector>
  7. #include "build/build_config.h"
  8. #include "v8/include/v8.h"
  9. namespace node {
  10. class Environment;
  11. }
  12. namespace electron::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 electron::util
  25. #endif // ELECTRON_SHELL_COMMON_NODE_UTIL_H_