5

I have a .js file linked to a .htm file and the only code within the .js file is the line:

Object.setPrototypeOf(Object.prototype,{x:616});

On loading the .htm page the "chrome console" displays the error:

Uncaught TypeError: Immutable prototype object '#<Object>' cannot have their prototype set

I've never seen this error before and can't find anything for it here or online.

I assumed that the object had been sealed/frozen, so ran the tests:

console.warn('sealed        ⇒',Object.isSealed(Object.prototype));      //  false
console.warn('frozen        ⇒',Object.isFrozen(Object.prototype));      //  false
console.warn('extensible    ⇒',Object.isExtensible(Object.prototype));  //  true

But this shed no light on the problem and as such has left me stumped. This is the first ever time that this has happened when setting the prototype of Object.prototype and has me wondering if my Chrome browser has auto-updated with new features or something?

halfer
  • 19,824
  • 17
  • 99
  • 186
LostInCyberSpace
  • 413
  • 4
  • 19

1 Answers1

8

This is new in ES7 (aka ES2016). The builtin prototype object Object.prototype is now an Immutable Prototype Exotic Objects which has its [[prototype]] internal slot locked down.

It is supposed to prevent proxies from being inserted in the global lookup mechanism, see this commit for details. It has recently been implemented in V8.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375