Thanks for your answer! I'm confused about your example, why would the first comparison 'f1==f2' return false if they refer to the same function?
I checked the v8 document and found two member functions from v8 Function class, which are* int ScriptID() *and *int GetIdentityHash().* Could I use them to distinguish two v8::Local<v8::Function>? If two v8::Local<v8::Function> refer to the same function, would this two function return the same value? Best regards! On Wednesday, March 22, 2017 at 9:09:22 AM UTC-4, Jakob Kummerow wrote: > > The == operator on v8::Local compares if two Locals are referring to the > same JavaScript object (which can, of course, be a function) by object > identity (aka reference). (Structural equality is the opposite!) > > Note that two functions can contain the same code, but have different > object identity: > > function GetFun() { > return function() { /* do something funny */ } > } > var f1 = GetFun(); > var f2 = GetFun(); > f1 === f2; // false! > f1.property = "yay"; > f2.property === undefined; // true! > > If you had v8::Locals for f1 and f2, then local1 == local2 would be false. > > On Tue, Mar 21, 2017 at 7:15 PM, Hanyun Tao <taoha...@gmail.com > <javascript:>> wrote: > >> Hi all, >> >> I'm new to v8 and I want to know more about the equality check (==) >> between two v8::Local<v8::Object>. >> >> Currently I'm using instrumenting chromium browser. In chromium, >> registered event listeners are stored inside a map like data structure, and >> I can use the getListenerObject() method to get the v8::Local<v8::Object> >> correspond to each event listener, which could be a function reference, or >> reference to an object with handleEvent property. >> >> My goal is to tell if two different event listener will invoke the same >> javascript or not. Someone told me that I can do this by comparing two >> v8::Local<v8::Object> by value. I followed the suggestion and implements a >> function that returns unique integer ID for unique v8::Local<v8::Object> >> value. However when I test it on real webpage, I found that almost every >> event listeners are mapped to the same ID. >> >> I'm not confident with this result so I want to ask a question here. What >> does the equality check (==) between two v8::Local<v8::Object> check? Does >> it implies that the two object are structurally equal (contains the same >> function/object reference), or it means something else? >> >> Best regards, >> >> >> -- >> -- >> v8-users mailing list >> v8-u...@googlegroups.com <javascript:> >> 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+u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > > -- -- 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. For more options, visit https://groups.google.com/d/optout.