michael@0: dump('loaded child cpow test\n'); michael@0: michael@0: content.document.title = "Hello, Kitty"; michael@0: michael@0: (function start() { michael@0: sync_test(); michael@0: async_test(); michael@0: rpc_test(); michael@0: nested_sync_test(); michael@0: // The sync-ness of this call is important, because otherwise michael@0: // we tear down the child's document while we are michael@0: // still in the async test in the parent. michael@0: sendSyncMessage("cpows:done", {}); michael@0: } michael@0: )(); michael@0: michael@0: function ok(condition, message) { michael@0: dump('condition: ' + condition + ', ' + message + '\n'); michael@0: if (!condition) { michael@0: sendAsyncMessage("cpows:fail", { message: message }); michael@0: throw 'failed check: ' + message; michael@0: } michael@0: } michael@0: michael@0: var sync_obj; michael@0: var async_obj; michael@0: michael@0: function make_object() michael@0: { michael@0: let o = { }; michael@0: o.i = 5; michael@0: o.b = true; michael@0: o.s = "hello"; michael@0: o.x = { i: 10 }; michael@0: o.f = function () { return 99; }; michael@0: michael@0: // Doing anything with this Proxy will throw. michael@0: var throwing = new Proxy({}, new Proxy({}, { michael@0: get: function (trap) { throw trap; } michael@0: })); michael@0: michael@0: let array = [1, 2, 3]; michael@0: michael@0: let for_json = { "n": 3, "a": array, "s": "hello", o: { "x": 10 } }; michael@0: michael@0: return { "data": o, michael@0: "throwing": throwing, michael@0: "document": content.document, michael@0: "array": array, michael@0: "for_json": for_json michael@0: }; michael@0: } michael@0: michael@0: function make_json() michael@0: { michael@0: return { check: "ok" }; michael@0: } michael@0: michael@0: function sync_test() michael@0: { michael@0: dump('beginning cpow sync test\n'); michael@0: sync_obj = make_object(); michael@0: sendSyncMessage("cpows:sync", michael@0: make_json(), michael@0: make_object()); michael@0: } michael@0: michael@0: function async_test() michael@0: { michael@0: dump('beginning cpow async test\n'); michael@0: async_obj = make_object(); michael@0: sendAsyncMessage("cpows:async", michael@0: make_json(), michael@0: async_obj); michael@0: } michael@0: michael@0: function rpc_test() michael@0: { michael@0: dump('beginning cpow rpc test\n'); michael@0: rpc_obj = make_object(); michael@0: rpc_obj.data.reenter = function () { michael@0: sendRpcMessage("cpows:reenter", { }, { data: { valid: true } }); michael@0: return "ok"; michael@0: } michael@0: sendRpcMessage("cpows:rpc", michael@0: make_json(), michael@0: rpc_obj); michael@0: } michael@0: michael@0: function nested_sync_test() michael@0: { michael@0: dump('beginning cpow nested sync test\n'); michael@0: sync_obj = make_object(); michael@0: sync_obj.data.reenter = function () { michael@0: let caught = false; michael@0: try { michael@0: sendSyncMessage("cpows:reenter_sync", { }, { }); michael@0: } catch (e) { michael@0: caught = true; michael@0: } michael@0: if (!ok(caught, "should not allow nested sync")) michael@0: return "fail"; michael@0: return "ok"; michael@0: } michael@0: sendSyncMessage("cpows:nested_sync", michael@0: make_json(), michael@0: rpc_obj); michael@0: }