Object property defined with Object.defineProperty gets immediately evaluated
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 35/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript, ruby
Direzione di ricerca
Start by reading the MiniRacer context loading path and how it handles enumerable properties with getters; the issue does not name source files or tests. Reproduce the behavior with the provided Object.defineProperty example in a MiniRacer context, then compare it with browser behavior. Done means explaining whether the getter evaluation is expected or fixing the discrepancy, with a regression test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Hello,
I hope this is the right place to ask...
I have a lot of components defined in different files and in my ruby code I'm loading them using the load function:
def initialize_js(config, locale = nil)
ctx = MiniRacer::Context.new
...
Dir.entries(path.join('auto', 'utils')).sort.each do |ent|
next if ent.start_with? '.'
if ent.end_with? '.js'
ctx.load(path.join('auto', 'utils', ent))
else
next unless File.directory?(path.join('auto', 'utils', ent))
Dir.entries(path.join('auto', 'utils', ent)).sort.each do |ent2|
next if ent2.start_with? '.'
ctx.load(path.join('auto', 'utils', ent, ent2))
end
end
end
...
ctx
end
I moved outside of the component's init function the definition of a property:
Before:
utils.components.accessory_power_adapter = {
init: function(config, components) {
if(this.initialized) return;
Object.defineProperty(components, 'accessory_power_adapter', {
enumerable: true,
get: function() {
return this.component;
}.bind(utils.components.accessory_power_adapter)
});
// Initialize component
this._init_component(config, components);
this.initialized = true;
},
...
};
After:
utils.components.accessory_power_adapter = {
init: function(config, components) {
if(this.initialized) return;
// Initialize component
this._init_component(config, components);
this.initialized = true;
},
...
};
Object.defineProperty(components, 'accessory_power_adapter', {
enumerable: true,
get: function() {
if(!this.initialized) {
throw 'call to components.accessory_power_adapter but the component is not initialized yet!';
}
return this.component;
}.bind(utils.components.accessory_power_adapter)
});
And now I'm getting the exception
call to components.accessory_power_adapter but the component is not initialized yet!'
when I simply load the file in the context.
It looks to me that somehow after defining the property, the engine tries to access it and since the component is not initialized yet, I get the exception.
I don't know if this is a bug or it's the expected behavior, I'm running the same code in the browser and it's fine.
If I make the property not enumerable it doesn't happen, but I need the property to be enumerable, so the only workaround is to change the code to skip that check if I'm running the code server side:
Object.defineProperty(components, 'accessory_power_adapter', {
enumerable: true,
get: function() {
if(!this.initialized && !ruby) {
throw 'call to components.accessory_power_adapter but the component is not initialized yet!';
}
return this.component;
}.bind(utils.components.accessory_power_adapter)
});
But I wanted to know why it is happening, if I've found a bug or I'm doing something wrong.
Thank you for your support!
mini_racer 0.4.0
libv8-node (15.14.0.0)
- Lingua principale
- JavaScript
- Stelle
- 628
- Fork
- 100
- Merge medio
- 1g 20h
- PR unite (30g)
- 2
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rubyjs/mini_racer
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
rubyjs/mini_racer#449 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
rubyjs/mini_racer#450 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 52/100
rubyjs/mini_racer#448 ·
-
bug/crash platform: linux/x86
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
rubyjs/mini_racer#422 · 10 commenti ·
-
platform: darwin/x86
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
rubyjs/mini_racer#388 · 4 commenti ·
Tutte le issue di rubyjs/mini_racer
Issue simili
-
ew
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
priority: medium status: needs-decision work-class: scoped
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
melodic-software/claude-code-plugins#9339 · 2 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
bug-report bug-report-triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
Codeinwp/templates-patterns-collection#539 ·
I maintainer di solito rispondono entro 1 giorno
-
建议增加URL参数构建的工具Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
[Bug] dsh 0.2.1 返回 session/not-found 时 sessionExists 不重建会话,消息恒失败并被误报为 INTERNAL_UNKNOWNForse già presa @ANIIAN91 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
xmanrui/dsh-im#444 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno