From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from resqmta-ch2-01v.sys.comcast.net (resqmta-ch2-11v.sys.comcast.net [IPv6:2001:558:fe21:29:69:252:207:43]) by hurricane.the-brannons.com (Postfix) with ESMTPS id 8AC867788C for ; Sat, 31 Oct 2020 20:24:04 -0700 (PDT) Received: from resomta-ch2-17v.sys.comcast.net ([69.252.207.113]) by resqmta-ch2-11v.sys.comcast.net with ESMTP id Z3y1kXoeBdQwjZ3yNkXbsQ; Sun, 01 Nov 2020 03:24:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comcast.net; s=20190202a; t=1604201043; bh=SWLv5SkEGkG9DFOhQoR1f5pvujYpwVg/JaWuxzQybUI=; h=Received:Received:To:From:Reply-to:Subject:Date:Message-ID: Mime-Version:Content-Type; b=cv9h9OA4sUToDlfytxtnz+UWj2pxvyNigL1f2Pio7aQ+FsB506sdqhV39MYGFi0O0 dgy1bFcolUw+Rl69re5Nnt2nUov/msu6uzc/5VRgTstuJr3jhlXVXSJkkjCXNUMJnO 28TbDG3r33Wt0MmJtMUJ4muJ6rs+NV2D5aveHUWgPJHrzh7/y9SPJ9U84elRCZOkU5 Z8nrE/xsRzMpRy/x32Iymd3r59UaopOq3smhCUyY4R5rPDW4qyRjg9gLX7h5tn298Y MW1eRy7K8boDwn325XOIOGVE+1ZnbhTr3KcqykLmfE96/ALoA7NUEGrYac/AgQfYWc 8jGP6tEdQlUEw== Received: from unknown ([IPv6:2601:408:c300:a3d0::32fe]) by resomta-ch2-17v.sys.comcast.net with ESMTPSA id Z3y9km1aRZjcdZ3yFkhwoF; Sun, 01 Nov 2020 03:23:56 +0000 X-Xfinity-VMeta: sc=0.00;st=legit To:edbrowse-dev@edbrowse.org From: Karl Dahlke Reply-to: Karl Dahlke User-Agent: edbrowse/3.7.6 Subject: [edbrowse-dev] Rooted Date: Sat, 31 Oct 2020 23:23:49 -0400 Message-ID: <20200931232349.eklhad@comcast.net> X-BeenThere: edbrowse-dev@edbrowse.org List-Id: Edbrowse Development List Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=nextpart-eb-666225 Content-Transfer-Encoding: 7bit This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. --nextpart-eb-666225 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Spider monkey has a rooting guide, which I bookmarked, and I need to = read, but sometimes I learn more just playing withthe the software. First the existential crisis. I stored a pointer to the document object, swallowed startwindow.js and = third.js, which is a lot of stuff, Fetched the document object from the global object, and verified that = the pointer changed out from under me. Pointer to object is not permanent and guaranteed, as it is in duktape. Just one of many reasons duktape is sooooo much easier to use. We have to have reliable pointers. When I go to a hyperlink, tag, there's an object with that, edbrowse keeps a pointer to that object, I need to be able to bounce = through that pointer and look at the object, and see if the href has changed, or if there is onclick code to run, = and so on and so on. If the garbage collector has moved that object somewhere else, or if it = moved by realloc because it got bigger, then I'm fucking screwed. A seg fault that I'll never be able to debug. That is the existential crisis. And the crisis is confirmed by my hello program, wherein the document = object moved to a new location because of executing 16,000 lines of js. This of course put me into a deep depression, along with everything = else that is happening in my life. But I wanted to learn something. Still haven't read the rooting guide, but I knew it had something to do = with rooting. There is a general Rooted class. template class Rooted { ... } (This is where you have to learn c++.) Lots of things can be rooted but I'm mostly interested in objects. So specialize the template as Rooted They have some convenient typedefs for the common ones. typedef Rooted RootedObject; typedef Rooted RootedValue; A rooted thing is 12 bytes. The first 8 bytes do the rooting, somehow, and the last 4 bytes point = to the thing. The * operator is overloaded to push the pointer out. (Other important operators are overloaded as well.) So if d is an object from class Rooted, then *d returns those last = 4 bytes, which is a pointer to something of type foo. But only use that pointer in a transient way. I thought rooting would prevent the pointer from changing, prevent the = thing from moving. WRONG! But it does update the pointer in each root if it does move. So, my document object moved, and it updated the pointer in my rooted = document object. In fact they really want you to deal with the rooted things, not the = pointers at all, if you can help it. Their functions take and return rooted things. If objects move around in memory, all the rooted things are updated. I have a structure htmlTag, with a member jv, javascript variable. It's just a void * I could point to the object and feel good about it, in duktape, because = the object never moved. In mozjs, I can't just point to the object, it might move, I have to = use something rooted. I could have RootedObject in the html tag, but then all of edbrowse has = to read in jsapi.h, and all of edbrowse has to know about RootedObject, and all of edbrowse = has to be processed by g++. There's no more encapsulation, keeping it all within jseng-moz.cpp. That would piss me off! (Yeah, that's how we handled it many years ago.) Or I could just say ok, jv is an opaque 12 bytes that I don't know = anything about, but that's hardly portable. What if it's 16 bytes on some other machine, or even 24? I could point to or index an array of rooted things that is only known = inside jseng-moz.cpp. I sort of like that idea but not sure how to implement it in practice. Holy shit this stuff is complicated. Karl Dahlke --nextpart-eb-666225--