Skip to content

Commit

Permalink
Use agent::lock instead of Isolate*
Browse files Browse the repository at this point in the history
  • Loading branch information
laverdet committed Sep 19, 2024
1 parent 601d65b commit 2dec147
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
7 changes: 4 additions & 3 deletions packages/libivm-v8/include/realm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ class realm::scope : util::non_copyable {
scope() = delete;
scope(agent::lock& agent, v8::Local<v8::Context> context);

[[nodiscard]] auto context() const -> v8::Local<v8::Context> { return context_; }
[[nodiscard]] auto isolate() const -> v8::Isolate* { return isolate_; }
[[nodiscard]] auto agent() const -> agent::lock&;
[[nodiscard]] auto context() const -> v8::Local<v8::Context>;
[[nodiscard]] auto isolate() const -> v8::Isolate*;

private:
v8::Isolate* isolate_;
agent::lock* agent_lock_;
v8::Local<v8::Context> context_;
};

Expand Down
8 changes: 5 additions & 3 deletions packages/libivm-v8/include/script.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module;
#include <utility>
export module ivm.isolated_v8:script;
import :agent;
import :realm;
Expand All @@ -11,7 +13,7 @@ namespace ivm {
export class script : util::non_copyable {
public:
script() = delete;
script(v8::Isolate* isolate, v8::Local<v8::UnboundScript> script);
script(agent::lock& agent, v8::Local<v8::UnboundScript> script);

auto run(realm::scope& realm_scope) -> value::value_t;
static auto compile(agent::lock& agent, auto&& code_string) -> script;
Expand All @@ -23,8 +25,8 @@ export class script : util::non_copyable {
};

auto script::compile(agent::lock& agent, auto&& code_string) -> script {
auto local_string = value::transfer_strict<v8::Local<v8::String>>(code_string, agent->isolate());
return script::compile(agent, local_string);
auto local_code_string = value::transfer_strict<v8::Local<v8::String>>(std::forward<decltype(code_string)>(code_string), agent->isolate());
return script::compile(agent, local_code_string);
}

} // namespace ivm
14 changes: 13 additions & 1 deletion packages/libivm-v8/realm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,22 @@ auto realm::make(agent::lock& agent) -> realm {
}

realm::scope::scope(agent::lock& agent, v8::Local<v8::Context> context) :
isolate_{agent->isolate()},
agent_lock_{&agent},
context_{context} {
}

auto realm::scope::agent() const -> agent::lock& {
return *agent_lock_;
}

auto realm::scope::context() const -> v8::Local<v8::Context> {
return context_;
}

auto realm::scope::isolate() const -> v8::Isolate* {
return (*agent_lock_)->isolate();
}

realm::managed_scope::managed_scope(agent::lock& agent, realm& realm) :
scope{agent, v8::Local<v8::Context>::New(agent->isolate(), realm.context)},
context_scope{context()} {
Expand Down
6 changes: 3 additions & 3 deletions packages/libivm-v8/script.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import v8;

namespace ivm {

script::script(v8::Isolate* isolate, v8::Local<v8::UnboundScript> script) :
unbound_script_{isolate, script} {
script::script(agent::lock& agent, v8::Local<v8::UnboundScript> script) :
unbound_script_{agent->isolate(), script} {
}

auto script::run(realm::scope& realm_scope) -> value::value_t {
Expand All @@ -26,7 +26,7 @@ auto script::compile(agent::lock& agent, v8::Local<v8::String> code_string) -> s
v8::ScriptCompiler::Source source{code_string};
auto* isolate = agent->isolate();
auto script_handle = v8::ScriptCompiler::CompileUnboundScript(isolate, &source).ToLocalChecked();
return script{isolate, script_handle};
return script{agent, script_handle};
}

} // namespace ivm

0 comments on commit 2dec147

Please sign in to comment.