summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/class/extendBuiltinConstructors.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/class/extendBuiltinConstructors.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/class/extendBuiltinConstructors.js')
-rw-r--r--js/src/tests/non262/class/extendBuiltinConstructors.js110
1 files changed, 110 insertions, 0 deletions
diff --git a/js/src/tests/non262/class/extendBuiltinConstructors.js b/js/src/tests/non262/class/extendBuiltinConstructors.js
new file mode 100644
index 0000000000..f823d81343
--- /dev/null
+++ b/js/src/tests/non262/class/extendBuiltinConstructors.js
@@ -0,0 +1,110 @@
+function testBuiltinInstanceIsInstanceOf(instance, builtin, class_) {
+ assertEq(instance instanceof class_, true);
+ assertEq(instance instanceof builtin, true);
+
+ if (builtin === Array)
+ assertEq(Array.isArray(instance), true);
+}
+
+function testBuiltinInstance(builtin, ...args) {
+ class sub extends builtin {
+ constructor(...args) {
+ super(...args);
+ this.called = true;
+ }
+ }
+
+ let instance = new sub(...args);
+ assertEq(instance.called, true);
+ testBuiltinInstanceIsInstanceOf(instance, builtin, sub);
+}
+
+function testBuiltinMultipleSubclasses(builtin, ...args) {
+ function f(obj, prop) {
+ assertEq(obj.prop, prop);
+ }
+
+ class sub1 extends builtin { };
+ class sub2 extends builtin { };
+
+ const prop1 = "A";
+ const prop2 = "B";
+
+ sub1.prototype.prop = prop1;
+ sub2.prototype.prop = prop2;
+
+ let instance1 = new sub1(...args);
+ let instance2 = new sub2(...args);
+
+ // Also make sure we get the properties we want with a default constructor
+ testBuiltinInstanceIsInstanceOf(instance1, builtin, sub1);
+
+ for (let i = 0; i < 10; i++) {
+ f(instance1, prop1);
+ f(instance2, prop2);
+ }
+}
+
+function testBuiltin(builtin, ...args) {
+ testBuiltinInstance(builtin, ...args);
+ testBuiltinMultipleSubclasses(builtin, ...args);
+}
+
+function testBuiltinTypedArrays() {
+ let typedArrays = [Int8Array,
+ Uint8Array,
+ Uint8ClampedArray,
+ Int16Array,
+ Uint16Array,
+ Int32Array,
+ Uint32Array,
+ Float32Array,
+ Float64Array];
+
+ for (let array of typedArrays) {
+ testBuiltin(array);
+ testBuiltin(array, 5);
+ testBuiltin(array, new array());
+ testBuiltin(array, new ArrayBuffer());
+ }
+}
+
+testBuiltin(Function);
+testBuiltin(Object);
+testBuiltin(Boolean);
+testBuiltin(Error);
+testBuiltin(EvalError);
+testBuiltin(RangeError);
+testBuiltin(ReferenceError);
+testBuiltin(SyntaxError);
+testBuiltin(TypeError);
+testBuiltin(URIError);
+testBuiltin(Number);
+testBuiltin(Date);
+testBuiltin(Date, 5);
+testBuiltin(Date, 5, 10);
+testBuiltin(RegExp);
+testBuiltin(RegExp, /Regexp Argument/);
+testBuiltin(RegExp, "String Argument");
+testBuiltin(Map);
+testBuiltin(Set);
+testBuiltin(WeakMap);
+testBuiltin(WeakSet);
+testBuiltin(ArrayBuffer);
+testBuiltinTypedArrays();
+testBuiltin(DataView, new ArrayBuffer());
+testBuiltin(DataView, new (newGlobal().ArrayBuffer)());
+testBuiltin(String);
+testBuiltin(Array);
+testBuiltin(Array, 15);
+testBuiltin(Array, 3.0);
+testBuiltin(Array, "non-length one-arg");
+testBuiltin(Array, 5, 10, 15, "these are elements");
+// More Promise subclassing tests can be found in non262/Promise/promise-subclassing.js
+testBuiltin(Promise, _=>{});
+
+if (this.SharedArrayBuffer)
+ testBuiltin(SharedArrayBuffer);
+
+if (typeof reportCompare === 'function')
+ reportCompare(0,0,"OK");