bare-module 3.1.8 → 3.1.10
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.
- package/binding.c +19 -0
- package/index.js +26 -8
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/bare-module.bare +0 -0
- package/prebuilds/darwin-x64/bare-module.bare +0 -0
- package/prebuilds/linux-arm64/bare-module.bare +0 -0
- package/prebuilds/linux-x64/bare-module.bare +0 -0
- package/prebuilds/win32-x64/bare-module.bare +0 -0
package/binding.c
CHANGED
|
@@ -465,6 +465,25 @@ bare_module_run_module (js_env_t *env, js_callback_info_t *info) {
|
|
|
465
465
|
err = js_run_module(env, module, &result);
|
|
466
466
|
if (err < 0) return NULL;
|
|
467
467
|
|
|
468
|
+
bool is_promise;
|
|
469
|
+
err = js_is_promise(env, result, &is_promise);
|
|
470
|
+
assert(err == 0);
|
|
471
|
+
|
|
472
|
+
if (is_promise) {
|
|
473
|
+
js_promise_state_t state;
|
|
474
|
+
err = js_get_promise_state(env, result, &state);
|
|
475
|
+
assert(err == 0);
|
|
476
|
+
|
|
477
|
+
if (state == js_promise_rejected) {
|
|
478
|
+
js_value_t *error;
|
|
479
|
+
err = js_get_promise_result(env, result, &error);
|
|
480
|
+
if (err < 0) return NULL;
|
|
481
|
+
|
|
482
|
+
err = js_set_named_property(env, result, "error", error);
|
|
483
|
+
if (err < 0) return NULL;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
|
|
468
487
|
return result;
|
|
469
488
|
}
|
|
470
489
|
|
package/index.js
CHANGED
|
@@ -162,7 +162,7 @@ const Module = module.exports = exports = class Module {
|
|
|
162
162
|
break
|
|
163
163
|
}
|
|
164
164
|
|
|
165
|
-
case constants.types.MODULE:
|
|
165
|
+
case constants.types.MODULE:
|
|
166
166
|
module._evaluate()
|
|
167
167
|
|
|
168
168
|
for (const name of Object.keys(module._exports)) {
|
|
@@ -170,13 +170,11 @@ const Module = module.exports = exports = class Module {
|
|
|
170
170
|
}
|
|
171
171
|
|
|
172
172
|
break
|
|
173
|
-
}
|
|
174
173
|
|
|
175
|
-
case constants.types.JSON:
|
|
174
|
+
case constants.types.JSON:
|
|
176
175
|
for (const name of Object.keys(module._exports)) {
|
|
177
176
|
names.push(name)
|
|
178
177
|
}
|
|
179
|
-
}
|
|
180
178
|
}
|
|
181
179
|
}
|
|
182
180
|
|
|
@@ -190,12 +188,16 @@ const Module = module.exports = exports = class Module {
|
|
|
190
188
|
|
|
191
189
|
this._state |= constants.states.EVALUATED
|
|
192
190
|
|
|
191
|
+
let result
|
|
192
|
+
|
|
193
193
|
if (this._type === constants.types.SCRIPT) {
|
|
194
194
|
const require = createRequire(this._url, { module: this })
|
|
195
195
|
|
|
196
196
|
this._exports = {}
|
|
197
197
|
|
|
198
|
-
this._function
|
|
198
|
+
const fn = this._function // Bind to variable to ensure proper stack trace
|
|
199
|
+
|
|
200
|
+
fn(
|
|
199
201
|
require,
|
|
200
202
|
this,
|
|
201
203
|
this._exports,
|
|
@@ -203,14 +205,24 @@ const Module = module.exports = exports = class Module {
|
|
|
203
205
|
urlToDirname(this._url)
|
|
204
206
|
)
|
|
205
207
|
|
|
206
|
-
if (eagerRun) binding.runModule(this._handle, Module._handle)
|
|
208
|
+
if (eagerRun) result = binding.runModule(this._handle, Module._handle)
|
|
207
209
|
}
|
|
208
210
|
|
|
209
211
|
if (this._type === constants.types.MODULE) {
|
|
210
|
-
binding.runModule(this._handle, Module._handle)
|
|
212
|
+
result = binding.runModule(this._handle, Module._handle)
|
|
211
213
|
|
|
212
214
|
this._exports = binding.getNamespace(this._handle)
|
|
213
215
|
}
|
|
216
|
+
|
|
217
|
+
if (this._type === constants.types.ADDON) {
|
|
218
|
+
if (eagerRun) result = binding.runModule(this._handle, Module._handle)
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (result && result.error) {
|
|
222
|
+
result.catch(() => {}) // Handle the promise rejection
|
|
223
|
+
|
|
224
|
+
throw result.error
|
|
225
|
+
}
|
|
214
226
|
}
|
|
215
227
|
|
|
216
228
|
[Symbol.for('bare.inspect')] () {
|
|
@@ -387,7 +399,13 @@ const Module = module.exports = exports = class Module {
|
|
|
387
399
|
}
|
|
388
400
|
}
|
|
389
401
|
|
|
390
|
-
|
|
402
|
+
try {
|
|
403
|
+
return module._transform(isImport, isDynamicImport)
|
|
404
|
+
} catch (err) {
|
|
405
|
+
delete cache[url.href]
|
|
406
|
+
|
|
407
|
+
throw err
|
|
408
|
+
}
|
|
391
409
|
}
|
|
392
410
|
|
|
393
411
|
static resolve (specifier, parentURL, opts = {}) {
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|