Merge lp:~marcustomlinson/v8-cpp/async-callbacks into lp:v8-cpp

Proposed by Marcus Tomlinson on 2015-07-28
Status: Merged
Merged at revision: 23
Proposed branch: lp:~marcustomlinson/v8-cpp/async-callbacks
Merge into: lp:v8-cpp
Diff against target: 90 lines (+64/-1)
3 files modified
src/internal/require.h (+1/-1)
src/locker.h (+62/-0)
src/v8-cpp.h (+1/-0)
To merge this branch: bzr merge lp:~marcustomlinson/v8-cpp/async-callbacks
Reviewer Review Type Date Requested Status
Marcus Tomlinson Pending
Review via email: mp+266085@code.launchpad.net

Commit message

Added v8cpp::Locker class

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/internal/require.h'
2--- src/internal/require.h 2015-07-16 14:30:30 +0000
3+++ src/internal/require.h 2015-07-29 10:40:55 +0000
4@@ -41,7 +41,7 @@
5 };
6
7 ///!extern "C" void node_module_register(void* m)
8-///!
9+///!{
10 ///! auto mp = static_cast<NodeModule*>(m);
11 ///!
12 ///! // For now we only know that version 14 works here
13
14=== added file 'src/locker.h'
15--- src/locker.h 1970-01-01 00:00:00 +0000
16+++ src/locker.h 2015-07-29 10:40:55 +0000
17@@ -0,0 +1,62 @@
18+/*
19+ * Copyright (C) 2015 Canonical Ltd
20+ *
21+ * This program is free software: you can redistribute it and/or modify
22+ * it under the terms of the GNU Lesser General Public License version 3 as
23+ * published by the Free Software Foundation.
24+ *
25+ * This program is distributed in the hope that it will be useful,
26+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28+ * GNU Lesser General Public License for more details.
29+ *
30+ * You should have received a copy of the GNU Lesser General Public License
31+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
32+ *
33+ * Authored by: Marcus Tomlinson <marcus.tomlinson@canonical.com>
34+ */
35+
36+#pragma once
37+
38+#include <memory>
39+
40+namespace v8cpp
41+{
42+
43+class Locker
44+{
45+public:
46+ explicit Locker(v8::Isolate* isolate)
47+ {
48+ if (v8::Locker::IsActive() && !v8::Locker::IsLocked(isolate))
49+ {
50+ locker_ = std::make_shared<v8::Locker>(isolate);
51+ isolate_scope_ = std::make_shared<v8::Isolate::Scope>(isolate);
52+ handle_scope_ = std::make_shared<v8::HandleScope>(isolate);
53+ context_scope_ = std::make_shared<v8::Context::Scope>(v8::Context::New(isolate));
54+ }
55+ }
56+
57+private:
58+ std::shared_ptr<v8::Locker> locker_;
59+ std::shared_ptr<v8::Isolate::Scope> isolate_scope_;
60+ std::shared_ptr<v8::HandleScope> handle_scope_;
61+ std::shared_ptr<v8::Context::Scope> context_scope_;
62+};
63+
64+class Unlocker
65+{
66+public:
67+ explicit Unlocker(v8::Isolate* isolate)
68+ {
69+ if (v8::Locker::IsActive() && v8::Locker::IsLocked(isolate))
70+ {
71+ unlocker_ = std::make_shared<v8::Unlocker>(isolate);
72+ }
73+ }
74+
75+private:
76+ std::shared_ptr<v8::Unlocker> unlocker_;
77+};
78+
79+} // namespace v8cpp
80
81=== modified file 'src/v8-cpp.h'
82--- src/v8-cpp.h 2015-06-18 12:48:38 +0000
83+++ src/v8-cpp.h 2015-07-29 10:40:55 +0000
84@@ -19,5 +19,6 @@
85 #include <call.h>
86 #include <class.h>
87 #include <convert.h>
88+#include <locker.h>
89 #include <module.h>
90 #include <run.h>

Subscribers

People subscribed via source and target branches

to all changes: