archives

« Bugzilla Issues Index

#108 — Missing coverage? http://code.google.com/p/google-caja/issues/detail?id=1362


<Thanks>Mark Miller</Thanks>

We might be missing coverage for the following test scenario. Add test case(s)
assuming this scenario can be mapped to ES5.1 somewhere
--------------------------------------------------------------------------
*See
http://codereview.appspot.com/4547070/diff/6003/src/com/google/caja/ses/es5shim.js?context=10&column_width=80
for the original*

/**


191 * Workaround for http://code.google.com/p/google-caja/issues/detail?id=1362

192 *

193 * <p>This is an unfortunate oversight in the ES5 spec: Even if

194 * Date.prototype is frozen, it is still defined to be a Date, and

195 * so has mutable state in internal properties that can be mutated

196 * by the primordial mutation methods on Date.prototype, such as

197 * {@code Date.prototype.setFullYear}.

198 *

199 * <p>This kludge is safety preserving.



200 */

201 function test_MUTABLE_DATE_PROTO() {

202 try {

203 Date.prototype.setFullYear(1957);

204 } catch (err) {

205 if (err instanceof TypeError) { return false; }

206 log('New symptom: Mutating Date.prototype failed with ' + err);

207 return true;

208 }

209 var v = Date.prototype.getFullYear();

210 if (v !== v && typeof v === 'number') {

211 // NaN indicates we're probably ok.

212 return false;

213 }

214 if (v === 1957) {

215 log('Date.prototype is a global communication channel. ' +

216 'See http://code.google.com/p/google-caja/issues/detail?id=1362');

217 } else {

218 log('New symptom: Mutating Date.prototype did not throw');

219 }

220 return true;

221 }

222 //var TOLERATE_MUTABLE_DATE_PROTO = false;

223 var TOLERATE_MUTABLE_DATE_PROTO = test_MUTABLE_DATE_PROTO();

224


IETC has some very limited testing for this in the form of Date.prototype.toISOString:
E:\262\test262\test\suite\ch15\15.9\15.9.5\15.9.5.43\15.9.5.43-0-16.js(23): * @description Date.prototype.toISOString - when this is a String object that value format is 'YYYY-MM-DDTHH:mm:ss.sssZ' Date.prototype.toISOString throw the TypeError
E:\262\test262\test\suite\ch15\15.9\15.9.5\15.9.5.43\15.9.5.43-0-16.js(34): return ex instanceof TypeError;
E:\262\test262\test\suite\ch15\15.9\15.9.5\15.9.5.43\15.9.5.43-0-6.js(23): * @description Date.prototype.toISOString - TypeError is thrown when this is any other objects instead of Date object
E:\262\test262\test\suite\ch15\15.9\15.9.5\15.9.5.43\15.9.5.43-0-6.js(33): return ex instanceof TypeError;
E:\262\test262\test\suite\ch15\15.9\15.9.5\15.9.5.43\15.9.5.43-0-7.js(23): * @description Date.prototype.toISOString - TypeError is thrown when this is any primitive values
E:\262\test262\test\suite\ch15\15.9\15.9.5\15.9.5.43\15.9.5.43-0-7.js(33): return ex instanceof TypeError;

I think we can do a bit better than this though, and will extend the coverage shortly.


*will add test files under TestCases\ch15\15.9\15.9.5\15.9.5.40*


Tests are now live on test262.ecmascript.org.