Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

transcontextual safe type checks #864

Merged
merged 3 commits into from
Mar 28, 2023
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
6 changes: 3 additions & 3 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ function mergeFunctionArgs (argv, start, end) {
const handlers = []

for (let i = start; i < end; i++) {
if (argv[i] instanceof Array) {
if (Array.isArray(argv[i])) {
const arr = argv[i]
for (let j = 0; j < arr.length; j++) {
if (!(arr[j] instanceof Function)) {
if (typeof arr[j] !== 'function') {
throw new TypeError('Invalid argument type: ' + typeof (arr[j]))
}
handlers.push(arr[j])
}
} else if (argv[i] instanceof Function) {
} else if (typeof argv[i] === 'function') {
handlers.push(argv[i])
} else {
throw new TypeError('Invalid argument type: ' + typeof (argv[i]))
Expand Down
14 changes: 14 additions & 0 deletions test/server.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
const net = require('net')
const tap = require('tap')
const vasync = require('vasync')
const vm = require('node:vm')
const { getSock } = require('./utils')
const ldap = require('../lib')

Expand Down Expand Up @@ -434,3 +435,16 @@ tap.test('multithreading support via hook', function (t) {
})
})
})

tap.test('cross-realm type checks', function (t) {
const server = ldap.createServer()
const ctx = vm.createContext({})
vm.runInContext(
'globalThis.search=function(){};\n' +
'globalThis.searches=[function(){}];'
, ctx)
server.search('', ctx.search)
server.search('', ctx.searches)
t.ok(server)
t.end()
})