Bug 145202

Summary: ES6: Implement Object.setPrototypeOf
Product: WebKit Reporter: Joseph Pecoraro <joepeck>
Component: JavaScriptCoreAssignee: Joseph Pecoraro <joepeck>
Status: RESOLVED FIXED    
Severity: Normal CC: benjamin, commit-queue, dino, ggaren, joepeck, rniwa, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
[PATCH] Proposed Fix none

Description Joseph Pecoraro 2015-05-19 21:39:07 PDT
* SUMMARY
Add support for Object.setPrototypeOf.

This is already very similar to __proto__ assignment, which we already support, with a few minor differences (throwing exceptions in some cases, and return values).

* REFERENCE
<https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/setPrototypeOf>

* SPEC
ES6 19.1.2.18 <https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.setprototypeof>

> When the setPrototypeOf function is called with arguments O and proto, the following steps are taken:
> 
>     1. Let O be RequireObjectCoercible(O).
>     2. ReturnIfAbrupt(O).
>     3. If Type(proto) is neither Object nor Null, throw a TypeError exception.
>     4. If Type(O) is not Object, return O.
>     5. Let status be O.[[SetPrototypeOf]](proto).
>     6. ReturnIfAbrupt(status).
>     7. If status is false, throw a TypeError exception.
>     8. Return O.

Compare this to Object.prototype.__proto__:
<https://people.mozilla.org/~jorendorff/es6-draft.html#sec-set-object.prototype.__proto__>

* TEST

  js> o = {}; Object.setPrototypeOf(o, Array.prototype); o instanceof Array;
    => should be true

* NOTES
- This is covered by the ES6 Compat Table: <https://kangax.github.io/compat-table/es6/#Object_static_methods_Object.setPrototypeOf>
- Other browsers have implemented this: (their tests cases are nearly identical)
  - Chrome (v8): <https://code.google.com/p/v8/source/detail?r=18739>
  - Firefox: <https://bugzilla.mozilla.org/show_bug.cgi?id=885788>
Comment 1 Radar WebKit Bug Importer 2015-05-19 21:39:27 PDT
<rdar://problem/21032827>
Comment 2 Joseph Pecoraro 2015-05-19 21:43:53 PDT
Created attachment 253425 [details]
[PATCH] Proposed Fix
Comment 3 WebKit Commit Bot 2015-05-20 10:23:13 PDT
Comment on attachment 253425 [details]
[PATCH] Proposed Fix

Clearing flags on attachment: 253425

Committed r184642: <http://trac.webkit.org/changeset/184642>
Comment 4 WebKit Commit Bot 2015-05-20 10:23:17 PDT
All reviewed patches have been landed.  Closing bug.