Closed Bug 756203 Opened 12 years ago Closed 9 years ago

setters are not called on Float32Array

Categories

(Core :: JavaScript Engine, defect)

x86
macOS
defect
Not set
normal

Tracking

()

RESOLVED WORKSFORME

People

(Reporter: erich.ocean, Unassigned)

Details

(Whiteboard: [js:inv:p2])

Attachments

(1 file)

When using Object.defineProperty() on Float32Array.prototype, getters are called, but setters are not. This does not match the behavior of v8, JavaScriptCore, or Internet Explorer.

If you do Float32Array.prototype.__lookupSetter__, you can retrieve the setter and then call it, and the result is correct.

I have attached an HTML file demonstrating the issue.
This appears to be intentional, and comes from this code in obj_setGeneric in js/src/jstypedarray.cpp:

        // We can't just chain to js_SetPropertyHelper, because we're not a normal object.
        if (!isArrayIndex(cx, tarray, id, &index)) {
            // Silent ignore is better than an exception here, because
            // at some point we may want to support other properties on
            // these objects.  This is especially true when these arrays
            // are used to implement HTML Canvas 2D's PixelArray objects,
            // which used to be plain old arrays.
            vp->setUndefined();
            return true;
        }

Apparently, the spec is ambiguous on this point. But at the very least, it seems odd for getters to work but setters to be ignored.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Okay, so I get that you don't support adding properties. My code, however, doesn't add new properties, so it would be safe to call. Perhaps setters should be allowed, and the above if () amended to only disallow actual, honest-to-goodness property setting, not merely calling a setter itself.

Presumably, that wouldn't break anything else in the runtime, and would at least be an improvement over what is there now pending a fuller implementation.
Expanding on my comment, basically we could do whatever it is __lookupSetter__ is doing now, and if we get a result, call it. Otherwise, the existing behavior stands.
Please add the ES5 tag to this bug.  Host objects can do whatever they want with respect to setters, but it would be in the spirit of ES5 strict to throw rather than failing silently.
That is, it would be nice if it threw while in strict mode.
Whiteboard: [js:inv:p2]
Any new thoughts on this? It's unfortunate that Firefox behaves differently from the others :/
I too am trying todo something similar to Erich, by having aliases to positions in the array. 

Having consistant behaviour here would be wonderful.
This will be fixed in the process of fixing bug 586842, which has been, and continues to be, a long slog.  I keep getting tripped up on other things that need to be fixed in the way of that, but I expect it to happen sometime this fall.
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.

Attachment

General

Creator:
Created:
Updated:
Size: