Made use of ECMAScript 5 meta-stuff; methods defined in prefix header are now non-enumerable and non-writeable just like native ones.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@4016 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2011-01-06 12:05:16 +00:00
parent 62f35e872c
commit 926b2f81ea
2 changed files with 68 additions and 43 deletions

View File

@ -306,7 +306,7 @@ this.prettifyArray = function prettifyArray(value, indent)
this.prettifyObject = function prettifyObject(value, indent) this.prettifyObject = function prettifyObject(value, indent)
{ {
indent = indent || ""; indent = indent || "";
var subIndent = indent + "\t"; var subIndent = indent + " ";
var appendedAny = false; var appendedAny = false;
var result = "{"; var result = "{";

View File

@ -53,11 +53,16 @@ this.version = "1.75";
/**** Utilities, not intended to be retired ****/ /**** Utilities, not intended to be retired ****/
// Ship.spawnOne(): like spawn(role, 1), but returns the ship rather than an array. // Ship.spawnOne(): like spawn(role, 1), but returns the ship rather than an array.
Object.getPrototypeOf(Ship).spawnOne = function Ship_spawnOne(role) Object.defineProperty(Object.getPrototypeOf(Ship), "spawnOne",
{
value: function Ship_spawnOne(role)
{ {
var result = this.spawn(role, 1); var result = this.spawn(role, 1);
return result ? result[0] : null; return result ? result[0] : null;
}; },
writable: false,
enumerable: false
});
// mission.addMessageTextKey(): load mission text from mission.plist and append to mission screen or info screen. // mission.addMessageTextKey(): load mission text from mission.plist and append to mission screen or info screen.
@ -70,7 +75,9 @@ mission.addMessageTextKey = function mission_addMessageTextKey(textKey)
/* SystemInfo.systemsInRange(): return SystemInfos for all systems within a /* SystemInfo.systemsInRange(): return SystemInfos for all systems within a
certain distance. certain distance.
*/ */
SystemInfo.systemsInRange = function SystemInfo_systemsInRange(range) Object.defineProperty(SystemInfo, "systemsInRange",
{
value: function SystemInfo_systemsInRange(range)
{ {
if (range === undefined) if (range === undefined)
{ {
@ -98,7 +105,10 @@ SystemInfo.systemsInRange = function SystemInfo_systemsInRange(range)
{ {
return (other.systemID !== thisSystem.systemID) && (thisSystem.distanceToSystem(other) <= range); return (other.systemID !== thisSystem.systemID) && (thisSystem.distanceToSystem(other) <= range);
}); });
}; },
writable: false,
enumerable: false
});
/* system.scrambledPseudoRandom(salt : Number (integer)) : Number /* system.scrambledPseudoRandom(salt : Number (integer)) : Number
@ -115,7 +125,9 @@ SystemInfo.systemsInRange = function SystemInfo_systemsInRange(range)
system.scrambledPseudoRandomNumber() with different salt values, there will system.scrambledPseudoRandomNumber() with different salt values, there will
be no obvious correlation between the different stations distributions. be no obvious correlation between the different stations distributions.
*/ */
system.scrambledPseudoRandomNumber = function system_scrambledPseudoRandomNumber(salt) Object.defineProperty(system, "scrambledPseudoRandomNumber",
{
value: function system_scrambledPseudoRandomNumber(salt)
{ {
// Convert from float in [0..1) with 24 bits of precision to integer. // Convert from float in [0..1) with 24 bits of precision to integer.
var n = Math.floor(system.pseudoRandomNumber * 16777216.0); var n = Math.floor(system.pseudoRandomNumber * 16777216.0);
@ -130,11 +142,24 @@ system.scrambledPseudoRandomNumber = function system_scrambledPseudoRandomNumber
// Convert from (effectively) 32-bit signed integer to float in [0..1). // Convert from (effectively) 32-bit signed integer to float in [0..1).
return n / 4294967296.0 + 0.5; return n / 4294967296.0 + 0.5;
}; },
writable: false,
enumerable: false
});
/**** Built-in in ECMAScript 5, to be removed when Linux builds transition ****/ /**** Built-in in ECMAScript 5, to be removed when Linux builds transition ****/
// Object.defineProperty: only value key is supported. Getter and setter are possible, but not required.
if (typeof Object.defineProperty !== "function")
{
Object.defineProperty = function (object, name, definition)
{
object[name] = definition.value;
}
}
// Object.getPrototypeOf(): ECMAScript 5th Edition eqivalent to __proto__ extension. // Object.getPrototypeOf(): ECMAScript 5th Edition eqivalent to __proto__ extension.
if (typeof Object.getPrototypeOf !== "function") if (typeof Object.getPrototypeOf !== "function")
{ {