1'use strict'; 2 3// Tests below are not from WPT. 4 5const common = require('../common'); 6if (!common.hasIntl) { 7 // A handful of the tests fail when ICU is not included. 8 common.skip('missing Intl'); 9} 10 11const assert = require('assert'); 12const { test, assert_equals } = require('../common/wpt').harness; 13const fixtures = require('../common/fixtures'); 14 15// TODO(joyeecheung): we should submit these to the upstream 16const additionalTestCases = 17 require(fixtures.path('url-setter-tests-additional.js')); 18 19{ 20 for (const attributeToBeSet in additionalTestCases) { 21 if (attributeToBeSet === 'comment') { 22 continue; 23 } 24 const testCases = additionalTestCases[attributeToBeSet]; 25 for (const testCase of testCases) { 26 let name = `Setting <${testCase.href}>.${attributeToBeSet}` + 27 ` = "${testCase.new_value}"`; 28 if ('comment' in testCase) { 29 name += ` ${testCase.comment}`; 30 } 31 test(function() { 32 const url = new URL(testCase.href); 33 url[attributeToBeSet] = testCase.new_value; 34 for (const attribute in testCase.expected) { 35 assert_equals(url[attribute], testCase.expected[attribute]); 36 } 37 }, `URL: ${name}`); 38 } 39 } 40} 41 42{ 43 const url = new URL('http://example.com/'); 44 const obj = { 45 toString() { throw new Error('toString'); }, 46 valueOf() { throw new Error('valueOf'); } 47 }; 48 const sym = Symbol(); 49 const props = Object.getOwnPropertyDescriptors(Object.getPrototypeOf(url)); 50 for (const [name, { set }] of Object.entries(props)) { 51 if (set) { 52 assert.throws(() => url[name] = obj, 53 /^Error: toString$/, 54 `url.${name} = { toString() { throw ... } }`); 55 assert.throws(() => url[name] = sym, 56 /^TypeError: Cannot convert a Symbol value to a string$/, 57 `url.${name} = ${String(sym)}`); 58 } 59 } 60} 61