Skip to content

Commit

Permalink
fix Symbol for Android 2
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed May 25, 2015
1 parent 13e8b60 commit 15a6dce
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 6 deletions.
25 changes: 22 additions & 3 deletions library/modules/es6.symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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){
Expand Down
25 changes: 22 additions & 3 deletions modules/es6.symbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand All @@ -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){
Expand Down

0 comments on commit 15a6dce

Please sign in to comment.