bare-module 3.1.11 → 3.1.13
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 +16 -5
- package/index.js +33 -21
- 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
|
@@ -442,13 +442,13 @@ static js_value_t *
|
|
|
442
442
|
bare_module_run_module (js_env_t *env, js_callback_info_t *info) {
|
|
443
443
|
int err;
|
|
444
444
|
|
|
445
|
-
size_t argc =
|
|
446
|
-
js_value_t *argv[
|
|
445
|
+
size_t argc = 3;
|
|
446
|
+
js_value_t *argv[3];
|
|
447
447
|
|
|
448
448
|
err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
|
|
449
449
|
assert(err == 0);
|
|
450
450
|
|
|
451
|
-
assert(argc ==
|
|
451
|
+
assert(argc == 3);
|
|
452
452
|
|
|
453
453
|
js_module_t *module;
|
|
454
454
|
err = js_get_value_external(env, argv[0], (void **) &module);
|
|
@@ -479,8 +479,19 @@ bare_module_run_module (js_env_t *env, js_callback_info_t *info) {
|
|
|
479
479
|
err = js_get_promise_result(env, result, &error);
|
|
480
480
|
if (err < 0) return NULL;
|
|
481
481
|
|
|
482
|
-
|
|
483
|
-
|
|
482
|
+
js_value_t *exception;
|
|
483
|
+
err = js_get_and_clear_last_exception(env, &exception);
|
|
484
|
+
assert(err == 0);
|
|
485
|
+
|
|
486
|
+
js_value_t *ctx;
|
|
487
|
+
err = js_get_reference_value(env, context->ctx, &ctx);
|
|
488
|
+
assert(err == 0);
|
|
489
|
+
|
|
490
|
+
js_value_t *args[2] = {result, error};
|
|
491
|
+
|
|
492
|
+
js_call_function(env, ctx, argv[2], 2, args, NULL);
|
|
493
|
+
|
|
494
|
+
return NULL;
|
|
484
495
|
}
|
|
485
496
|
}
|
|
486
497
|
|
package/index.js
CHANGED
|
@@ -132,7 +132,7 @@ const Module = module.exports = exports = class Module {
|
|
|
132
132
|
|
|
133
133
|
if (this._type === constants.types.MODULE) return
|
|
134
134
|
|
|
135
|
-
const names = ['default']
|
|
135
|
+
const names = new Set(['default'])
|
|
136
136
|
const queue = [this]
|
|
137
137
|
const seen = new Set()
|
|
138
138
|
|
|
@@ -147,7 +147,7 @@ const Module = module.exports = exports = class Module {
|
|
|
147
147
|
case constants.types.SCRIPT: {
|
|
148
148
|
const result = parse(module._function.toString())
|
|
149
149
|
|
|
150
|
-
|
|
150
|
+
for (const name of result.exports) names.add(name)
|
|
151
151
|
|
|
152
152
|
const referrer = module
|
|
153
153
|
|
|
@@ -165,31 +165,29 @@ const Module = module.exports = exports = class Module {
|
|
|
165
165
|
case constants.types.MODULE:
|
|
166
166
|
module._evaluate()
|
|
167
167
|
|
|
168
|
-
for (const name of Object.keys(module._exports))
|
|
169
|
-
names.push(name)
|
|
170
|
-
}
|
|
168
|
+
for (const name of Object.keys(module._exports)) names.add(name)
|
|
171
169
|
|
|
172
170
|
break
|
|
173
171
|
|
|
174
172
|
case constants.types.JSON:
|
|
175
|
-
for (const name of Object.keys(module._exports))
|
|
176
|
-
names.push(name)
|
|
177
|
-
}
|
|
173
|
+
for (const name of Object.keys(module._exports)) names.add(name)
|
|
178
174
|
}
|
|
179
175
|
}
|
|
180
176
|
|
|
181
|
-
this._names = names
|
|
177
|
+
this._names = Array.from(names)
|
|
182
178
|
|
|
183
179
|
this._handle = binding.createSyntheticModule(this._url.href, this._names, Module._handle)
|
|
184
180
|
}
|
|
185
181
|
|
|
182
|
+
_run () {
|
|
183
|
+
binding.runModule(this._handle, Module._handle, Module._onrejection)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
186
|
_evaluate (eagerRun = false) {
|
|
187
187
|
if ((this._state & constants.states.EVALUATED) !== 0) return
|
|
188
188
|
|
|
189
189
|
this._state |= constants.states.EVALUATED
|
|
190
190
|
|
|
191
|
-
let result
|
|
192
|
-
|
|
193
191
|
if (this._type === constants.types.SCRIPT) {
|
|
194
192
|
const require = createRequire(this._url, { module: this })
|
|
195
193
|
|
|
@@ -205,23 +203,17 @@ const Module = module.exports = exports = class Module {
|
|
|
205
203
|
urlToDirname(this._url)
|
|
206
204
|
)
|
|
207
205
|
|
|
208
|
-
if (eagerRun)
|
|
206
|
+
if (eagerRun) this._run()
|
|
209
207
|
}
|
|
210
208
|
|
|
211
209
|
if (this._type === constants.types.MODULE) {
|
|
212
|
-
|
|
210
|
+
this._run()
|
|
213
211
|
|
|
214
212
|
this._exports = binding.getNamespace(this._handle)
|
|
215
213
|
}
|
|
216
214
|
|
|
217
215
|
if (this._type === constants.types.ADDON) {
|
|
218
|
-
if (eagerRun)
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
if (result && result.error) {
|
|
222
|
-
result.catch(() => {}) // Handle the promise rejection
|
|
223
|
-
|
|
224
|
-
throw result.error
|
|
216
|
+
if (eagerRun) this._run()
|
|
225
217
|
}
|
|
226
218
|
}
|
|
227
219
|
|
|
@@ -296,7 +288,21 @@ const Module = module.exports = exports = class Module {
|
|
|
296
288
|
module._evaluate()
|
|
297
289
|
|
|
298
290
|
for (const name of module._names) {
|
|
299
|
-
|
|
291
|
+
let value
|
|
292
|
+
|
|
293
|
+
if (
|
|
294
|
+
name === 'default' && (
|
|
295
|
+
typeof module._exports !== 'object' ||
|
|
296
|
+
module._exports === null ||
|
|
297
|
+
name in module._exports === false
|
|
298
|
+
)
|
|
299
|
+
) {
|
|
300
|
+
value = module._exports
|
|
301
|
+
} else {
|
|
302
|
+
value = module._exports[name]
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
binding.setExport(module._handle, name, value)
|
|
300
306
|
}
|
|
301
307
|
}
|
|
302
308
|
|
|
@@ -337,6 +343,12 @@ const Module = module.exports = exports = class Module {
|
|
|
337
343
|
}
|
|
338
344
|
}
|
|
339
345
|
|
|
346
|
+
static _onrejection (promise, err) {
|
|
347
|
+
promise.catch(() => {}) // Don't leak the rejection
|
|
348
|
+
|
|
349
|
+
throw err
|
|
350
|
+
}
|
|
351
|
+
|
|
340
352
|
static Protocol = Protocol
|
|
341
353
|
static Bundle = Bundle
|
|
342
354
|
static constants = constants
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|