Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ jobs:
if ($result.eligible_interfaces -ne 7929) {
throw "Classic COM census denominator changed: $($result.eligible_interfaces)"
}
if ($result.complete_interfaces -lt 5560) {
if ($result.complete_interfaces -lt 5567) {
throw "Classic COM complete coverage regressed: $($result.complete_interfaces)"
}
if ($result.coverage_percent -lt 70.0) {
Expand Down
13 changes: 12 additions & 1 deletion bindings/js/__test__/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import test from 'ava'
import { spawn, spawnSync } from 'node:child_process'
import { existsSync } from 'node:fs'
import { existsSync, readFileSync } from 'node:fs'
import { createRequire } from 'node:module'
import { resolve } from 'node:path'
import { fileURLToPath } from 'node:url'
Expand Down Expand Up @@ -113,12 +113,14 @@ test('package facades exactly partition native exports', (t) => {
const expectedWinrt = nativeKeys.filter((name) => !name.startsWith('DynCom') && name !== 'initializeCom')
const safeComNames = new Set([
'DynComDispatchParams',
'DynComAllocation',
'DynComExcepInfo',
'DynComNativeStruct',
'DynComNativeStructArray',
'DynComNativeUnion',
'DynComPropVariant',
'DynComSafeArray',
'DynComStatStg',
'DynComVariant',
'DynWinRtValue',
'WinGuid',
Expand Down Expand Up @@ -157,6 +159,15 @@ test('package facades exactly partition native exports', (t) => {
}
})

test('COM allocation declaration is opaque and non-constructible', (t) => {
const declaration = readFileSync(
fileURLToPath(new URL('../dist/com.d.ts', import.meta.url)),
'utf8',
)
t.regex(declaration, /export interface DynComAllocation/)
t.notRegex(declaration, /export \{[^}]*DynComAllocation[^}]*\} from/)
})

test('WinRT root facade exposes usable native primitives', (t) => {
t.truthy(winrtRuntime.DynWinRtType.i32())
t.is(winrtRuntime.DynWinRtValue.i32(1).toNumber(), 1)
Expand Down
34 changes: 31 additions & 3 deletions bindings/js/scripts/generate-entrypoints.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,34 @@ if (nativeExports.length === 0) {

const comExports = new Set([
'DynComDispatchParams',
'DynComAllocation',
'DynComExcepInfo',
'DynComNativeStruct',
'DynComNativeStructArray',
'DynComNativeUnion',
'DynComPropVariant',
'DynComSafeArray',
'DynComStatStg',
'DynComVariant',
'DynWinRtValue',
'WinGuid',
'initializeCom',
])
const comTypeAliases = ['DynWinRTValue', 'WinGUID']
const comTypeExports = [...comExports, ...comTypeAliases, 'DynComSafeArrayBound']
const opaqueComTypes = new Set(['DynComAllocation'])
const comTypeExports = [
...[...comExports].filter((name) => !opaqueComTypes.has(name)),
...comTypeAliases,
'DynComSafeArrayBound',
]
const opaqueComDeclarations = [
'declare const dynComAllocationBrand: unique symbol',
'export interface DynComAllocation {',
' readonly [dynComAllocationBrand]: never',
' readonly released: boolean',
' release(): void',
'}',
]
const comUnsafeExports = new Set([
...comExports,
'DynCom',
Expand All @@ -42,7 +57,11 @@ const comUnsafeExports = new Set([
'DynComUnsafe',
'DynComUnsafeInterface',
])
const comUnsafeTypeExports = [...comUnsafeExports, ...comTypeAliases, 'DynComSafeArrayBound']
const comUnsafeTypeExports = [
...[...comUnsafeExports].filter((name) => !opaqueComTypes.has(name)),
...comTypeAliases,
'DynComSafeArrayBound',
]

writeFacade(
'winrt',
Expand All @@ -53,15 +72,23 @@ writeFacade(
nativeExports.filter((name) => comExports.has(name)),
comTypeExports,
comExports,
opaqueComDeclarations,
)
writeFacade(
'com-unsafe',
nativeExports.filter((name) => comUnsafeExports.has(name)),
comUnsafeTypeExports,
comUnsafeExports,
opaqueComDeclarations,
)

function writeFacade(name, exports, typeExports = exports, requiredExports = []) {
function writeFacade(
name,
exports,
typeExports = exports,
requiredExports = [],
extraTypeDeclarations = [],
) {
const missing = [...requiredExports].filter((value) => !exports.includes(value))
if (missing.length > 0) {
throw new Error(`Missing required ${name} exports: ${missing.join(', ')}`)
Expand All @@ -77,6 +104,7 @@ function writeFacade(name, exports, typeExports = exports, requiredExports = [])
const dts = [
'// Generated by scripts/generate-entrypoints.mjs - do not edit',
`export { ${typeExports.join(', ')} } from './index.js'`,
...extraTypeDeclarations,
'',
].join('\n')

Expand Down
Loading
Loading