English 中文(简体)
页: 1 数据
原标题:vm.SourceTextModule with cachedData
  • 时间:2024-03-30 14:47:36
  •  标签:
  • node.js
  • v8

新的来源地图图图图图图()和<代码>后选择。

它说: 未具体说明动态进口回升。

但是,<编码>进口模块()选择显然已经存在。

import vm from "vm";

let context = vm.createContext({console})

async function importModuleDynamically(name) {
    let stt = new vm.SyntheticModule([ name ], function () {
        this.setExport( name , name)
    })
    await stt.link(() => null)
    await stt.evaluate()
    return stt
}

function initializeImportMeta(meta, module) {
    meta.url = module.identifier
}

let code =  export default () => import("fs") 
let mod1 = new vm.SourceTextModule(code, {
    context,
    identifier:  mod1 ,
    importModuleDynamically,
    initializeImportMeta
})

let cachedData = mod1.createCachedData()

await mod1.link(() => null)
await mod1.evaluate()
console.log(await mod1.namespace.default())


let mod2 = new vm.SourceTextModule(code, {
    context,
    identifier:  mod1 ,
    cachedData,
    importModuleDynamically,
    initializeImportMeta
})

await mod2.link(() => null)
await mod2.evaluate()
console.log(await mod2.namespace.default())

console.log(mod1, mod2)

一旦设定了<代码>附后Data,即不能再再使用<代码>import(<>/code>?

问题回答

这似乎是<代码>v8的缩略语。 我不知道何时可以确定。

function importModuleDynamically(spec: string, ref: any, attributes: any) {
    if (ref === global) {
        let identifier = new Error().stack!.match(/(file://.+?)(:d+){2}$/m)![1]
        ref = {identifier}
    }
    return linker(spec, ref, {attributes})
}

// it ll fallback when options.cachedData is set
vm.createContext(global, {importModuleDynamically})





相关问题
Where Do I Download TraceMonkey?

I can get the Spidermonkey javascript engine from here: http://www.mozilla.org/js/spidermonkey/ And, I know that Tracemonkey is the newer version released after SpiderMonkey but I cannot find the ...

Executing JavaScript without a browser?

I am looking into Javascript programming without a browser. I want to run scripts from the Linux or Mac OS X command line, much like we run any other scripting language (ruby, php, perl, python...) $ ...

Google Javascript v8 - multithreading

Suppose I have the following piece of code bool run (void) { HandleScope hande_scope; Handle<String> source; Local<Script> script; Persistent<Context> context; ...

Java制发动机

我现在混淆了 Java本发动机。 我知道,第8版是一件大事,因为它将Java文编纂成本地法典。

Confusing operation of JavaScript `var` keyword

I’ve run into a very strange (to me) problem with the var keyword. I’ve reduced it to a fairly minimal test case, and found it’s exhibited in Node.js (thus, V8 and Chrome), Safari 4’s inspector (thus, ...

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

Is it possible to use d8 to measure memory usage?

With the release of the Closure compiler, I was hoping to see if there was a difference in memory usage between a js file using the compiler and one which had not. In particular, on a mobile ...

热门标签