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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ part of the same npm package, while the package root remains WinRT-only. See
[Classic COM support](docs/architecture/classic-com-support.md) for the supported ABI,
common-interface test matrix, unsupported native types, and ownership rules.
See [Classic COM JavaScript usage](docs/guides/windows/classic-com-usage.md) for codegen,
GUID/IID/CLSID, lifecycle, Automation, and explicit unsafe ABI examples.
GUID/IID/CLSID, lifecycle, generated same-thread event sinks, Automation, and explicit unsafe ABI
examples.

Generated bindings project unambiguous public WinRT activation metadata as JavaScript
constructors, including overloads such as `new Uri(base, relative)`. Existing
Expand Down
32 changes: 32 additions & 0 deletions bindings/js/__test__/tsfn-com-sink-exception-child.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
import { registerTestComSinkInterface } from './tsfn-com-sink-helpers.mjs'

const runtime = createRequire(import.meta.url)(process.env.DYNWINRT_TEST_RUNTIME)
let observed
process.once('uncaughtException', (error) => {
observed = error
})

const sink = runtime.DynCom.createIUnknownSink(registerTestComSinkInterface(runtime), () => {
throw new Error('COM sink callback failure')
})
runtime.tsfnTestRetainComSink(sink)
assert.equal(runtime.tsfnTestRegisteredHandleCount(), 1)

const hr = runtime.tsfnTestInvokeRetainedComSink()
assert.equal(hr, 0x80004005 | 0)
runtime.tsfnTestReleaseRetainedComSink()
sink.release()

const deadline = Date.now() + 2_000
while ((observed === undefined || runtime.tsfnTestRegisteredHandleCount() !== 0) && Date.now() < deadline) {
await new Promise((resolve) => setTimeout(resolve, 5))
}

assert.equal(observed?.message, 'COM sink callback failure')
assert.equal(runtime.tsfnTestRegisteredHandleCount(), 0)
console.log(`com-sink-uncaught:${observed.message};hr:${hr}`)
18 changes: 18 additions & 0 deletions bindings/js/__test__/tsfn-com-sink-helpers.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

export function registerTestComSinkInterface(runtime, withOutput = false) {
const iid = runtime.WinGuid.parse('7ac2eaa2-97a4-43f0-9b0f-421c2363ef11')
const interfaceType = runtime.DynCom.interfaceType(runtime.WinGuid.parse('00000000-0000-0000-c000-000000000046'))
let signature = new runtime.DynComMethodSig().addIn(interfaceType)
if (withOutput) {
signature = signature.addIn(interfaceType).addOut(runtime.DynCom.i32Type())
}
return runtime.DynCom.registerIUnknownInterface('Tests.IComSink', iid).addMethodAt(3, 'Invoke', signature)
}

export function registerTestComI32SinkInterface(runtime) {
const iid = runtime.WinGuid.parse('7ac2eaa2-97a4-43f0-9b0f-421c2363ef11')
const signature = new runtime.DynComMethodSig().addIn(runtime.DynCom.i32Type())
return runtime.DynCom.registerIUnknownInterface('Tests.IComI32Sink', iid).addMethodAt(3, 'Invoke', signature)
}
23 changes: 23 additions & 0 deletions bindings/js/__test__/tsfn-worker-com-sink-child.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
import { Worker } from 'node:worker_threads'

const runtimePath = process.env.DYNWINRT_TEST_RUNTIME
const runtime = createRequire(import.meta.url)(runtimePath)
const worker = new Worker(new URL('./tsfn-worker-com-sink-worker.mjs', import.meta.url), {
workerData: { runtimePath },
})

await new Promise((resolve, reject) => {
worker.once('message', resolve)
worker.once('error', reject)
})
await worker.terminate()

const hr = runtime.tsfnTestInvokeRetainedComSink()
console.log(`late-com-sink-hr:${hr}`)
assert.equal(hr, 0x8001010e | 0)
runtime.tsfnTestReleaseRetainedComSink()
13 changes: 13 additions & 0 deletions bindings/js/__test__/tsfn-worker-com-sink-worker.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { createRequire } from 'node:module'
import { parentPort, workerData } from 'node:worker_threads'
import { registerTestComSinkInterface } from './tsfn-com-sink-helpers.mjs'

const runtime = createRequire(import.meta.url)(workerData.runtimePath)
const sink = runtime.DynCom.createIUnknownSink(registerTestComSinkInterface(runtime), () => 0)
runtime.tsfnTestRetainComSink(sink)
parentPort.postMessage('retained')

Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 5_000)
Loading
Loading