Page 1 of 1
Does "native" have special meaning?
Posted: 16 Nov 2012, 21:15
by aubergine
Can someone explain why this throws an error:
Code: Select all
(function(_global) {
_global.native = _global;
})(this);
function foo() {
if (typeof native == "undefined") { // Error here
console("native undefined");
} else {
console("native: "+(typeof native));
console("include: "+(typeof native.include));
}
}
function eventStartLevel() {
setTimer("foo", 10000);
}
And this works fine (rename "native" to "nativ"):
Code: Select all
(function(_global) {
_global.nativ = _global;
})(this);
function foo() {
if (typeof nativ == "undefined") {
console("nativ undefined");
} else {
console("nativ: "+(typeof nativ));
console("includ: "+(typeof nativ.include));
}
}
function eventStartLevel() {
setTimer("foo", 10000);
}
The only difference is that rename of "native" to "nativ" -- I've searched everywhere but I can't find any reference to special meaning of "native" in JS or the WZ JS API.... Any ideas?
Re: Does "native" have special meaning?
Posted: 16 Nov 2012, 21:53
by Per
No idea. Maybe something qtscript has defined internally? What is the error message you get?
Re: Does "native" have special meaning?
Posted: 16 Nov 2012, 22:24
by cybersphinx
Seems it's a Chrome/V8 extension:
http://stackoverflow.com/questions/6733 ... 23#6733023
Does QtScript use V8?
Re: Does "native" have special meaning?
Posted: 17 Nov 2012, 01:38
by aubergine
This is the error it gives:
Code: Select all
info |07:17:28: [loadPlayerScript:378] Syntax error in multiplay/skirmish/eggplant.js line 6:
info |07:17:28: [loadPlayerScript:378] Assert in Warzone: /Users/dak180/Applications/Build/wz2100/hg/wz2100-git/macosx/../src/qtscript.cpp:378 (syntax.state() == QScriptSyntaxCheckResult::Valid), last script event: '<none>'
I'll try "Native" instead of "native" and see if that works. It might be jslint related as the error is being triggered prior to the function being invoked?
EDIT: I've done some searching of the global object and it's proto chain (it only has one level deep proto) and there's nothing called "native" defined there. I've also tried Object.getOwnPropertyDescriptor() on the global object and it's proto and that confirms nothing called "native" there. So something else is treating it as a reserved keyword or operator of some kind.
Anyway, I've renamed the property to "Native" and that seems to get round the problem.
Re: Does "native" have special meaning?
Posted: 17 Nov 2012, 04:26
by aubergine
Ok, for my next bit of JS weirdness, does anyone know why adding accessor properties (hidden, non-configurable getter/setter) to Object.prototype would cause WZ to crash to desktop?
Also, is there a limit to the amount of RAM assigned to each JS environment in WZ? My script repository is getting somewhat large.
Re: Does "native" have special meaning?
Posted: 17 Nov 2012, 12:26
by Per
I'm not aware of any such limitations.
Crashing is bad, obviously. Any way to make the game crash from a script is a bad bug and should be posted as a bug ticket.
Re: Does "native" have special meaning?
Posted: 17 Nov 2012, 13:59
by cybersphinx
Re: Does "native" have special meaning?
Posted: 17 Nov 2012, 17:41
by aubergine
@Per - I'll make a test script to reproduce and create ticket, will prolly be tomorrow some time.
@cybersphinx - that list is awesome! thanks! I actually have that book on my desk, but the first edition doesn't list those extra keywords.