{"action":"opened","issue":{"url":"https://api.github.com/repos/joyent/node/issues/25613","labels_url":"https://api.github.com/repos/joyent/node/issues/25613/labels{/name}","comments_url":"https://api.github.com/repos/joyent/node/issues/25613/comments","events_url":"https://api.github.com/repos/joyent/node/issues/25613/events","html_url":"https://github.com/joyent/node/issues/25613","id":92581836,"number":25613,"title":"toString on native object does not return a valid function declaration.","user":{"login":"Mbodin","id":1829786,"avatar_url":"https://avatars.githubusercontent.com/u/1829786?v=3","gravatar_id":"","url":"https://api.github.com/users/Mbodin","html_url":"https://github.com/Mbodin","followers_url":"https://api.github.com/users/Mbodin/followers","following_url":"https://api.github.com/users/Mbodin/following{/other_user}","gists_url":"https://api.github.com/users/Mbodin/gists{/gist_id}","starred_url":"https://api.github.com/users/Mbodin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Mbodin/subscriptions","organizations_url":"https://api.github.com/users/Mbodin/orgs","repos_url":"https://api.github.com/users/Mbodin/repos","events_url":"https://api.github.com/users/Mbodin/events{/privacy}","received_events_url":"https://api.github.com/users/Mbodin/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-07-02T08:33:18Z","updated_at":"2015-07-02T08:33:18Z","closed_at":null,"body":"Hi,\r\nThe value “Function.prototype.toString” is defined by the Ecma standard as follows:\r\n```\r\nAn implementation-dependent representation of the function is returned. This representation has the syntax of a FunctionDeclaration. Note in particular that the use and placement of white space, line terminators, and semicolons within the representation String is implementation-dependent.\r\n```\r\nIn particular, one should be able to parse or to pass to “eval” the result without getting a syntax error. However, there is no guarantee on the behaviour of the returned function.\r\n\r\nThe problem comes when calling this function with native objects as “this”:\r\n```javascript\r\n$ node\r\n> String.toString === Function.prototype.toString // Just checking whether “String” has a special “toString“ function, which is not the case here.\r\ntrue\r\n> String.toString()\r\n'function String() { [native code] }'\r\n> eval ('function String() { [native code] }') // Syntax error\r\n```\r\nAs you can see, “[native code]” is not a valid body for a function.\r\n\r\nWhat I suggest is to return the following string instead:\r\n```javascript\r\n$ node\r\n> String.toString()\r\n'function String() { \"native code\" /* native code */ }'\r\n```\r\nIt uses a tag to warn users that the following is a native code, and a comment to warn users that there is some code left.\r\nFor this part, the specification is extremely loose: I think it would be a good think to follow the specification here, as it is easy to do…\r\n\r\nMartin.\r\nP.S.: I’m running version v0.10.36 of Node, on Fedora, x86, 64 bits."}}