{"action":"created","issue":{"url":"https://api.github.com/repos/jerryscript-project/jerryscript/issues/1740","repository_url":"https://api.github.com/repos/jerryscript-project/jerryscript","labels_url":"https://api.github.com/repos/jerryscript-project/jerryscript/issues/1740/labels{/name}","comments_url":"https://api.github.com/repos/jerryscript-project/jerryscript/issues/1740/comments","events_url":"https://api.github.com/repos/jerryscript-project/jerryscript/issues/1740/events","html_url":"https://github.com/jerryscript-project/jerryscript/pull/1740","id":222079672,"number":1740,"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},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":36,"created_at":"2017-04-17T07:04:01Z","updated_at":"2017-05-03T07:23:42Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/jerryscript-project/jerryscript/pulls/1740","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"},"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` "},"comment":{"url":"https://api.github.com/repos/jerryscript-project/jerryscript/issues/comments/298839782","html_url":"https://github.com/jerryscript-project/jerryscript/pull/1740#issuecomment-298839782","issue_url":"https://api.github.com/repos/jerryscript-project/jerryscript/issues/1740","id":298839782,"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},"created_at":"2017-05-03T07:23:42Z","updated_at":"2017-05-03T07:23:42Z","body":"I'd suggest squashing the current 4 commits and rebasing to latest master on the next update so that we can get a better look at the PR status."}}
{"actor":{"display_login":"akosthekiss"}}