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
_______________________________________________
Edbrowse-dev mailing list
[email protected]
http://lists.the-brannons.com/mailman/listinfo/edbrowse-dev

Reply via email to