Closed Bug 600702 Opened 14 years ago Closed 13 years ago

Harmony proxies: for-in loop on proxy does not suppress properties deleted during enumeration

Categories

(Core :: JavaScript Engine, defect, P2)

x86
macOS
defect

Tracking

()

RESOLVED FIXED

People

(Reporter: tomvc.be, Assigned: gal)

Details

(Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file)

In tracemonkey, for-in loops normally suppress properties deleted during enumeration:

var obj = {a:0,b:1,c:2};
for (var p in obj) { delete obj['c']; print(p) };

prints: a,b

For proxies, this is not the case:

var target = {a:0,b:1,c:2};
var proxy = Proxy.create({
  has: function(name) {
    return name in target;
  },
  delete: function(name) {
    return delete target[name];
  },
  enumerate: function() {
    return ['a','b','c'];
  }
});

for (var prop in proxy) {
  delete proxy['c']; // delete a yet-to-be-enumerated property
  print(prop);
}

This prints a,b,c instead of the expected a,b.
It turns out enumeration on proxies does not invoke the proxy's has() trap to determine whether the property is still present on the proxy when it is enumerated.

While the semantics of proxy enumeration is still largely left unspecified in the spec, I think there was agreement that existing properties deleted during an enumeration should no longer be enumerated.
Priority: -- → P2
Attached patch patchSplinter Review
Assignee: general → gal
Attachment #479596 - Flags: review?(jorendorff)
Comment on attachment 479596 [details] [diff] [review]
patch

>diff --git a/js/src/jsproxy.cpp b/js/src/jsproxy.cpp
>--- a/js/src/jsproxy.cpp
>+++ b/js/src/jsproxy.cpp
>@@ -890,17 +890,18 @@ proxy_SetAttributes(JSContext *cx, JSObj
>     return JSProxy::defineProperty(cx, obj, id, &desc);
> }
> 
> static JSBool
> proxy_DeleteProperty(JSContext *cx, JSObject *obj, jsid id, Value *rval, JSBool strict)
> {
>     // TODO: throwing away strict
>     bool deleted;
>-    if (!JSProxy::delete_(cx, obj, id, &deleted))
>+    if (!JSProxy::delete_(cx, obj, id, &deleted) ||
>+        !js_SuppressDeletedProperty(cx, obj, id))
>         return false;

Braces for multiline any-part of if and if/else, but:

>+    if (!JSProxy::delete_(cx, obj, id, &deleted) || !js_SuppressDeletedProperty(cx, obj, id))
..1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890

this fits well within the 100-column style guide limit, so you can pull the condition up to fit in one line and avoid bracing.

r=me with that, another steal to relieve jorendorff.

/be
Attachment #479596 - Flags: review?(jorendorff) → review+
Was this patch forgotten? Does it still need pushing?
Looks like it. Want to grab it jdm or should I land it?
Please feel free. I'm supposed to be packing to go travelling for six weeks.
http://hg.mozilla.org/tracemonkey/rev/556ec2a89192
Whiteboard: fixed-in-tracemonkey
http://hg.mozilla.org/mozilla-central/rev/556ec2a89192
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: