Skip to content

Commit

Permalink
Fixed unit test for constructors in class hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
mean-ui-thread committed Apr 12, 2018
1 parent d11e4b9 commit d1a5f62
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 9 additions & 2 deletions src/duktape-cpp/PushConstructorInspector.h
Expand Up @@ -14,16 +14,23 @@ class PushConstructorInspector: public EmptyInspector {

template <class C, class ... A>
void construct(std::shared_ptr<C> (*constructor) (A...)) {
Constructor<C, A...>::push(_ctx, constructor);
if (!_hasConstructor) {
_hasConstructor = true;
Constructor<C, A...>::push(_ctx, constructor);
}
}

template <class C, class ... A>
void construct(std::unique_ptr<C> (*constructor) (A...)) {
ConstructorUnique<C, A...>::push(_ctx, constructor);
if (!_hasConstructor) {
_hasConstructor = true;
ConstructorUnique<C, A...>::push(_ctx, constructor);
}
}

private:
duk::Context &_ctx;
bool _hasConstructor = false;
};

}}
8 changes: 4 additions & 4 deletions tests/ConstructorTests.cpp
Expand Up @@ -148,12 +148,12 @@ TEST_CASE("PushConstructorInspector", "[duktape]") {

duk_push_global_object(d);

duk::details::PushConstructorInspector i(d);

SimpleConstructible().inspect(i);
duk::details::PushConstructorInspector simpleInspector(d);
SimpleConstructible().inspect(simpleInspector);
duk_put_prop_string(d, -2, "SimpleConstructible");

ComplexConstructible().inspect(i);
duk::details::PushConstructorInspector complexInspector(d);
ComplexConstructible().inspect(complexInspector);
duk_put_prop_string(d, -2, "ComplexConstructible");

auto evalRes = duk_peval_string(d, script);
Expand Down

0 comments on commit d1a5f62

Please sign in to comment.