Re: minisphere 1.2.3
Reply #582 –
I just realized I may be able to fix the "invalid base value" issue when variables are declared overwriting Sphere constructors. I don't actually have to--it's a very bad practice I don't like to condone, but Duktape's error message for it is so obtuse that working around it is actually preferable at this point.
The issue arises because minisphere stores internal metadata properties in the object prototypes. So when you declare a variable named, say,
Font and then call a function which works with Font objects (e.g. GetSystemFont), the engine tries to access the Font prototype (this is why there is no line number--the error happened on the native side), which fails the same as if you did this in script:
var Font; var foo = Font.prototype;
To elaborate on that: the boundary between native and script in Duktape is very thin. Duktape's bytecode interpreter internally calls many of the same functions its public API does. That's the reason why half of the Duktape API is macros and a big reason it can be as fast as it is.
Luckily Duktape also has this thing called the "stash" where you can store JS objects out of band such that they won't be garbage collected but are not otherwise accessible from script. I could keep the object prototypes in the stash so that, if
Font.prototype itself became inaccessible, the engine could still access it internally through the stash. This would be enough to stop the errors, I think.