wasm/web: o.isPrototypeOf(x) and o.hasOwnProperty(k) throw "Cannot convert undefined or null to object"
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
- javascript, rust, typescript
Línea de trabajo
Empieza por crates/perry-codegen-wasm/src/wasm_runtime.js, alrededor de mem_call, mem_call_i32 y sus tablas de despacho. Comprueba si la búsqueda del puente solo acepta propiedades propias de una tabla y luego añade una prueba unitaria de perry-codegen-wasm para llamadas con los nombres isPrototypeOf, hasOwnProperty y propertyIsEnumerable. El objetivo se cumple cuando estas llamadas llegan al método del receptor y la prueba pasa; el comportamiento de la cadena de prototipos de las clases se sigue por separado.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
On --target web, calling a method whose name is also an Object.prototype member — isPrototypeOf, hasOwnProperty, propertyIsEnumerable — on an object throws Cannot convert undefined or null to object. The same method called through .call works.
class A {}
class B extends A {}
const base: any = { k: 1 };
const child: any = { own: 2 };
Object.setPrototypeOf(child, base);
const typed: { k: number } = { k: 1 };
const show = (label: string, f: () => any) => { try { console.log(label + ": " + f()); } catch (e: any) { console.log(label + ": threw " + e.message); } };
show("base.isPrototypeOf(child)", () => base.isPrototypeOf(child));
show("Object.prototype.isPrototypeOf({})", () => Object.prototype.isPrototypeOf({}));
show("child.hasOwnProperty('own')", () => child.hasOwnProperty("own"));
show("typed.hasOwnProperty('k')", () => typed.hasOwnProperty("k"));
show("child.propertyIsEnumerable('own')", () => child.propertyIsEnumerable("own"));
show("A.isPrototypeOf(B)", () => A.isPrototypeOf(B));
show("A.prototype.isPrototypeOf(new B())", () => A.prototype.isPrototypeOf(new B()));
show("Object.prototype.hasOwnProperty.call(child, 'own') (control)", () => Object.prototype.hasOwnProperty.call(child, "own"));
| case | Node 26.12.1 | --target web on main |
|---|---|---|
base.isPrototypeOf(child) |
true |
threw Cannot convert undefined or null to object |
Object.prototype.isPrototypeOf({}) |
true |
threw Cannot convert undefined or null to object |
child.hasOwnProperty('own') |
true |
threw Cannot convert undefined or null to object |
typed.hasOwnProperty('k') |
true |
threw Cannot convert undefined or null to object |
child.propertyIsEnumerable('own') |
true |
threw Cannot convert undefined or null to object |
A.isPrototypeOf(B) |
true |
threw Cannot convert undefined or null to object |
A.prototype.isPrototypeOf(new B()) |
true |
threw Cannot convert undefined or null to object |
Object.prototype.hasOwnProperty.call(child, 'own') (control) |
true |
true |
Run with perry compile fc.ts --target web -o fc.html, then node scripts/parity_web_host.cjs fc.html. Tested on macOS arm64 against main at 88b1e37142, with Node 26.12.1.
Cause. A method call the emitter does not special-case reaches mem_call under the method's own name, with the receiver as the first argument. mem_call looks that name up with a plain index, __memDispatch[name] (crates/perry-codegen-wasm/src/wasm_runtime.js:1419, and __perryUiDispatch[name] at :1424; mem_call_i32 at :1447). Both tables are object literals, so __memDispatch["isPrototypeOf"] is Object.prototype.isPrototypeOf itself. mem_call calls it as a bridge, coreFn(...args), with no receiver, and it throws. A name that is not an Object.prototype member misses both tables and falls through to __classDispatch(receiver, name, args), which calls the receiver's method. The control is Object.prototype.hasOwnProperty.call(child, "own"), which does not go through the method-name lookup.
Proposed fix. mem_call and mem_call_i32 take only a table's own bridges (Object.prototype.hasOwnProperty.call(table, name)), so these names fall through to __classDispatch like any other method. I'll send a PR with a perry-codegen-wasm unit test.
With that fix, the two class rows stop throwing but print false: A.isPrototypeOf(B) also needs #15053 (B's class value inherits from A's), and A.prototype.isPrototypeOf(new B()) needs instances and class prototypes to share one prototype chain (filed separately).
- Lenguaje dominante
- Rust
- Estrellas
- 4.9k
- Forks
- 166
- Merge medio
- 6 h 5 min
- PR fusionados (30 d)
- 949
Preparar el entorno
- Incluye un Dockerfile o un archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de PerryTS/perry
-
area:stdlib effort:S impact:med platform:linux type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
Los mantenedores suelen responder en 1 día
-
area:compiler effort:S impact:low platform:wasm type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
area:compiler effort:S impact:low platform:wasm type:chore
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
area:compiler effort:S impact:med platform:wasm type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
area:compiler effort:S impact:low platform:wasm type:chore
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
Todos los issues de PerryTS/perry
Issues similares
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 76/100
416rehman/Guardrails#1716 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
dginev/latexml-oxide#943 ·
Los mantenedores suelen responder en 1 día
-
bug ready
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
MartinPTielemans/ilo#3731 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
oetiker/shadcn-egui#50 ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 83/100
vymalo/another-agentic-system#412 ·
Los mantenedores suelen responder en 1 día