Debian Codegraph @

js/src/tests/test262/built-ins/RegExp/escape/non-string-inputs.js

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