summaryrefslogtreecommitdiff
path: root/ext/node/polyfills/vm.ts
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-12-11 12:38:45 +0530
committerGitHub <noreply@github.com>2023-12-11 07:08:45 +0000
commit02e138dca9c9fd79f47d352114b45b21dbb2b2ba (patch)
tree396fce46b544635ecec93a0c7592d570e48474cb /ext/node/polyfills/vm.ts
parent0bee37a5e24048cbf92c1b56efd0c65deaea1418 (diff)
fix(ext/node): basic vm.runInNewContext implementation (#21527)
Simple implementation to support webpack (& Next.js): https://github.com/webpack/webpack/blob/87660921808566ef3b8796f8df61bd79fc026108/lib/javascript/JavascriptParser.js#L4329
Diffstat (limited to 'ext/node/polyfills/vm.ts')
-rw-r--r--ext/node/polyfills/vm.ts21
1 files changed, 15 insertions, 6 deletions
diff --git a/ext/node/polyfills/vm.ts b/ext/node/polyfills/vm.ts
index 39cd1ce36..45c67526e 100644
--- a/ext/node/polyfills/vm.ts
+++ b/ext/node/polyfills/vm.ts
@@ -6,6 +6,7 @@
import { notImplemented } from "ext:deno_node/_utils.ts";
const { core } = globalThis.__bootstrap;
+const ops = core.ops;
export class Script {
code: string;
@@ -25,8 +26,13 @@ export class Script {
notImplemented("Script.prototype.runInContext");
}
- runInNewContext(_contextObject: any, _options: any) {
- notImplemented("Script.prototype.runInNewContext");
+ runInNewContext(contextObject: any, options: any) {
+ if (options) {
+ console.warn(
+ "Script.runInNewContext options are currently not supported",
+ );
+ }
+ return ops.op_vm_run_in_new_context(this.code, contextObject);
}
createCachedData() {
@@ -51,11 +57,14 @@ export function runInContext(
}
export function runInNewContext(
- _code: string,
- _contextObject: any,
- _options: any,
+ code: string,
+ contextObject: any,
+ options: any,
) {
- notImplemented("runInNewContext");
+ if (options) {
+ console.warn("vm.runInNewContext options are currently not supported");
+ }
+ return ops.op_vm_run_in_new_context(code, contextObject);
}
export function runInThisContext(