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] Array != Array
Date: Thu, 01 Feb 2018 15:38:08 -0500	[thread overview]
Message-ID: <20180101153808.eklhad@comcast.net> (raw)

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

Folks there's a really long saga I could tell you, but maybe I can cut it down to a Readers Digest version.
It started about 5 commits ago (back up if you like),
and I found that I could browse jsrt, our regression test, unbrowse, and browse, and the second time there was a type error, which you see with db3.
Why the second time and not the first?
I spent an entire day tracking it down.
I distilled it to a 70 line C program, which I thought revealed a bug in duktape.
I sent it to Sami for review.
He felt it was not a bug, but a consequence of different windows and different name spaces.
We didn't run into this until we started doing cross frame references, and building universal edbrowse functions in the master window that must run in all frames. Now it shows up.
When a function references a global variable foo, foo is locked into foo in that window (at compile time), not another window.
That's not too surprising, but Array is a native class, never declared by us at all. I thought it was universal.
I created an array in one frame, and asked instanceof Array from another, and it failed.
Even though it is native, Array is still a class per window.
Below is my reply to Sami's explanation.
Yes I fixed the problem, and am on the prowl for other problems of this ilk.

============================================================

I will have to digest what you are saying.
Array is a native class, so I thought it was somewhat universal, but it is not.
I have a small web page with a frame, and in my js debugger,

window.Array !== frames[0].contentWindow.Array;

Indeed they are different.
It follows that their prototypes will also be different objects, and perhaps that is key.
I've seen some web pages, not many, but some, that add things to Array.prototype, and you wouldn't want that to spill over into unrelated websites that were up at the same time,
so I (grudgingly) admit this is how it has to be.
So then how do I ask instanceof Array when dipping into other frames or building master functions that apply to all frames?
Looking at js from www.nasa.gov, I see that they use Array.isArray(x) instead of x instanceof Array.
You support that, and hey ho, it works.
I guess other developers have run into this same issue.
This has solved my current problem / confusion, I'll send you additional questions if they come up.
I don't remember now if your programmers guide talks about lexical bindings and realms and such, but you should mention that even native functions or classes are distinct entities, as they are bound to various contexts.
Even implicit classes like Array and Date.

Karl Dahlke

                 reply	other threads:[~2018-02-01 20:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20180101153808.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).