non-string-inputs.js (1056B)
1 // Copyright (C) 2024 Leo Balter. All rights reserved. 2 // This code is governed by the BSD license found in the LICENSE file. 3 4 /*--- 5 esid: sec-regexp.escape 6 description: Non-string inputs throw a TypeError 7 info: | 8 RegExp.escape ( string ) 9 10 This method throws a TypeError if the input is not a string. 11 12 features: [RegExp.escape] 13 ---*/ 14 15 // Avoids a false positive when the feature is not supported 16 assert.sameValue(typeof RegExp.escape, 'function', 'RegExp.escape is a function'); 17 18 assert.throws(TypeError, function () { RegExp.escape(123); }, 'non-string input (number) throws TypeError'); 19 assert.throws(TypeError, function () { RegExp.escape({}); }, 'non-string input (object) throws TypeError'); 20 assert.throws(TypeError, function () { RegExp.escape([]); }, 'non-string input (array) throws TypeError'); 21 assert.throws(TypeError, function () { RegExp.escape(null); }, 'non-string input (null) throws TypeError'); 22 assert.throws(TypeError, function () { RegExp.escape(undefined); }, 'non-string input (undefined) throws TypeError'); 23 24 reportCompare(0, 0);