Files
YouTube.js/src/platform/jsruntime/jinter.ts
absidue 142a7d0428 fix(Player): Fix extracting the n-token decipher algorithm (#682)
* fix(Player): Fix extracting the n-token decipher algorithm

* fix: bump Jinter to v2

---------

Co-authored-by: Luan <luan.lrt4@gmail.com>
2024-07-10 02:21:39 -03:00

21 lines
523 B
TypeScript

import { Jinter } from 'jintr';
import type { VMPrimative } from '../../types/PlatformShim.js';
import { Log } from '../lib.js';
const TAG = 'JsRuntime';
export default function evaluate(code: string, env: Record<string, VMPrimative>) {
Log.debug(TAG, 'Evaluating JavaScript:\n', code);
const runtime = new Jinter();
for (const [ key, value ] of Object.entries(env)) {
runtime.scope.set(key, value);
}
const result = runtime.evaluate(code);
Log.debug(TAG, 'Done. Result:', result);
return result;
}