edbrowse-dev - development list for edbrowse
 help / color / mirror / Atom feed
* [Edbrowse-dev] Array != Array
@ 2018-02-01 20:38 Karl Dahlke
  0 siblings, 0 replies; only message in thread
From: Karl Dahlke @ 2018-02-01 20:38 UTC (permalink / raw)
  To: Edbrowse-dev

[-- 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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-02-01 20:37 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-01 20:38 [Edbrowse-dev] Array != Array Karl Dahlke

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