mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 1239060 - add exports hook in loader r=zer0
This commit is contained in:
parent
50ce69640f
commit
85b15a21a0
@ -283,7 +283,7 @@ Loader.evaluate = evaluate;
|
||||
// Populates `exports` of the given CommonJS `module` object, in the context
|
||||
// of the given `loader` by evaluating code associated with it.
|
||||
const load = iced(function load(loader, module) {
|
||||
let { sandboxes, globals } = loader;
|
||||
let { sandboxes, globals, loadModuleHook } = loader;
|
||||
let require = Require(loader, module);
|
||||
|
||||
// We expose set of properties defined by `CommonJS` specification via
|
||||
@ -368,6 +368,10 @@ const load = iced(function load(loader, module) {
|
||||
});
|
||||
}
|
||||
|
||||
if(loadModuleHook) {
|
||||
module = loadModuleHook(module, require);
|
||||
}
|
||||
|
||||
if (loader.checkCompatibility) {
|
||||
let err = XulApp.incompatibility(module);
|
||||
if (err) {
|
||||
@ -588,7 +592,7 @@ const Require = iced(function Require(loader, requirer) {
|
||||
let {
|
||||
modules, mapping, resolve: loaderResolve, load,
|
||||
manifest, rootURI, isNative, requireMap,
|
||||
overrideRequire
|
||||
requireHook
|
||||
} = loader;
|
||||
|
||||
function require(id) {
|
||||
@ -596,8 +600,8 @@ const Require = iced(function Require(loader, requirer) {
|
||||
throw Error('You must provide a module name when calling require() from '
|
||||
+ requirer.id, requirer.uri);
|
||||
|
||||
if (overrideRequire) {
|
||||
return overrideRequire(id, _require);
|
||||
if (requireHook) {
|
||||
return requireHook(id, _require);
|
||||
}
|
||||
|
||||
return _require(id);
|
||||
@ -930,7 +934,8 @@ function Loader(options) {
|
||||
value: options.invisibleToDebugger || false },
|
||||
load: { enumerable: false, value: options.load || load },
|
||||
checkCompatibility: { enumerable: false, value: checkCompatibility },
|
||||
overrideRequire: { enumerable: false, value: options.require },
|
||||
requireHook: { enumerable: false, value: options.requireHook },
|
||||
loadModuleHook: { enumerable: false, value: options.loadModuleHook },
|
||||
// Main (entry point) module, it can be set only once, since loader
|
||||
// instance can have only one main module.
|
||||
main: new function() {
|
||||
|
@ -572,7 +572,7 @@ exports['test user global'] = function(assert) {
|
||||
exports['test custom require caching'] = function(assert) {
|
||||
const loader = Loader({
|
||||
paths: { '': root + "/" },
|
||||
require: (id, require) => {
|
||||
requireHook: (id, require) => {
|
||||
// Just load it normally
|
||||
return require(id);
|
||||
}
|
||||
@ -594,7 +594,7 @@ exports['test caching when proxying a loader'] = function(assert) {
|
||||
const parentRequire = require;
|
||||
const loader = Loader({
|
||||
paths: { '': root + "/" },
|
||||
require: (id, childRequire) => {
|
||||
requireHook: (id, childRequire) => {
|
||||
if(id === 'gimmejson') {
|
||||
return childRequire('fixtures/loader/json/mutation.json')
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ function BrowserLoader(baseURI, window) {
|
||||
sandboxPrototype: window,
|
||||
paths: Object.assign({}, dynamicPaths, loaderOptions.paths),
|
||||
invisibleToDebugger: loaderOptions.invisibleToDebugger,
|
||||
require: (id, require) => {
|
||||
requireHook: (id, require) => {
|
||||
const uri = require.resolve(id);
|
||||
const isBrowserDir = BROWSER_BASED_DIRS.filter(dir => {
|
||||
return uri.startsWith(dir);
|
||||
|
Loading…
Reference in New Issue
Block a user