sane-wasm 0.3.1 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Binary file
@@ -27,23 +27,15 @@ if (ENVIRONMENT_IS_NODE) {
27
27
 
28
28
  Object.assign(global, {
29
29
  self: global,
30
- require: require,
31
- Module: Module,
30
+ require,
31
+ Module,
32
32
  location: {
33
33
  href: __filename
34
34
  },
35
35
  Worker: nodeWorkerThreads.Worker,
36
- importScripts: function(f) {
37
- (0, eval)(fs.readFileSync(f, 'utf8') + '//# sourceURL=' + f);
38
- },
39
- postMessage: function(msg) {
40
- parentPort.postMessage(msg);
41
- },
42
- performance: global.performance || {
43
- now: function() {
44
- return Date.now();
45
- }
46
- },
36
+ importScripts: (f) => (0, eval)(fs.readFileSync(f, 'utf8') + '//# sourceURL=' + f),
37
+ postMessage: (msg) => parentPort.postMessage(msg),
38
+ performance: global.performance || { now: Date.now },
47
39
  });
48
40
  }
49
41
 
@@ -65,7 +57,7 @@ function threadPrintErr() {
65
57
  }
66
58
  function threadAlert() {
67
59
  var text = Array.prototype.slice.call(arguments).join(' ');
68
- postMessage({cmd: 'alert', text: text, threadId: Module['_pthread_self']()});
60
+ postMessage({cmd: 'alert', text, threadId: Module['_pthread_self']()});
69
61
  }
70
62
  // We don't need out() for now, but may need to add it if we want to use it
71
63
  // here. Or, if this code all moves into the main JS, that problem will go
