From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../Function/function-toString-builtin-name.js | 53 ++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 js/src/tests/non262/Function/function-toString-builtin-name.js (limited to 'js/src/tests/non262/Function/function-toString-builtin-name.js') diff --git a/js/src/tests/non262/Function/function-toString-builtin-name.js b/js/src/tests/non262/Function/function-toString-builtin-name.js new file mode 100644 index 0000000000..709e7e846b --- /dev/null +++ b/js/src/tests/non262/Function/function-toString-builtin-name.js @@ -0,0 +1,53 @@ +// Repeats the test from 'Function/function-toString-builtin.js' and additionally +// verifies the name matches the expected value. +// +// This behaviour is not required by the ECMAScript standard. + +// Greatly (!) simplified patterns for the PropertyName production. +var propertyName = [ + // PropertyName :: LiteralPropertyName :: IdentifierName + "\\w+", + + // PropertyName :: LiteralPropertyName :: StringLiteral + "(?:'[^']*')", + "(?:\"[^\"]*\")", + + // PropertyName :: LiteralPropertyName :: NumericLiteral + "\\d+", + + // PropertyName :: ComputedPropertyName + "(?:\\[[^\\]]+\\])", +].join("|") + +var nativeCode = RegExp([ + "^", "function", ("(" + propertyName + ")?"), "\\(", "\\)", "\\{", "\\[native code\\]", "\\}", "$" +].join("\\s*")); + +function assertFunctionName(fun, expected) { + var match = nativeCode.exec(fun.toString()); + assertEq(match[1], expected); +} + +// Bound functions are considered built-ins. +assertFunctionName(function(){}.bind(), undefined); +assertFunctionName(function fn(){}.bind(), undefined); + +// Built-ins which are well-known intrinsic objects. +assertFunctionName(Array, "Array"); +assertFunctionName(Object.prototype.toString, "toString"); +assertFunctionName(decodeURI, "decodeURI"); + +// Other built-in functions. +assertFunctionName(Math.asin, "asin"); +assertFunctionName(String.prototype.blink, "blink"); +assertFunctionName(RegExp.prototype[Symbol.split], "[Symbol.split]"); + +// Built-in getter functions. +assertFunctionName(Object.getOwnPropertyDescriptor(RegExp.prototype, "flags").get, "flags"); +assertFunctionName(Object.getOwnPropertyDescriptor(Object.prototype, "__proto__").get, "__proto__"); + +// Built-in setter functions. +assertFunctionName(Object.getOwnPropertyDescriptor(Object.prototype, "__proto__").set, "__proto__"); + +if (typeof reportCompare === "function") + reportCompare(0, 0); -- cgit v1.2.3