2011-07-17 19:09:13 +00:00
|
|
|
/**
|
|
|
|
* Any copyright is dedicated to the Public Domain.
|
|
|
|
* http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
*/
|
2010-03-17 19:56:49 +00:00
|
|
|
var cyclicalObject = {};
|
|
|
|
cyclicalObject.foo = cyclicalObject;
|
|
|
|
|
|
|
|
var cyclicalArray = [];
|
|
|
|
cyclicalArray.push(cyclicalArray);
|
|
|
|
|
|
|
|
function makeCrazyNested(obj, count) {
|
|
|
|
var innermostobj;
|
|
|
|
for (var i = 0; i < count; i++) {
|
|
|
|
obj.foo = { bar: 5 }
|
|
|
|
innermostobj = obj.foo;
|
|
|
|
obj = innermostobj;
|
|
|
|
}
|
|
|
|
return innermostobj;
|
|
|
|
}
|
|
|
|
|
|
|
|
var crazyNestedObject = {};
|
|
|
|
makeCrazyNested(crazyNestedObject, 100);
|
|
|
|
|
|
|
|
var crazyCyclicalObject = {};
|
|
|
|
var innermost = makeCrazyNested(crazyCyclicalObject, 1000);
|
|
|
|
innermost.baz = crazyCyclicalObject;
|
|
|
|
|
|
|
|
var objectWithSaneGetter = { };
|
|
|
|
objectWithSaneGetter.__defineGetter__("foo", function() { return 5; });
|
|
|
|
|
|
|
|
// We don't walk prototype chains for cloning so this won't actually do much...
|
|
|
|
function objectWithSaneGetter2() { }
|
|
|
|
objectWithSaneGetter2.prototype = {
|
|
|
|
get foo() {
|
|
|
|
return 5;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2011-07-17 19:09:13 +00:00
|
|
|
const throwingGetterThrownString = "bad";
|
|
|
|
|
2010-03-17 19:56:49 +00:00
|
|
|
var objectWithThrowingGetter = { };
|
2011-07-17 19:09:13 +00:00
|
|
|
objectWithThrowingGetter.__defineGetter__("foo", function() {
|
|
|
|
throw throwingGetterThrownString;
|
|
|
|
});
|
2010-03-17 19:56:49 +00:00
|
|
|
|
2010-04-07 20:55:12 +00:00
|
|
|
var typedArrayWithValues = new Int8Array(5);
|
|
|
|
for (var index in typedArrayWithValues) {
|
|
|
|
typedArrayWithValues[index] = index;
|
|
|
|
}
|
|
|
|
|
|
|
|
var typedArrayWithFunBuffer = new Int8Array(4);
|
|
|
|
for (var index in typedArrayWithFunBuffer) {
|
|
|
|
typedArrayWithFunBuffer[index] = 255;
|
|
|
|
}
|
|
|
|
|
|
|
|
var typedArrayWithFunBuffer2 = new Int32Array(typedArrayWithFunBuffer.buffer);
|
|
|
|
|
2010-04-29 01:32:16 +00:00
|
|
|
var xhr = new XMLHttpRequest();
|
|
|
|
|
2008-12-08 00:15:49 +00:00
|
|
|
var messages = [
|
|
|
|
{
|
|
|
|
type: "object",
|
2010-03-17 19:56:49 +00:00
|
|
|
value: { },
|
|
|
|
jsonValue: '{}'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: {foo: "bar"},
|
|
|
|
jsonValue: '{"foo":"bar"}'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: {foo: "bar", foo2: {bee: "bop"}},
|
|
|
|
jsonValue: '{"foo":"bar","foo2":{"bee":"bop"}}'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: {foo: "bar", foo2: {bee: "bop"}, foo3: "baz"},
|
|
|
|
jsonValue: '{"foo":"bar","foo2":{"bee":"bop"},"foo3":"baz"}'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: {foo: "bar", foo2: [1,2,3]},
|
|
|
|
jsonValue: '{"foo":"bar","foo2":[1,2,3]}'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: cyclicalObject,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: [null, 2, false, cyclicalObject],
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: cyclicalArray,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: {foo: 1, bar: cyclicalArray},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: crazyNestedObject,
|
|
|
|
jsonValue: JSON.stringify(crazyNestedObject)
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: crazyCyclicalObject,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: objectWithSaneGetter,
|
|
|
|
jsonValue: '{"foo":5}'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: new objectWithSaneGetter2(),
|
|
|
|
jsonValue: '{}'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: objectWithThrowingGetter,
|
|
|
|
exception: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
array: true,
|
|
|
|
value: [9, 8, 7],
|
|
|
|
jsonValue: '[9,8,7]'
|
2008-12-08 00:15:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
array: true,
|
2010-03-17 19:56:49 +00:00
|
|
|
value: [9, false, 10.5, {foo: "bar"}],
|
|
|
|
jsonValue: '[9,false,10.5,{"foo":"bar"}]'
|
2008-12-08 00:15:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
shouldEqual: true,
|
|
|
|
value: null
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "undefined",
|
|
|
|
shouldEqual: true,
|
2010-03-17 19:56:49 +00:00
|
|
|
value: undefined
|
2008-12-08 00:15:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "string",
|
|
|
|
shouldEqual: true,
|
|
|
|
value: "Hello"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "string",
|
|
|
|
shouldEqual: true,
|
2010-03-17 19:56:49 +00:00
|
|
|
value: JSON.stringify({ foo: "bar" }),
|
|
|
|
compareValue: '{"foo":"bar"}'
|
2008-12-08 00:15:49 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "number",
|
|
|
|
shouldEqual: true,
|
|
|
|
value: 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "number",
|
|
|
|
shouldEqual: true,
|
|
|
|
value: 0
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "number",
|
|
|
|
shouldEqual: true,
|
|
|
|
value: -1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "number",
|
|
|
|
shouldEqual: true,
|
|
|
|
value: 238573459843702923492399923049
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "number",
|
|
|
|
shouldEqual: true,
|
|
|
|
value: -238573459843702923492399923049
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "number",
|
|
|
|
shouldEqual: true,
|
|
|
|
value: 0.25
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "number",
|
|
|
|
shouldEqual: true,
|
|
|
|
value: -0.25
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "boolean",
|
|
|
|
shouldEqual: true,
|
|
|
|
value: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "boolean",
|
|
|
|
shouldEqual: true,
|
|
|
|
value: false
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
2010-03-17 19:56:49 +00:00
|
|
|
value: function (foo) { return "Bad!"; },
|
2010-04-29 01:32:16 +00:00
|
|
|
exception: true
|
2008-12-08 00:15:49 +00:00
|
|
|
},
|
|
|
|
{
|
2010-03-17 19:56:49 +00:00
|
|
|
type: "number",
|
|
|
|
isNaN: true,
|
|
|
|
value: NaN
|
2008-12-08 00:15:49 +00:00
|
|
|
},
|
|
|
|
{
|
2010-03-17 19:56:49 +00:00
|
|
|
type: "number",
|
|
|
|
isInfinity: true,
|
|
|
|
value: Infinity
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "number",
|
|
|
|
isNegativeInfinity: true,
|
|
|
|
value: -Infinity
|
2008-12-08 00:15:49 +00:00
|
|
|
},
|
2010-04-07 20:55:12 +00:00
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: new Int32Array(10),
|
|
|
|
jsonValue: '{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0}'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: new Float32Array(5),
|
|
|
|
jsonValue: '{"0":0,"1":0,"2":0,"3":0,"4":0}'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: typedArrayWithValues,
|
|
|
|
jsonValue: '{"0":0,"1":1,"2":2,"3":3,"4":4}'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "number",
|
|
|
|
value: typedArrayWithValues[2],
|
|
|
|
compareValue: 2,
|
|
|
|
shouldEqual: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: typedArrayWithValues.buffer,
|
|
|
|
jsonValue: '{}'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: typedArrayWithFunBuffer2,
|
2010-04-29 01:32:16 +00:00
|
|
|
jsonValue: '{"0":-1}'
|
2010-04-07 20:55:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: { foo: typedArrayWithFunBuffer2 },
|
2010-04-29 01:32:16 +00:00
|
|
|
jsonValue: '{"foo":{"0":-1}}'
|
2010-04-07 20:55:12 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: [ typedArrayWithFunBuffer2 ],
|
2010-04-29 01:32:16 +00:00
|
|
|
jsonValue: '[{"0":-1}]'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: { foo: function(a) { alert(b); } },
|
|
|
|
exception: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: xhr,
|
|
|
|
exception: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "number",
|
|
|
|
value: xhr.readyState,
|
|
|
|
shouldEqual: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: { xhr: xhr },
|
|
|
|
exception: true
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: self,
|
|
|
|
exception: true
|
2010-04-07 20:55:12 +00:00
|
|
|
},
|
2010-08-19 19:16:53 +00:00
|
|
|
{
|
|
|
|
type: "object",
|
|
|
|
value: { p: ArrayBuffer.prototype },
|
|
|
|
exception: true
|
|
|
|
},
|
2008-12-08 00:15:49 +00:00
|
|
|
{
|
|
|
|
type: "string",
|
|
|
|
shouldEqual: true,
|
|
|
|
value: "testFinished"
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
for (var index = 0; index < messages.length; index++) {
|
|
|
|
var message = messages[index];
|
|
|
|
if (message.hasOwnProperty("compareValue")) {
|
|
|
|
continue;
|
|
|
|
}
|
2010-03-17 19:56:49 +00:00
|
|
|
if (message.hasOwnProperty("shouldEqual") ||
|
|
|
|
message.hasOwnProperty("shouldCompare")) {
|
|
|
|
message.compareValue = message.value;
|
|
|
|
}
|
2008-12-08 00:15:49 +00:00
|
|
|
}
|
|
|
|
|
2011-07-17 19:09:13 +00:00
|
|
|
onmessage = function(event) {
|
2008-12-08 00:15:49 +00:00
|
|
|
for (var index = 0; index < messages.length; index++) {
|
2010-03-17 19:56:49 +00:00
|
|
|
var exception = undefined;
|
2008-12-08 00:15:49 +00:00
|
|
|
|
|
|
|
try {
|
|
|
|
postMessage(messages[index].value);
|
|
|
|
}
|
|
|
|
catch (e) {
|
2011-07-17 19:09:13 +00:00
|
|
|
if (e instanceof DOMException) {
|
|
|
|
if (e.code != DOMException.DATA_CLONE_ERR) {
|
|
|
|
throw "DOMException with the wrong code: " + e.code;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (e != throwingGetterThrownString) {
|
|
|
|
throw "Exception of the wrong type: " + e;
|
2010-10-10 22:39:11 +00:00
|
|
|
}
|
2010-03-17 19:56:49 +00:00
|
|
|
exception = e;
|
2008-12-08 00:15:49 +00:00
|
|
|
}
|
|
|
|
|
2010-03-17 19:56:49 +00:00
|
|
|
if ((exception !== undefined && !messages[index].exception) ||
|
|
|
|
(exception === undefined && messages[index].exception)) {
|
2010-04-29 01:32:16 +00:00
|
|
|
throw "Exception inconsistency [index = " + index + ", " +
|
|
|
|
messages[index].toSource() + "]: " + exception;
|
2008-12-08 00:15:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|