Closed Bug 394964 Opened 17 years ago Closed 9 years ago

Object.prototype.watch should not add properties

Categories

(Core :: JavaScript Engine, enhancement)

x86
macOS
enhancement
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: jruderman, Unassigned)

References

Details

"this.watch('x', fun)" adds "x" to the list of properties shown by enumeration, but "delete x" doesn't remove the watchpoint.  Should it?

I think it would be nice if "for (var p in this) delete p" would completely clear the global scope.
The primary usecase for 'watch' is for debuggers. So, in reality, the fact that this.watch('x', fun) adds an enumerable property is probably a bug and delete should have no effect on the watchpoint. See also bug 361856 comment 5.
Watchpoints are what they are. Blake is right to note the use-case, which is about debugging a property identifier in an object (not a particular instance of an id), but more basic: we can't really change 'em after all these years. We don't know the downstream users and their expectations, but this bug proposes an incompatible change. That's never good in our world unless most or all of the current users are all confused, and the change actually improves their lives.

/be
(In reply to comment #1)
> So, in reality, the fact that
> this.watch('x', fun) adds an enumerable property is probably a bug

From usage point of view this should be indeed a bug. It should not be that difficult to fix this since a watch point for non-yet-existing property can be implemented is the same way as watchpoints for deleted properties.

I suggest to morph the bug accordingly.
Perhaps most importantly, the JS references have always noted that watchpoints do not disappear when a property is deleted; given that, I have an extremely hard time believing nobody depends on this.

http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.3/reference/object.html#1193628
http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Object:watch
(In reply to comment #3)
> (In reply to comment #1)
> I suggest to morph the bug accordingly.

Agreed -- check for dups, though.

/be
Here is an example of how this breaks my app. After calling watch, arr[0] is 'undefined'

>>> arr = []
[]
>>> arr.length
0
>>> arr.watch('0', function(id, oldval, newval){ alert('hi'); return newval; });
>>> arr.length
1
Not a regression from JS1.7 / Firefox 2 / Mozilla 1.8 branch:

js> arr=[]

js> arr.length
0
js> arr.watch('0', function(id, oldval, newval){ alert('hi'); return newval; });
js> arr.length
1

Shaver, you want to take this one?

/be
Debuggers need better support for property addition and change than watch() provides. In addition to this bug, I don't think there is a way to use watch() on local properties of scopes.
(In reply to comment #10)
> Debuggers need better support for property addition and change than watch()
> provides.

Is that filed as an RFE bug yet?

> In addition to this bug, I don't think there is a way to use watch()
> on local properties of scopes.

Scopes are not objects, variables are not properties -- so no.

/be
(In reply to comment #11)
> (In reply to comment #10)
> > Debuggers need better support for property addition and change than watch()
> > provides.
> 
> Is that filed as an RFE bug yet?

https://bugzilla.mozilla.org/show_bug.cgi?id=579342

> 
> > In addition to this bug, I don't think there is a way to use watch()
> > on local properties of scopes.
> 
> Scopes are not objects, variables are not properties -- so no.

Sure, but we need the equivalent functionality. Perhaps there is a better title for bug 579342

> 
> /be
Assignee: general → nobody
No longer reproducible - Resolving as WFM.
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.