Skip to content

Commit

Permalink
Implemented Reflect.setPrototypeOf
Browse files Browse the repository at this point in the history
  • Loading branch information
Victorystick committed Jan 4, 2015
1 parent cc34a87 commit ccc3f5b
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -2265,13 +2265,50 @@
return func.apply(context, args);
},

setPrototypeOf: function setPrototypeOf(object, proto) {
if (!ES.TypeIsObject(object)) {
throw new TypeError('target must be an object');
}

if (proto !== null && !ES.TypeIsObject(proto)) {
throw new TypeError('proto must be an object or null');
}

// If they already are the same, we're done.
if (proto === Reflect.getPrototypeOf(object)) {
return true;
}

// Cannot alter prototype if object not extensible.
if (!Reflect.isExtensible(object)) {
return false;
}

// Ensure that we do not create
// a circular prototype chain.
if (proto !== null) {
var p = proto;

while (p) {
if (object === p) {
return false;
}

p = Reflect.getPrototypeOf(p);
}
}

Object.setPrototypeOf(object, proto);

return true;
},

// Same as Object global.
defineProperty: Object.defineProperty,
getOwnPropertyDescriptor: Object.getOwnPropertyDescriptor,
getPrototypeOf: Object.getPrototypeOf,
isExtensible: Object.isExtensible,
preventExtensions: Object.preventExtensions,
setPrototypeOf: Object.setPrototypeOf,

// Different name.
ownKeys: Object.keys
Expand Down

0 comments on commit ccc3f5b

Please sign in to comment.