Skip to content

Commit

Permalink
add Object#toString.toString as fallback for lodash, lodash/lodash#1197
Browse files Browse the repository at this point in the history
  • Loading branch information
zloirock committed May 11, 2015
1 parent 0c28267 commit 136130f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 7 deletions.
12 changes: 9 additions & 3 deletions library/modules/es6.object.to-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
// 19.1.3.6 Object.prototype.toString()
var $ = require('./$')
, cof = require('./$.cof')
, src = String({}.toString)
, tmp = {};
tmp[require('./$.wks')('toStringTag')] = 'z';
if($.FW && cof(tmp) != 'z')$.hide(Object.prototype, 'toString', function toString(){
function toString(){
return '[object ' + cof.classof(this) + ']';
});
}
// lodash uses String(Object.prototype.toString) in isNative
toString.toString = function(){
return src;
};
tmp[require('./$.wks')('toStringTag')] = 'z';
if($.FW && cof(tmp) != 'z')$.hide(Object.prototype, 'toString', toString);
12 changes: 9 additions & 3 deletions modules/es6.object.to-string.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@
// 19.1.3.6 Object.prototype.toString()
var $ = require('./$')
, cof = require('./$.cof')
, src = String({}.toString)
, tmp = {};
tmp[require('./$.wks')('toStringTag')] = 'z';
if($.FW && cof(tmp) != 'z')$.hide(Object.prototype, 'toString', function toString(){
function toString(){
return '[object ' + cof.classof(this) + ']';
});
}
// lodash uses String(Object.prototype.toString) in isNative
toString.toString = function(){
return src;
};
tmp[require('./$.wks')('toStringTag')] = 'z';
if($.FW && cof(tmp) != 'z')$.hide(Object.prototype, 'toString', toString);
1 change: 1 addition & 0 deletions tests/tests.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion tests/tests/es6.object.to-string.ls
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ test 'Object#toString' !->
eq toString.call(JSON), '[object JSON]', 'classof JSON is `JSON`'
class Class
@::[Symbol.toStringTag] = \Class
eq '' + new Class, '[object Class]', 'classof user class is [Symbol.toStringTag]'
eq '' + new Class, '[object Class]', 'classof user class is [Symbol.toStringTag]'

ok /native code/.test(Object::toString), 'Object#toString.toString'

0 comments on commit 136130f

Please sign in to comment.