@@ -73,6 +65,7 @@ function threadAlert() {
73
65
  var out = () => { throw 'out() is not defined in worker.js.'; }
74
66
  var err = threadPrintErr;
75
67
  self.alert = threadAlert;
68
+ var dbg = threadPrintErr;
76
69
 
77
70
  Module['instantiateWasm'] = (info, receiveInstance) => {
78
71
  // Instantiate from the module posted from the main thread.
@@ -90,7 +83,7 @@ Module['instantiateWasm'] = (info, receiveInstance) => {
90
83
  // Turn unhandled rejected promises into errors so that the main thread will be
91
84
  // notified about them.
92
85
  self.onunhandledrejection = (e) => {
93
- throw e.reason ?? e;
86
+ throw e.reason || e;
94
87
  };
95
88
 
96
89
  function handleMessage(e) {
@@ -120,8 +113,8 @@ function handleMessage(e) {
120
113
  // Use `const` here to ensure that the variable is scoped only to
121
114
  // that iteration, allowing safe reference from a closure.
122
115
  for (const handler of e.data.handlers) {
123
- Module[handler] = function() {
124
- postMessage({ cmd: 'callHandler', handler, args: [...arguments] });
116
+ Module[handler] = (...args) => {
117
+ postMessage({ cmd: 'callHandler', handler, args: args });
125
118
  }
126
119
  }
127
120
 
@@ -143,7 +136,7 @@ function handleMessage(e) {
143
136
  LibSANE(Module);
144
137
  } else if (e.data.cmd === 'run') {
145
138
  // Pass the thread address to wasm to store it for fast access.
146
- Module['__emscripten_thread_init'](e.data.pthread_ptr, /*isMainBrowserThread=*/0, /*isMainRuntimeThread=*/0, /*canBlock=*/1);
139
+ Module['__emscripten_thread_init'](e.data.pthread_ptr, /*is_main=*/0, /*is_runtime=*/0, /*can_block=*/1);
147
140
 
148
141
  // Await mailbox notifications with `Atomics.waitAsync` so we can start
149
142
  // using the fast `Atomics.notify` notification path.
@@ -186,11 +179,11 @@ function handleMessage(e) {
186
179
  // The received message looks like something that should be handled by this message
187
180
  // handler, (since there is a e.data.cmd field present), but is not one of the
188
181
  // recognized commands:
189
- err('worker.js received unknown command ' + e.data.cmd);
182
+ err(`worker.js received unknown command ${e.data.cmd}`);
190
183
  err(e.data);
191
184
  }
192
185
  } catch(ex) {
193
- err('worker.js onmessage() captured an uncaught exception: ' + ex);
186
+ err(`worker.js onmessage() captured an uncaught exception: ${ex}`);
194
187
  if (ex && ex.stack) err(ex.stack);
195
188
  if (Module['__emscripten_thread_crashed']) {
196
189
  Module['__emscripten_thread_crashed']();
@@ -200,5 +193,3 @@ function handleMessage(e) {
200
193
  };
201
194
 
202
195
  self.onmessage = handleMessage;
203
-
204
-
package/dist/index.d.ts CHANGED
@@ -371,9 +371,9 @@ export interface LibSANE {
371
371
  * Equivalent to the SANE API C function `sane_start`.
372
372
  * @see {@link https://sane-project.gitlab.io/standard/1.06/api.html#sane-start}
373
373
  */
374
- sane_start: () => {
374
+ sane_start: () => Promise<{
375
375
  status: SANEStatus;
376
- };
376
+ }>;
377
377
  /**
378
378
  * Equivalent to the SANE API C function `sane_read`.
379
379
  * @see {@link https://sane-project.gitlab.io/standard/1.06/api.html#sane-read}
package/dist/readers.d.ts CHANGED
@@ -52,7 +52,7 @@ export declare class ScanDataReader<T extends ScanDataReaderEventMap = ScanDataR
52
52
  /**
53
53
  * Start scanning operation.
54
54
  */
55
- start(): {
55
+ start(): Promise<{
56
56
  status: SANEStatus.UNSUPPORTED | SANEStatus.CANCELLED | SANEStatus.DEVICE_BUSY | SANEStatus.INVAL | SANEStatus.EOF | SANEStatus.JAMMED | SANEStatus.NO_DOCS | SANEStatus.COVER_OPEN | SANEStatus.IO_ERROR | SANEStatus.NO_MEM | SANEStatus.ACCESS_DENIED;
57
57
  parameters: null;
58
58
  promise: Promise<void>;
@@ -60,7 +60,7 @@ export declare class ScanDataReader<T extends ScanDataReaderEventMap = ScanDataR
60
60
  status: SANEStatus.GOOD;
61
61
  parameters: SANEParameters;
62
62
  promise: Promise<void>;
63
- };
63
+ }>;
64
64
  /**
65
65
  * Cancel scanning operation.
66
66
  */
package/dist/readers.js CHANGED
@@ -136,48 +136,46 @@ class ScanDataReader extends EventBaseClass {
136
136
  * Start scanning operation.
137
137
  */
138
138
  start() {
139
- if (this._used) {
140
- // readers are single use
141
- return {
142
- status: _1.SANEStatus.INVAL,
143
- parameters: null,
144
- promise: Promise.reject(new Error("Scan readers cannot be reused.")),
145
- };
146
- }
147
- else {
148
- const { status } = this._lib.sane_start();
139
+ return __awaiter(this, void 0, void 0, function* () {
140
+ if (this._used) {
141
+ // readers are single use
142
+ throw new Error("Scan readers cannot be reused.");
143
+ }
144
+ else {
145
+ const { status } = yield this._lib.sane_start();
146
+ if (status !== _1.SANEStatus.GOOD) {
147
+ return {
148
+ status,
149
+ parameters: null,
150
+ promise: Promise.reject(new Error(`Status ${_1.SANEStatus[status]} during sane_start().`)),
151
+ };
152
+ }
153
+ this._used = true;
154
+ }
155
+ // after successful start, sane_cancel needs to be called and we need
156
+ // to wait for sane_read, so subsequent fails need to use this._killed
157
+ // and run the read loop
158
+ const { status, parameters } = this._lib.sane_get_parameters();
149
159
  if (status !== _1.SANEStatus.GOOD) {
160
+ this._killed = new Error(`Status ${_1.SANEStatus[status]} during sane_get_parameters().`);
150
161
  return {
151
- status,
152
- parameters: null,
153
- promise: Promise.reject(new Error(`Status ${_1.SANEStatus[status]} during sane_start().`)),
162
+ status, parameters,
163
+ promise: this._readPromise(parameters),
154
164
  };
155
165
  }
156
- this._used = true;
157
- }
158
- // after successful start, sane_cancel needs to be called and we need
159
- // to wait for sane_read, so subsequent fails need to use this._killed
160
- // and run the read loop
161
- const { status, parameters } = this._lib.sane_get_parameters();
162
- if (status !== _1.SANEStatus.GOOD) {
163
- this._killed = new Error(`Status ${_1.SANEStatus[status]} during sane_get_parameters().`);
166
+ try {
167
+ this.fire('start', parameters);
168
+ }
169
+ catch (e) {
170
+ this._killed = e instanceof Error ? e : new Error("Unknown error while starting the scan.");
171
+ }
164
172
  return {
165
173
  status, parameters,
166
- promise: this._readPromise(parameters),
174
+ promise: this._readPromise(parameters).finally(() => {
175
+ this.fire('stop', parameters, this._killed instanceof Error ? this._killed : null);
176
+ }),
167
177
  };
168
- }
169
- try {
170
- this.fire('start', parameters);
171
- }
172
- catch (e) {
173
- this._killed = e instanceof Error ? e : new Error("Unknown error while starting the scan.");
174
- }
175
- return {
176
- status, parameters,
177
- promise: this._readPromise(parameters).finally(() => {
178
- this.fire('stop', parameters, this._killed instanceof Error ? this._killed : null);
179
- }),
180
- };
178
+ });
181
179
  }
182
180
  /**
183
181
  * Cancel scanning operation.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sane-wasm",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "A project to bring the SANE API to the web.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",