Avoid object mutation in getRawTag. [closes #2755]

This commit is contained in:
Richard Gibson
2016-10-25 16:55:47 -04:00
committed by John-David Dalton
parent e485e16d28
commit 1c9a9f364d
2 changed files with 54 additions and 32 deletions

View File

@@ -5956,15 +5956,21 @@
* @returns {string} Returns the raw `toStringTag`.
*/
function getRawTag(value) {
var isOwn = hasOwnProperty.call(value, symToStringTag),
tag = value[symToStringTag];
try {
var symbol = value[symToStringTag];
value[symToStringTag] = undefined;
} catch (e) {
symbol = undefined;
}
var isSet = true;
} catch (e) {}
var result = nativeObjectToString.call(value);
if (symbol) {
value[symToStringTag] = symbol;
if (isSet) {
if (isOwn) {
value[symToStringTag] = tag;
} else {
delete value[symToStringTag];
}
}
return result;
}