Merge lp:~abreu-alexandre/v8-cpp/fix-constructor-var-args into lp:v8-cpp

Proposed by Alexandre Abreu
Status: Merged
Approved by: Marcus Tomlinson
Approved revision: 38
Merged at revision: 36
Proposed branch: lp:~abreu-alexandre/v8-cpp/fix-constructor-var-args
Merge into: lp:v8-cpp
Diff against target: 123 lines (+56/-5)
4 files modified
src/internal/call.h (+18/-5)
tests/objects/module.cpp (+7/-0)
tests/objects/test.cpp (+12/-0)
tests/objects/test.h (+19/-0)
To merge this branch: bzr merge lp:~abreu-alexandre/v8-cpp/fix-constructor-var-args
Reviewer Review Type Date Requested Status
Marcus Tomlinson (community) Approve
Review via email: mp+276702@code.launchpad.net

Commit message

Fix constructor call with v8 var args (instead of plain args).

Description of the change

Fix constructor call with v8 var args (instead of plain args).

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

These changes have broken 2 other tests:

marcustomlinson@ubuntu:~/Projects/work/v8-cpp/trunk-build$ make test
Running tests...
Test project /home/marcustomlinson/Projects/work/v8-cpp/trunk-build
    Start 1: test-errors
1/6 Test #1: test-errors ...................... Passed 0.23 sec
    Start 2: test-functions
2/6 Test #2: test-functions ................... Passed 0.07 sec
    Start 3: test-members
3/6 Test #3: test-members ..................... Passed 0.02 sec
    Start 4: test-methods
4/6 Test #4: test-methods .....................***Failed 0.07 sec
    Start 5: test-objects
5/6 Test #5: test-objects ..................... Passed 0.10 sec
    Start 6: test-run
6/6 Test #6: test-run .........................***Failed 0.03 sec

67% tests passed, 2 tests failed out of 6

Total Test time (real) = 0.52 sec

The following tests FAILED:
   4 - test-methods (Failed)
   6 - test-run (Failed)
Errors while running CTest
Makefile:75: recipe for target 'test' failed
make: *** [test] Error 8

review: Needs Fixing
37. By Alexandre Abreu

remove const & refs to properly compare IsDirectArgs

38. By Alexandre Abreu

Add removed test

Revision history for this message
Alexandre Abreu (abreu-alexandre) wrote :

updated

Revision history for this message
Marcus Tomlinson (marcustomlinson) wrote :

Nice, works well. 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/call.h'
2--- src/internal/call.h 2015-06-10 05:57:04 +0000
3+++ src/internal/call.h 2015-11-05 19:43:55 +0000
4@@ -95,12 +95,16 @@
5
6 template <typename F>
7 using IsolateV8ArgsCallTraits = V8ArgsCallTraits<F, 1>;
8-
9+
10 template <typename F, size_t Offset>
11-using IsDirectArgs = std::integral_constant<bool,
12- CallFromV8Traits<F>::arg_count == (Offset + 1) &&
13- std::is_same<typename CallFromV8Traits<F>::template ArgType<Offset>,
14- v8::FunctionCallbackInfo<v8::Value> const&>::value>;
15+using IsDirectArgs =
16+ std::integral_constant<bool,
17+ CallFromV8Traits<F>::arg_count == (Offset + 1)
18+ && std::is_same<
19+ typename std::remove_const<
20+ typename std::remove_reference<typename CallFromV8Traits<F>::template ArgType<Offset>>::type
21+ >::type,
22+ v8::FunctionCallbackInfo<v8::Value>>::value>;
23
24 template <typename F>
25 using IsFirstArgIsolate =
26@@ -123,6 +127,15 @@
27 return func(CallTraits::template args_from_v8<Indices>(args)...);
28 }
29
30+template <typename F, size_t... Indices>
31+typename FunctionTraits<F>::ReturnType call_from_v8_impl(F&& func,
32+ v8::FunctionCallbackInfo<v8::Value> const& args,
33+ IsolateV8ArgsCallTraits<F>,
34+ IndexSequence<Indices...>)
35+{
36+ return func(args.GetIsolate(), IsolateV8ArgsCallTraits<F>::template args_from_v8<Indices>(args)...);
37+}
38+
39 template <typename T, typename F, typename CallTraits, size_t... Indices>
40 typename FunctionTraits<F>::ReturnType call_from_v8_impl(
41 T& obj, F&& func, v8::FunctionCallbackInfo<v8::Value> const& args, CallTraits, IndexSequence<Indices...>)
42
43=== modified file 'tests/objects/module.cpp'
44--- tests/objects/module.cpp 2015-10-09 10:43:41 +0000
45+++ tests/objects/module.cpp 2015-11-05 19:43:55 +0000
46@@ -27,6 +27,12 @@
47 // Get current isolate
48 Isolate* isolate = Isolate::GetCurrent();
49
50+ // Prepare TestClassVariableConstructorArgs binding
51+ v8cpp::Class<TestClassVariableConstructorArgs> testvarargsclass(isolate);
52+ testvarargsclass
53+ .set_constructor<v8::FunctionCallbackInfo<v8::Value>>()
54+ .add_method("zero", &TestClassVariableConstructorArgs::zero);
55+
56 // Prepare TestClass binding
57 v8cpp::Class<TestClass> testclass(isolate);
58 testclass
59@@ -52,6 +58,7 @@
60
61 module.add_class("TestClass", testclass);
62 module.add_class("EmbeddedTestClass", embeddedtestclass);
63+ module.add_class("TestClassVariableConstructorArgs", testvarargsclass);
64
65 module.add_function("new_TestClass", &new_TestClass);
66
67
68=== modified file 'tests/objects/test.cpp'
69--- tests/objects/test.cpp 2015-10-09 10:43:41 +0000
70+++ tests/objects/test.cpp 2015-11-05 19:43:55 +0000
71@@ -151,3 +151,15 @@
72
73 EXPECT_EQ(result, 2);
74 }
75+
76+TEST(Test, construct_var_args_class_via_new)
77+{
78+ auto test_object = v8cpp::run_script<TestClassVariableConstructorArgs>(
79+ R"(
80+ var module = require("./test-objects-module");
81+ var test_object = new module.TestClassVariableConstructorArgs(1, 2, "me");
82+ test_object;
83+ )");
84+
85+ EXPECT_EQ(test_object.zero(), 1);
86+}
87
88=== modified file 'tests/objects/test.h'
89--- tests/objects/test.h 2015-10-09 10:43:41 +0000
90+++ tests/objects/test.h 2015-11-05 19:43:55 +0000
91@@ -22,6 +22,8 @@
92
93 #include <memory>
94
95+#include <v8-cpp.h>
96+
97 class EmbeddedTestClass
98 {
99 public:
100@@ -41,6 +43,23 @@
101 int i_;
102 };
103
104+class TestClassVariableConstructorArgs
105+{
106+public:
107+ TestClassVariableConstructorArgs(v8::FunctionCallbackInfo<v8::Value> const& args) {
108+ if (args.Length() > 0 && args[0]->IsNumber()) {
109+ v_ = args[0]->ToNumber()->Value();
110+ }
111+ }
112+
113+ int zero() const {
114+ return v_;
115+ }
116+
117+ private:
118+ int v_;
119+};
120+
121 class TestClass
122 {
123 public:

Subscribers

People subscribed via source and target branches