gpt4 book ai didi

javascript - V8 JavaScript : Why do C++ constructor functions filter Proxy?

转载 作者:行者123 更新时间:2023-11-29 21:06:56 25 4
gpt4 key购买 nike

V8 C++ 代码(测试程序)似乎没有将 Proxy 视为对象,而是返回了默认目标。纯 JavaScript(其他)中的相同场景按预期工作。

C++实现的pass thru函数

static void tester(const FunctionCallbackInfo<Value>& info) {
if (info.Length() > 0) {
info.GetReturnValue().Set(info[0]);
}
}

安装代码(从应用周围收集。)

Local<String> testerString = String::NewFromUtf8(isolate, "tester", NewStringType::kNormal).ToLocalChecked();
Local<ObjectTemplate> globalTemplate = ObjectTemplate::New(isolate);
globalTemplate->Set(testerString, FunctionTemplate::New(isolate, tester), DontEnum);
Local<Context> context = Context::New(isolate, nullptr, globalTemplate, Local<Value>());

JavaScript 测试,交替使用 C++ 和 JavaScript、对象和代理、函数和构造函数。

function other(x) {
return x;
}

{
let a = tester({x: 10});
let b = new tester({x: 10});
let c = tester(new Proxy({}, {get: function(target, name) { return name; }}));
let d = new tester(new Proxy({}, {get: function(target, name) { return name; }}));

print(a.x);
print(b.x);
print(c.x);
print(d.x);
}

{
let a = other({x: 10});
let b = new other({x: 10});
let c = other(new Proxy({}, {get: function(target, name) { return name; }}));
let d = new other(new Proxy({}, {get: function(target, name) { return name; }}));

print(a.x);
print(b.x);
print(c.x);
print(d.x);
}

输出:

10
10
x
undefined
10
10
x
x

最佳答案

这里是 V8 开发者。这确实看起来像一个错误。你能提交错误报告吗?

关于javascript - V8 JavaScript : Why do C++ constructor functions filter Proxy?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43559004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com