diff --git a/es5-shim.js b/es5-shim.js index 8f7e531b..ffc9a131 100644 --- a/es5-shim.js +++ b/es5-shim.js @@ -126,6 +126,27 @@ }; }(ObjectPrototype.hasOwnProperty)); + // this is needed in Chrome 15 (probably earlier) - 36 + // https://bugs.chromium.org/p/v8/issues/detail?id=3334 + if ($Object.defineProperty) { + var F = function () {}; + var toStringSentinel = {}; + var sentinel = { toString: toStringSentinel }; + $Object.defineProperty(F, 'prototype', { value: sentinel, writable: false }); + if ((new F()).toString !== toStringSentinel) { + var $dP = $Object.defineProperty; + defineProperties($Object, { + defineProperty: function defineProperty(o, k, d) { + var key = $String(k); + if (key === 'prototype' && 'writable' in d && 'value' in d) { + o[key] = d.value; // eslint-disable-line no-param-reassign + } + return $dP(o, key, d); + } + }, true); + } + } + // // Util // ====== diff --git a/tests/spec/s-object.js b/tests/spec/s-object.js index 3fb6e79c..43a019cb 100644 --- a/tests/spec/s-object.js +++ b/tests/spec/s-object.js @@ -247,6 +247,20 @@ describe('Object', function () { Object.defineProperty({}, 'name', {}); }).not.toThrow(); }); + + (supportsDescriptors ? it : xit)('allows setting a nonwritable prototype', function () { + var F = function () {}; + expect((new F()).toString).toEqual(Object.prototype.toString); + + F.prototype = Number.prototype; + expect((new F()).toString).toEqual(Number.prototype.toString); + + var toStringSentinel = {}; + var sentinel = { toString: toStringSentinel }; + Object.defineProperty(F, 'prototype', { value: sentinel, writable: false }); + + expect((new F()).toString).toEqual(toStringSentinel); + }); }); describe('.getOwnPropertyDescriptor()', function () {