Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enumeration types in Node.js native addon

Is it possible to create some enum in C++ code of Node.js addon and then expose this type to js code? I found that native enum types exist in js, but there's no information about their implementation in v8 engine.

like image 610
Ivan Avatar asked Mar 26 '13 04:03

Ivan


1 Answers

Note that in the example given by Kevin you need to create an instance of Local<Object> before using it so make sure you call Object::New().

Local<Object> obj = Object::New();
const char* k = "HEADERS_RECEIVED";
int v = 1;
obj->Set(v8::String::NewSymbol(k), v8::Int32::New(v), ReadOnly); // Use PropertyAttribute ReadOnly so that value won't be changed by javascript.
like image 117
alternative4 Avatar answered Oct 05 '22 11:10

alternative4