Move test VM crypto definition (#1584)

This commit is contained in:
toasted-nutbread 2021-04-02 12:43:37 -04:00 committed by GitHub
parent 8179846e38
commit 28fa3fa795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 10 deletions

View File

@ -150,6 +150,13 @@ class VM {
constructor(context={}) {
this._urlMap = new Map();
context.URL = createURLClass(this._urlMap);
context.crypto = {
getRandomValues: (array) => {
const buffer = crypto.randomBytes(array.byteLength);
buffer.copy(array);
return array;
}
};
this._context = vm.createContext(context);
this._assert = {
deepStrictEqual

View File

@ -16,19 +16,10 @@
*/
const assert = require('assert');
const crypto = require('crypto');
const {testMain} = require('../dev/util');
const {VM} = require('../dev/vm');
const vm = new VM({
crypto: {
getRandomValues: (array) => {
const buffer = crypto.randomBytes(array.byteLength);
buffer.copy(array);
return array;
}
}
});
const vm = new VM();
vm.execute([
'js/core.js'
]);