1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-29 16:30:56 -05:00
denoland-deno/ext/node/polyfills/vm.ts
Bartek Iwańczuk b40086fd7d
refactor(core): include_js_files! 'dir' option doesn't change specifiers (#18019)
This commit changes "include_js_files!" macro from "deno_core"
in a way that "dir" option doesn't cause specifiers to be rewritten 
to include it.

Example:
```
include_js_files! {
  dir "js",
  "hello.js",
}
```

The above definition required embedders to use:
`import ... from "internal:<ext_name>/js/hello.js"`. 
But with this change, the "js" directory in which the files are stored
is an implementation detail, which for embedders results in: 
`import ... from "internal:<ext_name>/hello.js"`.

The directory the files are stored in, is an implementation detail and 
in some cases might result in a significant size difference for the 
snapshot. As an example, in "deno_node" extension, we store the 
source code in "polyfills" directory; which resulted in each specifier 
to look like "internal:deno_node/polyfills/<module_name>", but with 
this change it's "internal:deno_node/<module_name>". 

Given that "deno_node" has over 100 files, many of them having 
several import specifiers to the same extension, this change removes
10 characters from each import specifier.
2023-03-05 02:31:38 +00:00

83 lines
1.7 KiB
TypeScript

// Copyright 2018-2023 the Deno authors. All rights reserved. MIT license.
// deno-lint-ignore-file no-explicit-any
import { notImplemented } from "internal:deno_node/_utils.ts";
export class Script {
code: string;
constructor(code: string, _options = {}) {
this.code = `${code}`;
}
runInThisContext(_options: any) {
return eval.call(globalThis, this.code);
}
runInContext(_contextifiedObject: any, _options: any) {
notImplemented("Script.prototype.runInContext");
}
runInNewContext(_contextObject: any, _options: any) {
notImplemented("Script.prototype.runInNewContext");
}
createCachedData() {
notImplemented("Script.prototyp.createCachedData");
}
}
export function createContext(_contextObject: any, _options: any) {
notImplemented("createContext");
}
export function createScript(code: string, options: any) {
return new Script(code, options);
}
export function runInContext(
_code: string,
_contextifiedObject: any,
_options: any,
) {
notImplemented("runInContext");
}
export function runInNewContext(
_code: string,
_contextObject: any,
_options: any,
) {
notImplemented("runInNewContext");
}
export function runInThisContext(
code: string,
options: any,
) {
return createScript(code, options).runInThisContext(options);
}
export function isContext(_maybeContext: any) {
notImplemented("isContext");
}
export function compileFunction(_code: string, _params: any, _options: any) {
notImplemented("compileFunction");
}
export function measureMemory(_options: any) {
notImplemented("measureMemory");
}
export default {
Script,
createContext,
createScript,
runInContext,
runInNewContext,
runInThisContext,
isContext,
compileFunction,
measureMemory,
};