2014-10-31 18:17:05 +00:00
|
|
|
// Copyright (c) 2013 GitHub, Inc.
|
2014-07-28 08:00:15 +00:00
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#ifndef ELECTRON_SHELL_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
|
|
|
|
#define ELECTRON_SHELL_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
|
2014-07-28 08:00:15 +00:00
|
|
|
|
2018-10-15 15:26:47 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2023-05-11 20:07:39 +00:00
|
|
|
#include "base/memory/raw_ptr.h"
|
2014-09-01 08:41:26 +00:00
|
|
|
#include "gin/public/isolate_holder.h"
|
2020-04-24 19:57:41 +00:00
|
|
|
#include "uv.h" // NOLINT(build/include_directory)
|
2021-09-01 19:55:07 +00:00
|
|
|
#include "v8/include/v8-locker.h"
|
2014-07-28 08:00:15 +00:00
|
|
|
|
2017-02-28 00:56:09 +00:00
|
|
|
namespace node {
|
|
|
|
class Environment;
|
2018-01-06 15:58:24 +00:00
|
|
|
class MultiIsolatePlatform;
|
2018-04-18 01:44:10 +00:00
|
|
|
} // namespace node
|
2017-02-28 00:56:09 +00:00
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2014-07-28 08:00:15 +00:00
|
|
|
|
2018-10-15 15:26:47 +00:00
|
|
|
class MicrotasksRunner;
|
2017-02-28 00:56:09 +00:00
|
|
|
// Manage the V8 isolate and context automatically.
|
2014-07-28 08:00:15 +00:00
|
|
|
class JavascriptEnvironment {
|
|
|
|
public:
|
2023-02-09 08:48:49 +00:00
|
|
|
JavascriptEnvironment(uv_loop_t* event_loop,
|
|
|
|
bool setup_wasm_streaming = false);
|
2018-04-17 23:37:22 +00:00
|
|
|
~JavascriptEnvironment();
|
2014-07-28 08:00:15 +00:00
|
|
|
|
2021-11-03 11:41:45 +00:00
|
|
|
// disable copy
|
|
|
|
JavascriptEnvironment(const JavascriptEnvironment&) = delete;
|
|
|
|
JavascriptEnvironment& operator=(const JavascriptEnvironment&) = delete;
|
|
|
|
|
2022-10-20 05:49:49 +00:00
|
|
|
void CreateMicrotasksRunner();
|
|
|
|
void DestroyMicrotasksRunner();
|
2016-06-24 05:45:31 +00:00
|
|
|
|
2022-11-10 21:31:20 +00:00
|
|
|
node::MultiIsolatePlatform* platform() const { return platform_.get(); }
|
2014-07-28 08:00:15 +00:00
|
|
|
v8::Isolate* isolate() const { return isolate_; }
|
|
|
|
|
2020-04-27 18:38:43 +00:00
|
|
|
static v8::Isolate* GetIsolate();
|
|
|
|
|
2014-07-28 08:00:15 +00:00
|
|
|
private:
|
2022-12-05 17:07:49 +00:00
|
|
|
v8::Isolate* Initialize(uv_loop_t* event_loop, bool setup_wasm_streaming);
|
2022-11-10 21:31:20 +00:00
|
|
|
std::unique_ptr<node::MultiIsolatePlatform> platform_;
|
2017-12-08 00:23:17 +00:00
|
|
|
|
2018-10-05 18:40:17 +00:00
|
|
|
gin::IsolateHolder isolate_holder_;
|
2023-08-17 04:06:24 +00:00
|
|
|
|
|
|
|
// owned-by: isolate_holder_
|
|
|
|
const raw_ptr<v8::Isolate> isolate_;
|
|
|
|
|
|
|
|
// depends-on: isolate_
|
2023-09-12 23:53:20 +00:00
|
|
|
const v8::Locker locker_;
|
2014-07-28 08:00:15 +00:00
|
|
|
|
2018-10-15 15:26:47 +00:00
|
|
|
std::unique_ptr<MicrotasksRunner> microtasks_runner_;
|
2014-07-28 08:00:15 +00:00
|
|
|
};
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|
2014-07-28 08:00:15 +00:00
|
|
|
|
2021-11-22 07:34:31 +00:00
|
|
|
#endif // ELECTRON_SHELL_BROWSER_JAVASCRIPT_ENVIRONMENT_H_
|