On Sun, Feb 1, 2015 at 10:25 AM, Danny Dorfman <[email protected]> wrote: > Hello there, > > I am trying to write a deep-copy function for objects, and I am having > trouble with non-enumerable properties. > The method GetPropertyNames() does not retrieve those, and I cannot find any > other API function for that purpose. > If there any way around this limitation? > > Sample code: > > #include <v8.h> > #include <iostream> > > > int main(int argc, char* argv[]) > { > v8::Isolate* isolate = v8::Isolate::New(); > v8::Isolate::Scope isolate_scope(isolate); > v8::HandleScope handle_scope(isolate); > v8::Handle<v8::Context> context = v8::Context::New(isolate); > v8::Context::Scope context_scope(context); > v8::Handle<v8::Object> glob = context->Global(); > > glob->ForceSet(v8::String::NewFromUtf8(isolate,"field1"), > v8::String::NewFromUtf8(isolate,"value1"), v8::DontEnum); > glob->ForceSet(v8::String::NewFromUtf8(isolate,"field2"), > v8::String::NewFromUtf8(isolate,"value2"), v8::None); > v8::Local<v8::Array> property_names = glob->GetPropertyNames(); > std::cout << "got " << property_names->Length() << " field(s)" << > std::endl; // prints "1" instead of "2" > > > return 0; > }
GetPropertyNames() is equivalent to iterating over the object with for..in loop. You probably want GetOwnPropertyNames() + GetOwnPropertyDescriptor() and follow the prototype chain with GetPrototype(). -- -- v8-users mailing list [email protected] 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
