Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@miniflare/runner-vm

Package Overview
Dependencies
Maintainers
1
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@miniflare/runner-vm - npm Package Compare versions

Comparing version 2.0.0-rc.5 to 2.0.0

20

dist/src/index.d.ts

@@ -12,24 +12,10 @@ /// <reference types="node" />

export declare function makeProxiedGlobals(blockCodeGeneration?: boolean): {
Object: ObjectConstructor;
Array: ArrayConstructor;
Promise: PromiseConstructor;
RegExp: RegExpConstructor;
Error: ErrorConstructor;
EvalError: EvalErrorConstructor;
RangeError: RangeErrorConstructor;
ReferenceError: ReferenceErrorConstructor;
SyntaxError: SyntaxErrorConstructor;
TypeError: TypeErrorConstructor;
URIError: URIErrorConstructor;
Function: FunctionConstructor;
};
export declare function defineHasInstances(ctx: vm.Context): void;
export declare class VMScriptRunner implements ScriptRunner {
private context?;
private blockCodeGeneration;
constructor(context?: vm.Context | undefined, blockCodeGeneration?: boolean);
constructor(context?: vm.Context | undefined);
private runAsScript;
private runAsModule;
run(globalScope: Context, blueprint: ScriptBlueprint, modulesRules?: ProcessedModuleRule[], additionalModules?: AdditionalModules, proxyPrimitiveInstanceOf?: boolean): Promise<ScriptRunnerResult>;
run(globalScope: Context, blueprint: ScriptBlueprint, modulesRules?: ProcessedModuleRule[], additionalModules?: AdditionalModules): Promise<ScriptRunnerResult>;
}

@@ -36,0 +22,0 @@

146

dist/src/index.js

@@ -29,5 +29,5 @@ var __create = Object.create;

VMScriptRunnerError: () => VMScriptRunnerError,
makeProxiedGlobals: () => makeProxiedGlobals
defineHasInstances: () => defineHasInstances
});
var import_vm2 = __toModule(require("vm"));
var import_vm3 = __toModule(require("vm"));

@@ -39,2 +39,52 @@ // packages/runner-vm/src/error.ts

// packages/runner-vm/src/instanceof.ts
var import_util = __toModule(require("util"));
var import_vm = __toModule(require("vm"));
function isObject(value) {
return value !== null && typeof value === "object";
}
function isFunction(value) {
return typeof value === "function";
}
function isError(errorCtor) {
const name = errorCtor.prototype.name;
return function(value) {
if (!import_util.default.types.isNativeError(value))
return false;
let prototype = value;
while ((prototype = Object.getPrototypeOf(prototype)) !== null) {
if (prototype.name === name)
return true;
}
return false;
};
}
var types = {
isObject,
isFunction,
isArray: Array.isArray,
isPromise: import_util.default.types.isPromise,
isRegExp: import_util.default.types.isRegExp,
isError
};
var defineHasInstancesScript = new import_vm.default.Script(`(function(types) {
// Only define properties once, will throw if we try doing this twice
if (Object[Symbol.hasInstance] === types.isObject) return;
Object.defineProperty(Object, Symbol.hasInstance, { value: types.isObject });
Object.defineProperty(Function, Symbol.hasInstance, { value: types.isFunction });
Object.defineProperty(Array, Symbol.hasInstance, { value: types.isArray });
Object.defineProperty(Promise, Symbol.hasInstance, { value: types.isPromise });
Object.defineProperty(RegExp, Symbol.hasInstance, { value: types.isRegExp });
Object.defineProperty(Error, Symbol.hasInstance, { value: types.isError(Error) });
Object.defineProperty(EvalError, Symbol.hasInstance, { value: types.isError(EvalError) });
Object.defineProperty(RangeError, Symbol.hasInstance, { value: types.isError(RangeError) });
Object.defineProperty(ReferenceError, Symbol.hasInstance, { value: types.isError(ReferenceError) });
Object.defineProperty(SyntaxError, Symbol.hasInstance, { value: types.isError(SyntaxError) });
Object.defineProperty(TypeError, Symbol.hasInstance, { value: types.isError(TypeError) });
Object.defineProperty(URIError, Symbol.hasInstance, { value: types.isError(URIError) });
})`, { filename: "<defineHasInstancesScript>" });
function defineHasInstances(ctx) {
defineHasInstancesScript.runInContext(ctx)(types);
}
// packages/runner-vm/src/linker.ts

@@ -44,3 +94,3 @@ var import_fs = __toModule(require("fs"));

var import_path = __toModule(require("path"));
var import_vm = __toModule(require("vm"));
var import_vm2 = __toModule(require("vm"));
var import_shared2 = __toModule(require("@miniflare/shared"));

@@ -78,3 +128,3 @@ var SUGGEST_BUNDLE = "If you're trying to import an npm package, you'll need to bundle your Worker first.";

