question

brendan avatar image
brendan asked

CloudScript... ECMAScript?

richjoslin
started a topic on Tue, 22 September 2015 at 8:04 PM

Does CloudScript follow the ECMAScript standard, and if so, which version? Or is it a proprietary language based on ECMAScript syntax?

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
brendan avatar image
brendan answered

5 Comments
Brendan Vanous said on Tue, 06 Oct at 12:36 AM

Hi Rich,
Sorry for the delay on this. Our Cloud Script uses the latest V8 javascript engine, which makes it ECMA-262, edition 5.1, and features from upcoming 6 (https://en.wikipedia.org/wiki/ECMAScript).
Brendan

richjoslin said on Tue, 06 Oct at 12:38 PM

Good to know, thanks!

I ran into a bug with Object.getOwnPropertyNames with a non-object argument that appears to be a V8 bug, so that makes sense. I've worked around it for now with this:

if (typeof obj === 'object' && Object.getOwnPropertyNames(obj).length === 0)
{
// etc...
}

Brendan Vanous said on Tue, 06 Oct at 4:50 PM

If there are issues in the latest V8, then yes, it's likely you'd run into the same issues in Cloud Script. Could you post the specifics on the actual bug you're working around, for the benefit of others following the thread?

richjoslin said on Tue, 06 Oct at 5:04 PM

Well, I might not be correct in my conclusion, as the bug page I found is marked as resolved over a year ago.

https://code.google.com/p/v8/issues/detail?id=3443

This was my function to check if an object is empty:

function isObjectEmpty(obj)
{
    if (obj == null) return true;
    if (typeof obj === 'undefined') return true;
    if (Object.getOwnPropertyNames(obj).length === 0) return true;
    return false;
}

But I would sometimes get an error "TypeError: Object.getOwnPropertyNames called on non-object" on the "getOwnPropertyNames" line.

I added the check to make sure it's an object type, and that's my workaround:

function isObjectEmpty(obj)
{
    if (obj == null) return true;
    if (typeof obj === 'undefined') return true;
    if (typeof obj === 'object' && Object.getOwnPropertyNames(obj).length === 0) return true;
    return false;
}

What I don't know is: if something is not null or undefined, how is it still not an object?

(now that I think about it, I could debug the typeof and see what type is causing the problem)

richjoslin said on Tue, 06 Oct at 10:24 PM

I did a little debugging and confirmed that Object.getOwnPropertyNames is indeed throwing the "called on non-object" error when I use it on a string (in this case, a GUID representing a match between two players), I don't actually know what the expected result is, so I can't claim it's a bug or not. I might be misusing getOwnPropertyNames after all. To be more thorough, I can just check if the type is string, and then check for an empty string.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.