Object property defined with Object.defineProperty gets immediately evaluated
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Veraltet
- Tech-Stack
- javascript, ruby
Rechercherichtung
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.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
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)
- Vorherrschende Sprache
- JavaScript
- Sterne
- 628
- Forks
- 100
- Ø Merge
- 1 T. 20 Std.
- Gemergte PRs (30 T.)
- 2
Entwicklungsumgebung
- Enthält ein Dockerfile oder eine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Kein Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus rubyjs/mini_racer
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
rubyjs/mini_racer#449 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 52/100
rubyjs/mini_racer#450 ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 52/100
rubyjs/mini_racer#448 ·
-
bug/crash platform: linux/x86
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 42/100
rubyjs/mini_racer#422 · 10 Kommentare ·
-
platform: darwin/x86
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 35/100
rubyjs/mini_racer#388 · 4 Kommentare ·
Alle Issues in rubyjs/mini_racer
Ähnliche Issues
-
type/bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 66/100
Maintainer antworten meist innerhalb von 1 Tag
-
Update to mocha 12.xOffen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 67/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
rescript-lang/rescript#8996 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Add: Ministerstvoidey.ruOffencheck:passed logos:add
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100