diff --git a/library/modules/es6.symbol.js b/library/modules/es6.symbol.js index d21f39978232..f07cc9de2ce9 100644 --- a/library/modules/es6.symbol.js +++ b/library/modules/es6.symbol.js @@ -9,6 +9,8 @@ var $ = require('./$') , keyOf = require('./$.keyof') , enumKeys = require('./$.enum-keys') , assertObject = require('./$.assert').obj + , ObjectProto = Object.prototype + , DESC = $.DESC , has = $.has , $create = $.create , getDesc = $.getDesc @@ -25,13 +27,30 @@ var $ = require('./$') , AllSymbols = shared('symbols') , useNative = $.isFunction($Symbol); +var setSymbolDesc = DESC ? function(){ // fallback for old Android + try { + return $create(setDesc({}, HIDDEN, { + get: function(){ + return setDesc(this, HIDDEN, {value: false})[HIDDEN]; + } + }))[HIDDEN] || setDesc; + } catch(e){ + return function(it, key, D){ + var protoDesc = getDesc(ObjectProto, key); + if(protoDesc)delete ObjectProto[key]; + setDesc(it, key, D); + if(protoDesc && it !== ObjectProto)setDesc(ObjectProto, key, protoDesc); + }; + } +}() : setDesc; + function wrap(tag){ var sym = AllSymbols[tag] = $.set($create($Symbol.prototype), TAG, tag); - $.DESC && setter && setDesc(Object.prototype, tag, { + DESC && setter && setSymbolDesc(ObjectProto, tag, { configurable: true, set: function(value){ if(has(this, HIDDEN) && has(this[HIDDEN], tag))this[HIDDEN][tag] = false; - setDesc(this, tag, desc(1, value)); + setSymbolDesc(this, tag, desc(1, value)); } }); return sym; @@ -45,7 +64,7 @@ function defineProperty(it, key, D){ } else { if(has(it, HIDDEN) && it[HIDDEN][key])it[HIDDEN][key] = false; D = $create(D, {enumerable: desc(0, false)}); - } + } return setSymbolDesc(it, key, D); } return setDesc(it, key, D); } function defineProperties(it, P){ diff --git a/modules/es6.symbol.js b/modules/es6.symbol.js index d21f39978232..f07cc9de2ce9 100644 --- a/modules/es6.symbol.js +++ b/modules/es6.symbol.js @@ -9,6 +9,8 @@ var $ = require('./$') , keyOf = require('./$.keyof') , enumKeys = require('./$.enum-keys') , assertObject = require('./$.assert').obj + , ObjectProto = Object.prototype + , DESC = $.DESC , has = $.has , $create = $.create , getDesc = $.getDesc @@ -25,13 +27,30 @@ var $ = require('./$') , AllSymbols = shared('symbols') , useNative = $.isFunction($Symbol); +var setSymbolDesc = DESC ? function(){ // fallback for old Android + try { + return $create(setDesc({}, HIDDEN, { + get: function(){ + return setDesc(this, HIDDEN, {value: false})[HIDDEN]; + } + }))[HIDDEN] || setDesc; + } catch(e){ + return function(it, key, D){ + var protoDesc = getDesc(ObjectProto, key); + if(protoDesc)delete ObjectProto[key]; + setDesc(it, key, D); + if(protoDesc && it !== ObjectProto)setDesc(ObjectProto, key, protoDesc); + }; + } +}() : setDesc; + function wrap(tag){ var sym = AllSymbols[tag] = $.set($create($Symbol.prototype), TAG, tag); - $.DESC && setter && setDesc(Object.prototype, tag, { + DESC && setter && setSymbolDesc(ObjectProto, tag, { configurable: true, set: function(value){ if(has(this, HIDDEN) && has(this[HIDDEN], tag))this[HIDDEN][tag] = false; - setDesc(this, tag, desc(1, value)); + setSymbolDesc(this, tag, desc(1, value)); } }); return sym; @@ -45,7 +64,7 @@ function defineProperty(it, key, D){ } else { if(has(it, HIDDEN) && it[HIDDEN][key])it[HIDDEN][key] = false; D = $create(D, {enumerable: desc(0, false)}); - } + } return setSymbolDesc(it, key, D); } return setDesc(it, key, D); } function defineProperties(it, P){