Closed Bug 1296851 Opened 8 years ago Closed 8 years ago

Always allow SetPrototype with the same value as the current [[Prototype]]

Categories

(Core :: JavaScript Engine, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla51
Tracking Status
firefox51 --- fixed

People

(Reporter: evilpie, Assigned: evilpie)

References

(Blocks 1 open bug)

Details

Attachments

(1 file)

Basically our immutable or otherwise special objects didn't allow you to set the [[Prototype]] to the same value again. 9.4.7.1 [[SetPrototypeOf]] for Immutable Prototype Exotic Objects allows exactly that. (We don't seem to have a separate implementation of [[SetPrototypeOf]] for these anyway)
Attachment #8783187 - Flags: review?(jwalden+bmo)
Assignee: nobody → evilpies
Comment on attachment 8783187 [details] [diff] [review]
Always allow SetPrototype with the same value as the current [[Prototype]]

Review of attachment 8783187 [details] [diff] [review]:
-----------------------------------------------------------------

::: js/src/jsobj.cpp
@@ +2540,3 @@
>      /* Disallow mutation of immutable [[Prototype]]s. */
>      if (obj->staticPrototypeIsImmutable() && ImmutablePrototypesEnabled)
>          return result.fail(JSMSG_CANT_SET_PROTO);

Move this check immediately after the same-value check.  Putting it here means we have an extra IsExtensible trap-call.  That doesn't *happen* to be fatal, because all immutable-prototype things have the default extensibility stuff, but it seems unclean not to have the check immediately after, and to do gratuitous work for no reason.

::: js/src/tests/ecma_6/Object/setPrototypeOf-same-value.js
@@ +1,4 @@
> +// Setting a "new" prototype to the current [[Prototype]] value should never fail
> +
> +var t = {}, x = {};
> +Object.setPrototypeOf(t, x);

var x = {}, t = Object.create(x);
Attachment #8783187 - Flags: review?(jwalden+bmo) → review+
Pushed by evilpies@gmail.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/ff77c6e687bc
Always allow SetPrototype with the same value as the current [[Prototype]]. r=Waldo
https://hg.mozilla.org/mozilla-central/rev/ff77c6e687bc
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla51
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: