#ifndef V8_VALUE_HASHER_H #define V8_VALUE_HASHER_H #include #include #include #ifdef __APPLE__ #include #define hash std::tr1::hash #else #include #define hash std::hash #endif typedef Nan::Persistent > CopyablePersistent; struct v8_value_hash { size_t operator()(CopyablePersistent *k) const { Nan::HandleScope scope; v8::Local key = v8::Local::New(v8::Isolate::GetCurrent(), *k); std::string s; if (key->IsString() || key->IsBoolean() || key->IsNumber()) { return hash()(*Nan::Utf8String(key)); } return hash()(Nan::To(key).ToLocalChecked()->GetIdentityHash()); } }; struct v8_value_equal_to { bool operator()(CopyablePersistent *pa, CopyablePersistent *pb) const { Nan::HandleScope scope; if (*pa == *pb) { return true; } v8::Local a = v8::Local::New(v8::Isolate::GetCurrent(), *pa); v8::Local b = v8::Local::New(v8::Isolate::GetCurrent(), *pb); if (a->Equals(b)) { /* same as JS == */ return true; } return Nan::To(a).ToLocalChecked()->GetIdentityHash() == Nan::To(b).ToLocalChecked()->GetIdentityHash(); } }; #endif