+ also call ShowProp("AA") & ShowProp("user) void ShowProp(const char * name) { v8::Local<v8::Value> val = v8::String::NewFromUtf8(m_Isolate, name); Local<Object> obj = val->ToObject(m_Context).ToLocalChecked(); MaybeLocal<Array> bb = obj->GetPropertyNames(m_Context);
if (!bb.IsEmpty()) { Local<Array> arr = bb.ToLocalChecked(); int len = arr->Length(); for (uint32_t i = 0; i < len; ++i) { Local<Value> key = arr->Get(i); Local<Value> val = obj->Get(m_Context, key).ToLocalChecked(); printProperty(val); } } } void printProperty(Local<Value> val) { if (val->IsName() || val->IsStringObject()) { v8::String::Utf8Value str(m_Isolate, val); std::string cppStr(*str); OutputDebugStringA(cppStr.c_str()); } else if (val->IsNumberObject()) { Maybe<double> db = val->NumberValue(m_Context); } else if (val->IsFunction()) { Handle<v8::Function> func = v8::Handle<v8::Function>::Cast(val); if (func.IsEmpty()) return ; } else if (val->IsArray()) { Handle<v8::Array> array = v8::Handle<v8::Array>::Cast(val); int len = array->Length(); for (int i = 0; i < len; ++i) { const Handle<Value> key = array->Get(i); printProperty(key); } } else if (val->IsObject()) { bool a = val->IsObject(); bool b = val->IsArgumentsObject(); Local<Object> obj = val->ToObject(m_Context).ToLocalChecked(); if (obj.IsEmpty()) return; String::Utf8Value objascii(m_Isolate, obj); Handle<Array> properties = obj->GetOwnPropertyNames(m_Context).ToLocalChecked(); int len = properties->Length(); if (len == 0) return; for (int i = 0; i < len; ++i) { const Handle<Value> key = properties->Get(i); printProperty(key); } } } On Friday, June 26, 2020 at 2:52:23 PM UTC+3, Oren Gavriel wrote: > > Hi > After I compile a js source with v8, I would like to get the method/member > per request > Any idea how to do it ? > > For example for *user *i want to see : *User* & *sayHi *method and for > *AA* i want to see the *Z* & *b* keys > > const char * src= ("const AA = {Z: 5, b : 6 } ; class User { User() > {alert('con');} sayHi() {alert('hi');}} let user = new User()"); > Local<v8::String> source = v8::String::NewFromUtf8(m_Isolate, src); > // Compile the script and check for errors.Local<Script> compiled_script;if > (!Script::Compile(m_Context, source).ToLocal(&compiled_script)){ > } > ... > > Thanks > Oren > > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/d5854969-5476-40cd-8909-a718a45fa851o%40googlegroups.com.