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

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

Subscribers

People subscribed via source and target branches

to all changes: