import.meta in any non-builtin module fails with "uncaught exception: undefined" (module_metadata_hook returns false without an exception)

Abierto Apto para principiantes
#355 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
78/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
c, javascript, wasm
Área
backend

Línea de trabajo

Empieza en runtime/script_loader.cpp, en module_metadata_hook, donde el issue identifica la devolución de false para los módulos ordinarios como la causa. Revisa las pruebas de carga de módulos y añade un caso de regresión que evalúe typeof import.meta en un módulo de usuario. El issue está resuelto cuando la evaluación de módulos ordinarios tiene éxito y el caso de regresión pasa; los módulos integrados deben conservar su comportamiento de import.meta.builtin.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Summary

Evaluating import.meta in a user module aborts the module with an uncatchable error, because the module metadata
hook returns false without setting an exception. try/catch around it does not help. In a ComponentizeJS component
the exported function traps.

Environment

  • StarlingMonkey v0.4.0 release starling.wasm, wasmtime 50.0.1, module mode (wasmtime run -S http --dir . starling.wasm main.js).
  • runtime/script_loader.cpp is unchanged on main (54b3329b).
  • Also seen with @bytecodealliance/componentize-js 0.23.0.
  • Checked on 2026-11-03. Reference: SpiderMonkey jsshell 147.0.4 (the SpiderMonkey version StarlingMonkey v0.4.0 embeds), js -m.

Reproduction

// main.js
console.log(typeof import.meta);
console.log(import.meta.url);

StarlingMonkey:

Exception while evaluating top-level script
uncaught exception: undefined
Additionally, some promises were rejected, but the rejection never handled:
Promise rejected but never handled: (void 0)

jsshell prints object and the module's location. The same failure happens in an imported (non-entry) module, and
when the access is wrapped in try { … } catch (e) { … }: neither the catch block nor the code after it runs.

ComponentizeJS 0.23.0:

export function run() {
  try { return typeof import.meta + " " + import.meta.url; } catch (e) { return "threw " + e; }
}

wasmtime run -S http --invoke 'run()' component.wasm prints uncaught exception: undefined and the instance traps
(wasm 'unreachable' instruction executed).

test262: language/expressions/import.meta/same-object-returned.js and import-meta-is-an-ordinary-object.js fail
the same way.

Expected

import.meta is an ordinary object and evaluating it does not throw
(spec). The host hooks
HostGetImportMetaProperties and
HostFinalizeImportMeta return a List / nothing, not a
completion, so they cannot fail. Hosts may add properties such as url.

Cause

runtime/script_loader.cpp:

bool module_metadata_hook(JSContext *cx, HandleValue ref_priv, HandleObject meta_obj) {
  ...
  RootedValue builtin_val(cx);
  if (!MapGet(cx, builtinModules, parent_id_val, &builtin_val)) {
    return false;
  }
  if (builtin_val.isUndefined()) {
    return false;          // every non-builtin module ends up here, with no pending exception
  }
  JS_SetProperty(cx, meta_obj, "builtin", builtin_val);
  return true;
}

The hook exists to give builtin modules import.meta.builtin. For ordinary modules it returns false, which
SpiderMonkey treats as an uncatchable error. (The !parent_id_val.isString() branch has the same problem.)

Suggested fix

  if (builtin_val.isUndefined()) {
    return true;   // ordinary module: nothing to add
  }

Optionally also set import.meta.url (as a file:// URL built from the resolved module path) and
import.meta.resolve, as other hosts do. A regression test is console.log(typeof import.meta) in a user module.

Lenguaje dominante
C
Estrellas
297
Forks
64
Merge medio
2 d 2 h
PR fusionados (30 d)
19

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de bytecodealliance/StarlingMonkey

Todos los issues de bytecodealliance/StarlingMonkey

Issues similares

Más issues de C

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.