This question is related to an interesting issue raised on the node-sqlite3 project:
TryGhost/node-sqlite3#1355
The JavaScript code from the issue looks like:
constvm=require('vm');constsqlite3=require('sqlite3').verbose();constdb=newsqlite3.Database(':memory:');constcontextObject={ db, console };db.each('select ?',newDate(),console.log);vm.runInNewContext("db.each('select ?', [new Date()], console.log);",contextObject);The pertinent code using node-addon-api looks like:
boolOtherInstanceOf(Napi::Object source, constchar* object_type) {
if (strncmp(object_type, "Date", 4) == 0) {
return source.InstanceOf(source.Env().Global().Get("Date").As<Function>());
} elseif (strncmp(object_type, "RegExp", 6) == 0) {
return source.InstanceOf(source.Env().Global().Get("RegExp").As<Function>());
}
returnfalse;
}The code to determine if source is a Date object is failing apparently because source has been allocated outside the global context.
The author of the node-sqlite3 issue has identified the IsDate method as a way to address this issue. But is there another more general approach that would work to identify type of an NAPI::Object in a non-global context?
This question is related to an interesting issue raised on the
node-sqlite3project:TryGhost/node-sqlite3#1355
The JavaScript code from the issue looks like:
The pertinent code using
node-addon-apilooks like:The code to determine if
sourceis aDateobject is failing apparently becausesourcehas been allocated outside the global context.The author of the
node-sqlite3issue has identified theIsDatemethod as a way to address this issue. But is there another more general approach that would work to identify type of an NAPI::Object in a non-global context?