Merge lp:~abreu-alexandre/v8-cpp/handle-enum-class-to-v8-convert into lp:v8-cpp

Proposed by Alexandre Abreu
Status: Merged
Approved by: Marcus Tomlinson
Approved revision: 37
Merged at revision: 37
Proposed branch: lp:~abreu-alexandre/v8-cpp/handle-enum-class-to-v8-convert
Merge into: lp:v8-cpp
Diff against target: 76 lines (+29/-2)
4 files modified
src/internal/convert.h (+2/-1)
tests/functions/module.cpp (+2/-1)
tests/functions/test.cpp (+12/-0)
tests/functions/test.h (+13/-0)
To merge this branch: bzr merge lp:~abreu-alexandre/v8-cpp/handle-enum-class-to-v8-convert
Reviewer Review Type Date Requested Status
Marcus Tomlinson (community) Approve
Review via email: mp+282203@code.launchpad.net

Commit message

Handle "enum class" as a type for to_v8 conversions.

Description of the change

Handle "enum class" as a type for to_v8 conversions. As is the Convert template struct that handles the from_v8 and to_v8 bits for integral types (used for v8::Number -> int conversion) is statically declared as having one to_v8 non parametric polymorph function, which does not work when called for non scoped enums (that do convert to int) and scoped enums (that dont),

To post a comment you must log in.
Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

Excellent! Thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/internal/convert.h'
2--- src/internal/convert.h 2015-10-19 13:20:40 +0000
3+++ src/internal/convert.h 2016-01-11 17:21:51 +0000
4@@ -156,7 +156,8 @@
5 }
6 }
7
8- static ToType to_v8(v8::Isolate* isolate, T value)
9+ template <typename O>
10+ static ToType to_v8(v8::Isolate* isolate, O value)
11 {
12 if (bits <= 32)
13 {
14
15=== modified file 'tests/functions/module.cpp'
16--- tests/functions/module.cpp 2015-10-16 17:01:43 +0000
17+++ tests/functions/module.cpp 2016-01-11 17:21:51 +0000
18@@ -37,7 +37,8 @@
19 .set_constructor<Local<Function>>()
20 .add_method("get_shared", &TestCaller::get_shared)
21 .add_method("call_me_with_shared", &TestCaller::call_me_with_shared)
22- .add_method("call_me", &TestCaller::call_me);
23+ .add_method("call_me", &TestCaller::call_me)
24+ .add_method("return_enum_function", &TestCaller::return_enum_function);
25
26 // Prepare Shared binding
27 v8cpp::Class<Shared> shared(isolate);
28
29=== modified file 'tests/functions/test.cpp'
30--- tests/functions/test.cpp 2015-10-16 17:01:43 +0000
31+++ tests/functions/test.cpp 2016-01-11 17:21:51 +0000
32@@ -109,3 +109,15 @@
33 EXPECT_FLOAT_EQ(result4.count("3"), 1);
34 EXPECT_FLOAT_EQ(result4.count("0"), 1);
35 }
36+
37+TEST(Test, call_return_enum)
38+{
39+ auto result = v8cpp::run_script<TestCaller::TestEnum>(
40+ R"(
41+ var module = require("./test-functions-module");
42+ var tc = new module.TestCaller(function() {});
43+ tc.return_enum_function();
44+ )");
45+
46+ EXPECT_EQ(result, TestCaller::TestEnum::ONE);
47+}
48
49=== modified file 'tests/functions/test.h'
50--- tests/functions/test.h 2015-10-16 17:01:43 +0000
51+++ tests/functions/test.h 2016-01-11 17:21:51 +0000
52@@ -34,11 +34,24 @@
53 class TestCaller
54 {
55 public:
56+ enum class TestEnum
57+ {
58+ ZERO,
59+ ONE,
60+ TWO,
61+ THREE
62+ };
63+
64 explicit TestCaller(v8::Local<v8::Function> const& cb)
65 : cb_(v8::Isolate::GetCurrent(), cb)
66 {
67 }
68
69+ TestEnum return_enum_function() const
70+ {
71+ return TestEnum::ONE;
72+ }
73+
74 std::string call_me() const
75 {
76 v8::Local<v8::Function> cb = v8cpp::to_local<v8::Function>(v8::Isolate::GetCurrent(), cb_);

Subscribers

People subscribed via source and target branches