Skip to content

Commit

Permalink
fixup! lib: enable global WebCrypto by default
Browse files Browse the repository at this point in the history
  • Loading branch information
aduh95 committed Feb 23, 2022
1 parent c6e34bc commit 46be211
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 19 deletions.
26 changes: 16 additions & 10 deletions lib/internal/bootstrap/pre_execution.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const {
} = require('internal/util');

const { Buffer } = require('buffer');
const { ERR_MANIFEST_ASSERT_INTEGRITY } = require('internal/errors').codes;
const { ERR_MANIFEST_ASSERT_INTEGRITY, ERR_NO_CRYPTO } = require('internal/errors').codes;
const assert = require('internal/assert');

function prepareMainThreadExecution(expandArgv1 = false) {
Expand Down Expand Up @@ -203,19 +203,25 @@ function setupWebCrypto() {
return;
}

let webcrypto;
ObjectDefineProperty(globalThis, 'crypto',
ObjectGetOwnPropertyDescriptor({
get crypto() {
webcrypto ??= require('internal/crypto/webcrypto');
return webcrypto.crypto;
}
}, 'crypto'));
if (internalBinding('config').hasOpenSSL) {
webcrypto ??= require('internal/crypto/webcrypto');
const webcrypto = require('internal/crypto/webcrypto');
ObjectDefineProperty(globalThis, 'crypto',
ObjectGetOwnPropertyDescriptor({
get crypto() {
return webcrypto.crypto;
}
}, 'crypto'));
exposeInterface(globalThis, 'Crypto', webcrypto.Crypto);
exposeInterface(globalThis, 'CryptoKey', webcrypto.CryptoKey);
exposeInterface(globalThis, 'SubtleCrypto', webcrypto.SubtleCrypto);
} else {
ObjectDefineProperty(globalThis, 'crypto',
ObjectGetOwnPropertyDescriptor({
get crypto() {
throw new ERR_NO_CRYPTO();
}
}, 'crypto'));

}
}

Expand Down
7 changes: 6 additions & 1 deletion test/parallel/test-assert-checktag.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
'use strict';
require('../common');
const common = require('../common');

if (!common.hasCrypto) {
common.skip('missing crypto');
}

const assert = require('assert');

// Disable colored output to prevent color codes from breaking assertion
Expand Down
19 changes: 11 additions & 8 deletions test/parallel/test-bootstrap-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const expectedModules = new Set([
'Internal Binding constants',
'Internal Binding contextify',
'Internal Binding credentials',
'Internal Binding crypto',
'Internal Binding errors',
'Internal Binding fs_dir',
'Internal Binding fs_event_wrap',
Expand Down Expand Up @@ -56,12 +55,6 @@ const expectedModules = new Set([
'NativeModule internal/console/constructor',
'NativeModule internal/console/global',
'NativeModule internal/constants',
'NativeModule internal/crypto/hash',
'NativeModule internal/crypto/hashnames',
'NativeModule internal/crypto/keys',
'NativeModule internal/crypto/random',
'NativeModule internal/crypto/util',
'NativeModule internal/crypto/webcrypto',
'NativeModule internal/dtrace',
'NativeModule internal/encoding',
'NativeModule internal/errors',
Expand Down Expand Up @@ -127,7 +120,6 @@ const expectedModules = new Set([
'NativeModule internal/streams/duplex',
'NativeModule internal/streams/end-of-stream',
'NativeModule internal/streams/from',
'NativeModule internal/streams/lazy_transform',
'NativeModule internal/streams/legacy',
'NativeModule internal/streams/operators',
'NativeModule internal/streams/passthrough',
Expand Down Expand Up @@ -203,6 +195,17 @@ if (common.hasIntl) {
expectedModules.add('NativeModule url');
}

if (common.hasCrypto) {
expectedModules.add('Internal Binding crypto')
.add('NativeModule internal/crypto/hash')
.add('NativeModule internal/crypto/hashnames')
.add('NativeModule internal/crypto/keys')
.add('NativeModule internal/crypto/random')
.add('NativeModule internal/crypto/util')
.add('NativeModule internal/crypto/webcrypto')
.add('NativeModule internal/streams/lazy_transform');
}

if (process.features.inspector) {
expectedModules.add('Internal Binding inspector');
expectedModules.add('NativeModule internal/inspector_async_hook');
Expand Down

0 comments on commit 46be211

Please sign in to comment.