Re: [v8-users] Re: Where are let / const objects stored?
Jakob, I can see why that is the case for lexical scoped variables. Can you point me to more docs (LOL) or examples of how to traverse these Context objects? I will also check Zac's suggestion of looking at the debugging interface. Cheers! On Thursday, June 21, 2018 at 11:31:24 PM UTC+2, Jakob Kummerow wrote: > > Variable allocation is complicated. In short, Function-local variables are > allocated on the stack. When nested closures refer to them, they get > allocated in a Context object. > > > On Thu, Jun 21, 2018 at 12:15 AM Zac Hansen > wrote: > >> I don't know the answer, but they are accessible via the debugging >> interface, so that may be a place to look. >> >> On Wednesday, June 20, 2018 at 11:01:23 PM UTC-7, Gonzalo Diethelm wrote: >>> >>> I run the following JS code in the Chrome console: >>> >>> // Version 67.0.3396.87 (Official Build) (64-bit) >>> >>> var p = 11 >>> p // returns 11 >>> >>> let q = 12 >>> q // returns 12 >>> >>> const r = 13 >>> r // returns 13 >>> >>> Now, from C++ code, I can look up p in the global context, and it is >>> found; its value is, unsurprisingly, 11. >>> >>> On the other hand, q and r are not found in the global context. This is >>> fine, I guess, since let / const have lexical scoping. >>> >>> My question is: how does Chrome / V8 find q and r? Where is it looking >>> for them? >>> >>> Thanks! >>> >> -- >> -- >> v8-users mailing list >> v8-u...@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+u...@googlegroups.com . >> 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.
Re: [v8-users] Running instanceof from C++ given a class name as a string
This works perfectly. I knew I was being naive, thank you Jakob for pointing me in the right direction! On Thursday, June 21, 2018 at 11:28:51 PM UTC+2, Jakob Kummerow wrote: > > Well, if you're creating a new FunctionTemplate, then of course your > existing "car" object isn't an instance of that new class ;-) > > Value::InstanceOf is the C++ equivalent of JavaScript "instanceof": > > Local object = Local::Cast(FindObject("car")); // Assuming > "car" is, indeed, a Value. Check first if needed. > Local car_class = FindObject("Car"); > object->InstanceOf(context, car_class); // Should return Just(true). > Throws if car_class is not a function. > > On Wed, Jun 20, 2018 at 11:00 PM Gonzalo Diethelm > wrote: > >> I run the following JS code in the Chrome console: >> >> // Version 67.0.3396.87 (Official Build) (64-bit) >> >> function Car(make) { this.make = make } >> var car = new Car('Ferrari') >> car instanceof Car // returns true >> >> Now, on my C++ code I get ahold of car (by looking "car" up in the global >> context), and want to run the equivalent instanceof code, given only the >> class name "Car" as a string. Notice that I do not have a C++ class / >> function backing up Car. >> >> Just to make it clear, compiling and running "car instanceof Car" as JS >> code in my C++ code, works totally fine. >> >> I naively tried to do something like this, which didn't work: >> >> Local object = FindObject("car"); // this works >> Local ft = FunctionTemplate::New(isolate); >> Local name = String::NewFromUtf8( >> isolate, "Car", NewStringType::kNormal).ToLocalChecked(); >> ft->SetClassName(name); >> if (ft->HasInstance(object)) { >> // this never happens >> } >> >> How can I do this, without manually compiling / running JS code? >> >> Thanks! >> >> -- >> -- >> v8-users mailing list >> v8-u...@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+u...@googlegroups.com . >> 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.
Re: [v8-users] Re: Finding cycles in an object
Jakob, you rule. That in fact fixed all my problems. Thanks to you and Zac for all the guidance! On Thursday, June 21, 2018 at 11:12:24 PM UTC+2, Jakob Kummerow wrote: > > The Local class defines an operator == that should do exactly what you > need. > > On Thu, Jun 21, 2018 at 5:43 AM Gonzalo Diethelm > wrote: > >> Sure, slot does have a value, I just didn't include it in the code. >> Something like: >> >> Local slot = String::NewFromUtf8(isolate, "MyBeautifulSlot", >> NewStringType::kNormal).ToLocalChecked(); >> >> Cheers! >> >> On Thursday, June 21, 2018 at 2:27:00 PM UTC+2, Zac Hansen wrote: >>> >>> You're dereferencing a "super pointer" to get to a "pointer", hence * >>> not &. You can't "go back" because the local/global represents an >>> "reference count" to the object which must be known to the JS runtime. >>> >>> As for p0 and p1, have you tried setting slot to a fixed string value >>> before using it as a key for storing/lookup? I don't know what the >>> expected behavior of using an empty value as a key into an object is. >>> >>> These are all just guesses - if someone else answers differently, I'm >>> probably wrong. >>> >>> >>> On Thursday, June 21, 2018 at 5:07:50 AM UTC-7, Gonzalo Diethelm wrote: Note to self: this might be related to Local vs Global (or Persistent? so many names...) Need to look into that. On Thursday, June 21, 2018 at 7:58:37 AM UTC+2, Gonzalo Diethelm wrote: > > I run the following JS code in the Chrome console: > > // Version 67.0.3396.87 (Official Build) (64-bit) > > var x = [1, 2, {"foo": 11}]; > x[2].bar = x; > > Now from C++ code, I get ahold of x as a Local, and wish to > traverse the whole structure; for the sake of the example, let's say I am > converting it into serialized data (I know I can use JSON.stringify() to > do > this, serializing is just an example to clarify ideas). My question is, > how can I keep track of the nodes in the structure that I have already > seen, and their associated serialized value, so that I can avoid an > infinite traversal? > > It seems to me doing this would require a way to get a unique identity > for each node, so that the C++ code can do something similar to this: > > typedef map NodeMap; > NodeMap seen; > ... > Local node = current.GetNextChild(); > NodeId id = node.GetUniqueId(); > NodeMap::iterator k = seen.find(id); > NodeData data; > if (k != seen.end()) { > // node already seen, reuse its serialization > data = k->first; > } else { > // first time we see node, serialize and remember > data = node.Serialize(); // recurses > seen[id] = data; > } > > The specific question is: what type could be NodeId, and how do I get > the equivalent of GetUniqueId()? > > I am very tempted to ask for a way to get a raw void* to each node, > but I guess any way of doing this is fine, as long as I can get a unique > id > that is stable while I'm traversing the data. For these reasons, > GetIdentityHash() does not seem to fit the bill: "*The return value > will never be 0. Also, it is not guaranteed to be unique.*" > > Incidentally, If I try to use JSON.stringify for my data, I get this: > > JSON.stringify(x) > VM170:1 Uncaught TypeError: Converting circular structure to JSON > at JSON.stringify () > at :1:6 > > This is taken care of here in the V8 code: > > JsonStringifier::Result JsonStringifier::StackPush(Handle > object) { > ... > // member stack_ is: Handle stack_; > int length = Smi::ToInt(stack_->length()); > FixedArray* elements = FixedArray::cast(stack_->elements()); > for (int i = 0; i < length; i++) { > FixedArray* elements = FixedArray::cast(stack_->elements()); > if (elements->get(i) == *object) { > // boom > } > } > } > > So, operator*() in a Handle gives me a unique id? Which is the > type for this? Can I store that in a C++ map? Is it stable (enough)? > > Thanks! > -- >> -- >> v8-users mailing list >> v8-u...@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+u...@googlegroups.com . >> 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
[v8-users] Re: how to debug torque
I just want to debug the code in ".tq" file or the code which is created by torque 在 2018年6月22日星期五 UTC+8上午11:34:30,cyril写道: > > Recently, I discovered that v8 has added a module named torque. Anyone > know how to debug it ?? > -- -- 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.
[v8-users] git cl upload failing
I've been using git to submit changes for review for a while. Now when I run 'git cl upload' it fails with the following message. bstell@bstell:$ git cl upload Running presubmit upload checks ... Done processing /usr/local/google/home/bstell/v8/v8/src/objects/intl-objects.cc Total errors found: 0 Failed to process /usr/local/google/home/bstell/v8/v8/src/objects/intl-objects.cc Total errors found: 1 Total violating files: 0 ** Presubmit ERRORS ** C++ lint check failed Presubmit checks took 1.7s to calculate. -- -- 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.
[v8-users] Re: how to debug torque
That's not a very detailed question. What is insufficient with the usual tools? On Thursday, June 21, 2018 at 8:34:30 PM UTC-7, cyril wrote: > > Recently, I discovered that v8 has added a module named torque. Anyone > know how to debug it ?? > -- -- 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.
[v8-users] how to debug torque
Recently, I discovered that v8 has added a module named torque. Anyone know how to debug it ?? -- -- 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.
Re: [v8-users] How Date.now() function value is returned (Is it from kernel of v8 engine has its own implementation)
Yes gin has its own implementation of time apart from default-platform. I have one more concern. How can i implement my own javascript API? Basically I am thinking to create two javascript API which calls two respective calls from my shared library (external). Instead of creating two new api's is there any other method from JavaScript which calls my external library functions. I dont want to fork processes from javascript to execute my library functions since I am planning to profile chrome browser. Regards, K Abhishek On Thu, Jun 21, 2018 at 1:34 PM Jakob Kummerow wrote: > gin provides its own v8::Platform implementation, overriding the default > platform. > > On Thu, Jun 21, 2018 at 9:55 AM Abhishek Kanike < > kai.dranzer32...@gmail.com> wrote: > >> Hi Jakob and v8-users, >> I have following observations on printing logs in v8 and date.now call >> trace. >> >>1. *Logs in v8:* >> >>*printf* and *std::cout* were not outputting any logs in adb logcat. >>I tried redirecting stdio logs to logcat by following commands - >> >>$ adb shell stop$ adb shell setprop log.redirect-stdio true$ adb shell >> start >> >>But still logs were not getting displayed in adb logcat. So I used >>android log library. Following is the procedure >> >>- Import header file: >> >> #if defined(V8_OS_ANDROID) >> #include >> #endif >> >> - Print log: >> >> #if defined(V8_OS_ANDROID) >> __android_log_print(ANDROID_LOG_INFO, "", ""); >> #endif >> >> >>2. Date.now() final system call: >>Date.now() calls *V8Platform::CurrentClockTimeMillis()* from* >>src/gin/v8_platform.cc *---> *Time::Now() *from >>*src/base/time/time.cc* ---> *getTimeofDay() *rather than >> *base::OS::TimeCurrentMillis. >>*Can anyone explain this behaviour? >> >> Regards, >> K Abhishek >> >> >> >> On Mon, Jun 18, 2018 at 7:07 PM Jakob Kummerow >> wrote: >> >>> Sure, just use printf or std::cout << "print\n". I don't know whether >>> adb logcat has any special requirements. >>> >>> On Mon, Jun 18, 2018 at 3:48 PM Abhishek Kanike < >>> kai.dranzer32...@gmail.com> wrote: >>> Jakob, Thanks for quick reply. That's a good point, should have tried with gdb. Will check with that. Is there a way to add logs in v8 source code, it will be lot faster to debug. In cc (compositor), i used *LOG(INFO)<<"print";* from *base/logging.h *(of main chromium *src*) On Mon, Jun 18, 2018 at 5:12 PM Jakob Kummerow wrote: > Yes, it is. > > Have you tried using a debugger? You can set a breakpoint in > the BUILTIN(DateNow) function here: > > > https://cs.chromium.org/chromium/src/v8/src/builtins/builtins-date.cc?q=builtins-date.cc&sq=package:chromium&dr&l=282 > > and step through the code from there. > > On Mon, Jun 18, 2018 at 2:39 PM Abhishek Kanike < > kai.dranzer32...@gmail.com> wrote: > >> Hi, >> For confirmation i am using a simple Date.now() call on button click >> [Attached]. >> I have added a print log in Time::NOW() at >> https://cs.chromium.org/chromium/src/v8/src/base/platform/time.cc?type=cs&sq=package:chromium&g=0&l=402 >> as printf("v8:DEBUG::TIME:NOW called"). >> I am not getting this log in adb logcat. So is this the correct place >> from where Date.now() is getting called? >> >> Regards, >> K Abhishek >> >> On Mon, May 21, 2018 at 6:51 PM Abhishek Kanike < >> kai.dranzer32...@gmail.com> wrote: >> >>> Sorry JaKob >>> >>> On Mon, May 21, 2018, 6:51 PM Abhishek Kanike < >>> kai.dranzer32...@gmail.com> wrote: >>> Cool.. I see it. Thanks a lot Jacob. On Mon, May 21, 2018, 5:40 PM Jakob Kummerow < jkumme...@chromium.org> wrote: > The time always has to be retrieved from the kernel. V8's > implementation is in base::OS::TimeCurrentMillis, implemented in > src/base/platform/platform-{win32,posix}.cc. > > On Mon, May 21, 2018 at 3:22 PM Abhishek Kanike < > kai.dranzer32...@gmail.com> wrote: > >> Hi, >> I want to know how the date.now() function is called in >> javascript (or how it returns the value). I believe that javascript >> uses >> date.now() by system call. I want to in chrome source code how it is >> being >> set. >> This is useful for one of the performance benchmark that I am >> working on. >> Can someone please guide me to know how this happens in v8 engine. >> >> Thanks in advance. >> >> Regards, >> K Abhishek >> >> -- >> -- >> 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 Gr
Re: [v8-users] Re: Where are let / const objects stored?
Variable allocation is complicated. In short, Function-local variables are allocated on the stack. When nested closures refer to them, they get allocated in a Context object. On Thu, Jun 21, 2018 at 12:15 AM Zac Hansen wrote: > I don't know the answer, but they are accessible via the debugging > interface, so that may be a place to look. > > On Wednesday, June 20, 2018 at 11:01:23 PM UTC-7, Gonzalo Diethelm wrote: >> >> I run the following JS code in the Chrome console: >> >> // Version 67.0.3396.87 (Official Build) (64-bit) >> >> var p = 11 >> p // returns 11 >> >> let q = 12 >> q // returns 12 >> >> const r = 13 >> r // returns 13 >> >> Now, from C++ code, I can look up p in the global context, and it is >> found; its value is, unsurprisingly, 11. >> >> On the other hand, q and r are not found in the global context. This is >> fine, I guess, since let / const have lexical scoping. >> >> My question is: how does Chrome / V8 find q and r? Where is it looking >> for them? >> >> Thanks! >> > -- > -- > 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. > -- -- 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.
Re: [v8-users] Running instanceof from C++ given a class name as a string
Well, if you're creating a new FunctionTemplate, then of course your existing "car" object isn't an instance of that new class ;-) Value::InstanceOf is the C++ equivalent of JavaScript "instanceof": Local object = Local::Cast(FindObject("car")); // Assuming "car" is, indeed, a Value. Check first if needed. Local car_class = FindObject("Car"); object->InstanceOf(context, car_class); // Should return Just(true). Throws if car_class is not a function. On Wed, Jun 20, 2018 at 11:00 PM Gonzalo Diethelm < gonzalo.dieth...@gmail.com> wrote: > I run the following JS code in the Chrome console: > > // Version 67.0.3396.87 (Official Build) (64-bit) > > function Car(make) { this.make = make } > var car = new Car('Ferrari') > car instanceof Car // returns true > > Now, on my C++ code I get ahold of car (by looking "car" up in the global > context), and want to run the equivalent instanceof code, given only the > class name "Car" as a string. Notice that I do not have a C++ class / > function backing up Car. > > Just to make it clear, compiling and running "car instanceof Car" as JS > code in my C++ code, works totally fine. > > I naively tried to do something like this, which didn't work: > > Local object = FindObject("car"); // this works > Local ft = FunctionTemplate::New(isolate); > Local name = String::NewFromUtf8( > isolate, "Car", NewStringType::kNormal).ToLocalChecked(); > ft->SetClassName(name); > if (ft->HasInstance(object)) { > // this never happens > } > > How can I do this, without manually compiling / running JS code? > > Thanks! > > -- > -- > 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. > -- -- 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.
Re: [v8-users] Re: Finding cycles in an object
The Local class defines an operator == that should do exactly what you need. On Thu, Jun 21, 2018 at 5:43 AM Gonzalo Diethelm wrote: > Sure, slot does have a value, I just didn't include it in the code. > Something like: > > Local slot = String::NewFromUtf8(isolate, "MyBeautifulSlot", > NewStringType::kNormal).ToLocalChecked(); > > Cheers! > > On Thursday, June 21, 2018 at 2:27:00 PM UTC+2, Zac Hansen wrote: >> >> You're dereferencing a "super pointer" to get to a "pointer", hence * not >> &. You can't "go back" because the local/global represents an >> "reference count" to the object which must be known to the JS runtime. >> >> As for p0 and p1, have you tried setting slot to a fixed string value >> before using it as a key for storing/lookup? I don't know what the >> expected behavior of using an empty value as a key into an object is. >> >> These are all just guesses - if someone else answers differently, I'm >> probably wrong. >> >> >> On Thursday, June 21, 2018 at 5:07:50 AM UTC-7, Gonzalo Diethelm wrote: >>> >>> Note to self: this might be related to Local vs Global >>> (or Persistent? so many names...) >>> >>> Need to look into that. >>> >>> On Thursday, June 21, 2018 at 7:58:37 AM UTC+2, Gonzalo Diethelm wrote: I run the following JS code in the Chrome console: // Version 67.0.3396.87 (Official Build) (64-bit) var x = [1, 2, {"foo": 11}]; x[2].bar = x; Now from C++ code, I get ahold of x as a Local, and wish to traverse the whole structure; for the sake of the example, let's say I am converting it into serialized data (I know I can use JSON.stringify() to do this, serializing is just an example to clarify ideas). My question is, how can I keep track of the nodes in the structure that I have already seen, and their associated serialized value, so that I can avoid an infinite traversal? It seems to me doing this would require a way to get a unique identity for each node, so that the C++ code can do something similar to this: typedef map NodeMap; NodeMap seen; ... Local node = current.GetNextChild(); NodeId id = node.GetUniqueId(); NodeMap::iterator k = seen.find(id); NodeData data; if (k != seen.end()) { // node already seen, reuse its serialization data = k->first; } else { // first time we see node, serialize and remember data = node.Serialize(); // recurses seen[id] = data; } The specific question is: what type could be NodeId, and how do I get the equivalent of GetUniqueId()? I am very tempted to ask for a way to get a raw void* to each node, but I guess any way of doing this is fine, as long as I can get a unique id that is stable while I'm traversing the data. For these reasons, GetIdentityHash() does not seem to fit the bill: "*The return value will never be 0. Also, it is not guaranteed to be unique.*" Incidentally, If I try to use JSON.stringify for my data, I get this: JSON.stringify(x) VM170:1 Uncaught TypeError: Converting circular structure to JSON at JSON.stringify () at :1:6 This is taken care of here in the V8 code: JsonStringifier::Result JsonStringifier::StackPush(Handle object) { ... // member stack_ is: Handle stack_; int length = Smi::ToInt(stack_->length()); FixedArray* elements = FixedArray::cast(stack_->elements()); for (int i = 0; i < length; i++) { FixedArray* elements = FixedArray::cast(stack_->elements()); if (elements->get(i) == *object) { // boom } } } So, operator*() in a Handle gives me a unique id? Which is the type for this? Can I store that in a C++ map? Is it stable (enough)? Thanks! >>> -- > -- > 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. > -- -- 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.
Re: [v8-users] How Date.now() function value is returned (Is it from kernel of v8 engine has its own implementation)
gin provides its own v8::Platform implementation, overriding the default platform. On Thu, Jun 21, 2018 at 9:55 AM Abhishek Kanike wrote: > Hi Jakob and v8-users, > I have following observations on printing logs in v8 and date.now call > trace. > >1. *Logs in v8:* > >*printf* and *std::cout* were not outputting any logs in adb logcat. I >tried redirecting stdio logs to logcat by following commands - > >$ adb shell stop$ adb shell setprop log.redirect-stdio true$ adb shell > start > >But still logs were not getting displayed in adb logcat. So I used >android log library. Following is the procedure > >- Import header file: > > #if defined(V8_OS_ANDROID) > #include > #endif > > - Print log: > > #if defined(V8_OS_ANDROID) > __android_log_print(ANDROID_LOG_INFO, "", ""); > #endif > > >2. Date.now() final system call: >Date.now() calls *V8Platform::CurrentClockTimeMillis()* from* >src/gin/v8_platform.cc *---> *Time::Now() *from *src/base/time/time.cc* >---> *getTimeofDay() *rather than *base::OS::TimeCurrentMillis. *Can >anyone explain this behaviour? > > Regards, > K Abhishek > > > > On Mon, Jun 18, 2018 at 7:07 PM Jakob Kummerow > wrote: > >> Sure, just use printf or std::cout << "print\n". I don't know whether >> adb logcat has any special requirements. >> >> On Mon, Jun 18, 2018 at 3:48 PM Abhishek Kanike < >> kai.dranzer32...@gmail.com> wrote: >> >>> Jakob, >>> Thanks for quick reply. >>> That's a good point, should have tried with gdb. Will check with that. >>> Is there a way to add logs in v8 source code, it will be lot faster to >>> debug. >>> In cc (compositor), i used *LOG(INFO)<<"print";* from *base/logging.h *(of >>> main chromium *src*) >>> >>> On Mon, Jun 18, 2018 at 5:12 PM Jakob Kummerow >>> wrote: >>> Yes, it is. Have you tried using a debugger? You can set a breakpoint in the BUILTIN(DateNow) function here: https://cs.chromium.org/chromium/src/v8/src/builtins/builtins-date.cc?q=builtins-date.cc&sq=package:chromium&dr&l=282 and step through the code from there. On Mon, Jun 18, 2018 at 2:39 PM Abhishek Kanike < kai.dranzer32...@gmail.com> wrote: > Hi, > For confirmation i am using a simple Date.now() call on button click > [Attached]. > I have added a print log in Time::NOW() at > https://cs.chromium.org/chromium/src/v8/src/base/platform/time.cc?type=cs&sq=package:chromium&g=0&l=402 > as printf("v8:DEBUG::TIME:NOW called"). > I am not getting this log in adb logcat. So is this the correct place > from where Date.now() is getting called? > > Regards, > K Abhishek > > On Mon, May 21, 2018 at 6:51 PM Abhishek Kanike < > kai.dranzer32...@gmail.com> wrote: > >> Sorry JaKob >> >> On Mon, May 21, 2018, 6:51 PM Abhishek Kanike < >> kai.dranzer32...@gmail.com> wrote: >> >>> Cool.. I see it. Thanks a lot Jacob. >>> >>> On Mon, May 21, 2018, 5:40 PM Jakob Kummerow >>> wrote: >>> The time always has to be retrieved from the kernel. V8's implementation is in base::OS::TimeCurrentMillis, implemented in src/base/platform/platform-{win32,posix}.cc. On Mon, May 21, 2018 at 3:22 PM Abhishek Kanike < kai.dranzer32...@gmail.com> wrote: > Hi, > I want to know how the date.now() function is called in javascript > (or how it returns the value). I believe that javascript uses > date.now() by > system call. I want to in chrome source code how it is being set. > This is useful for one of the performance benchmark that I am > working on. > Can someone please guide me to know how this happens in v8 engine. > > Thanks in advance. > > Regards, > K Abhishek > > -- > -- > 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. > -- -- 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. >>> > > -- > Cheers, > K Abhishek > > -- > --
Re: [v8-users] How Date.now() function value is returned (Is it from kernel of v8 engine has its own implementation)
Hi Jakob and v8-users, I have following observations on printing logs in v8 and date.now call trace. 1. *Logs in v8:* *printf* and *std::cout* were not outputting any logs in adb logcat. I tried redirecting stdio logs to logcat by following commands - $ adb shell stop$ adb shell setprop log.redirect-stdio true$ adb shell start But still logs were not getting displayed in adb logcat. So I used android log library. Following is the procedure - Import header file: #if defined(V8_OS_ANDROID) #include #endif - Print log: #if defined(V8_OS_ANDROID) __android_log_print(ANDROID_LOG_INFO, "", ""); #endif 2. Date.now() final system call: Date.now() calls *V8Platform::CurrentClockTimeMillis()* from* src/gin/v8_platform.cc *---> *Time::Now() *from *src/base/time/time.cc* ---> *getTimeofDay() *rather than *base::OS::TimeCurrentMillis. *Can anyone explain this behaviour? Regards, K Abhishek On Mon, Jun 18, 2018 at 7:07 PM Jakob Kummerow wrote: > Sure, just use printf or std::cout << "print\n". I don't know whether adb > logcat has any special requirements. > > On Mon, Jun 18, 2018 at 3:48 PM Abhishek Kanike < > kai.dranzer32...@gmail.com> wrote: > >> Jakob, >> Thanks for quick reply. >> That's a good point, should have tried with gdb. Will check with that. >> Is there a way to add logs in v8 source code, it will be lot faster to >> debug. >> In cc (compositor), i used *LOG(INFO)<<"print";* from *base/logging.h *(of >> main chromium *src*) >> >> On Mon, Jun 18, 2018 at 5:12 PM Jakob Kummerow >> wrote: >> >>> Yes, it is. >>> >>> Have you tried using a debugger? You can set a breakpoint in >>> the BUILTIN(DateNow) function here: >>> >>> >>> https://cs.chromium.org/chromium/src/v8/src/builtins/builtins-date.cc?q=builtins-date.cc&sq=package:chromium&dr&l=282 >>> >>> and step through the code from there. >>> >>> On Mon, Jun 18, 2018 at 2:39 PM Abhishek Kanike < >>> kai.dranzer32...@gmail.com> wrote: >>> Hi, For confirmation i am using a simple Date.now() call on button click [Attached]. I have added a print log in Time::NOW() at https://cs.chromium.org/chromium/src/v8/src/base/platform/time.cc?type=cs&sq=package:chromium&g=0&l=402 as printf("v8:DEBUG::TIME:NOW called"). I am not getting this log in adb logcat. So is this the correct place from where Date.now() is getting called? Regards, K Abhishek On Mon, May 21, 2018 at 6:51 PM Abhishek Kanike < kai.dranzer32...@gmail.com> wrote: > Sorry JaKob > > On Mon, May 21, 2018, 6:51 PM Abhishek Kanike < > kai.dranzer32...@gmail.com> wrote: > >> Cool.. I see it. Thanks a lot Jacob. >> >> On Mon, May 21, 2018, 5:40 PM Jakob Kummerow >> wrote: >> >>> The time always has to be retrieved from the kernel. V8's >>> implementation is in base::OS::TimeCurrentMillis, implemented in >>> src/base/platform/platform-{win32,posix}.cc. >>> >>> On Mon, May 21, 2018 at 3:22 PM Abhishek Kanike < >>> kai.dranzer32...@gmail.com> wrote: >>> Hi, I want to know how the date.now() function is called in javascript (or how it returns the value). I believe that javascript uses date.now() by system call. I want to in chrome source code how it is being set. This is useful for one of the performance benchmark that I am working on. Can someone please guide me to know how this happens in v8 engine. Thanks in advance. Regards, K Abhishek -- -- 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. >>> -- >>> -- >>> 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. >>> >> -- Cheers, K Abhishek -- -- 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+un
[v8-users] Re: Finding cycles in an object
Sure, slot does have a value, I just didn't include it in the code. Something like: Local slot = String::NewFromUtf8(isolate, "MyBeautifulSlot", NewStringType::kNormal).ToLocalChecked(); Cheers! On Thursday, June 21, 2018 at 2:27:00 PM UTC+2, Zac Hansen wrote: > > You're dereferencing a "super pointer" to get to a "pointer", hence * not > &. You can't "go back" because the local/global represents an > "reference count" to the object which must be known to the JS runtime. > > As for p0 and p1, have you tried setting slot to a fixed string value > before using it as a key for storing/lookup? I don't know what the > expected behavior of using an empty value as a key into an object is. > > These are all just guesses - if someone else answers differently, I'm > probably wrong. > > > On Thursday, June 21, 2018 at 5:07:50 AM UTC-7, Gonzalo Diethelm wrote: >> >> Note to self: this might be related to Local vs Global >> (or Persistent? so many names...) >> >> Need to look into that. >> >> On Thursday, June 21, 2018 at 7:58:37 AM UTC+2, Gonzalo Diethelm wrote: >>> >>> I run the following JS code in the Chrome console: >>> >>> // Version 67.0.3396.87 (Official Build) (64-bit) >>> >>> var x = [1, 2, {"foo": 11}]; >>> x[2].bar = x; >>> >>> Now from C++ code, I get ahold of x as a Local, and wish to >>> traverse the whole structure; for the sake of the example, let's say I am >>> converting it into serialized data (I know I can use JSON.stringify() to do >>> this, serializing is just an example to clarify ideas). My question is, >>> how can I keep track of the nodes in the structure that I have already >>> seen, and their associated serialized value, so that I can avoid an >>> infinite traversal? >>> >>> It seems to me doing this would require a way to get a unique identity >>> for each node, so that the C++ code can do something similar to this: >>> >>> typedef map NodeMap; >>> NodeMap seen; >>> ... >>> Local node = current.GetNextChild(); >>> NodeId id = node.GetUniqueId(); >>> NodeMap::iterator k = seen.find(id); >>> NodeData data; >>> if (k != seen.end()) { >>> // node already seen, reuse its serialization >>> data = k->first; >>> } else { >>> // first time we see node, serialize and remember >>> data = node.Serialize(); // recurses >>> seen[id] = data; >>> } >>> >>> The specific question is: what type could be NodeId, and how do I get >>> the equivalent of GetUniqueId()? >>> >>> I am very tempted to ask for a way to get a raw void* to each node, but >>> I guess any way of doing this is fine, as long as I can get a unique id >>> that is stable while I'm traversing the data. For these reasons, >>> GetIdentityHash() does not seem to fit the bill: "*The return value >>> will never be 0. Also, it is not guaranteed to be unique.*" >>> >>> Incidentally, If I try to use JSON.stringify for my data, I get this: >>> >>> JSON.stringify(x) >>> VM170:1 Uncaught TypeError: Converting circular structure to JSON >>> at JSON.stringify () >>> at :1:6 >>> >>> This is taken care of here in the V8 code: >>> >>> JsonStringifier::Result JsonStringifier::StackPush(Handle object >>> ) { >>> ... >>> // member stack_ is: Handle stack_; >>> int length = Smi::ToInt(stack_->length()); >>> FixedArray* elements = FixedArray::cast(stack_->elements()); >>> for (int i = 0; i < length; i++) { >>> FixedArray* elements = FixedArray::cast(stack_->elements()); >>> if (elements->get(i) == *object) { >>> // boom >>> } >>> } >>> } >>> >>> So, operator*() in a Handle gives me a unique id? Which is the >>> type for this? Can I store that in a C++ map? Is it stable (enough)? >>> >>> Thanks! >>> >> -- -- 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.
[v8-users] Re: Finding cycles in an object
You're dereferencing a "super pointer" to get to a "pointer", hence * not &. You can't "go back" because the local/global represents an "reference count" to the object which must be known to the JS runtime. As for p0 and p1, have you tried setting slot to a fixed string value before using it as a key for storing/lookup? I don't know what the expected behavior of using an empty value as a key into an object is. These are all just guesses - if someone else answers differently, I'm probably wrong. On Thursday, June 21, 2018 at 5:07:50 AM UTC-7, Gonzalo Diethelm wrote: > > Note to self: this might be related to Local vs Global (or > Persistent? so many names...) > > Need to look into that. > > On Thursday, June 21, 2018 at 7:58:37 AM UTC+2, Gonzalo Diethelm wrote: >> >> I run the following JS code in the Chrome console: >> >> // Version 67.0.3396.87 (Official Build) (64-bit) >> >> var x = [1, 2, {"foo": 11}]; >> x[2].bar = x; >> >> Now from C++ code, I get ahold of x as a Local, and wish to >> traverse the whole structure; for the sake of the example, let's say I am >> converting it into serialized data (I know I can use JSON.stringify() to do >> this, serializing is just an example to clarify ideas). My question is, >> how can I keep track of the nodes in the structure that I have already >> seen, and their associated serialized value, so that I can avoid an >> infinite traversal? >> >> It seems to me doing this would require a way to get a unique identity >> for each node, so that the C++ code can do something similar to this: >> >> typedef map NodeMap; >> NodeMap seen; >> ... >> Local node = current.GetNextChild(); >> NodeId id = node.GetUniqueId(); >> NodeMap::iterator k = seen.find(id); >> NodeData data; >> if (k != seen.end()) { >> // node already seen, reuse its serialization >> data = k->first; >> } else { >> // first time we see node, serialize and remember >> data = node.Serialize(); // recurses >> seen[id] = data; >> } >> >> The specific question is: what type could be NodeId, and how do I get the >> equivalent of GetUniqueId()? >> >> I am very tempted to ask for a way to get a raw void* to each node, but I >> guess any way of doing this is fine, as long as I can get a unique id that >> is stable while I'm traversing the data. For these reasons, >> GetIdentityHash() does not seem to fit the bill: "*The return value will >> never be 0. Also, it is not guaranteed to be unique.*" >> >> Incidentally, If I try to use JSON.stringify for my data, I get this: >> >> JSON.stringify(x) >> VM170:1 Uncaught TypeError: Converting circular structure to JSON >> at JSON.stringify () >> at :1:6 >> >> This is taken care of here in the V8 code: >> >> JsonStringifier::Result JsonStringifier::StackPush(Handle object) >> { >> ... >> // member stack_ is: Handle stack_; >> int length = Smi::ToInt(stack_->length()); >> FixedArray* elements = FixedArray::cast(stack_->elements()); >> for (int i = 0; i < length; i++) { >> FixedArray* elements = FixedArray::cast(stack_->elements()); >> if (elements->get(i) == *object) { >> // boom >> } >> } >> } >> >> So, operator*() in a Handle gives me a unique id? Which is the >> type for this? Can I store that in a C++ map? Is it stable (enough)? >> >> Thanks! >> > -- -- 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.
[v8-users] Re: Finding cycles in an object
Note to self: this might be related to Local vs Global (or Persistent? so many names...) Need to look into that. On Thursday, June 21, 2018 at 7:58:37 AM UTC+2, Gonzalo Diethelm wrote: > > I run the following JS code in the Chrome console: > > // Version 67.0.3396.87 (Official Build) (64-bit) > > var x = [1, 2, {"foo": 11}]; > x[2].bar = x; > > Now from C++ code, I get ahold of x as a Local, and wish to > traverse the whole structure; for the sake of the example, let's say I am > converting it into serialized data (I know I can use JSON.stringify() to do > this, serializing is just an example to clarify ideas). My question is, > how can I keep track of the nodes in the structure that I have already > seen, and their associated serialized value, so that I can avoid an > infinite traversal? > > It seems to me doing this would require a way to get a unique identity for > each node, so that the C++ code can do something similar to this: > > typedef map NodeMap; > NodeMap seen; > ... > Local node = current.GetNextChild(); > NodeId id = node.GetUniqueId(); > NodeMap::iterator k = seen.find(id); > NodeData data; > if (k != seen.end()) { > // node already seen, reuse its serialization > data = k->first; > } else { > // first time we see node, serialize and remember > data = node.Serialize(); // recurses > seen[id] = data; > } > > The specific question is: what type could be NodeId, and how do I get the > equivalent of GetUniqueId()? > > I am very tempted to ask for a way to get a raw void* to each node, but I > guess any way of doing this is fine, as long as I can get a unique id that > is stable while I'm traversing the data. For these reasons, > GetIdentityHash() does not seem to fit the bill: "*The return value will > never be 0. Also, it is not guaranteed to be unique.*" > > Incidentally, If I try to use JSON.stringify for my data, I get this: > > JSON.stringify(x) > VM170:1 Uncaught TypeError: Converting circular structure to JSON > at JSON.stringify () > at :1:6 > > This is taken care of here in the V8 code: > > JsonStringifier::Result JsonStringifier::StackPush(Handle object) > { > ... > // member stack_ is: Handle stack_; > int length = Smi::ToInt(stack_->length()); > FixedArray* elements = FixedArray::cast(stack_->elements()); > for (int i = 0; i < length; i++) { > FixedArray* elements = FixedArray::cast(stack_->elements()); > if (elements->get(i) == *object) { > // boom > } > } > } > > So, operator*() in a Handle gives me a unique id? Which is the > type for this? Can I store that in a C++ map? Is it stable (enough)? > > Thanks! > -- -- 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.
[v8-users] Re: Finding cycles in an object
Never mind my last question, it didn't really make much sense. So, I have found some basic behaviour related to this, which really surprised me: Local parent; // this will be a JS object Local slot;// this will be a new slot in parent Local object = // this will be the value we want to put in that slot => another object // store object in parent Local value = Local::Cast(object); parent->Set(slot, value); // remember its pointer and hash int h0 = object->GetIdentityHash(); Value* p0 = *value; // retrieve it back Local check_value = parent->Get(slot); Local check_object = Local::Cast(check_value); // remember its pointer and hash int h1 = check_object->GetIdentityHash(); Value* p1 = *check_value; My surprise is that p0 and p1 are not the same, although h0 and h1 are the same. So, the object I store in that slot is actually not identical to what I retrieve back from the slot. Is there any way to store that object so that what you get back is actually the same pointer? I'm pretty sure this must be possible, because when you do this in the Chrome console, JSON does detect the cyclic reference. Cheers! On Thursday, June 21, 2018 at 9:35:09 AM UTC+2, Gonzalo Diethelm wrote: > > Thanks, that is useful (not sure why it is unary * instead of unary &, but > meh). > > Do you know if there is any way to then go from the T* back into the > Local? Something like: > > Handle object = Object::New(isolate); > Local ret = Local::Cast(object); > Object* ptr = *object; // this works, according to your comment > ... > ret = Local::Cast(ptr); // this doesn't work > > Cheers! > > On Thursday, June 21, 2018 at 9:13:16 AM UTC+2, Zac Hansen wrote: >> >> unary * on a local gives a T*: >> https://v8.paulfryzel.com/docs/master/classv8_1_1_local.html#a3c96c0bc5db1288bad5769e8e54e26da >> >> On Wednesday, June 20, 2018 at 10:58:37 PM UTC-7, Gonzalo Diethelm wrote: >>> >>> I run the following JS code in the Chrome console: >>> >>> // Version 67.0.3396.87 (Official Build) (64-bit) >>> >>> var x = [1, 2, {"foo": 11}]; >>> x[2].bar = x; >>> >>> Now from C++ code, I get ahold of x as a Local, and wish to >>> traverse the whole structure; for the sake of the example, let's say I am >>> converting it into serialized data (I know I can use JSON.stringify() to do >>> this, serializing is just an example to clarify ideas). My question is, >>> how can I keep track of the nodes in the structure that I have already >>> seen, and their associated serialized value, so that I can avoid an >>> infinite traversal? >>> >>> It seems to me doing this would require a way to get a unique identity >>> for each node, so that the C++ code can do something similar to this: >>> >>> typedef map NodeMap; >>> NodeMap seen; >>> ... >>> Local node = current.GetNextChild(); >>> NodeId id = node.GetUniqueId(); >>> NodeMap::iterator k = seen.find(id); >>> NodeData data; >>> if (k != seen.end()) { >>> // node already seen, reuse its serialization >>> data = k->first; >>> } else { >>> // first time we see node, serialize and remember >>> data = node.Serialize(); // recurses >>> seen[id] = data; >>> } >>> >>> The specific question is: what type could be NodeId, and how do I get >>> the equivalent of GetUniqueId()? >>> >>> I am very tempted to ask for a way to get a raw void* to each node, but >>> I guess any way of doing this is fine, as long as I can get a unique id >>> that is stable while I'm traversing the data. For these reasons, >>> GetIdentityHash() does not seem to fit the bill: "*The return value >>> will never be 0. Also, it is not guaranteed to be unique.*" >>> >>> Incidentally, If I try to use JSON.stringify for my data, I get this: >>> >>> JSON.stringify(x) >>> VM170:1 Uncaught TypeError: Converting circular structure to JSON >>> at JSON.stringify () >>> at :1:6 >>> >>> This is taken care of here in the V8 code: >>> >>> JsonStringifier::Result JsonStringifier::StackPush(Handle object >>> ) { >>> ... >>> // member stack_ is: Handle stack_; >>> int length = Smi::ToInt(stack_->length()); >>> FixedArray* elements = FixedArray::cast(stack_->elements()); >>> for (int i = 0; i < length; i++) { >>> FixedArray* elements = FixedArray::cast(stack_->elements()); >>> if (elements->get(i) == *object) { >>> // boom >>> } >>> } >>> } >>> >>> So, operator*() in a Handle gives me a unique id? Which is the >>> type for this? Can I store that in a C++ map? Is it stable (enough)? >>> >>> Thanks! >>> >> -- -- 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.
[v8-users] Re: Finding cycles in an object
Thanks, that is useful (not sure why it is unary * instead of unary &, but meh). Do you know if there is any way to then go from the T* back into the Local? Something like: Handle object = Object::New(isolate); Local ret = Local::Cast(object); Object* ptr = *object; // this works, according to your comment ... ret = Local::Cast(ptr); // this doesn't work Cheers! On Thursday, June 21, 2018 at 9:13:16 AM UTC+2, Zac Hansen wrote: > > unary * on a local gives a T*: > https://v8.paulfryzel.com/docs/master/classv8_1_1_local.html#a3c96c0bc5db1288bad5769e8e54e26da > > On Wednesday, June 20, 2018 at 10:58:37 PM UTC-7, Gonzalo Diethelm wrote: >> >> I run the following JS code in the Chrome console: >> >> // Version 67.0.3396.87 (Official Build) (64-bit) >> >> var x = [1, 2, {"foo": 11}]; >> x[2].bar = x; >> >> Now from C++ code, I get ahold of x as a Local, and wish to >> traverse the whole structure; for the sake of the example, let's say I am >> converting it into serialized data (I know I can use JSON.stringify() to do >> this, serializing is just an example to clarify ideas). My question is, >> how can I keep track of the nodes in the structure that I have already >> seen, and their associated serialized value, so that I can avoid an >> infinite traversal? >> >> It seems to me doing this would require a way to get a unique identity >> for each node, so that the C++ code can do something similar to this: >> >> typedef map NodeMap; >> NodeMap seen; >> ... >> Local node = current.GetNextChild(); >> NodeId id = node.GetUniqueId(); >> NodeMap::iterator k = seen.find(id); >> NodeData data; >> if (k != seen.end()) { >> // node already seen, reuse its serialization >> data = k->first; >> } else { >> // first time we see node, serialize and remember >> data = node.Serialize(); // recurses >> seen[id] = data; >> } >> >> The specific question is: what type could be NodeId, and how do I get the >> equivalent of GetUniqueId()? >> >> I am very tempted to ask for a way to get a raw void* to each node, but I >> guess any way of doing this is fine, as long as I can get a unique id that >> is stable while I'm traversing the data. For these reasons, >> GetIdentityHash() does not seem to fit the bill: "*The return value will >> never be 0. Also, it is not guaranteed to be unique.*" >> >> Incidentally, If I try to use JSON.stringify for my data, I get this: >> >> JSON.stringify(x) >> VM170:1 Uncaught TypeError: Converting circular structure to JSON >> at JSON.stringify () >> at :1:6 >> >> This is taken care of here in the V8 code: >> >> JsonStringifier::Result JsonStringifier::StackPush(Handle object) >> { >> ... >> // member stack_ is: Handle stack_; >> int length = Smi::ToInt(stack_->length()); >> FixedArray* elements = FixedArray::cast(stack_->elements()); >> for (int i = 0; i < length; i++) { >> FixedArray* elements = FixedArray::cast(stack_->elements()); >> if (elements->get(i) == *object) { >> // boom >> } >> } >> } >> >> So, operator*() in a Handle gives me a unique id? Which is the >> type for this? Can I store that in a C++ map? Is it stable (enough)? >> >> Thanks! >> > -- -- 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.
[v8-users] Re: Where are let / const objects stored?
I don't know the answer, but they are accessible via the debugging interface, so that may be a place to look. On Wednesday, June 20, 2018 at 11:01:23 PM UTC-7, Gonzalo Diethelm wrote: > > I run the following JS code in the Chrome console: > > // Version 67.0.3396.87 (Official Build) (64-bit) > > var p = 11 > p // returns 11 > > let q = 12 > q // returns 12 > > const r = 13 > r // returns 13 > > Now, from C++ code, I can look up p in the global context, and it is > found; its value is, unsurprisingly, 11. > > On the other hand, q and r are not found in the global context. This is > fine, I guess, since let / const have lexical scoping. > > My question is: how does Chrome / V8 find q and r? Where is it looking > for them? > > Thanks! > -- -- 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.
[v8-users] Re: Finding cycles in an object
unary * on a local gives a T*: https://v8.paulfryzel.com/docs/master/classv8_1_1_local.html#a3c96c0bc5db1288bad5769e8e54e26da On Wednesday, June 20, 2018 at 10:58:37 PM UTC-7, Gonzalo Diethelm wrote: > > I run the following JS code in the Chrome console: > > // Version 67.0.3396.87 (Official Build) (64-bit) > > var x = [1, 2, {"foo": 11}]; > x[2].bar = x; > > Now from C++ code, I get ahold of x as a Local, and wish to > traverse the whole structure; for the sake of the example, let's say I am > converting it into serialized data (I know I can use JSON.stringify() to do > this, serializing is just an example to clarify ideas). My question is, > how can I keep track of the nodes in the structure that I have already > seen, and their associated serialized value, so that I can avoid an > infinite traversal? > > It seems to me doing this would require a way to get a unique identity for > each node, so that the C++ code can do something similar to this: > > typedef map NodeMap; > NodeMap seen; > ... > Local node = current.GetNextChild(); > NodeId id = node.GetUniqueId(); > NodeMap::iterator k = seen.find(id); > NodeData data; > if (k != seen.end()) { > // node already seen, reuse its serialization > data = k->first; > } else { > // first time we see node, serialize and remember > data = node.Serialize(); // recurses > seen[id] = data; > } > > The specific question is: what type could be NodeId, and how do I get the > equivalent of GetUniqueId()? > > I am very tempted to ask for a way to get a raw void* to each node, but I > guess any way of doing this is fine, as long as I can get a unique id that > is stable while I'm traversing the data. For these reasons, > GetIdentityHash() does not seem to fit the bill: "*The return value will > never be 0. Also, it is not guaranteed to be unique.*" > > Incidentally, If I try to use JSON.stringify for my data, I get this: > > JSON.stringify(x) > VM170:1 Uncaught TypeError: Converting circular structure to JSON > at JSON.stringify () > at :1:6 > > This is taken care of here in the V8 code: > > JsonStringifier::Result JsonStringifier::StackPush(Handle object) > { > ... > // member stack_ is: Handle stack_; > int length = Smi::ToInt(stack_->length()); > FixedArray* elements = FixedArray::cast(stack_->elements()); > for (int i = 0; i < length; i++) { > FixedArray* elements = FixedArray::cast(stack_->elements()); > if (elements->get(i) == *object) { > // boom > } > } > } > > So, operator*() in a Handle gives me a unique id? Which is the > type for this? Can I store that in a C++ map? Is it stable (enough)? > > Thanks! > -- -- 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.