Permalink
Browse files

Fixed native constructor serialization

  • Loading branch information...
1 parent e304d89 commit 382e8c92697d96fa91f1ba0ef637c9d10337ae92 @kriszyp committed Apr 28, 2010
Showing with 6 additions and 3 deletions.
  1. +6 −3 lib/json-ext.js
View
@@ -107,11 +107,11 @@ replace(/(?:^|:|,|&&)(?:\s*\[)+/g, ''))) {
var cx = /[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g;
-
+var nativeConstructors = {"String":String, "Object":Object, "Number":Number, "Boolean":Boolean, "Array":Array, "Date":Date};
exports.stringify = ({}).toSource ?
// we will use toSource if it is available
(function(){
- ["String", "Object", "Number", "Boolean", "Array", "Date"].forEach(function(name){
+ Object.keys(nativeConstructors).forEach(function(name){
global[name].toSource = function(){
return name;
};
@@ -196,10 +196,13 @@ exports.stringify = ({}).toSource ?
case 'string':
return quote(value);
+ case 'function':
+ if(nativeConstructors[value.name] === value){
+ return value.name;
+ }
case 'number':
case 'boolean':
case 'undefined':
- case 'function':
case 'null':
return String(value);

0 comments on commit 382e8c9

Please sign in to comment.