Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Data Callback
Comlink.proxy(
this._processDataCallback.bind(this, {
commandOptionIndex,
sync: false
})
),
// End Callback
Comlink.proxy(
this._processEndCallback.bind(this, {
commandOptionIndex,
processWorker
})
),
// Error Callback
Comlink.proxy(
this._processErrorCallback.bind(this, { commandOptionIndex })
),
// Shared Array Bufer
sharedStdinBuffer,
// Stdin read callback
Comlink.proxy(this._processStartStdinReadCallback.bind(this))
);
// Initialize the shared Stdin.
// Index 0 will be number of elements in buffer
const sharedStdin = new Int32Array(sharedStdinBuffer);
sharedStdin[0] = -1;
return {
process,
commandOptionIndex,
),
// End Callback
Comlink.proxy(
this._processEndCallback.bind(this, {
commandOptionIndex,
processWorker
})
),
// Error Callback
Comlink.proxy(
this._processErrorCallback.bind(this, { commandOptionIndex })
),
// Shared Array Bufer
sharedStdinBuffer,
// Stdin read callback
Comlink.proxy(this._processStartStdinReadCallback.bind(this))
);
// Initialize the shared Stdin.
// Index 0 will be number of elements in buffer
const sharedStdin = new Int32Array(sharedStdinBuffer);
sharedStdin[0] = -1;
return {
process,
commandOptionIndex,
worker: processWorker,
sharedStdin: sharedStdin
};
}
if (
commandOptionIndex <
this.commandOptionsForProcessesToRun.length - 1
) {
// Try to spawn the next process, if we haven't already
this.tryToSpawnProcess(commandOptionIndex + 1);
} else {
// We are now done!
// Call the passed end callback
this.isRunning = false;
this.endCallback();
}
}),
// Error Callback
Comlink.proxy((error: string) => {
this.xterm.write(
`Program ${this.commandOptionsForProcessesToRun[commandOptionIndex].args[0]}: ${error}\r\n`
);
this.kill();
this.endCallback();
}),
// Stdin
this.initialStdinDataForNextProcess.length > 0
? this.initialStdinDataForNextProcess
: undefined,
// Binary Script (Fallback case)
this.isUsingFallback ? binaryenScript : undefined
);
// Remove the initial stdin if we added it
if (this.initialStdinDataForNextProcess.length > 0) {
const sharedStdinBuffer = new SharedArrayBuffer(8192);
// Get our filesystem state
const wasmFsJson = this.wasmTerminalConfig.wasmFs.toJSON();
// Create our Io Device Window
const ioDeviceWindow = new IoDeviceWindow();
// @ts-ignore
const process: any = await new processComlink(
// Command Options
this.commandOptionsForProcessesToRun[commandOptionIndex],
// WasmFs File System JSON
wasmFsJson,
// Data Callback
Comlink.proxy(
this._processDataCallback.bind(this, {
commandOptionIndex,
sync: false
})
),
// End Callback
Comlink.proxy(
this._processEndCallback.bind(this, {
commandOptionIndex,
processWorker
})
),
// Error Callback
Comlink.proxy(
this._processErrorCallback.bind(this, { commandOptionIndex })
),
// Data Callback
Comlink.proxy(
this._processDataCallback.bind(this, {
commandOptionIndex,
sync: false
})
),
// End Callback
Comlink.proxy(
this._processEndCallback.bind(this, {
commandOptionIndex,
processWorker
})
),
// Error Callback
Comlink.proxy(
this._processErrorCallback.bind(this, { commandOptionIndex })
),
// Io Device Window
Comlink.proxy(ioDeviceWindow),
// Shared Array Bufer
sharedStdinBuffer,
// Stdin read callback
Comlink.proxy(this._processStartStdinReadCallback.bind(this))
);
// Initialize the shared Stdin.
// Index 0 will be number of elements in buffer
const sharedStdin = new Int32Array(sharedStdinBuffer);
sharedStdin[0] = -1;
return {
// @ts-ignore
const process: any = await new processComlink(
// Command Options
this.commandOptionsForProcessesToRun[commandOptionIndex],
// WasmFs File System JSON
wasmFsJson,
// Data Callback
Comlink.proxy(
this._processDataCallback.bind(this, {
commandOptionIndex,
sync: false
})
),
// End Callback
Comlink.proxy(
this._processEndCallback.bind(this, {
commandOptionIndex,
processWorker
})
),
// Error Callback
Comlink.proxy(
this._processErrorCallback.bind(this, { commandOptionIndex })
),
// Io Device Window
Comlink.proxy(ioDeviceWindow),
// Shared Array Bufer
sharedStdinBuffer,
// Stdin read callback
Comlink.proxy(this._processStartStdinReadCallback.bind(this))
);
// @ts-ignore
const process: any = await new processComlink(
// Command Options
this.commandOptionsForProcessesToRun[commandOptionIndex],
// WasmFs File System JSON
wasmFsJson,
// Data Callback
Comlink.proxy(
this._processDataCallback.bind(this, {
commandOptionIndex,
sync: false
})
),
// End Callback
Comlink.proxy(
this._processEndCallback.bind(this, {
commandOptionIndex,
processWorker
})
),
// Error Callback
Comlink.proxy(
this._processErrorCallback.bind(this, { commandOptionIndex })
),
// Shared Array Bufer
sharedStdinBuffer,
// Stdin read callback
Comlink.proxy(this._processStartStdinReadCallback.bind(this))
);
// Initialize the shared Stdin.
this._connectionStateChanged.next({
type: 'progress',
message: 'Creating VM...',
progress: 0.2,
});
const wrapper = wrap(this._channel.port1);
this._proxy = await new wrapper(
location.origin,
this._initialUser,
this._config
);
let statusMapper = remapProgressPercent(0.2, 1);
return await this._proxy.init(
proxy(events => this._localEvents.next(events)),
proxy(events => this._deviceEvents.next(events)),
proxy(state => this._stateUpdated.next(state)),
proxy(state =>
this._connectionStateChanged.next(statusMapper(state))
),
proxy(err => this._onError.next(err))
);
}
async init(): Promise {
const proxies = [
proxy((bots: Bot[]) => this._handleOnBotsAdded(bots)),
proxy((bots: string[]) => this._handleOnBotsRemoved(bots)),
proxy((bots: UpdatedBot[]) => this._handleOnBotsUpdated(bots)),
proxy((error: any) => this._onError.next(error)),
proxy((events: DeviceAction[]) => this._onEvents.next(events)),
proxy((status: StatusUpdate) => this._onStatusUpdated.next(status)),
] as const;
this._proxies = proxies;
await this._bridge.addListeners(...proxies);
}
const setup = new Link().then(async (thread: PenumbraWorkerAPI) => {
await thread.setup(proxy(reDispatchEvent));
});
await setup;