Closed
Bug 394964
Opened 17 years ago
Closed 9 years ago
Object.prototype.watch should not add properties
Categories
(Core :: JavaScript Engine, enhancement)
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.
Comment 1•17 years ago
|
||
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.
Comment 2•17 years ago
|
||
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
Comment 3•17 years ago
|
||
(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.
Comment 4•17 years ago
|
||
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
Comment 5•17 years ago
|
||
(In reply to comment #3)
> (In reply to comment #1)
> I suggest to morph the bug accordingly.
Agreed -- check for dups, though.
/be
Comment 6•17 years ago
|
||
I am morphing the bug: to https://bugzilla.mozilla.org/buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=&product=Core&component=JavaScript+Engine&long_desc_type=substring&long_desc=&bug_file_loc_type=allwordssubstr&bug_file_loc=&status_whiteboard_type=allwordssubstr&status_whiteboard=&keywords_type=allwords&keywords=&bug_status=NEW&bug_status=ASSIGNED&bug_status=REOPENED&emailassigned_to1=1&emailtype1=exact&email1=&emailassigned_to2=1&emailreporter2=1&emailqa_contact2=1&emailtype2=exact&email2=&bugidtype=include&bug_id=&votes=&chfieldfrom=&chfieldto=Now&chfieldvalue=&cmdtype=doit&order=Reuse+same+sort+as+last+time&known_name=JS&query_based_on=JS&field0-0-0=noop&type0-0-0=noop&value0-0-0= does not show any bugs related to watch points for non-existing properties.
Summary: Should |delete| clear watchpoints? → Object.prototype.watch should not add properties
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
Comment 8•17 years ago
|
||
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
Comment 10•14 years ago
|
||
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.
Comment 11•14 years ago
|
||
(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
Comment 12•14 years ago
|
||
(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 | ||
Updated•10 years ago
|
Assignee: general → nobody
Comment 13•9 years ago
|
||
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.
Description
•