Is it possible to create several enumin C ++ code from a Node.js addon and then expose this type to js code? I found that native types of enums exist in js, but there is no information about their implementation in the v8 engine.
enum
Please note that in the example provided by Kevin , you need to create an instance Local<Object>before using it, so make sure you call Object::New().
Local<Object>
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.
javascript , int, , web, UNSENT,OPENED, HEADERS_RECEIVED,LOADING,DONE of XMLHttpRequest ++. v8 javascript, :
UNSENT,OPENED, HEADERS_RECEIVED,LOADING,DONE
XMLHttpRequest
Local<Object> obj; 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.
Now this has changed according to the latest v8 API ref
Isolate* isolate = args.GetIsolate(); Local<Context> context = isolate->GetCurrentContext(); Local<Object> obj; obj->DefineOwnProperty( context, String::NewFromUtf8(isolate,"enum"), Number::New(isolate,1), v8::ReadOnly );