summaryrefslogtreecommitdiffstats
path: root/vendor/wasm-bindgen/tests/wasm/arg_names.js
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/wasm-bindgen/tests/wasm/arg_names.js')
-rw-r--r--vendor/wasm-bindgen/tests/wasm/arg_names.js16
1 files changed, 16 insertions, 0 deletions
diff --git a/vendor/wasm-bindgen/tests/wasm/arg_names.js b/vendor/wasm-bindgen/tests/wasm/arg_names.js
new file mode 100644
index 000000000..255604b3e
--- /dev/null
+++ b/vendor/wasm-bindgen/tests/wasm/arg_names.js
@@ -0,0 +1,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']);
+};