Last Comment Bug 394964 - Object.prototype.watch should not add properties
: Object.prototype.watch should not add properties
Status: RESOLVED WORKSFORME
:
Product: Core
Classification: Components
Component: JavaScript Engine (show other bugs)
: Trunk
: x86 macOS
-- enhancement (vote)
: ---
Assigned To: Nobody; OK to take it and work on it
:
: Steven DeTar [:sdetar]
Mentors:
: 613706 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2007-09-04 17:05 PDT by Jesse Ruderman
Modified: 2015-09-21 09:49 PDT (History)
10 users (show)
See Also:
Crash Signature:
(edit)
QA Whiteboard:
Iteration: ---
Points: ---
Has Regression Range: ---
Has STR: ---


Attachments

Description User image Jesse Ruderman 2007-09-04 17:05:49 PDT
"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 User image Blake Kaplan (:mrbkap) (inactive, use needinfo) 2007-09-04 18:15:16 PDT
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 User image Brendan Eich [:brendan] 2007-09-06 00:15:26 PDT
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 User image Igor Bukanov 2007-09-06 01:55:59 PDT
(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 User image Jeff Walden [:Waldo] 2007-09-06 08:59:03 PDT
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 User image Brendan Eich [:brendan] 2007-09-06 10:19:46 PDT
(In reply to comment #3)
> (In reply to comment #1)
> I suggest to morph the bug accordingly.

Agreed -- check for dups, though.

/be
Comment 7 User image Jeff Moss 2008-04-09 01:34:57 PDT
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 User image Brendan Eich [:brendan] 2008-04-09 12:18:33 PDT
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 9 User image John J. Barton 2011-03-01 15:07:30 PST
*** Bug 613706 has been marked as a duplicate of this bug. ***
Comment 10 User image John J. Barton 2011-03-01 15:15:59 PST
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 User image Brendan Eich [:brendan] 2011-03-01 15:18:46 PST
(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 User image John J. Barton 2011-03-01 15:31:58 PST
(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
Comment 13 User image André Bargull [:anba] 2015-09-21 09:49:18 PDT
No longer reproducible - Resolving as WFM.

Note You need to log in before you can comment on or make changes to this bug.