Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#14746 closed defect (fixed)

has.js feature detection and undefined features

Reported by: chuckd Owned by: Rawld Gill
Priority: undecided Milestone: 1.8
Component: Loader Version: 1.7.0
Keywords: Cc: dante
Blocked By: Blocking:

Description

The implementations of the has() function in the new AMD loader, and in dojo/has.js, currently have the unfortunate side effect of modifying the has cache when querying the value of a feature that is not currently in the cache. The missing feature is added to the cache with a value of undefined. Since it is perfectly valid to call has.add() and specify a value of undefined for a feature (dojo/_base/sniff.js does this for features that are not supported on the current client), this means that there is no way to determine if a feature that is in the has cache is there because the feature is undefined, or the feature was added to the has cache using has.add() with a value of undefined.

Under normal circumstances, this distinction has no meaning. However, I'm working on code that uses the combo API support in the dojo AMD loader (thanks Rawld) to request modules from a server process, and part of the processing that the server does uses the currently defined feature set that is sent by the client as part of the request. The feature set is determined by iterating through the has cache (yes, I know this is unsupported, but there is no supported way that I know of for client code to query the currently defined feature set). Because the processing performed by the server is based on the feature set on the client at the time the request for the modules is made rather than at the time the code in the modules is executed, the difference between an undefined feature and a feature that is defined with a value of undefined becomes significant. This is because the server can take action on features that are defined using the value of undefined (treating them the same as features that are defined with a value of false). An undefined feature, however, cannot be acted upon because of the distinct possibility that the reason it is undefined is simply the fact that the JavaScript? code to define the feature hadn't run yet on the client at the time the request for the modules is made. Of course I'm ignoring here the possibility that previously defined features can be redefined, but this seems unlikely and in any case, we have the ability to filter out problem features.

So I am requesting that the implementation of the has() function in the loader, and in has.js, to be changed so that the only entries that can be found in the has cache are those that were explicitly added to the cache using has.add() and that the action of calling has() for a feature that is not currently in the cache no longer has the side effect of adding the feature name to the cache. I've attached patch files for both dojo.js and has.js with the change I am proposing.

Thanks for listening.

Attachments (2)

dojo.js.patch (547 bytes) - added by chuckd 8 years ago.
has.js.patch (582 bytes) - added by chuckd 8 years ago.

Download all attachments as: .zip

Change History (7)

Changed 8 years ago by chuckd

Attachment: dojo.js.patch added

Changed 8 years ago by chuckd

Attachment: has.js.patch added

comment:1 Changed 8 years ago by Adam Peller

Cc: dante added

comment:2 Changed 8 years ago by Rawld Gill

Milestone: tbd1.8

comment:3 Changed 8 years ago by Rawld Gill

Status: newassigned

comment:4 Changed 8 years ago by Rawld Gill

Resolution: fixed
Status: assignedclosed

In [27777]:

improved had feature caching algorithm; thanks chunk dumont; fixes #14746; !strict

comment:5 Changed 8 years ago by Rawld Gill

In [27785]:

backport [27777]; refs #14746; !strict

Note: See TracTickets for help on using tickets.