| 1 |
const wasm = require('wasm-bindgen-test.js'); |
| 2 |
const assert = require('assert'); |
| 3 |
|
| 4 |
const ARGUMENT_NAMES = /([^\s,]+)/g; |
| 5 |
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg; |
| 6 |
|
| 7 |
// https://stackoverflow.com/q/1007981/210304 |
| 8 |
function getArgNames(func) { |
| 9 |
let fnStr = func.toString().replace(STRIP_COMMENTS, ''); |
| 10 |
let result = fnStr.slice(fnStr.indexOf('(')+1, fnStr.indexOf(')')).match(ARGUMENT_NAMES); |
| 11 |
return result === null ? [] : result; |
| 12 |
} |
| 13 |
|
| 14 |
exports.js_arg_names = () => { |
| 15 |
assert.deepEqual(getArgNames(wasm.fn_with_many_args), ['_a', '_b', '_c', '_d']); |
| 16 |
}; |