Skip to content

Commit 0976c9b

Browse files
committed
[[ Element Chunk ]] Refactor get/set custom property
1 parent 17019cf commit 0976c9b

File tree

3 files changed

+60
-34
lines changed

3 files changed

+60
-34
lines changed

engine/src/chunk.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4527,6 +4527,58 @@ bool MCChunk::setprop(MCExecContext& ctxt, Properties which, MCNameRef index, Bo
45274527
return getsetprop(ctxt, which, index, effective, false, p_value);
45284528
}
45294529

4530+
bool MCChunk::getsetcustomprop(MCExecContext &ctxt, MCNameRef p_prop_name, MCNameRef p_index_name, bool p_is_get_operation, MCExecValue &r_value)
4531+
{
4532+
bool t_success;
4533+
t_success = true;
4534+
4535+
MCObject *t_object;
4536+
uint4 t_parid;
4537+
if (t_success)
4538+
t_success = getobjforprop(ctxt, t_object, t_parid);
4539+
4540+
// MW-2011-09-02: Moved handling of customprop != nil case into resolveprop,
4541+
// so t_prop_name is always non-nil if t_prop == P_CUSTOM.
4542+
// MW-2011-11-23: [[ Array Chunk Props ]] Moved handling of arrayprops into
4543+
// MCChunk::setprop.
4544+
if (t_success)
4545+
{
4546+
if (p_index_name == nil)
4547+
{
4548+
if (p_is_get_operation)
4549+
t_success = t_object -> getcustomprop(ctxt, t_object -> getdefaultpropsetname(), p_prop_name, r_value);
4550+
else
4551+
t_success = t_object -> setcustomprop(ctxt, t_object -> getdefaultpropsetname(), p_prop_name, r_value);
4552+
}
4553+
else
4554+
{
4555+
if (p_is_get_operation)
4556+
t_success = t_object -> getcustomprop(ctxt, p_prop_name, p_index_name, r_value);
4557+
else
4558+
t_success = t_object -> setcustomprop(ctxt, p_prop_name, p_index_name, r_value);
4559+
}
4560+
}
4561+
4562+
if (t_success)
4563+
{
4564+
// MM-2012-09-05: [[ Property Listener ]] Make sure setting a custom property sends propertyChanged message to listeners.
4565+
t_object -> signallisteners(P_CUSTOM);
4566+
return true;
4567+
}
4568+
4569+
return false;
4570+
}
4571+
4572+
bool MCChunk::getcustomprop(MCExecContext& ctxt, MCNameRef p_prop_name, MCNameRef p_index_name, MCExecValue& r_value)
4573+
{
4574+
return getsetcustomprop(ctxt, p_prop_name, p_index_name, true, r_value);
4575+
}
4576+
4577+
bool MCChunk::setcustomprop(MCExecContext& ctxt, MCNameRef p_prop_name, MCNameRef p_index_name, MCExecValue p_value)
4578+
{
4579+
return getsetcustomprop(ctxt, p_prop_name, p_index_name, false, p_value);
4580+
}
4581+
45304582
Chunk_term MCChunk::getlastchunktype(void)
45314583
{
45324584
if (byte != nil)

engine/src/chunk.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@ class MCChunk : public MCExpression
181181
bool getprop(MCExecContext& ctxt, Properties which, MCNameRef index, Boolean effective, MCExecValue& r_value);
182182
bool setprop(MCExecContext& ctxt, Properties which, MCNameRef index, Boolean effective, MCExecValue p_value);
183183

184+
bool getsetcustomprop(MCExecContext& ctxt, MCNameRef p_prop_name, MCNameRef p_index_name, bool p_is_get_operation, MCExecValue& r_value);
185+
186+
bool getcustomprop(MCExecContext& ctxt, MCNameRef p_prop_name, MCNameRef p_index_name, MCExecValue& r_value);
187+
bool setcustomprop(MCExecContext& ctxt, MCNameRef p_prop_name, MCNameRef p_index_name, MCExecValue p_value);
188+
184189
#ifdef LEGACY_EXEC
185190
Exec_stat getprop_legacy(Properties w, MCExecPoint &, MCNameRef index, Boolean effective);
186191
Exec_stat setprop_legacy(Properties w, MCExecPoint &, MCNameRef index, Boolean effective);

engine/src/property.cpp

Lines changed: 3 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5540,22 +5540,8 @@ void MCProperty::eval_object_property_ctxt(MCExecContext& ctxt, MCExecValue& r_v
55405540

55415541
if (t_prop == P_CUSTOM)
55425542
{
5543-
MCObject *t_object;
5544-
uint4 t_parid;
5545-
if (t_success)
5546-
t_success = target -> getobjforprop(ctxt, t_object, t_parid);
5547-
5548-
// MW-2011-09-02: Moved handling of customprop != nil case into resolveprop,
5549-
// so t_prop_name is always non-nil if t_prop == P_CUSTOM.
5550-
// MW-2011-11-23: [[ Array Chunk Props ]] Moved handling of arrayprops into
5551-
// MCChunk::setprop.
5552-
if (t_success)
5553-
{
5554-
if (*t_index_name == nil)
5555-
t_success = t_object -> getcustomprop(ctxt, t_object -> getdefaultpropsetname(), *t_prop_name, r_value);
5556-
else
5557-
t_success = t_object -> getcustomprop(ctxt, *t_prop_name, *t_index_name, r_value);
5558-
}
5543+
if (t_success)
5544+
t_success = target -> getcustomprop(ctxt, *t_prop_name, *t_index_name, r_value);
55595545
}
55605546
else
55615547
{
@@ -5646,24 +5632,7 @@ void MCProperty::set_object_property(MCExecContext& ctxt, MCExecValue p_value)
56465632

56475633
if (t_prop == P_CUSTOM)
56485634
{
5649-
MCObject *t_object;
5650-
uint4 t_parid;
5651-
t_success = target -> getobjforprop(ctxt, t_object, t_parid);
5652-
5653-
// MW-2011-09-02: Moved handling of customprop != nil case into resolveprop,
5654-
// so t_prop_name is always non-nil if t_prop == P_CUSTOM.
5655-
// MW-2011-11-23: [[ Array Chunk Props ]] Moved handling of arrayprops into
5656-
// MCChunk::setprop.
5657-
if (t_success)
5658-
{
5659-
if (*t_index_name == nil)
5660-
t_success = t_object -> setcustomprop(ctxt, t_object -> getdefaultpropsetname(), *t_prop_name, p_value);
5661-
else
5662-
t_success = t_object -> setcustomprop(ctxt, *t_prop_name, *t_index_name, p_value);
5663-
// MM-2012-09-05: [[ Property Listener ]] Make sure setting a custom property sends propertyChanged message to listeners.
5664-
if (t_success)
5665-
t_object -> signallisteners(t_prop);
5666-
}
5635+
t_success = target -> setcustomprop(ctxt, *t_prop_name, *t_index_name, p_value);
56675636
}
56685637
else
56695638
{

0 commit comments

Comments
 (0)