Debian Codegraph @

.cargo/vendor/wasm-bindgen/tests/wasm/imports.js

raw
1 const assert = require('assert');
2 const wasm = require('wasm-bindgen-test');
3 const fs = require('fs');
4
5 let ARG = null;
6 let ANOTHER_ARG = null;
7 let SYM = Symbol('a');
8
9 exports.simple_foo = function(s) {
10 assert.strictEqual(ARG, null);
11 assert.strictEqual(s, "foo");
12 ARG = s;
13 };
14
15 exports.simple_another = function(s) {
16 assert.strictEqual(ANOTHER_ARG, null);
17 assert.strictEqual(s, 21);
18 ANOTHER_ARG = s;
19 return 35;
20 };
21
22 exports.simple_take_and_return_bool = function(s) {
23 return s;
24 };
25 exports.simple_return_object = function() {
26 return SYM;
27 };
28 exports.test_simple = function() {
29 assert.strictEqual(ARG, null);
30 wasm.simple_take_str("foo");
31 assert.strictEqual(ARG, "foo");
32
33 assert.strictEqual(ANOTHER_ARG, null);
34 assert.strictEqual(wasm.simple_another_thunk(21), 35);
35 assert.strictEqual(ANOTHER_ARG, 21);
36
37 assert.strictEqual(wasm.simple_bool_thunk(true), true);
38 assert.strictEqual(wasm.simple_bool_thunk(false), false);
39
40 assert.strictEqual(wasm.simple_get_the_object(), SYM);
41 };
42
43 exports.return_string = function() {
44 return 'bar';
45 };
46
47 exports.take_and_ret_string = function(a) {
48 return a + 'b';
49 };
50
51 exports.exceptions_throw = function() {
52 throw new Error('error!');
53 };
54 exports.exceptions_throw2 = function() {
55 throw new Error('error2');
56 };
57 exports.test_exception_propagates = function() {
58 assert.throws(wasm.exceptions_propagate, /error!/);
59 };
60
61 exports.assert_valid_error = function(obj) {
62 assert.strictEqual(obj instanceof Error, true);
63 assert.strictEqual(obj.message, 'error2');
64 };
65
66 exports.IMPORT = 1.0;
67
68 exports.return_three = function() { return 3; };
69
70 exports.underscore = function(x) {};
71
72 exports.pub = function() { return 2; };
73
74 exports.bar = { foo: 3 };
75
76 let CUSTOM_TYPE = null;
77
78 exports.take_custom_type = function(f) {
79 CUSTOM_TYPE = f;
80 return f;
81 };
82
83 exports.custom_type_return_2 = function() {
84 return 2;
85 };
86
87 exports.touch_custom_type = function() {
88 assert.throws(() => CUSTOM_TYPE.touch(),
89 /Attempt to use a moved value|null pointer passed to rust/);
90 };
91
92 exports.interpret_2_as_custom_type = function() {
93 assert.throws(wasm.interpret_2_as_custom_type, /expected instance of CustomType/);
94 };
95
96 exports.baz$ = function() {};
97 exports.$foo = 1.0;
98
99 exports.assert_dead_import_not_generated = function() {
100 const filename = require.resolve("wasm-bindgen-test");
101 const bindings = fs.readFileSync(filename);
102 assert.ok(!bindings.includes("unused_import"));
103 };
104
105 exports.import_inside_function_works = function() {};
106 exports.import_inside_private_module = function() {};
107 exports.should_call_undefined_functions = () => false;
108
109 exports.STATIC_STRING = 'x';
110
111 class StaticMethodCheck {
112 static static_method_of_right_this() {
113 assert.ok(this === StaticMethodCheck);
114 }
115 }
116
117 exports.StaticMethodCheck = StaticMethodCheck;
118
119 exports.receive_undefined = val => {
120 assert.strictEqual(val, undefined);
121 };
122
123 const VAL = {};
124
125 exports.receive_some = val => {
126 assert.strictEqual(val, VAL);
127 };
128
129 exports.get_some_val = () => VAL;
130
131 exports.Math = {
132 func_from_module_math: (a) => a * 2
133 }
134
135 exports.Number = {
136 func_from_module_number: () => 3.0
137 }
138
139 exports.same_name_from_import = (a) => a * 3;
140
141 exports.same_js_namespace_from_module = {
142 func_from_module_1_same_js_namespace: (a) => a * 5
143 }
144
145 exports["kebab-case"] = () => 42;
146 exports["\"string'literal\nbreakers\r"] = () => 42;