1'use strict'; 2 3// Tests below are not from WPT. 4 5require('../common'); 6const assert = require('assert'); 7const URLSearchParams = require('url').URLSearchParams; 8 9{ 10 const params = new URLSearchParams(); 11 assert.throws(() => { 12 params.append.call(undefined); 13 }, { 14 code: 'ERR_INVALID_THIS', 15 name: 'TypeError', 16 message: 'Value of "this" must be of type URLSearchParams' 17 }); 18 assert.throws(() => { 19 params.append('a'); 20 }, { 21 code: 'ERR_MISSING_ARGS', 22 name: 'TypeError', 23 message: 'The "name" and "value" arguments must be specified' 24 }); 25 26 const obj = { 27 toString() { throw new Error('toString'); }, 28 valueOf() { throw new Error('valueOf'); } 29 }; 30 const sym = Symbol(); 31 assert.throws(() => params.set(obj, 'b'), /^Error: toString$/); 32 assert.throws(() => params.set('a', obj), /^Error: toString$/); 33 assert.throws(() => params.set(sym, 'b'), 34 /^TypeError: Cannot convert a Symbol value to a string$/); 35 assert.throws(() => params.set('a', sym), 36 /^TypeError: Cannot convert a Symbol value to a string$/); 37} 38