Does "native" have special meaning?

For AI and campaign script related discussions and questions
Post Reply
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Does "native" have special meaning?

Post 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?
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Does "native" have special meaning?

Post by Per »

No idea. Maybe something qtscript has defined internally? What is the error message you get?
cybersphinx
Inactive
Inactive
Posts: 1695
Joined: 01 Sep 2006, 19:17

Re: Does "native" have special meaning?

Post by cybersphinx »

Seems it's a Chrome/V8 extension: http://stackoverflow.com/questions/6733 ... 23#6733023
Does QtScript use V8?
We want information... information... information.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Does "native" have special meaning?

Post 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.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Does "native" have special meaning?

Post 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.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Does "native" have special meaning?

Post 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.
cybersphinx
Inactive
Inactive
Posts: 1695
Joined: 01 Sep 2006, 19:17

Re: Does "native" have special meaning?

Post by cybersphinx »

We want information... information... information.
User avatar
aubergine
Professional
Professional
Posts: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: Does "native" have special meaning?

Post 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.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Post Reply