当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript vm.runInThisContext函数代码示例

本文整理汇总了TypeScript中vm.runInThisContext函数的典型用法代码示例。如果您正苦于以下问题:TypeScript runInThisContext函数的具体用法?TypeScript runInThisContext怎么用?TypeScript runInThisContext使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了runInThisContext函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: load

function load(Class:String) {
    var fs = require("fs"), vm = require("vm");
    if(Class.substr(Class.length-3) != ".js") Class += ".js";
    var script = fs.readFileSync(Class, "utf-8");
    var node = node;
    vm.runInThisContext(script, Class);
};
开发者ID:jariz,项目名称:PlatformerEngine,代码行数:7,代码来源:Loader.ts

示例2: callback

const evalCommand: repl.REPLEval = (
  cmd: string,
  _context: any,
  _filename: string,
  callback: (e: Error | null, result?: any) => void,
) => {
  let result;
  try {
    if (transformer) {
      const transformResult = transformer.process(
        cmd,
        jestGlobalConfig.replname || 'jest.js',
        jestProjectConfig,
      );
      cmd =
        typeof transformResult === 'string'
          ? transformResult
          : transformResult.code;
    }
    result = vm.runInThisContext(cmd);
  } catch (e) {
    return callback(isRecoverableError(e) ? new repl.Recoverable(e) : e);
  }
  return callback(null, result);
};
开发者ID:Volune,项目名称:jest,代码行数:25,代码来源:repl.ts

示例3: loadScript

 loadScript: function loadScript(filename: string) {
     let fullPath = path.join(visPath, filename);
     let data = fs.readFileSync(fullPath);
     // TODO: try to enable this again once https://github.com/electron/electron/pull/7909 is merged
    /* if (vm.isContext(sandbox)) {
         vm.runInContext(data, sandbox, { filename });
     } else {*/
         vm.runInThisContext(data, {filename});
    // }
 }
开发者ID:michaelbromley,项目名称:skqw,代码行数:10,代码来源:skqw-core.ts

示例4: function

const runContentScript = function (this: any, extensionId: string, url: string, code: string) {
  const context: { chrome?: any } = {}
  require('@electron/internal/renderer/chrome-api').injectTo(extensionId, false, context)
  const wrapper = `((chrome) => {\n  ${code}\n  })`
  const compiledWrapper = runInThisContext(wrapper, {
    filename: url,
    lineOffset: 1,
    displayErrors: true
  })
  return compiledWrapper.call(this, context.chrome)
}
开发者ID:vwvww,项目名称:electron,代码行数:11,代码来源:content-scripts-injector.ts

示例5:

const getExportsFromCodeString = (codeString: string): Object => {
  const module = {
    exports: {},
  };

  const code = `(function(require, module, exports) {
      ${codeString}
  })`;

  vm.runInThisContext(code, {
    filename: `${process.cwd()}/fixtures/index.js`,
  })(require, module, module.exports);

  return module.exports;
};
开发者ID:morlay,项目名称:babel-plugin-webpack-loaders-inline-exports,代码行数:15,代码来源:getExportsFromCodeString.ts

示例6:

        getTsBinPathWithLoad = (): string => {
            var typeScriptBinPath = _path.dirname(require.resolve("typescript")),
                typeScriptPath = _path.resolve(typeScriptBinPath, "typescript.js"),
                code: string;

            if (!typeScriptBinPath) {
                grunt.fail.warn("typescript.js not found. please 'npm install typescript'.");
                return "";
            }

            code = grunt.file.read(typeScriptPath);
            _vm.runInThisContext(code, typeScriptPath);

            return typeScriptBinPath;
        },
开发者ID:aaronryden,项目名称:grunt-typescript,代码行数:15,代码来源:index.ts

示例7: function

        loadTypeScript = function(){
            var typeScriptBinPath = _path.dirname(require.resolve("typescript")), //resolveTypeScriptBinPath(currentPath, 0),
                typeScriptPath = _path.resolve(typeScriptBinPath, "typescript.js"),
                code;

            if (!typeScriptBinPath) {
                grunt.fail.warn("typescript.js not found. please 'npm install typescript'.");
                return false;
            }

            code = grunt.file.read(typeScriptPath);
            _vm.runInThisContext(code, typeScriptPath);

            return typeScriptBinPath;
        };
开发者ID:nakalsio,项目名称:grunt-typescript,代码行数:15,代码来源:task.ts

示例8: getAPI

const runContentScript = (url: string, code: string, manifest: Manifest) => {
  const context = getAPI(manifest);

  const wrapper = `((wexond) => {
    var chrome = wexond;
    var browser = wexond;
    ${code}
  });`;

  const compiledWrapper = runInThisContext(wrapper, {
    filename: url,
    lineOffset: 1,
    displayErrors: true,
  });

  return compiledWrapper.call(window, context);
};
开发者ID:laquereric,项目名称:wexond,代码行数:17,代码来源:webview-preload.ts

示例9: internalEval

export function internalEval (source: string, include, isGlobalCtx: boolean = false) {
    let module = currentModule;

    global.include = include;
    global.require = global.require;
    global.exports = module.exports;
    global.__filename = path_getFile(include.url);
    global.__dirname = path_getDir(global.__filename);
    global.module = module;

    if (isGlobalCtx !== true) {
        source = '(function(){ ' + source + '\n}())';
    }

    try {
        if (!isGlobalCtx) {
            let filename = global.__filename
            module = currentModule = new Module(filename, module);
            module.paths = (Module as any)._nodeModulePaths(path_getDir(filename));
            module.filename = filename;
            (module as any)._compile(source, filename);
            module.loaded = true;
        }

        else {
            module.exports = {};
            vm.runInThisContext(source, global.__filename);
        }

    } catch(e) {
        console.error('Module Evaluation Error', include.url);
        console.error(e.stack);
    }

    if (isEmpty(include.exports)) {
        var exports = module.exports;

        if (typeof exports !== 'object' || isEmpty(exports) === false) {
            include.exports = module.exports;
        }
    }
};
开发者ID:atmajs,项目名称:IncludeJS,代码行数:42,代码来源:eval.ts


注:本文中的vm.runInThisContext函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。