Closed Bug 855428 Opened 8 years ago Closed 8 years ago

Setting a non-writable, non-configurable property to its current value should silently do nothing in strict mode code

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: Waldo, Assigned: Waldo)

Details

"use strict"; var obj = Object.defineProperty({}, "x", { value: 17, writable: false, configurable: false }); obj.x = 17; "PASS"

should evaluate to "PASS".  Instead it throws a TypeError.  This is because of this portion of js::SetPropertyHelper:

    if (!shape->writable()) {
        /* Error in strict mode code, warn with strict option, otherwise do nothing. */
        if (strict)
            return JSObject::reportReadOnly(cx, id, JSREPORT_ERROR);
        if (cx->hasStrictOption())
            return JSObject::reportReadOnly(cx, id, JSREPORT_STRICT | JSREPORT_WARNING);
        return JS_TRUE;
    }

Setting a non-configurable, non-writable property to its current value should do nothing in strict mode.  Warning may be reasonable, but language semantics require such sets to not throw.  So at least the |if (strict)| needs to be conditioned on !SameValue(old, new).
Er, no, I misremembered.  [[CanPut]] returns false here, and a TypeError's thrown, entirely ignoring the value being set.
No longer blocks: es5
Status: ASSIGNED → RESOLVED
Closed: 8 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.