{"action":"created","comment":{"url":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/comments/114445784","pull_request_review_id":35911396,"id":114445784,"diff_hunk":"@@ -0,0 +1,256 @@\n+/* Copyright JS Foundation and other contributors, http://js.foundation\n+ *\n+ * Licensed under the Apache License, Version 2.0 (the \"License\");\n+ * you may not use this file except in compliance with the License.\n+ * You may obtain a copy of the License at\n+ *\n+ *     http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+#ifndef JERRYX_ARGS_IMPL_H\n+#define JERRYX_ARGS_IMPL_H\n+\n+/* transform functions for each type. */\n+jerry_value_t jerryx_arg_transform_number_strict (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_number_strict_optional (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_number_optional (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_number (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_boolean_strict (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_boolean_strict_optional (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_boolean_optional (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_boolean (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_string_strict (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_string_strict_optional (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_string_optional (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_string (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_function (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_function_optional (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_constructor (jerryx_arg_iterator_t *iterator_p);\n+jerry_value_t jerryx_arg_transform_constructor_optional (jerryx_arg_iterator_t *iterator_p);","path":"jerry-ext/include/jerryscript-ext/args.impl.h","position":35,"original_position":35,"commit_id":"ef20483c5e5823b0491236ca5c3dd4fe9ddac254","original_commit_id":"ef20483c5e5823b0491236ca5c3dd4fe9ddac254","user":{"login":"akosthekiss","id":9976482,"avatar_url":"https://avatars3.githubusercontent.com/u/9976482?v=3","gravatar_id":"","url":"https://api.github.com/users/akosthekiss","html_url":"https://github.com/akosthekiss","followers_url":"https://api.github.com/users/akosthekiss/followers","following_url":"https://api.github.com/users/akosthekiss/following{/other_user}","gists_url":"https://api.github.com/users/akosthekiss/gists{/gist_id}","starred_url":"https://api.github.com/users/akosthekiss/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/akosthekiss/subscriptions","organizations_url":"https://api.github.com/users/akosthekiss/orgs","repos_url":"https://api.github.com/users/akosthekiss/repos","events_url":"https://api.github.com/users/akosthekiss/events{/privacy}","received_events_url":"https://api.github.com/users/akosthekiss/received_events","type":"User","site_admin":false},"body":"these two functions have no implementation","created_at":"2017-05-02T23:07:17Z","updated_at":"2017-05-02T23:10:22Z","html_url":"https://github.com/jerryscript-project/jerryscript/pull/1740#discussion_r114445784","pull_request_url":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/1740","_links":{"self":{"href":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/comments/114445784"},"html":{"href":"https://github.com/jerryscript-project/jerryscript/pull/1740#discussion_r114445784"},"pull_request":{"href":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/1740"}}},"pull_request":{"url":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/1740","id":116100286,"html_url":"https://github.com/jerryscript-project/jerryscript/pull/1740","diff_url":"https://github.com/jerryscript-project/jerryscript/pull/1740.diff","patch_url":"https://github.com/jerryscript-project/jerryscript/pull/1740.patch","issue_url":"https://api.github.com/repos/jerryscript-project/jerryscript/issues/1740","number":1740,"state":"open","locked":false,"title":"A tool in jerry-ext: arg validator for binding","user":{"login":"jiangzidong","id":15059452,"avatar_url":"https://avatars2.githubusercontent.com/u/15059452?v=3","gravatar_id":"","url":"https://api.github.com/users/jiangzidong","html_url":"https://github.com/jiangzidong","followers_url":"https://api.github.com/users/jiangzidong/followers","following_url":"https://api.github.com/users/jiangzidong/following{/other_user}","gists_url":"https://api.github.com/users/jiangzidong/gists{/gist_id}","starred_url":"https://api.github.com/users/jiangzidong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jiangzidong/subscriptions","organizations_url":"https://api.github.com/users/jiangzidong/orgs","repos_url":"https://api.github.com/users/jiangzidong/repos","events_url":"https://api.github.com/users/jiangzidong/events{/privacy}","received_events_url":"https://api.github.com/users/jiangzidong/received_events","type":"User","site_admin":false},"body":"**Updated on April 23th**\r\n\r\nthe patch is updated by combining review comments:\r\n\r\n* the folder name is jerry-ext, and all types/symbol inside are named by prefix jerryx_\r\n* the header is under jerry-ext/include/jerrycript-ext/xxx\r\n* the codes for args transformer are in jerry-ext/args/xxx\r\n* the unit test codes are in tests/unit-ext/test-ext-xxx\r\n\r\nThe doc is not added yet, since we don't get consensus.\r\n\r\n---\r\n\r\nIt provides some APIs for binding developers, so that\r\nthey can validate the type of the js argument and convert/assign them\r\nto the native argument.\r\n\r\nRelated Issue: #1716\r\n\r\nIt is the first patch of this util, and some **Notes**  are listed below:\r\n\r\n* Usage, the example is in `test/unit-ext/test-ext-args`\r\n```\r\n/**\r\n * The handler should have following arguments:\r\n *   this: Ignore.\r\n *   arg1: Bool.\r\n *   arg2: Number. It must be strict primitive number.\r\n *   arg3: String.\r\n *   arg4: function. It is an optional argument.\r\n *\r\n */\r\nstatic jerry_value_t\r\ntest_validator_handler (const jerry_value_t func_obj_val __attribute__((unused)), /**< function object */\r\n                        const jerry_value_t this_val, /**< this value */\r\n                        const jerry_value_t args_p[], /**< arguments list */\r\n                        const jerry_length_t args_cnt) /**< arguments length */\r\n{\r\n\r\n  bool arg1;\r\n  double arg2 = 0.0;\r\n  char arg3[5];\r\n  jerry_value_t arg4 = jerry_create_undefined ();\r\n\r\n  jerryx_arg_t mapping[] =\r\n  {\r\n    /* ignore this */\r\n    jerryx_arg_ignore (),\r\n    /* 1st argument should be boolean */\r\n    jerryx_arg_boolean (&arg1, JERRY_ARG_CONVERSION_YES, JERRY_ARG_REQUIRED),\r\n    /* 2nd argument should be strict number */\r\n    jerryx_arg_number (&arg2, JERRY_ARG_CONVERSION_NO, JERRY_ARG_REQUIRED),\r\n    /* 3th argument should be string */\r\n    jerryx_arg_string (arg3, 5, JERRY_ARG_CONVERSION_YES, JERRY_ARG_REQUIRED),\r\n    /* 4th argument should be function, and it is optional */\r\n    jerryx_arg_function (&arg4, JERRY_ARG_OPTIONAL)\r\n  };\r\n\r\n  jerry_value_t is_ok = jerryx_validate_and_assign_all (this_val,\r\n                                                        args_p,\r\n                                                        args_cnt,\r\n                                                        mapping,\r\n                                                        5);\r\n```\r\n\r\nWe use functions like `jerry_arg_string`, `jerry_arg_number` to create the jerry_arg_t item for each type.\r\n\r\n* **Dont differentiate specific type of number**, only `double`, which is the return value of `jerry_get_number_value`.  Users should handle the conversion between `double` to any other number types (e.g. int32, uint32, ...) for themselves.\r\n\r\n* `JERRY_ARG_CONVERSION_YES` means the js argument can be automatically invoked by toNumber, toString or toBoolean, i.e. both \"100\" and Number(100) will treated as number 100.\r\n\r\n* `JERRY_ARG_CONVERSION_NO` only accept the primitive type. i.e. neither \"100\" nor Number(100) will be treated as number.\r\n\r\n* `JERRY_ARG_REQUIRED`/`JERRY_ARG_OPTIOANL`  indicated whether the argument is mandatory or or optional. If it is optional, then when the js argument is `undefined`, it will stop the validator/assign but without returning any error.\r\n\r\n* Currently, string with malloc is not supported, it depends on the implementation of `jerry_port_malloc/free`\r\n\r\n* Currently, the error message is quite simple. The detailed error message depends on the `sprintf` in `jerry-libc` ","created_at":"2017-04-17T07:04:01Z","updated_at":"2017-05-02T23:10:22Z","closed_at":null,"merged_at":null,"merge_commit_sha":"520118941cebf8d67608c22186f73997980ac4d5","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/1740/commits","review_comments_url":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/1740/comments","review_comment_url":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jerryscript-project/jerryscript/issues/1740/comments","statuses_url":"https://api.github.com/repos/jerryscript-project/jerryscript/statuses/ef20483c5e5823b0491236ca5c3dd4fe9ddac254","head":{"label":"jiangzidong:argvalidation","ref":"argvalidation","sha":"ef20483c5e5823b0491236ca5c3dd4fe9ddac254","user":{"login":"jiangzidong","id":15059452,"avatar_url":"https://avatars2.githubusercontent.com/u/15059452?v=3","gravatar_id":"","url":"https://api.github.com/users/jiangzidong","html_url":"https://github.com/jiangzidong","followers_url":"https://api.github.com/users/jiangzidong/followers","following_url":"https://api.github.com/users/jiangzidong/following{/other_user}","gists_url":"https://api.github.com/users/jiangzidong/gists{/gist_id}","starred_url":"https://api.github.com/users/jiangzidong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jiangzidong/subscriptions","organizations_url":"https://api.github.com/users/jiangzidong/orgs","repos_url":"https://api.github.com/users/jiangzidong/repos","events_url":"https://api.github.com/users/jiangzidong/events{/privacy}","received_events_url":"https://api.github.com/users/jiangzidong/received_events","type":"User","site_admin":false},"repo":{"id":43999422,"name":"jerryscript","full_name":"jiangzidong/jerryscript","owner":{"login":"jiangzidong","id":15059452,"avatar_url":"https://avatars2.githubusercontent.com/u/15059452?v=3","gravatar_id":"","url":"https://api.github.com/users/jiangzidong","html_url":"https://github.com/jiangzidong","followers_url":"https://api.github.com/users/jiangzidong/followers","following_url":"https://api.github.com/users/jiangzidong/following{/other_user}","gists_url":"https://api.github.com/users/jiangzidong/gists{/gist_id}","starred_url":"https://api.github.com/users/jiangzidong/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jiangzidong/subscriptions","organizations_url":"https://api.github.com/users/jiangzidong/orgs","repos_url":"https://api.github.com/users/jiangzidong/repos","events_url":"https://api.github.com/users/jiangzidong/events{/privacy}","received_events_url":"https://api.github.com/users/jiangzidong/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jiangzidong/jerryscript","description":"Ultra-lightweight JavaScript engine for Internet of Things. http://www.jerryscript.net","fork":true,"url":"https://api.github.com/repos/jiangzidong/jerryscript","forks_url":"https://api.github.com/repos/jiangzidong/jerryscript/forks","keys_url":"https://api.github.com/repos/jiangzidong/jerryscript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jiangzidong/jerryscript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jiangzidong/jerryscript/teams","hooks_url":"https://api.github.com/repos/jiangzidong/jerryscript/hooks","issue_events_url":"https://api.github.com/repos/jiangzidong/jerryscript/issues/events{/number}","events_url":"https://api.github.com/repos/jiangzidong/jerryscript/events","assignees_url":"https://api.github.com/repos/jiangzidong/jerryscript/assignees{/user}","branches_url":"https://api.github.com/repos/jiangzidong/jerryscript/branches{/branch}","tags_url":"https://api.github.com/repos/jiangzidong/jerryscript/tags","blobs_url":"https://api.github.com/repos/jiangzidong/jerryscript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jiangzidong/jerryscript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jiangzidong/jerryscript/git/refs{/sha}","trees_url":"https://api.github.com/repos/jiangzidong/jerryscript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jiangzidong/jerryscript/statuses/{sha}","languages_url":"https://api.github.com/repos/jiangzidong/jerryscript/languages","stargazers_url":"https://api.github.com/repos/jiangzidong/jerryscript/stargazers","contributors_url":"https://api.github.com/repos/jiangzidong/jerryscript/contributors","subscribers_url":"https://api.github.com/repos/jiangzidong/jerryscript/subscribers","subscription_url":"https://api.github.com/repos/jiangzidong/jerryscript/subscription","commits_url":"https://api.github.com/repos/jiangzidong/jerryscript/commits{/sha}","git_commits_url":"https://api.github.com/repos/jiangzidong/jerryscript/git/commits{/sha}","comments_url":"https://api.github.com/repos/jiangzidong/jerryscript/comments{/number}","issue_comment_url":"https://api.github.com/repos/jiangzidong/jerryscript/issues/comments{/number}","contents_url":"https://api.github.com/repos/jiangzidong/jerryscript/contents/{+path}","compare_url":"https://api.github.com/repos/jiangzidong/jerryscript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jiangzidong/jerryscript/merges","archive_url":"https://api.github.com/repos/jiangzidong/jerryscript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jiangzidong/jerryscript/downloads","issues_url":"https://api.github.com/repos/jiangzidong/jerryscript/issues{/number}","pulls_url":"https://api.github.com/repos/jiangzidong/jerryscript/pulls{/number}","milestones_url":"https://api.github.com/repos/jiangzidong/jerryscript/milestones{/number}","notifications_url":"https://api.github.com/repos/jiangzidong/jerryscript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jiangzidong/jerryscript/labels{/name}","releases_url":"https://api.github.com/repos/jiangzidong/jerryscript/releases{/id}","deployments_url":"https://api.github.com/repos/jiangzidong/jerryscript/deployments","created_at":"2015-10-10T07:17:28Z","updated_at":"2016-11-25T06:26:19Z","pushed_at":"2017-05-02T12:38:09Z","git_url":"git://github.com/jiangzidong/jerryscript.git","ssh_url":"git@github.com:jiangzidong/jerryscript.git","clone_url":"https://github.com/jiangzidong/jerryscript.git","svn_url":"https://github.com/jiangzidong/jerryscript","homepage":"","size":13150,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"jerryscript-project:master","ref":"master","sha":"14c455bcd863f0afc7b3a975614ca6bb71a44510","user":{"login":"jerryscript-project","id":23194380,"avatar_url":"https://avatars2.githubusercontent.com/u/23194380?v=3","gravatar_id":"","url":"https://api.github.com/users/jerryscript-project","html_url":"https://github.com/jerryscript-project","followers_url":"https://api.github.com/users/jerryscript-project/followers","following_url":"https://api.github.com/users/jerryscript-project/following{/other_user}","gists_url":"https://api.github.com/users/jerryscript-project/gists{/gist_id}","starred_url":"https://api.github.com/users/jerryscript-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jerryscript-project/subscriptions","organizations_url":"https://api.github.com/users/jerryscript-project/orgs","repos_url":"https://api.github.com/users/jerryscript-project/repos","events_url":"https://api.github.com/users/jerryscript-project/events{/privacy}","received_events_url":"https://api.github.com/users/jerryscript-project/received_events","type":"Organization","site_admin":false},"repo":{"id":33339660,"name":"jerryscript","full_name":"jerryscript-project/jerryscript","owner":{"login":"jerryscript-project","id":23194380,"avatar_url":"https://avatars2.githubusercontent.com/u/23194380?v=3","gravatar_id":"","url":"https://api.github.com/users/jerryscript-project","html_url":"https://github.com/jerryscript-project","followers_url":"https://api.github.com/users/jerryscript-project/followers","following_url":"https://api.github.com/users/jerryscript-project/following{/other_user}","gists_url":"https://api.github.com/users/jerryscript-project/gists{/gist_id}","starred_url":"https://api.github.com/users/jerryscript-project/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jerryscript-project/subscriptions","organizations_url":"https://api.github.com/users/jerryscript-project/orgs","repos_url":"https://api.github.com/users/jerryscript-project/repos","events_url":"https://api.github.com/users/jerryscript-project/events{/privacy}","received_events_url":"https://api.github.com/users/jerryscript-project/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jerryscript-project/jerryscript","description":"Ultra-lightweight JavaScript engine for the Internet of Things.","fork":false,"url":"https://api.github.com/repos/jerryscript-project/jerryscript","forks_url":"https://api.github.com/repos/jerryscript-project/jerryscript/forks","keys_url":"https://api.github.com/repos/jerryscript-project/jerryscript/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jerryscript-project/jerryscript/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jerryscript-project/jerryscript/teams","hooks_url":"https://api.github.com/repos/jerryscript-project/jerryscript/hooks","issue_events_url":"https://api.github.com/repos/jerryscript-project/jerryscript/issues/events{/number}","events_url":"https://api.github.com/repos/jerryscript-project/jerryscript/events","assignees_url":"https://api.github.com/repos/jerryscript-project/jerryscript/assignees{/user}","branches_url":"https://api.github.com/repos/jerryscript-project/jerryscript/branches{/branch}","tags_url":"https://api.github.com/repos/jerryscript-project/jerryscript/tags","blobs_url":"https://api.github.com/repos/jerryscript-project/jerryscript/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jerryscript-project/jerryscript/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jerryscript-project/jerryscript/git/refs{/sha}","trees_url":"https://api.github.com/repos/jerryscript-project/jerryscript/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jerryscript-project/jerryscript/statuses/{sha}","languages_url":"https://api.github.com/repos/jerryscript-project/jerryscript/languages","stargazers_url":"https://api.github.com/repos/jerryscript-project/jerryscript/stargazers","contributors_url":"https://api.github.com/repos/jerryscript-project/jerryscript/contributors","subscribers_url":"https://api.github.com/repos/jerryscript-project/jerryscript/subscribers","subscription_url":"https://api.github.com/repos/jerryscript-project/jerryscript/subscription","commits_url":"https://api.github.com/repos/jerryscript-project/jerryscript/commits{/sha}","git_commits_url":"https://api.github.com/repos/jerryscript-project/jerryscript/git/commits{/sha}","comments_url":"https://api.github.com/repos/jerryscript-project/jerryscript/comments{/number}","issue_comment_url":"https://api.github.com/repos/jerryscript-project/jerryscript/issues/comments{/number}","contents_url":"https://api.github.com/repos/jerryscript-project/jerryscript/contents/{+path}","compare_url":"https://api.github.com/repos/jerryscript-project/jerryscript/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jerryscript-project/jerryscript/merges","archive_url":"https://api.github.com/repos/jerryscript-project/jerryscript/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jerryscript-project/jerryscript/downloads","issues_url":"https://api.github.com/repos/jerryscript-project/jerryscript/issues{/number}","pulls_url":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls{/number}","milestones_url":"https://api.github.com/repos/jerryscript-project/jerryscript/milestones{/number}","notifications_url":"https://api.github.com/repos/jerryscript-project/jerryscript/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jerryscript-project/jerryscript/labels{/name}","releases_url":"https://api.github.com/repos/jerryscript-project/jerryscript/releases{/id}","deployments_url":"https://api.github.com/repos/jerryscript-project/jerryscript/deployments","created_at":"2015-04-03T01:10:31Z","updated_at":"2017-05-02T02:55:54Z","pushed_at":"2017-05-02T15:54:38Z","git_url":"git://github.com/jerryscript-project/jerryscript.git","ssh_url":"git@github.com:jerryscript-project/jerryscript.git","clone_url":"https://github.com/jerryscript-project/jerryscript.git","svn_url":"https://github.com/jerryscript-project/jerryscript","homepage":"http://jerryscript.net","size":28702,"stargazers_count":2256,"watchers_count":2256,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":259,"mirror_url":null,"open_issues_count":36,"forks":259,"open_issues":36,"watchers":2256,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/1740"},"html":{"href":"https://github.com/jerryscript-project/jerryscript/pull/1740"},"issue":{"href":"https://api.github.com/repos/jerryscript-project/jerryscript/issues/1740"},"comments":{"href":"https://api.github.com/repos/jerryscript-project/jerryscript/issues/1740/comments"},"review_comments":{"href":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/1740/comments"},"review_comment":{"href":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/1740/commits"},"statuses":{"href":"https://api.github.com/repos/jerryscript-project/jerryscript/statuses/ef20483c5e5823b0491236ca5c3dd4fe9ddac254"}}}}
{"actor":{"display_login":"akosthekiss"}}