Opened 6 years ago
Last modified 3 years ago
#17702 assigned defect
[regression] dojo.publish fails when args are passed in function arguments array
Reported by: | chuckd | Owned by: | Kris Zyp |
---|---|---|---|
Priority: | undecided | Milestone: | 1.15 |
Component: | Events | Version: | 1.8.0 |
Keywords: | Cc: | cjolif | |
Blocked By: | Blocking: |
Description
This regression was introduced in 1.8 when the implementation of dojo.publish was delegated to dojo/topic.
The problem can be seen in the following test case:
dojo.subscribe("topic", function(arg) { console.log(arg); }); (function() { dojo.publish("topic", arguments); })("hello");
The console output is ["hello"]
instead of "hello"
which is what it would be if a real array were passed to dojo.publish.
The issue stems from the implementation of dojo.publish in dojo/_base/connect.js, where Array.concat() is used to build the argument values passed to topic/publish. The problem is that Array.concat() behaves differently for real arrays vs. function argument arrays. In the case of the former, the array elements are added to the target array. In the case of the latter, the arguments array itself is added to the target array.
One solution to this problem would change the implementation of publish in connect.js from
return hub.publish.apply(hub, [topic].concat(args));
to
return hub.publish.apply(hub, [topic].concat(Array.prototype.slice.call(args, 0)));
Change History (6)
comment:1 Changed 6 years ago by
Component: | General → Events |
---|---|
Owner: | set to Kris Zyp |
Status: | new → assigned |
comment:2 Changed 6 years ago by
Cc: | cjolif added |
---|
comment:3 Changed 6 years ago by
Yes, dojo.publish is deprecated, but this is a regression. Function argument arrays worked just fine when passed to dojo.publish prior to 1.8. This bug can complicate the task of upgrading to 1.8+ for affected code because it isn't at all clear why publish/subscribe no longer work as expected.
comment:4 Changed 6 years ago by
Summary: | dojo.publish fails when args are passed in function arguments array → [regression] dojo.publish fails when args are passed in function arguments array |
---|---|
Version: | 1.9.2 → 1.8.0 |
Ah that's a different story then. Sorry, I see you wrote that in the original description but I didn't notice it.
comment:5 Changed 4 years ago by
Milestone: | tbd → 1.12 |
---|
comment:6 Changed 3 years ago by
Milestone: | 1.13 → 1.15 |
---|
Ticket planning... move current 1.13 tickets out to 1.15 to make it easier to move tickets into the 1.13 milestone.
I would just close this as wontfix since the code is deprecated (in favor of dojo/topic). OTOH it's a trivial fix.