From bc8ef6dc128ac4c6f533a24bd53c6a487b122104 Mon Sep 17 00:00:00 2001 From: "kimi.zhang" Date: Wed, 2 Apr 2014 01:34:22 +0800 Subject: [PATCH] check hasDefinePropertiesPrototype. Relevant to #29 --- object.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/object.js b/object.js index 7861e42..e1e231c 100644 --- a/object.js +++ b/object.js @@ -131,6 +131,9 @@ define(function (require) { 'object-defineproperties-dom': function () { return doc && hasDefineProperties(testEl); }, + 'object-defineproperties-prototype': function () { + return hasDefinePropertiesPrototype(function () {}); + }, 'object-getownpropertydescriptor-obj': function () { return hasGetOwnPropertyDescriptor({}); }, @@ -196,6 +199,10 @@ define(function (require) { ? useNativeForDom(Object.defineProperties, defineProperties) : defineProperties; } + else if (!has('object-defineproperties-prototype')) { + Object.defineProperties = shims.defineProperties + = defineProperties; + } if (!has('object-defineproperty-obj')) { // check if dom has it (IE8) @@ -245,6 +252,17 @@ define(function (require) { } } + function hasDefinePropertiesPrototype(fn) { + if (('defineProperties' in Object)) { + try { + // test it + Object.defineProperties(fn, { 'prototype': { value: { test: true } } }) + return (new fn).test === true && fn.prototype.test === true; + } + catch (ex) { /* squelch */ } + } + } + function hasGetOwnPropertyDescriptor (object) { if (('getOwnPropertyDescriptor' in Object)) { object['sentinel3'] = true;