From 7b44ad5c1d8417c179d4a31e7f897ce41d9e8b6a Mon Sep 17 00:00:00 2001 From: Yutaka Hirano Date: Thu, 30 May 2019 15:53:52 +0900 Subject: [PATCH] Add structured clone tests for errors This is tests for spec changes. - https://github.com/whatwg/html/pull/4665 - https://github.com/heycam/webidl/pull/732 --- .../structuredclone_0.html | 219 +++++++++++++++++- 1 file changed, 218 insertions(+), 1 deletion(-) diff --git a/html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html b/html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html index 098283106ef87da..e67dbfb26200bab 100644 --- a/html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html +++ b/html/infrastructure/safe-passing-of-structured-data/structuredclone_0.html @@ -367,7 +367,224 @@ assert_throws('DATA_CLONE_ERR', function() {worker.postMessage(document)}); }); t.done(); - } + }, + function() { + var t = async_test("Empty Error objects can be cloned"); + t.id = 27; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), Error.prototype, "Checking prototype"); + assert_equals(e.data.constructor, Error, "Checking constructor"); + assert_equals(e.data.name, "Error", "Checking name"); + assert_false(e.data.hasOwnProperty("message"), "Checking message"); + assert_equals(e.data.foo, undefined, "Checking custom property"); + }); + t.step(function() { + const error = Error(); + assert_false(error.hasOwnProperty("message"), "Checking message on the source realm"); + worker.postMessage(error); + }); + }, + function() { + var t = async_test("Error objects can be cloned"); + t.id = 28; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), Error.prototype, "Checking prototype"); + assert_equals(e.data.constructor, Error, "Checking constructor"); + assert_equals(e.data.name, "Error", "Checking name"); + assert_equals(e.data.message, "some message", "Checking message"); + assert_equals(e.data.foo, undefined, "Checking custom property"); + }); + t.step(function() { + const error = Error("some message"); + error.foo = "bar"; + worker.postMessage(error); + }); + }, + function() { + var t = async_test("EvalError objects can be cloned"); + t.id = 29; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), EvalError.prototype, "Checking prototype"); + assert_equals(e.data.constructor, EvalError, "Checking constructor"); + assert_equals(e.data.name, "EvalError", "Checking name"); + assert_equals(e.data.message, "some message", "Checking message"); + assert_equals(e.data.foo, undefined, "Checking custom property"); + }); + t.step(function() { + const error = EvalError("some message"); + error.foo = "bar"; + worker.postMessage(error); + }); + }, + function() { + var t = async_test("RangeError objects can be cloned"); + t.id = 30; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), RangeError.prototype, "Checking prototype"); + assert_equals(e.data.constructor, RangeError, "Checking constructor"); + assert_equals(e.data.name, "RangeError", "Checking name"); + assert_equals(e.data.message, "some message", "Checking message"); + assert_equals(e.data.foo, undefined, "Checking custom property"); + }); + t.step(function() { + const error = RangeError("some message"); + error.foo = "bar"; + worker.postMessage(error); + }); + }, + function() { + var t = async_test("ReferenceError objects can be cloned"); + t.id = 31; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), ReferenceError.prototype, "Checking prototype"); + assert_equals(e.data.constructor, ReferenceError, "Checking constructor"); + assert_equals(e.data.name, "ReferenceError", "Checking name"); + assert_equals(e.data.message, "some message", "Checking message"); + assert_equals(e.data.foo, undefined, "Checking custom property"); + }); + t.step(function() { + const error = ReferenceError("some message"); + error.foo = "bar"; + worker.postMessage(error); + }); + }, + function() { + var t = async_test("SyntaxError objects can be cloned"); + t.id = 32; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), SyntaxError.prototype, "Checking prototype"); + assert_equals(e.data.constructor, SyntaxError, "Checking constructor"); + assert_equals(e.data.name, "SyntaxError", "Checking name"); + assert_equals(e.data.message, "some message", "Checking message"); + assert_equals(e.data.foo, undefined, "Checking custom property"); + }); + t.step(function() { + const error = SyntaxError("some message"); + error.foo = "bar"; + worker.postMessage(error); + }); + }, + function() { + var t = async_test("TypeError objects can be cloned"); + t.id = 33; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), TypeError.prototype, "Checking prototype"); + assert_equals(e.data.constructor, TypeError, "Checking constructor"); + assert_equals(e.data.name, "TypeError", "Checking name"); + assert_equals(e.data.message, "some message", "Checking message"); + assert_equals(e.data.foo, undefined, "Checking custom property"); + }); + t.step(function() { + const error = TypeError("some message"); + error.foo = "bar"; + worker.postMessage(error); + }); + }, + function() { + var t = async_test("URIError objects can be cloned"); + t.id = 34; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), URIError.prototype, "Checking prototype"); + assert_equals(e.data.constructor, URIError, "Checking constructor"); + assert_equals(e.data.name, "URIError", "Checking name"); + assert_equals(e.data.message, "some message", "Checking message"); + assert_equals(e.data.foo, undefined, "Checking custom property"); + }); + t.step(function() { + const error = URIError("some message"); + error.foo = "bar"; + worker.postMessage(error); + }); + }, + function() { + var t = async_test("Cloning a modified Error"); + t.id = 35; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), SyntaxError.prototype, "Checking prototype"); + assert_equals(e.data.constructor, SyntaxError, "Checking constructor"); + assert_equals(e.data.name, "SyntaxError", "Checking name"); + assert_equals(e.data.message, "another message", "Checking message"); + assert_equals(e.data.foo, undefined, "Checking custom property"); + }); + t.step(function() { + const error = URIError("some message"); + Object.setPrototypeOf(error, SyntaxError.prototype); + error.message = {toString: () => "another message" } + error.constructor = RangeError; + error.name = "TypeError"; + error.foo = "bar"; + worker.postMessage(error); + }); + }, + function() { + var t = async_test("Error.message: getter is ignored when cloning"); + t.id = 36; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), Error.prototype, "Checking prototype"); + assert_equals(e.data.constructor, Error, "Checking constructor"); + assert_equals(e.data.name, "Error", "Checking name"); + assert_false(e.data.hasOwnProperty("message"), "Checking message"); + assert_equals(e.data.foo, undefined, "Checking custom property"); + }); + t.step(function() { + const error = Error(); + Object.defineProperty(error, "message", { get: () => "hello" }); + assert_equals(error.message, "hello", "Checking message on the source realm"); + worker.postMessage(error); + }); + }, + function() { + var t = async_test("Error.message: undefined property is stringified"); + t.id = 37; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), Error.prototype, "Checking prototype"); + assert_equals(e.data.constructor, Error, "Checking constructor"); + assert_equals(e.data.name, "Error", "Checking name"); + assert_equals(e.data.message, "undefined", "Checking message"); + assert_equals(e.data.foo, undefined, "Checking custom property"); + }); + t.step(function() { + const error = Error(); + error.message = undefined; + assert_equals(error.message, undefined, "Checking message on the source realm"); + worker.postMessage(error); + }); + }, + function() { + var t = async_test("DOMException objects can be cloned"); + t.id = 38; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), DOMException.prototype, "Checking prototype"); + assert_equals(e.data.constructor, DOMException, "Checking constructor"); + assert_equals(e.data.name, "IndexSizeError", "Checking name"); + assert_equals(e.data.message, "some message", "Checking message"); + assert_equals(e.data.code, DOMException.INDEX_SIZE_ERR, "Checking code"); + assert_equals(e.data.foo, undefined, "Checking custom property"); + }); + t.step(function() { + const error = new DOMException("some message", "IndexSizeError"); + worker.postMessage(error); + }); + }, + function() { + var t = async_test("DOMException objects created by the UA can be cloned"); + t.id = 39; + worker.onmessage = t.step_func_done(function(e) { + assert_equals(Object.getPrototypeOf(e.data), DOMException.prototype, "Checking prototype"); + assert_equals(e.data.constructor, DOMException, "Checking constructor"); + assert_equals(e.data.code, DOMException.DATA_CLONE_ERR, "Checking code"); + assert_equals(e.data.name, "DataCloneError", "Checking name"); + }); + t.step(function() { + try { + worker.postMessage(window); + } catch (error) { + worker.postMessage(error); + return; + } + assert_unreached("Window must not be clonable"); + }); + }, ]; }, {explicit_done:true});