summaryrefslogtreecommitdiffstats
path: root/vendor/wasm-bindgen/tests/wasm/arg_names.js
blob: 255604b3e945192110f5a3018c4ac7139ecf16ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
const wasm = require('wasm-bindgen-test.js');
const assert = require('assert');

const ARGUMENT_NAMES = /([^\s,]+)/g;
const STRIP_COMMENTS = /((\/\/.*$)|(\/\*[\s\S]*?\*\/))/mg;

// https://stackoverflow.com/q/1007981/210304
function getArgNames(func) {
    let fnStr = func.toString().replace(STRIP_COMMENTS, '');
    let result = fnStr.slice(fnStr.indexOf('(')+1, fnStr.indexOf(')')).match(ARGUMENT_NAMES);
    return result === null ? [] : result;
}

exports.js_arg_names = () => {
    assert.deepEqual(getArgNames(wasm.fn_with_many_args), ['_a', '_b', '_c', '_d']);
};