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