Object property defined with Object.defineProperty gets immediately evaluated
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 35/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 停滞
- 技术栈
- javascript, ruby
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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)
- 主要语言
- JavaScript
- 星标
- 628
- 派生
- 100
- 平均合并
- 1 天 20 小时
- 30 天内合并 PR
- 2
环境准备
- 提供 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 没有贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rubyjs/mini_racer 的其他 Issue
-
platform: darwin/x86
难度 4/5 3-5 天 新手友好度 35/100
rubyjs/mini_racer#388 · 4 条评论 ·
-
难度 5/5 一周以上 新手友好度 20/100
rubyjs/mini_racer#376 ·
-
难度 4/5 3-5 天 新手友好度 45/100
rubyjs/mini_racer#353 ·
-
难度 3/5 1-2 天 新手友好度 35/100
rubyjs/mini_racer#346 · 6 条评论 · 1 个 reaction ·
-
难度 5/5 一周以上 新手友好度 25/100
rubyjs/mini_racer#324 · 1 条评论 · 1 个 reaction ·
查看 rubyjs/mini_racer 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
awesome-dsh-plugin/awesome-dsh-plugin#9184 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
0.2.1-rc.3 compatibility: 21 peer ranges enumerate exact versions, so rc.3 is rejected可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
NanmiCoder/dsh-agent-teams#277 ·
维护者通常 1 天内回复
-
[ordering-review] workshop order graph: 1 confirmed ordering problem, 3 cycles are false positives未关闭
难度 2/5 1-3 小时 新手友好度 78/100
githubnext/gh-aw-workshop#4943 · 1 条评论 ·
维护者通常 1 天内回复