當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。