Subversion Repositories JSX

Compare Revisions

Last modification

Ignore whitespace Rev 516 → Rev 517

/trunk/test/array.html
7,11 → 7,11
<title>PointedEars' JSX:array.js Unit Test</title>
<script type="text/javascript" src="../builder?src=object,string,test/test"></script>
<script type="text/javascript" src="../array.js"></script>
<script type="text/javascript" src="array.js"></script>
<script type="text/javascript" src="array-test.js"></script>
</head>
<body onload="runTests()">
<h1>PointedEars' <a href="/websvn/filedetails.php?repname=JSX&path=%2Ftrunk%2Farray.js"
<h1>PointedEars' <a href="/wsvn/JSX/trunk/array.js"
>JSX:<tt>array.js</tt></a> Unit Test</h1>
<p>See error console for details.</p>
</body>
/trunk/array.js
151,6 → 151,31
});
 
/**
* @param {Object} target
* @param {Object} traps
* @return {Proxy}
*/
function _getProxy (target, traps)
{
return jsx.tryThis(
function () {
return new Proxy(target, traps);
},
 
function () {
return jsx.tryThis(
function () {
return Proxy.create(target, traps);
},
function (e) {
return jsx.rethrowThis(e);
}
);
}
);
}
 
/**
* An <code>Array</code> whose last elements can be accessed
* by negative index. This additional functionality requires
* support for <code>Proxy</code> (ECMAScript Edition 6 “Harmony”
166,8 → 191,8
 
if (typeof Proxy != "undefined")
{
var traps = {
set: function (target, propertyName, value) {
return _getProxy(me, {
"get": function (target, propertyName) {
var index;
if (!isNaN(index = parseInt(propertyName, 10)))
{
177,10 → 202,9
}
}
 
return (target[propertyName] = value);
return target[propertyName];
},
 
get: function (target, propertyName) {
"set": function (target, propertyName, value) {
var index;
if (!isNaN(index = parseInt(propertyName, 10)))
{
190,31 → 214,40
}
}
 
return target[propertyName];
return (target[propertyName] = value);
}
};
});
}
 
return jsx.tryThis(
function () {
return new Proxy(me, traps);
},
return me;
}.extend(Array, {
"get": function (propertyName) {
var index;
if (!isNaN(index = parseInt(propertyName, 10)))
{
if (index < 0)
{
propertyName = target.length + index;
}
}
 
function () {
return jsx.tryThis(
function () {
return Proxy.create(me, traps);
},
function (e) {
return jsx.rethrowThis(e);
}
);
return target[propertyName];
},
 
"set": function (propertyName, value) {
var index;
if (!isNaN(index = parseInt(propertyName, 10)))
{
if (index < 0)
{
propertyName = target.length + index;
}
);
}
 
return (target[propertyName] = value);
}
});
 
return me;
}.extend(Array);
 
/**
* Array-like object which can hold up to 2<sup>53</sup> elements
*
313,6 → 346,30
}
}
}
 
if (typeof Proxy != "undefined")
{
return _getProxy(this, {
"get": function (target, propertyName) {
var index;
if (!isNaN(index = parseInt(propertyName, 10)))
{
this.get(index);
}
 
return target[propertyName];
},
"set": function (target, propertyName, value) {
var index;
if (!isNaN(index = parseInt(propertyName, 10)))
{
this.set(index, value);
}
 
return (target[propertyName] = value);
}
});
}
},
{
/**
367,7 → 424,7
* @param {int} index
* @return {any} the element of this array at <var>index</var>
*/
get: function BigArray_get (index) {
"get": function BigArray_get (index) {
if (arguments.length < 1)
{
return jsx.throwThis(jsx.InvalidArgumentError,
393,7 → 450,7
* @param {int} index
* @param {any} value
*/
set: function (index, value) {
"set": function (index, value) {
var length = this.getLength();
 
if (index < 0)