Skip to content

Commit

Permalink
fix: Add isSecureContext endowment (#2893)
Browse files Browse the repository at this point in the history
Adds `isSecureContext` for the browser environments, this will continue
to be undefined in the Node.js environment.

Fixes #2890
  • Loading branch information
FrederikBolding authored Nov 19, 2024
1 parent 5052aaa commit a645d0d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const commonEndowments: CommonEndowmentSpecification[] = [
{ endowment: Int8Array, name: 'Int8Array' },
{ endowment: Int16Array, name: 'Int16Array' },
{ endowment: Int32Array, name: 'Int32Array' },
{ endowment: globalThis.isSecureContext, name: 'isSecureContext' },
{ endowment: Uint8Array, name: 'Uint8Array' },
{ endowment: Uint8ClampedArray, name: 'Uint8ClampedArray' },
{ endowment: Uint16Array, name: 'Uint16Array' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ describe('endowments', () => {
factory: () => WebAssembly,
},

// Properties
isSecureContext: {
endowments: { isSecureContext: globalThis.isSecureContext },
factory: () => globalThis.isSecureContext,
},

// Functions.
atob: {
endowments: { atob },
Expand Down Expand Up @@ -358,6 +364,10 @@ describe('endowments', () => {
factory: expect.any(Function),
names: ['Int32Array'],
},
{
factory: expect.any(Function),
names: ['isSecureContext'],
},
{
factory: expect.any(Function),
names: ['Uint8Array'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ describe('getEndowments', () => {
"Int16Array",
"Uint16Array",
"Int32Array",
"isSecureContext",
"Uint32Array",
"Float32Array",
"Float64Array",
Expand Down
1 change: 1 addition & 0 deletions packages/snaps-utils/src/default-endowments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const DEFAULT_ENDOWMENTS: readonly string[] = Object.freeze([
'Int16Array',
'Uint16Array',
'Int32Array',
'isSecureContext',
'Uint32Array',
'Float32Array',
'Float64Array',
Expand Down

0 comments on commit a645d0d

Please sign in to comment.