I run the following JS code in the Chrome console:
// Version 67.0.3396.87 (Official Build) (64-bit)
function Car(make) { this.make = make }
var car = new Car('Ferrari')
car instanceof Car // returns true
Now, on my C++ code I get ahold of car (by looking "car" up in the global context), and want to run the equivalent instanceof code, given only the class name "Car" as a string. Notice that I do not have a C++ class / function backing up Car.
Just to make it clear, compiling and running "car instanceof Car" as JS code in my C++ code, works totally fine.
I naively tried to do something like this, which didn't work:
Local<Object> object = FindObject("car"); // this works
Local<FunctionTemplate> ft = FunctionTemplate::New(isolate);
Local<String> name = String::NewFromUtf8(
isolate, "Car", NewStringType::kNormal).ToLocalChecked();
ft->SetClassName(name);
if (ft->HasInstance(object)) {
// this never happens
}
How can I do this, without manually compiling / running JS code?
Thanks!