diff --git a/WebIDL/ecmascript-binding/es-exceptions/exceptions.html b/WebIDL/ecmascript-binding/es-exceptions/exceptions.html index 396d0a4c6c6de3..d26c66266994b2 100644 --- a/WebIDL/ecmascript-binding/es-exceptions/exceptions.html +++ b/WebIDL/ecmascript-binding/es-exceptions/exceptions.html @@ -9,8 +9,8 @@ /** * This file just picks one case where browsers are supposed to throw an * exception, and tests the heck out of whether it meets the spec. In the - * future, all these checks should be in assert_throws(), but we don't want - * every browser failing every assert_throws() check until they fix every + * future, all these checks should be in assert_throws_dom(), but we don't want + * every browser failing every assert_throws_dom() check until they fix every * single bug in their exception-throwing. * * We don't go out of our way to test everything that's already tested by diff --git a/common/test-setting-immutable-prototype.js b/common/test-setting-immutable-prototype.js index 7d69fdd08f23d2..de9bdd5919a794 100644 --- a/common/test-setting-immutable-prototype.js +++ b/common/test-setting-immutable-prototype.js @@ -1,5 +1,6 @@ self.testSettingImmutablePrototypeToNewValueOnly = - (prefix, target, newValue, newValueString, { isSameOriginDomain }) => { + (prefix, target, newValue, newValueString, { isSameOriginDomain }, + targetGlobal = window) => { test(() => { assert_throws_js(TypeError, () => { Object.setPrototypeOf(target, newValue); @@ -9,14 +10,21 @@ self.testSettingImmutablePrototypeToNewValueOnly = let dunderProtoError = "SecurityError"; let dunderProtoErrorName = "\"SecurityError\" DOMException"; if (isSameOriginDomain) { - dunderProtoError = new TypeError(); + // We're going to end up calling the __proto__ setter, which will + // enter the Realm of targetGlobal before throwing. + dunderProtoError = targetGlobal.TypeError; dunderProtoErrorName = "TypeError"; } test(() => { - assert_throws(dunderProtoError, function() { + const func = function() { target.__proto__ = newValue; - }); + }; + if (isSameOriginDomain) { + assert_throws_js(dunderProtoError, func); + } else { + assert_throws_dom(dunderProtoError, func); + } }, `${prefix}: setting the prototype to ${newValueString} via __proto__ should throw a ${dunderProtoErrorName}`); test(() => { @@ -25,8 +33,10 @@ self.testSettingImmutablePrototypeToNewValueOnly = }; self.testSettingImmutablePrototype = - (prefix, target, originalValue, { isSameOriginDomain }, newValue = {}, newValueString = "an empty object") => { - testSettingImmutablePrototypeToNewValueOnly(prefix, target, newValue, newValueString, { isSameOriginDomain }); + (prefix, target, originalValue, { isSameOriginDomain }, targetGlobal = window) => { + const newValue = {}; + const newValueString = "an empty object"; + testSettingImmutablePrototypeToNewValueOnly(prefix, target, newValue, newValueString, { isSameOriginDomain }, targetGlobal); const originalValueString = originalValue === null ? "null" : "its original value"; diff --git a/css/css-properties-values-api/register-property.html b/css/css-properties-values-api/register-property.html index 0ef88ae3222dbb..feb6c28d47e3aa 100644 --- a/css/css-properties-values-api/register-property.html +++ b/css/css-properties-values-api/register-property.html @@ -38,7 +38,7 @@ test(function() { CSS.registerProperty({name: '--re-register', syntax: '', initialValue: '0px', inherits: false}); - assert_throws({name: 'InvalidModificationError'}, + assert_throws_dom('InvalidModificationError', () => CSS.registerProperty({name: '--re-register', syntax: '', initialValue: '0%', inherits: false})); }, "registerProperty fails for an already registered property"); diff --git a/css/support/parsing-testcommon.js b/css/support/parsing-testcommon.js index 647bc125df9a87..bcb9d7cdd60546 100644 --- a/css/support/parsing-testcommon.js +++ b/css/support/parsing-testcommon.js @@ -79,7 +79,7 @@ function test_invalid_selector(selector) { const stringifiedSelector = JSON.stringify(selector); test(function(){ - assert_throws( + assert_throws_dom( DOMException.SYNTAX_ERR, () => document.querySelector(selector), stringifiedSelector + " should throw in querySelector"); @@ -89,7 +89,7 @@ function test_invalid_selector(selector) { const {sheet} = style; document.head.removeChild(style); - assert_throws( + assert_throws_dom( DOMException.SYNTAX_ERR, () => sheet.insertRule(selector + "{}"), stringifiedSelector + " should throw in insertRule"); diff --git a/domxpath/001.html b/domxpath/001.html index c26795a3115f8b..4931417af30102 100644 --- a/domxpath/001.html +++ b/domxpath/001.html @@ -30,7 +30,7 @@ function test_xpath_throws(path, error_code, resolver) { resolver = resolver ? resolver : null; - assert_throws(error_code, function() {document.evaluate(path, document, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)}) + assert_throws_dom(error_code, function() {document.evaluate(path, document, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)}) } function ns_resolver(x) { diff --git a/domxpath/002.html b/domxpath/002.html index 95b4afc4c10976..c5c1fcc52923ab 100644 --- a/domxpath/002.html +++ b/domxpath/002.html @@ -28,7 +28,7 @@ function test_xpath_throws(path, error_code, resolver) { resolver = resolver ? resolver : null; - assert_throws(error_code, function() {document.evaluate(path, document, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)}) + assert_throws_dom(error_code, function() {document.evaluate(path, document, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null)}) } function ns_resolver(x) { diff --git a/html/browsers/history/the-location-interface/location-prototype-setting-same-origin-domain.sub.html b/html/browsers/history/the-location-interface/location-prototype-setting-same-origin-domain.sub.html index 570dfccd40ff30..8ec7585daa1475 100644 --- a/html/browsers/history/the-location-interface/location-prototype-setting-same-origin-domain.sub.html +++ b/html/browsers/history/the-location-interface/location-prototype-setting-same-origin-domain.sub.html @@ -23,7 +23,7 @@ assert_not_equals(origProto, null); }, "Same-origin-domain prerequisite check: the original prototype is accessible"); - testSettingImmutablePrototype("Same-origin-domain", targetLocation, origProto, { isSameOriginDomain: true }); + testSettingImmutablePrototype("Same-origin-domain", targetLocation, origProto, { isSameOriginDomain: true }, frames[0]); done(); }; diff --git a/html/browsers/the-windowproxy-exotic-object/windowproxy-prototype-setting-same-origin-domain.sub.html b/html/browsers/the-windowproxy-exotic-object/windowproxy-prototype-setting-same-origin-domain.sub.html index 83d11a20e09328..fb18822ac5b006 100644 --- a/html/browsers/the-windowproxy-exotic-object/windowproxy-prototype-setting-same-origin-domain.sub.html +++ b/html/browsers/the-windowproxy-exotic-object/windowproxy-prototype-setting-same-origin-domain.sub.html @@ -23,7 +23,7 @@ assert_not_equals(origProto, null); }, "Same-origin-domain prerequisite check: the original prototype is accessible"); - testSettingImmutablePrototype("Same-origin-domain", target, origProto, { isSameOriginDomain: true }); + testSettingImmutablePrototype("Same-origin-domain", target, origProto, { isSameOriginDomain: true }, frames[0]); done(); }; diff --git a/orientation-sensor/orientation-sensor-tests.js b/orientation-sensor/orientation-sensor-tests.js index 11ba50b8b2cf80..5d35f3b9afcc52 100644 --- a/orientation-sensor/orientation-sensor-tests.js +++ b/orientation-sensor/orientation-sensor-tests.js @@ -37,7 +37,7 @@ async function checkPopulateMatrix(t, sensorProvider, sensorType) { () => sensor.populateMatrix(new Float32Array(15))); // Throws if no orientation data available. - assert_throws({ name: 'NotReadableError' }, + assert_throws_dom('NotReadableError', () => sensor.populateMatrix(new Float32Array(16))); // Throws if passed SharedArrayBuffer view. diff --git a/shadow-dom/Document-prototype-adoptNode.html b/shadow-dom/Document-prototype-adoptNode.html index e9b07d0c8095bf..6afd603618d7af 100644 --- a/shadow-dom/Document-prototype-adoptNode.html +++ b/shadow-dom/Document-prototype-adoptNode.html @@ -15,7 +15,7 @@ function testAdoptNode(mode) { test(function () { var newDocument = document.implementation.createHTMLDocument(); - assert_throws({'name': 'HierarchyRequestError'}, function () { + assert_throws_dom('HierarchyRequestError', function () { var element = document.createElement('div'); var shadowRoot = element.attachShadow({mode: mode}); newDocument.adoptNode(shadowRoot); diff --git a/trusted-types/TrustedTypePolicy-createXXX.tentative.html b/trusted-types/TrustedTypePolicy-createXXX.tentative.html index 08b24a961523d6..7e39042e1cb86c 100644 --- a/trusted-types/TrustedTypePolicy-createXXX.tentative.html +++ b/trusted-types/TrustedTypePolicy-createXXX.tentative.html @@ -55,7 +55,7 @@ [ s => s, "whatever" ], [ s => null, "" ], [ s => "well, " + s, "well, whatever" ], - [ s => { throw new Error() }, new Error() ], + [ s => { throw new Error() }, Error ], [ s => { aGlobalVarForSideEffectTesting = s; return s }, "whatever" ], [ s => aGlobalVarForSideEffectTesting + s, "whateverwhatever" ], [ aGlobalFunction.bind(aGlobalObject), "well, whatever" ], @@ -66,7 +66,7 @@ [ s => s, INPUTS.SCRIPTURL ], [ s => null, "" ], [ s => s + "#duck", INPUTS.SCRIPTURL + "#duck" ], - [ s => { throw new Error() }, new Error() ], + [ s => { throw new Error() }, Error ], [ s => s + "#" + aGlobalVarForSideEffectTesting, INPUTS.SCRIPTURL + "#global" ], [ anotherGlobalFunction.bind(aGlobalObject), INPUTS.SCRIPTURL + "#well," ], @@ -99,8 +99,8 @@ for (let [index, [policy_fn, value]] of test_cases.entries()) { let subtest_name = "TestPolicy" + trusted_class.name + index; test(t => { - if (value instanceof Error) { - assert_throws(value, () => builder(subtest_name, policy_fn)); + if (typeof value == "object") { + assert_throws_js(value, () => builder(subtest_name, policy_fn)); } else { assert_equals("" + builder(subtest_name, policy_fn), value); } diff --git a/trusted-types/TrustedTypePolicyFactory-metadata.tentative.html b/trusted-types/TrustedTypePolicyFactory-metadata.tentative.html index 73122deedd5db5..50f877cda07f05 100644 --- a/trusted-types/TrustedTypePolicyFactory-metadata.tentative.html +++ b/trusted-types/TrustedTypePolicyFactory-metadata.tentative.html @@ -66,7 +66,7 @@ // test_fn(); // assert_equals(element[property], value); // } else { - // assert_throws(..., test_fn, ...); + // assert_throws_js(..., test_fn, ...); // } // // Below is the same logic, but extended to handle the various edge diff --git a/web-animations/interfaces/KeyframeEffect/constructor.html b/web-animations/interfaces/KeyframeEffect/constructor.html index 46a23b0c2e87ae..f9d552e63ec55a 100644 --- a/web-animations/interfaces/KeyframeEffect/constructor.html +++ b/web-animations/interfaces/KeyframeEffect/constructor.html @@ -186,7 +186,7 @@ test(t => { const test_error = { name: 'test' }; - assert_throws(test_error, () => { + assert_throws_exactly(test_error, () => { new KeyframeEffect(target, { get left() { throw test_error }}) }); }, 'KeyframeEffect constructor propagates exceptions generated by accessing' diff --git a/web-animations/interfaces/KeyframeEffect/processing-a-keyframes-argument-001.html b/web-animations/interfaces/KeyframeEffect/processing-a-keyframes-argument-001.html index 6716133c9c2f99..87e60a2b108512 100644 --- a/web-animations/interfaces/KeyframeEffect/processing-a-keyframes-argument-001.html +++ b/web-animations/interfaces/KeyframeEffect/processing-a-keyframes-argument-001.html @@ -320,7 +320,7 @@ test(() => { const test_error = { name: 'test' }; const bad_keyframe = { get left() { throw test_error; } }; - assert_throws(test_error, () => { + assert_throws_exactly(test_error, () => { new KeyframeEffect(null, createIterable([ { done: false, value: { left: '100px' } }, { done: false, value: bad_keyframe }, @@ -390,7 +390,7 @@ return { next() { throw test_error; } }; }, }; - assert_throws(test_error, () => { + assert_throws_exactly(test_error, () => { new KeyframeEffect(null, keyframe_obj); }); }, 'If a custom iterator throws from next(), the exception should be rethrown'); @@ -404,7 +404,7 @@ throw test_error; }, }; - assert_throws(test_error, () => { + assert_throws_exactly(test_error, () => { new KeyframeEffect(null, keyframe_obj); }); }, 'Accessing a Symbol.iterator property that throws should rethrow'); diff --git a/web-nfc/NDEFRecord_constructor.https.html b/web-nfc/NDEFRecord_constructor.https.html index 93b79c641f5ebf..66befaa30a7e32 100644 --- a/web-nfc/NDEFRecord_constructor.https.html +++ b/web-nfc/NDEFRecord_constructor.https.html @@ -344,7 +344,7 @@ }, 'NDEFRecord constructor with record type string being treated as case sensitive'); test(() => { - assert_throws(new TypeError, () => new NDEFRecord(createRecord( + assert_throws_js(TypeError, () => new NDEFRecord(createRecord( 'example.com:hellö', test_buffer_data)), 'The external type must be an ASCII string.'); diff --git a/webaudio/the-audio-api/the-iirfilternode-interface/test-iirfilternode.html b/webaudio/the-audio-api/the-iirfilternode-interface/test-iirfilternode.html index 61c11ffc5083a9..001a2a61724382 100644 --- a/webaudio/the-audio-api/the-iirfilternode-interface/test-iirfilternode.html +++ b/webaudio/the-audio-api/the-iirfilternode-interface/test-iirfilternode.html @@ -9,7 +9,7 @@ function check_args(arg1, arg2, err, desc) { test(function() { - assert_throws(err, function() { + assert_throws_dom(err, function() { ac.createIIRFilter(arg1, arg2) }) }, desc) diff --git a/webmessaging/without-ports/026.html b/webmessaging/without-ports/026.html index e8d799c5d2553e..546da8a91b541c 100644 --- a/webmessaging/without-ports/026.html +++ b/webmessaging/without-ports/026.html @@ -6,9 +6,10 @@