Skip to content

Commit 883a025

Browse files
committed
Use pointer type to return list reference in list monitor
1 parent 93e330e commit 883a025

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/blocks/listblocks.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,9 @@ CompilerValue *ListBlocks::compileListContents(Compiler *compiler)
5050
assert(list);
5151

5252
// If this block is used in a list monitor, return the list pointer
53-
if (compiler->block()->isMonitorBlock()) {
54-
// TODO: Refactor this
55-
// List monitors expect a reference to the list
56-
// We don't have a list reference type, so cast the pointer to number
57-
return compiler->addConstValue((uintptr_t)list.get());
58-
} else
53+
if (compiler->block()->isMonitorBlock())
54+
return compiler->addConstValue(list.get());
55+
else
5956
return compiler->addListContents(static_cast<List *>(list.get()));
6057
}
6158

test/blocks/list_blocks_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ TEST_F(ListBlocksTest, ListMonitor)
114114
ASSERT_EQ(monitor1->name(), list1->name());
115115
ASSERT_EQ(monitor2->name(), list2->name());
116116

117-
EXPECT_CALL(iface1, onValueChanged(_)).WillOnce(Invoke([list1](const Value &value) { ASSERT_EQ(value.toDouble(), (uintptr_t)list1.get()); }));
118-
EXPECT_CALL(iface2, onValueChanged(_)).WillOnce(Invoke([list2](const Value &value) { ASSERT_EQ(value.toDouble(), (uintptr_t)list2.get()); }));
117+
EXPECT_CALL(iface1, onValueChanged(_)).WillOnce(Invoke([list1](const Value &value) { ASSERT_EQ(value.toPointer(), list1.get()); }));
118+
EXPECT_CALL(iface2, onValueChanged(_)).WillOnce(Invoke([list2](const Value &value) { ASSERT_EQ(value.toPointer(), list2.get()); }));
119119
m_engine->updateMonitors();
120120
}
121121

0 commit comments

Comments
 (0)