MCPcopy Create free account
hub / github.com/Kong/insomnia / installConsole

Function installConsole

packages/insomnia/src/scripting/quickjs-script-engine.ts:217–229  ·  view source on GitHub ↗
(vm: QuickJSContext, scriptConsole: Console)

Source from the content-addressed store, hash-verified

215`;
216
217const installConsole = (vm: QuickJSContext, scriptConsole: Console): void => {
218 const consoleHandle = vm.newObject();
219 (['log', 'warn', 'error', 'info', 'debug'] as const).forEach(level => {
220 const fn = vm.newFunction(level, (...argHandles: QuickJSHandle[]) => {
221 const values = argHandles.map(handle => vm.dump(handle));
222 scriptConsole[level](...values);
223 });
224 vm.setProp(consoleHandle, level, fn);
225 fn.dispose();
226 });
227 vm.setProp(vm.global, 'console', consoleHandle);
228 consoleHandle.dispose();
229};
230
231// Using one of these as a bracket-assignment key on a plain object rewires its prototype or
232// shadows the name instead of setting an ordinary property.

Callers 1

runScriptInQuickJsFunction · 0.85

Calls 1

mapMethod · 0.80

Tested by

no test coverage detected