Skip to content

Commit

Permalink
Add Value.preserveToString and use it on wrapped native methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Feb 24, 2015
1 parent 3838612 commit 31fd2e7
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion es6-shim.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@
} else {
object[property] = newValue;
}
},
preserveToString: function (target, source) {
defineProperty(target, 'toString', source.toString.bind(source), true);
}
};

Expand Down Expand Up @@ -1124,6 +1127,7 @@
defineProperty(Object, 'keys', function keys(value) {
return originalObjectKeys(ES.ToObject(value));
}, true);
Value.preserveToString(Object.keys, originalObjectKeys);
}

if (Object.getOwnPropertyNames) {
Expand All @@ -1140,6 +1144,7 @@
defineProperty(Object, 'getOwnPropertyNames', function getOwnPropertyNames(value) {
return originalObjectGetOwnPropertyNames(ES.ToObject(value));
}, true);
Value.preserveToString(Object.getOwnPropertyNames, originalObjectGetOwnPropertyNames);
}
}

Expand Down Expand Up @@ -1186,7 +1191,7 @@
}
return new OrigRegExp(pattern, flags);
};
defineProperty(RegExpShim, 'toString', OrigRegExp.toString.bind(OrigRegExp), true);
Value.preserveToString(RegExpShim, OrigRegExp);
if (Object.setPrototypeOf) {
// sets up proper prototype chain where possible
Object.setPrototypeOf(OrigRegExp, RegExpShim);
Expand Down

0 comments on commit 31fd2e7

Please sign in to comment.