Help with JavaScript type
-
I'm asking this here because it may be peculiar to the QML JavaScript engine.
What value of
xcould give me the following results:x !== null
x !== undefined
typeof x === "object"
String(x) === "?"
Object.getPrototypeOf(x) === undefinedIn my program
xcould benull, but the first test says otherwise, or it could be aUint8Array, but the string version of that is a comma-separated list of numbers. What, other than a quoted question mark, displays as a question mark?I'm wondering if it could be a reference to an object that has been garbage collected, and I've discovered some sort of bug in the engine.
-
Hi,
Can you post a minimal code sample that shows the situation you describe ?
-
I'm asking this here because it may be peculiar to the QML JavaScript engine.
What value of
xcould give me the following results:x !== null
x !== undefined
typeof x === "object"
String(x) === "?"
Object.getPrototypeOf(x) === undefinedIn my program
xcould benull, but the first test says otherwise, or it could be aUint8Array, but the string version of that is a comma-separated list of numbers. What, other than a quoted question mark, displays as a question mark?I'm wondering if it could be a reference to an object that has been garbage collected, and I've discovered some sort of bug in the engine.
-
@pderocco
Don't know, but don't forget you can try variousinstanceOf()if you can guess what the (base) type might be?@JonB The only two things I should get are null or a Uint8Array. When the failure occurs, it doesn't compare equal to null, and
x instanceof Uint8Arrayreturnsfalse. Also,x.prototypereturnsundefined. Other thannull, what kinds of things can report a type ofobject, but not have a prototype?Update: Apparently, things like Uint8Array report a type of
object, and have aprototypeofundefinedrather thannull. I guessed that I may have used an ArrayBuffer instead of a Uint8Array, and sure enough,x instanceof ArrayBufferreturns true. Soconsole.logdisplays anArrayBufferas a question mark.So, problem solved I guess. Thanks for pointing me to
instanceof. -
@JonB The only two things I should get are null or a Uint8Array. When the failure occurs, it doesn't compare equal to null, and
x instanceof Uint8Arrayreturnsfalse. Also,x.prototypereturnsundefined. Other thannull, what kinds of things can report a type ofobject, but not have a prototype?Update: Apparently, things like Uint8Array report a type of
object, and have aprototypeofundefinedrather thannull. I guessed that I may have used an ArrayBuffer instead of a Uint8Array, and sure enough,x instanceof ArrayBufferreturns true. Soconsole.logdisplays anArrayBufferas a question mark.So, problem solved I guess. Thanks for pointing me to
instanceof.