edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
From: Karl Dahlke <eklhad@comcast.net>
To: Edbrowse-dev@lists.the-brannons.com
Subject: [Edbrowse-dev] duktape and jsrt
Date: Thu, 13 Jul 2017 18:03:34 -0400	[thread overview]
Message-ID: <20170613180334.eklhad@comcast.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 3590 bytes --]

1. As I've been working with duktape I'm feeling free, free from the nightmare of rooted strings and rooted objects and mutable handles in moz js, and if you don't get all of that right all of the time it could seg fault one time in 100, in a manner that is almost impossible to track down and fix.
I love duktape.
But ... if you're using pointers to objects in your c program and you want those pointers to be valid forever more,
(that's how we connect html tags to their javascript objects), you do have to realize a couple things.
The manual guarantees these pointers are valid if each object is always "connected", as far as garbage collection is concerned.
Connected can mean accessible from the window object in the usual way, or, on the duktape stack.
So here's something you can't do.
A native method f1 in C calls duktape to create a new object,
passes the pointer to this object back to a calling function f2,
and then f2, or some other function f3, links it into the tree under document.
When f1 returns, its piece of the duktape stack goes away,
and for a short moment you have a pointer to a disconnected object, an object that could move or go away.
I learned all this while chasing a bug, which was actually caused by something else, but it's still good to understand.
As it happens, we did everything right, at least I think we did.
Look at the functions in ebprot.h.
Example:  instantiate(parent, name, classname);
This function creates a new object from the class classname, and links it in under parent.name, all in one fell swoop.
The new object sits happily on the duktape stack, then is linked int the window tree, then the function returns.
Other functions are the same way.
instantiate_array_element(a, idx, classname);
Create the new object and linke it into a[idx] all as part of that one function, before we give up the duktape stack.
So maybe by sheer good fortune the API is right,
and that made the conversion way easier.
I don't think I changed the API at all. Sure didn't want to!!

2. There are some differences between the engines, and I'm dealing with them one by one.
See the last push for an example, if you're interested.

3. As the subject says, jsrt now passes with duktape.
No errors, and I interacted with the form, select, reset, submit, etc, and it seems to work properly.
But ... a lot of web pages in the wild still cause duktape to seg fault.
It's more fragile than mozilla, either that or I have to do more checking as we go, and use more protected calls.
I use the protected eval and the protected compile, for example.
More work to do here.

4. Maybe it's time for others to play with it and provide feedback, but just remember that js will fail on you.
You know I want to merge branches as soon as possible, so we're all working on the same beast again, but I don't want to recklessly merge too early.
In other words, we want to be pretty confident that duktape is our future.
After the merge it will be awfully difficult to go back to mozilla.
I don't know about v8 and others, but I'm hoping never to do this kind of conversion again.

5. Interwindow communication seems possible, based on just a few sentences from the programmers guide.
I currently create a heap for each edbrowse window, then a js context in that heap.
We should create one heap for all of edbrowse, then a context for each window, and then the manual says these contexts can talk to each other.
This is all for another day of course, but I like the warm fuzzy feeling that it's at least doable.

Cheers,

Karl Dahlke

             reply	other threads:[~2017-07-13 22:02 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-13 22:03 Karl Dahlke [this message]
2017-07-14  6:25 ` Kevin Carhart
2017-07-14 20:17   ` Karl Dahlke

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170613180334.eklhad@comcast.net \
    --to=eklhad@comcast.net \
    --cc=Edbrowse-dev@lists.the-brannons.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).