{"action":"created","comment":{"url":"https://api.github.com/repos/artillery/emscripten/pulls/comments/28917597","id":28917597,"diff_hunk":"@@ -243,10 +263,64 @@ def render_function(class_name, func_name, sigs, return_type, non_pointer, copy,\n     body = ''\n     pre_arg = []\n \n+  fullname = \"%s::%s\" % (class_name, func_name)\n+\n   for i in range(max_args):\n+    if i >= min_args:\n+      optional = True\n+    else:\n+      optional = False\n+    arg = allargs[i]\n+    doDefault = False\n+    # Filter out arguments we don't know how to parse. Fast casing only common cases.\n+    compatibleArg = isinstance(arg, Dummy) or (isinstance(arg, WebIDL.IDLArgument) and arg.optional is False)\n     # note: null has typeof object, but is ok to leave as is, since we are calling into asm code where null|0 = 0\n-    body += \"  if (arg%d && typeof arg%d === 'object') arg%d = arg%d.ptr;\\n\" % (i, i, i, i)\n-    body += \"  else arg%d = ensureString(arg%d);\\n\" % (i, i)\n+    if not legacyMode and compatibleArg:\n+      if isinstance(arg, WebIDL.IDLArgument):\n+        argName = arg.identifier.name\n+      else:\n+        argName = ''\n+      # Format assert fail message\n+      checkMsg = \"[CHECK FAILED] %s(arg%d:%s): \" % (fullname, i, argName)\n+      if isinstance(arg.type, WebIDL.IDLWrapperType):\n+        inner = arg.type.inner\n+      else:\n+        inner = \"\"\n+\n+      # Print type info in comments.\n+      body += \"  /* arg%d <%s> [%s] */\\n\" % (i, arg.type.name, inner)\n+\n+      # Wrap asserts with existance check when argument is optional.\n+      if allChecks and optional: body += \"if(typeof arg%d !== 'undefined' && arg%d !== null) {\\n\" % (i, i)\n+      # Special case argument types.\n+      if arg.type.isNumeric():\n+        if allChecks: body += \"  assert(typeof arg%d === 'number' && !isNaN(arg%d), '%sExpecting <number>');\\n\" % (i, i, checkMsg)\n+        # No transform needed for numbers\n+      elif arg.type.isBoolean():\n+        if allChecks: body += \"  assert(typeof arg%d === 'number' && !isNaN(arg%d), '%sExpecting <number>');\\n\" % (i, i, checkMsg)\n+        # No transform needed for booleans\n+      elif arg.type.isString():\n+        # Strings can be DOM strings or pointers.\n+        if allChecks: body += \"  assert(typeof arg%d === 'string' || (arg%d && typeof arg%d === 'object' && typeof arg%d.ptr === 'number'), '%sExpecting <string>');\\n\" % (i, i, i, i, checkMsg)\n+        doDefault = True # legacy path is fast enough for strings.\n+      elif arg.type.isInterface():\n+        if allChecks: body += \"  assert(typeof arg%d === 'object' && typeof arg%d.ptr === 'number', '%sExpecting <pointer>');\\n\" % (i, i, checkMsg)","path":"tools/webidl_binder.py","position":90,"original_position":90,"commit_id":"62b109a52ce4c2a7c1f7f767aa71bd87f9e35aeb","original_commit_id":"7601f756208b9cb6766a9670fa76bfadb71c4120","user":{"login":"mlogan","id":708638,"avatar_url":"https://avatars.githubusercontent.com/u/708638?v=3","gravatar_id":"","url":"https://api.github.com/users/mlogan","html_url":"https://github.com/mlogan","followers_url":"https://api.github.com/users/mlogan/followers","following_url":"https://api.github.com/users/mlogan/following{/other_user}","gists_url":"https://api.github.com/users/mlogan/gists{/gist_id}","starred_url":"https://api.github.com/users/mlogan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mlogan/subscriptions","organizations_url":"https://api.github.com/users/mlogan/orgs","repos_url":"https://api.github.com/users/mlogan/repos","events_url":"https://api.github.com/users/mlogan/events{/privacy}","received_events_url":"https://api.github.com/users/mlogan/received_events","type":"User","site_admin":false},"body":"oh ok, nm. Then it is guaranteed to work that way I guess.","created_at":"2015-04-22T21:39:12Z","updated_at":"2015-04-22T21:39:12Z","html_url":"https://github.com/artillery/emscripten/pull/1#discussion_r28917597","pull_request_url":"https://api.github.com/repos/artillery/emscripten/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/artillery/emscripten/pulls/comments/28917597"},"html":{"href":"https://github.com/artillery/emscripten/pull/1#discussion_r28917597"},"pull_request":{"href":"https://api.github.com/repos/artillery/emscripten/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/artillery/emscripten/pulls/1","id":33903179,"html_url":"https://github.com/artillery/emscripten/pull/1","diff_url":"https://github.com/artillery/emscripten/pull/1.diff","patch_url":"https://github.com/artillery/emscripten/pull/1.patch","issue_url":"https://api.github.com/repos/artillery/emscripten/issues/1","number":1,"state":"open","locked":false,"title":"MARK: Add thorough type checking and fastpath modes for webidl_binder.py.","user":{"login":"BKcore","id":658297,"avatar_url":"https://avatars.githubusercontent.com/u/658297?v=3","gravatar_id":"","url":"https://api.github.com/users/BKcore","html_url":"https://github.com/BKcore","followers_url":"https://api.github.com/users/BKcore/followers","following_url":"https://api.github.com/users/BKcore/following{/other_user}","gists_url":"https://api.github.com/users/BKcore/gists{/gist_id}","starred_url":"https://api.github.com/users/BKcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BKcore/subscriptions","organizations_url":"https://api.github.com/users/BKcore/orgs","repos_url":"https://api.github.com/users/BKcore/repos","events_url":"https://api.github.com/users/BKcore/events{/privacy}","received_events_url":"https://api.github.com/users/BKcore/received_events","type":"User","site_admin":false},"body":"__PREVIEW BEFORE I SUBMIT ON ORIGINAL REPO__\r\n\r\n- Setting `IDL_CHECKS=ALL` in your env will add thorough argument checking to the wrapper methods, catching NaNs, invalid pointers, invalid strings, etc. Note that we only special cased the most common argument types for simplicity; may extend later as needed.\r\n- Setting `IDL_CHECKS=FAST` in your env will skip most type checking for performance (~3x faster than default).\r\n- Setting `IDL_CHECKS` to anything else, or not setting it will behave as before, ensuring backward compatibility.\r\n- Setting `IDL_VERBOSE=1` in your env will print debug info during render_function.\r\n- Added inline type comments for readability: `argN <Type> [innerType]`.\r\n\r\n```js\r\n// StringUser\r\nfunction StringUser(arg0, arg1) {\r\n  /* arg0 <String> [] */\r\n  if(typeof arg0 !== 'undefined' && arg0 !== null) {\r\n    assert(typeof arg0 === 'string' || (typeof arg0 === 'object' && typeof arg0.ptr === 'number'), '[CHECK FAILED] StringUser::StringUser(arg0:str): Expecting <string>');\r\n  }\r\n  if (arg0 && typeof arg0 === 'object') arg0 = arg0.ptr;\r\n  else arg0 = ensureString(arg0);\r\n  /* arg1 <Long> [] */\r\n  if(typeof arg1 !== 'undefined' && arg1 !== null) {\r\n    assert(typeof arg1 === 'number' && !isNaN(arg1), '[CHECK FAILED] StringUser::StringUser(arg1:i): Expecting <number>');\r\n  }\r\n  if (arg0 === undefined) { this.ptr = _emscripten_bind_StringUser_StringUser_0(); getCache(StringUser)[this.ptr] = this;return }\r\n  if (arg1 === undefined) { this.ptr = _emscripten_bind_StringUser_StringUser_1(arg0); getCache(StringUser)[this.ptr] = this;return }\r\n  this.ptr = _emscripten_bind_StringUser_StringUser_2(arg0, arg1);\r\n  getCache(StringUser)[this.ptr] = this;\r\n};\r\n```","created_at":"2015-04-22T21:27:54Z","updated_at":"2015-04-22T21:39:12Z","closed_at":null,"merged_at":null,"merge_commit_sha":"c771de3abaa9d076c303955b2bc016e1d5ac20bd","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/artillery/emscripten/pulls/1/commits","review_comments_url":"https://api.github.com/repos/artillery/emscripten/pulls/1/comments","review_comment_url":"https://api.github.com/repos/artillery/emscripten/pulls/comments{/number}","comments_url":"https://api.github.com/repos/artillery/emscripten/issues/1/comments","statuses_url":"https://api.github.com/repos/artillery/emscripten/statuses/62b109a52ce4c2a7c1f7f767aa71bd87f9e35aeb","head":{"label":"artillery:webidl-checks-and-fastpath","ref":"webidl-checks-and-fastpath","sha":"62b109a52ce4c2a7c1f7f767aa71bd87f9e35aeb","user":{"login":"artillery","id":1179961,"avatar_url":"https://avatars.githubusercontent.com/u/1179961?v=3","gravatar_id":"","url":"https://api.github.com/users/artillery","html_url":"https://github.com/artillery","followers_url":"https://api.github.com/users/artillery/followers","following_url":"https://api.github.com/users/artillery/following{/other_user}","gists_url":"https://api.github.com/users/artillery/gists{/gist_id}","starred_url":"https://api.github.com/users/artillery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artillery/subscriptions","organizations_url":"https://api.github.com/users/artillery/orgs","repos_url":"https://api.github.com/users/artillery/repos","events_url":"https://api.github.com/users/artillery/events{/privacy}","received_events_url":"https://api.github.com/users/artillery/received_events","type":"Organization","site_admin":false},"repo":{"id":22549488,"name":"emscripten","full_name":"artillery/emscripten","owner":{"login":"artillery","id":1179961,"avatar_url":"https://avatars.githubusercontent.com/u/1179961?v=3","gravatar_id":"","url":"https://api.github.com/users/artillery","html_url":"https://github.com/artillery","followers_url":"https://api.github.com/users/artillery/followers","following_url":"https://api.github.com/users/artillery/following{/other_user}","gists_url":"https://api.github.com/users/artillery/gists{/gist_id}","starred_url":"https://api.github.com/users/artillery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artillery/subscriptions","organizations_url":"https://api.github.com/users/artillery/orgs","repos_url":"https://api.github.com/users/artillery/repos","events_url":"https://api.github.com/users/artillery/events{/privacy}","received_events_url":"https://api.github.com/users/artillery/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/artillery/emscripten","description":"Emscripten: An LLVM-to-JavaScript Compiler","fork":true,"url":"https://api.github.com/repos/artillery/emscripten","forks_url":"https://api.github.com/repos/artillery/emscripten/forks","keys_url":"https://api.github.com/repos/artillery/emscripten/keys{/key_id}","collaborators_url":"https://api.github.com/repos/artillery/emscripten/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/artillery/emscripten/teams","hooks_url":"https://api.github.com/repos/artillery/emscripten/hooks","issue_events_url":"https://api.github.com/repos/artillery/emscripten/issues/events{/number}","events_url":"https://api.github.com/repos/artillery/emscripten/events","assignees_url":"https://api.github.com/repos/artillery/emscripten/assignees{/user}","branches_url":"https://api.github.com/repos/artillery/emscripten/branches{/branch}","tags_url":"https://api.github.com/repos/artillery/emscripten/tags","blobs_url":"https://api.github.com/repos/artillery/emscripten/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/artillery/emscripten/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/artillery/emscripten/git/refs{/sha}","trees_url":"https://api.github.com/repos/artillery/emscripten/git/trees{/sha}","statuses_url":"https://api.github.com/repos/artillery/emscripten/statuses/{sha}","languages_url":"https://api.github.com/repos/artillery/emscripten/languages","stargazers_url":"https://api.github.com/repos/artillery/emscripten/stargazers","contributors_url":"https://api.github.com/repos/artillery/emscripten/contributors","subscribers_url":"https://api.github.com/repos/artillery/emscripten/subscribers","subscription_url":"https://api.github.com/repos/artillery/emscripten/subscription","commits_url":"https://api.github.com/repos/artillery/emscripten/commits{/sha}","git_commits_url":"https://api.github.com/repos/artillery/emscripten/git/commits{/sha}","comments_url":"https://api.github.com/repos/artillery/emscripten/comments{/number}","issue_comment_url":"https://api.github.com/repos/artillery/emscripten/issues/comments{/number}","contents_url":"https://api.github.com/repos/artillery/emscripten/contents/{+path}","compare_url":"https://api.github.com/repos/artillery/emscripten/compare/{base}...{head}","merges_url":"https://api.github.com/repos/artillery/emscripten/merges","archive_url":"https://api.github.com/repos/artillery/emscripten/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/artillery/emscripten/downloads","issues_url":"https://api.github.com/repos/artillery/emscripten/issues{/number}","pulls_url":"https://api.github.com/repos/artillery/emscripten/pulls{/number}","milestones_url":"https://api.github.com/repos/artillery/emscripten/milestones{/number}","notifications_url":"https://api.github.com/repos/artillery/emscripten/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/artillery/emscripten/labels{/name}","releases_url":"https://api.github.com/repos/artillery/emscripten/releases{/id}","created_at":"2014-08-02T15:58:54Z","updated_at":"2015-04-22T21:11:37Z","pushed_at":"2015-04-22T21:35:39Z","git_url":"git://github.com/artillery/emscripten.git","ssh_url":"git@github.com:artillery/emscripten.git","clone_url":"https://github.com/artillery/emscripten.git","svn_url":"https://github.com/artillery/emscripten","homepage":"","size":125582,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"artillery:master","ref":"master","sha":"01d531a5fabc58d9f83a628df5c5b43ecc5950d5","user":{"login":"artillery","id":1179961,"avatar_url":"https://avatars.githubusercontent.com/u/1179961?v=3","gravatar_id":"","url":"https://api.github.com/users/artillery","html_url":"https://github.com/artillery","followers_url":"https://api.github.com/users/artillery/followers","following_url":"https://api.github.com/users/artillery/following{/other_user}","gists_url":"https://api.github.com/users/artillery/gists{/gist_id}","starred_url":"https://api.github.com/users/artillery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artillery/subscriptions","organizations_url":"https://api.github.com/users/artillery/orgs","repos_url":"https://api.github.com/users/artillery/repos","events_url":"https://api.github.com/users/artillery/events{/privacy}","received_events_url":"https://api.github.com/users/artillery/received_events","type":"Organization","site_admin":false},"repo":{"id":22549488,"name":"emscripten","full_name":"artillery/emscripten","owner":{"login":"artillery","id":1179961,"avatar_url":"https://avatars.githubusercontent.com/u/1179961?v=3","gravatar_id":"","url":"https://api.github.com/users/artillery","html_url":"https://github.com/artillery","followers_url":"https://api.github.com/users/artillery/followers","following_url":"https://api.github.com/users/artillery/following{/other_user}","gists_url":"https://api.github.com/users/artillery/gists{/gist_id}","starred_url":"https://api.github.com/users/artillery/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/artillery/subscriptions","organizations_url":"https://api.github.com/users/artillery/orgs","repos_url":"https://api.github.com/users/artillery/repos","events_url":"https://api.github.com/users/artillery/events{/privacy}","received_events_url":"https://api.github.com/users/artillery/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/artillery/emscripten","description":"Emscripten: An LLVM-to-JavaScript Compiler","fork":true,"url":"https://api.github.com/repos/artillery/emscripten","forks_url":"https://api.github.com/repos/artillery/emscripten/forks","keys_url":"https://api.github.com/repos/artillery/emscripten/keys{/key_id}","collaborators_url":"https://api.github.com/repos/artillery/emscripten/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/artillery/emscripten/teams","hooks_url":"https://api.github.com/repos/artillery/emscripten/hooks","issue_events_url":"https://api.github.com/repos/artillery/emscripten/issues/events{/number}","events_url":"https://api.github.com/repos/artillery/emscripten/events","assignees_url":"https://api.github.com/repos/artillery/emscripten/assignees{/user}","branches_url":"https://api.github.com/repos/artillery/emscripten/branches{/branch}","tags_url":"https://api.github.com/repos/artillery/emscripten/tags","blobs_url":"https://api.github.com/repos/artillery/emscripten/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/artillery/emscripten/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/artillery/emscripten/git/refs{/sha}","trees_url":"https://api.github.com/repos/artillery/emscripten/git/trees{/sha}","statuses_url":"https://api.github.com/repos/artillery/emscripten/statuses/{sha}","languages_url":"https://api.github.com/repos/artillery/emscripten/languages","stargazers_url":"https://api.github.com/repos/artillery/emscripten/stargazers","contributors_url":"https://api.github.com/repos/artillery/emscripten/contributors","subscribers_url":"https://api.github.com/repos/artillery/emscripten/subscribers","subscription_url":"https://api.github.com/repos/artillery/emscripten/subscription","commits_url":"https://api.github.com/repos/artillery/emscripten/commits{/sha}","git_commits_url":"https://api.github.com/repos/artillery/emscripten/git/commits{/sha}","comments_url":"https://api.github.com/repos/artillery/emscripten/comments{/number}","issue_comment_url":"https://api.github.com/repos/artillery/emscripten/issues/comments{/number}","contents_url":"https://api.github.com/repos/artillery/emscripten/contents/{+path}","compare_url":"https://api.github.com/repos/artillery/emscripten/compare/{base}...{head}","merges_url":"https://api.github.com/repos/artillery/emscripten/merges","archive_url":"https://api.github.com/repos/artillery/emscripten/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/artillery/emscripten/downloads","issues_url":"https://api.github.com/repos/artillery/emscripten/issues{/number}","pulls_url":"https://api.github.com/repos/artillery/emscripten/pulls{/number}","milestones_url":"https://api.github.com/repos/artillery/emscripten/milestones{/number}","notifications_url":"https://api.github.com/repos/artillery/emscripten/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/artillery/emscripten/labels{/name}","releases_url":"https://api.github.com/repos/artillery/emscripten/releases{/id}","created_at":"2014-08-02T15:58:54Z","updated_at":"2015-04-22T21:11:37Z","pushed_at":"2015-04-22T21:35:39Z","git_url":"git://github.com/artillery/emscripten.git","ssh_url":"git@github.com:artillery/emscripten.git","clone_url":"https://github.com/artillery/emscripten.git","svn_url":"https://github.com/artillery/emscripten","homepage":"","size":125582,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/artillery/emscripten/pulls/1"},"html":{"href":"https://github.com/artillery/emscripten/pull/1"},"issue":{"href":"https://api.github.com/repos/artillery/emscripten/issues/1"},"comments":{"href":"https://api.github.com/repos/artillery/emscripten/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/artillery/emscripten/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/artillery/emscripten/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/artillery/emscripten/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/artillery/emscripten/statuses/62b109a52ce4c2a7c1f7f767aa71bd87f9e35aeb"}}}}