I wrote a unit test to try, but there are some problems with the result
import { getQuickJS, QuickJSVm } from 'quickjs-emscripten'
import { withScope } from '../withScope'
describe('测试 deleteKey', () => {
let vm: QuickJSVm = undefined as any
beforeEach(async () => {
const quickJS = await getQuickJS()
vm = quickJS.createVm()
})
afterEach(() => {
vm.dispose()
vm = undefined as any
})
it('基本示例', () => {
withScope(vm, (vm) => {
vm.setProp(vm.global, 'name', vm.newString('liuli'))
const deleteProperty = vm.unwrapResult(
vm.evalCode('Reflect.deleteProperty'),
)
expect(vm.dump(vm.getProp(vm.global, 'name'))).toBe('liuli')
vm.callFunction(
deleteProperty,
vm.unwrapResult(vm.evalCode('globalThis')),
vm.newString('name'),
) // Not deleted here
console.log(vm.dump(vm.getProp(vm.global, 'name')))
vm.evalCode(`Reflect.deleteProperty(globalThis, 'name')`) // This step really takes effect, but I want to do it from the main process
console.log(vm.dump(vm.getProp(vm.global, 'name')))
}).dispose()
})
})
I wrote a unit test to try, but there are some problems with the result