Reputation: 1177
It seems that V8 C++ code (tester) is not treating Proxy as an object and thus returning the default target instead. The same scenario in pure JavaScript (other) works as expected.
The pass thru function implemented in C++
static void tester(const FunctionCallbackInfo<Value>& info) {
if (info.Length() > 0) {
info.GetReturnValue().Set(info[0]);
}
}
The installation code (gathered from around the app.)
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>());
The JavaScript test, alternating with C++ and JavaScript, object and proxy, function and constructor.
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);
}
Output:
10
10
x
undefined
10
10
x
x
Upvotes: 2
Views: 199
Reputation: 36118
V8 dev here. This indeed looks like a bug. Can you please file a bug report?
Upvotes: 2