if (additionalModule) {
module2 = new import_vm.default.SyntheticModule(Object.keys(additionalModule), function() {
module2 = new import_vm2.default.SyntheticModule(Object.keys(additionalModule), function() {
for (const [key, value] of Object.entries(additionalModule)) {

@@ -97,7 +147,7 @@ this.setExport(key, value);

case "ESModule":
module2 = new import_vm.default.SourceTextModule(data.toString("utf8"), moduleOptions);
module2 = new import_vm2.default.SourceTextModule(data.toString("utf8"), moduleOptions);
break;
case "CommonJS":
const exports = this.loadCommonJSModule(errorBase, identifier, spec, referencing.context);
module2 = new import_vm.default.SyntheticModule(["default"], function() {
module2 = new import_vm2.default.SyntheticModule(["default"], function() {
this.setExport("default", exports);

@@ -107,3 +157,3 @@ }, moduleOptions);

case "Text":
module2 = new import_vm.default.SyntheticModule(["default"], function() {
module2 = new import_vm2.default.SyntheticModule(["default"], function() {
this.setExport("default", data.toString("utf8"));

@@ -113,3 +163,3 @@ }, moduleOptions);

case "Data":
module2 = new import_vm.default.SyntheticModule(["default"], function() {
module2 = new import_vm2.default.SyntheticModule(["default"], function() {
this.setExport("default", (0, import_shared2.viewToBuffer)(data));

@@ -119,3 +169,3 @@ }, moduleOptions);

case "CompiledWasm":
module2 = new import_vm.default.SyntheticModule(["default"], function() {
module2 = new import_vm2.default.SyntheticModule(["default"], function() {
this.setExport("default", new WebAssembly.Module(data));

@@ -158,3 +208,3 @@ }, moduleOptions);

});`;
const script = new import_vm.default.Script(wrapped, {
const script = new import_vm2.default.Script(wrapped, {
filename: identifier,

@@ -192,64 +242,9 @@ lineOffset: -1

// packages/runner-vm/src/proxied.ts
var import_util = __toModule(require("util"));
function isObject(value) {
return value !== null && typeof value === "object";
}
function isFunction(value) {
return typeof value === "function";
}
function isError(errorCtor) {
const name = errorCtor.prototype.name;
return function(value) {
if (!import_util.types.isNativeError(value))
return false;
let prototype = value;
while ((prototype = Object.getPrototypeOf(prototype)) !== null) {
if (prototype.name === name)
return true;
}
return false;
};
}
function proxyHasInstance(target, hasInstance, handler) {
return new Proxy(target, {
get(target2, property, receiver) {
if (property === Symbol.hasInstance)
return hasInstance;
return Reflect.get(target2, property, receiver);
},
...handler
});
}
function makeProxiedGlobals(blockCodeGeneration) {
if (!blockCodeGeneration)
blockCodeGeneration = void 0;
return {
Object: proxyHasInstance(Object, isObject),
Array: proxyHasInstance(Array, Array.isArray),
Promise: proxyHasInstance(Promise, import_util.types.isPromise),
RegExp: proxyHasInstance(RegExp, import_util.types.isRegExp),
Error: proxyHasInstance(Error, isError(Error)),
EvalError: proxyHasInstance(EvalError, isError(EvalError)),
RangeError: proxyHasInstance(RangeError, isError(RangeError)),
ReferenceError: proxyHasInstance(ReferenceError, isError(ReferenceError)),
SyntaxError: proxyHasInstance(SyntaxError, isError(SyntaxError)),
TypeError: proxyHasInstance(TypeError, isError(TypeError)),
URIError: proxyHasInstance(URIError, isError(URIError)),
Function: proxyHasInstance(Function, isFunction, blockCodeGeneration && {
construct() {
throw new EvalError("Code generation from strings disallowed for this context");
}
})
};
}
// packages/runner-vm/src/index.ts
var VMScriptRunner = class {
constructor(context, blockCodeGeneration = true) {
constructor(context) {
this.context = context;
this.blockCodeGeneration = blockCodeGeneration;
}
runAsScript(context, blueprint) {
const script = new import_vm2.default.Script(blueprint.code, {
const script = new import_vm3.default.Script(blueprint.code, {
filename: blueprint.filePath

@@ -260,3 +255,3 @@ });

async runAsModule(context, blueprint, linker) {
const module2 = new import_vm2.default.SourceTextModule(blueprint.code, {
const module2 = new import_vm3.default.SourceTextModule(blueprint.code, {
identifier: blueprint.filePath,

@@ -269,10 +264,7 @@ context

}
async run(globalScope, blueprint, modulesRules, additionalModules, proxyPrimitiveInstanceOf = false) {
if (modulesRules && !("SourceTextModule" in import_vm2.default)) {
async run(globalScope, blueprint, modulesRules, additionalModules) {
if (modulesRules && !("SourceTextModule" in import_vm3.default)) {
throw new VMScriptRunnerError("ERR_MODULE_DISABLED", "Modules support requires the --experimental-vm-modules flag");
}
const linker = modulesRules && new ModuleLinker(modulesRules, additionalModules ?? {});
if (proxyPrimitiveInstanceOf) {
Object.assign(globalScope, makeProxiedGlobals(this.blockCodeGeneration));
}
let context = this.context;

@@ -282,7 +274,7 @@ if (context) {

} else {
const allow = !this.blockCodeGeneration;
context = import_vm2.default.createContext(globalScope, {
codeGeneration: { strings: allow, wasm: allow }
context = import_vm3.default.createContext(globalScope, {
codeGeneration: { strings: false, wasm: false }
});
}
defineHasInstances(context);
let exports = {};

@@ -306,4 +298,4 @@ let bundleSize = 0;

VMScriptRunnerError,
makeProxiedGlobals
defineHasInstances
});
//# sourceMappingURL=index.js.map
{
"name": "@miniflare/runner-vm",
"version": "2.0.0-rc.5",
"version": "2.0.0",
"description": "VM script runner module for Miniflare: a fun, full-featured, fully-local simulator for Cloudflare Workers",

@@ -38,7 +38,7 @@ "keywords": [

"dependencies": {
"@miniflare/shared": "2.0.0-rc.5"
"@miniflare/shared": "2.0.0"
},
"devDependencies": {
"@miniflare/shared-test": "2.0.0-rc.5"
"@miniflare/shared-test": "2.0.0"
}
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc