Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[js] Refactor src/vm/js/nqp-runtime/global-context.js
- Loading branch information
Showing
9 changed files
with
87 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,76 @@ | ||
'use strict'; | ||
|
||
class GlobalContext { | ||
constructor() { | ||
this.restore = []; | ||
this.save = []; | ||
} | ||
}; | ||
this.save = []; | ||
|
||
module.exports.context = new GlobalContext(); | ||
// Serialization context properties. | ||
this.scs = new Map(); | ||
this.compilingSCs = []; | ||
this.scwbDisableDepth = 0; | ||
this.neverRepossess = new WeakSet(); | ||
|
||
const initialization = []; | ||
// HLL properties. | ||
this.hllSyms = new Map(); | ||
this.hllConfigs = new Map(); | ||
this.compilerRegistry = new Map(); | ||
|
||
module.exports.initialize = function(setup) { | ||
setup(module.exports.context); | ||
initialization.push(setup); | ||
}; | ||
|
||
module.exports.freshGlobalContext = function(setup) { | ||
const old = module.exports.context; | ||
|
||
for (const save of old.save) { | ||
save(old); | ||
// Runtime properties. | ||
this.loadedCache = new WeakMap(); | ||
} | ||
} | ||
|
||
module.exports.context = new GlobalContext(); | ||
class GlobalContextWrapper { | ||
constructor() { | ||
this.context = new GlobalContext(); | ||
this.initialization = []; | ||
} | ||
|
||
for (const setup of initialization) { | ||
setup(module.exports.context); | ||
initialize(setup) { | ||
setup(this.context); | ||
this.initialization.push(setup); | ||
} | ||
|
||
return old; | ||
}; | ||
freshGlobalContext(setup) { | ||
const old = this.context; | ||
for (const save of old.save) { | ||
save(old); | ||
} | ||
|
||
module.exports.setGlobalContext = function(context) { | ||
const old = module.exports.context; | ||
this.context = new GlobalContext(); | ||
for (const setup of this.initialization) { | ||
setup(this.context); | ||
} | ||
|
||
for (const save of old.save) { | ||
save(old); | ||
return old; | ||
} | ||
|
||
module.exports.context = context; | ||
setGlobalContext(context) { | ||
const old = this.context; | ||
for (const save of old.save) { | ||
save(old); | ||
} | ||
|
||
for (const action of context.restore) { | ||
action(context); | ||
this.context = context; | ||
for (const action of this.context.restore) { | ||
action(this.context); | ||
} | ||
|
||
return old; | ||
} | ||
|
||
return old; | ||
}; | ||
restoreThisGlobalContext(callback) { | ||
callback(this.context); | ||
this.context.restore.push(callback); | ||
} | ||
|
||
module.exports.restoreThisGlobalContext = function(callback) { | ||
callback(module.exports.context); | ||
module.exports.context.restore.push(callback); | ||
}; | ||
saveThisGlobalContext(callback) { | ||
callback(this.context); | ||
this.context.save.push(callback); | ||
} | ||
|
||
module.exports.saveThisGlobalContext = function(callback) { | ||
callback(module.exports.context); | ||
module.exports.context.save.push(callback); | ||
// Think about compiling SCs. | ||
}; | ||
|
||
// Think about compilingSCs | ||
module.exports = new GlobalContextWrapper(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters