diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/tests/non262/extensions/extension-methods-reject-null-undefined-this.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/extensions/extension-methods-reject-null-undefined-this.js')
-rw-r--r-- | js/src/tests/non262/extensions/extension-methods-reject-null-undefined-this.js | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/js/src/tests/non262/extensions/extension-methods-reject-null-undefined-this.js b/js/src/tests/non262/extensions/extension-methods-reject-null-undefined-this.js new file mode 100644 index 0000000000..96689b0152 --- /dev/null +++ b/js/src/tests/non262/extensions/extension-methods-reject-null-undefined-this.js @@ -0,0 +1,105 @@ +// |reftest| skip-if(!Object.prototype.toSource) + +/* + * Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/licenses/publicdomain/ + */ + +//----------------------------------------------------------------------------- +var BUGNUMBER = 619283; +var summary = + "ECMAScript built-in methods that immediately throw when |this| is " + + "|undefined| or |null| (due to CheckObjectCoercible, ToObject, or ToString)"; + +print(BUGNUMBER + ": " + summary); + +/************** + * BEGIN TEST * + **************/ + +// This test fills out for the non-standard methods which +// non262/misc/builtin-methods-reject-null-undefined-this.js declines to test. + +var ClassToMethodMap = + { + Object: ["toSource"], + Function: ["toSource"], + Array: ["toSource"], + String: ["toSource"], + Boolean: ["toSource"], + Number: ["toSource"], + Date: ["toSource"], + RegExp: ["toSource"], + Error: ["toSource"], + }; + +var badThisValues = [null, undefined]; + +function testMethod(Class, className, method) +{ + var expr; + + // Try out explicit this values + for (var i = 0, sz = badThisValues.length; i < sz; i++) + { + var badThis = badThisValues[i]; + + expr = className + ".prototype." + method + ".call(" + badThis + ")"; + try + { + Class.prototype[method].call(badThis); + throw new Error(expr + " didn't throw a TypeError"); + } + catch (e) + { + assertEq(e instanceof TypeError, true, + "wrong error for " + expr + ", instead threw " + e); + } + + expr = className + ".prototype." + method + ".apply(" + badThis + ")"; + try + { + Class.prototype[method].apply(badThis); + throw new Error(expr + " didn't throw a TypeError"); + } + catch (e) + { + assertEq(e instanceof TypeError, true, + "wrong error for " + expr + ", instead threw " + e); + } + } + + // ..and for good measure.. + + expr = "(0, " + className + ".prototype." + method + ")()" + try + { + // comma operator to call GetValue() on the method and de-Reference it + (0, Class.prototype[method])(); + throw new Error(expr + " didn't throw a TypeError"); + } + catch (e) + { + assertEq(e instanceof TypeError, true, + "wrong error for " + expr + ", instead threw " + e); + } +} + +for (var className in ClassToMethodMap) +{ + var Class = this[className]; + + var methodNames = ClassToMethodMap[className]; + for (var i = 0, sz = methodNames.length; i < sz; i++) + { + var method = methodNames[i]; + testMethod(Class, className, method); + } +} + +/******************************************************************************/ + +if (typeof reportCompare === "function") + reportCompare(true, true); + +print("All tests passed!"); |