If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

Object.prototype.watch should not add properties

RESOLVED WORKSFORME

Status

()

Core
JavaScript Engine
--
enhancement
RESOLVED WORKSFORME
10 years ago
2 years ago

People

(Reporter: Jesse Ruderman, Unassigned)

Tracking

Trunk
x86
Mac OS X
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

10 years ago
"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

Comment 3

10 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.
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

Comment 6

10 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

Comment 7

10 years ago
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

Updated

7 years ago
Duplicate of this bug: 613706

Comment 10

7 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.
(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

7 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

3 years ago
Assignee: general → nobody

Comment 13

2 years ago
No longer reproducible - Resolving as WFM.
Status: NEW → RESOLVED
Last Resolved: 2 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.