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