• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript vm.runInThisContext函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript vm.Script类代码示例发布时间:2022-05-25
下一篇:
TypeScript vm.runInNewContext函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap