michael@0: // |reftest| skip-if(!xulRuntime.shell) michael@0: // -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: // Any copyright is dedicated to the Public Domain. michael@0: // http://creativecommons.org/licenses/publicdomain/ michael@0: michael@0: function assertThrows(f) { michael@0: var ok = false; michael@0: try { michael@0: f(); michael@0: } catch (exc) { michael@0: ok = true; michael@0: } michael@0: if (!ok) michael@0: throw new TypeError("Assertion failed: " + f + " did not throw as expected"); michael@0: } michael@0: michael@0: function byteArray(str) { michael@0: return [ c.charCodeAt(0) for (c of str.split('')) ]; michael@0: } michael@0: michael@0: // Don't allow forging bogus Date objects. michael@0: var mutated = byteArray(serialize(new Date(NaN)).clonebuffer); michael@0: michael@0: var a = [1/0, -1/0, michael@0: Number.MIN_VALUE, -Number.MIN_VALUE, michael@0: Math.PI, 1286523948674.5, michael@0: Number.MAX_VALUE, -Number.MAX_VALUE, michael@0: 8.64e15 + 1, -(8.64e15 + 1)]; michael@0: for (var i = 0; i < a.length; i++) { michael@0: var n = a[i]; michael@0: var nbuf = serialize(n); michael@0: var data = byteArray(nbuf.clonebuffer); michael@0: for (var j = 0; j < 8; j++) michael@0: mutated[j+8] = data[j]; michael@0: nbuf.clonebuffer = String.fromCharCode.apply(null, mutated); michael@0: assertThrows(function () { deserialize(nbuf); }); michael@0: } michael@0: michael@0: reportCompare(0, 0);