Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

167
Views
ejecutar document.querySelector no devuelve ningún resultado cuando se ejecuta desde el nodo vm a través de browserify

Tengo REPL de JavaScript . He preguntado antes ¿Cómo crear REPL de JavaScript que funcione con let y const? . Pude resolver mi problema con el módulo VM Node que está integrado en browserify y node-falafel (JS AST transformer).

El REPL funciona bien, pero tengo problema al evaluar:

 document.querySelectorAll('div');

La máquina virtual devuelve una lista de nodos vacía. Pero si llamo a jQuery $('div') obtengo todos los divs de la página.

Parte relevante del código:

 // before script tags: var window_names = Object.getOwnPropertyNames(window); function globals() { return Object.fromEntries(window_names.map(name => { const value = window[name]; return [name, value]; })); } const context = { __$$__: {}, ...globals(), // the same is with window here $, console: { log(...args) { console.log(...args); term.echo(args.map(repr).join(' ')); } } }; function unset(context, name) { delete context[name]; } // main interpreter funtion function exec(code, ctx = context) { ctx = {...ctx}; code = patch(code, ctx) return vm.runInNewContext(code, ctx); } function is_scoped(name, context) { return name in context.__$$__; } function patch(code, context) { let patching = []; let result = falafel(code, function(node) { if (node.type == 'VariableDeclaration') { node.declarations.forEach(declaration => { const name = declaration.id.name; if (is_scoped(name, context)) { unset(context, name); } patching.push(`__$$__.${name} = ${name}`); }); } else if (node.type === 'Identifier' && is_scoped(node.name, context) && node.parent.type !== 'VariableDeclarator') { const name = node.name; node.update(`__$$__.${name}`); } }); result = result.toString(); if (patching.length) { result += ';' + patching.join(';'); } return result; }

¿Alguien sabe por qué document.querySelector no funciona en vm.runInNewContext?

Solo para estar seguro de que estaba probando usando un documento fuera de contexto:

 var x = document x.querySelectorAll('div');

pero, por supuesto, el documento no es una función, por lo que no tiene su propio contexto como objeto de ventana. Entonces, ¿por qué no funciona?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!