summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/plain-object-prototypes-error.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/basic/plain-object-prototypes-error.js')
-rw-r--r--js/src/jit-test/tests/basic/plain-object-prototypes-error.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/plain-object-prototypes-error.js b/js/src/jit-test/tests/basic/plain-object-prototypes-error.js
new file mode 100644
index 0000000000..d62d7fbe72
--- /dev/null
+++ b/js/src/jit-test/tests/basic/plain-object-prototypes-error.js
@@ -0,0 +1,40 @@
+// Make sure the error has a sensible error message.
+function assertThrowsObjectError(f, name) {
+ try {
+ f();
+ assertEq(true, false);
+ } catch (e) {
+ assertEq(e instanceof TypeError, true);
+ assertEq(e.message.includes("called on incompatible " + name), true, e.message);
+ }
+}
+
+// Call methods on the prototypes where the methods themselves are defined.
+assertThrowsObjectError(() => Map.prototype.has(0), "Map.prototype");
+assertThrowsObjectError(() => Set.prototype.has(0), "Set.prototype");
+assertThrowsObjectError(() => WeakMap.prototype.has({}), "WeakMap.prototype");
+assertThrowsObjectError(() => WeakSet.prototype.has({}), "WeakSet.prototype");
+assertThrowsObjectError(() => Date.prototype.getSeconds(), "Date.prototype");
+assertThrowsObjectError(() => RegExp.prototype.compile(), "RegExp.prototype");
+
+// Call methods with different prototype objects.
+assertThrowsObjectError(() => Map.prototype.has.call(ArrayBuffer.prototype), "ArrayBuffer.prototype");
+assertThrowsObjectError(() => Map.prototype.has.call(BigInt.prototype), "BigInt.prototype");
+assertThrowsObjectError(() => Map.prototype.has.call(DataView.prototype), "DataView.prototype");
+assertThrowsObjectError(() => Map.prototype.has.call(Date.prototype), "Date.prototype");
+assertThrowsObjectError(() => Map.prototype.has.call(FinalizationRegistry.prototype), "FinalizationRegistry.prototype");
+assertThrowsObjectError(() => Map.prototype.has.call(Int32Array.prototype), "Int32Array.prototype");
+assertThrowsObjectError(() => Map.prototype.has.call(Promise.prototype), "Promise.prototype");
+if (this.hasOwnProperty("ReadableStream")) {
+ // ReadableStream is only present for the JS Streams implementation
+ assertThrowsObjectError(() => Map.prototype.has.call(ReadableStream.prototype), "ReadableStream.prototype");
+}
+assertThrowsObjectError(() => Map.prototype.has.call(RegExp.prototype), "RegExp.prototype");
+assertThrowsObjectError(() => Map.prototype.has.call(Set.prototype), "Set.prototype");
+assertThrowsObjectError(() => Map.prototype.has.call(TypeError.prototype), "TypeError.prototype");
+assertThrowsObjectError(() => Map.prototype.has.call(WeakMap.prototype), "WeakMap.prototype");
+assertThrowsObjectError(() => Map.prototype.has.call(WeakRef.prototype), "WeakRef.prototype");
+
+// Call methods with different objects.
+assertThrowsObjectError(() => Map.prototype.has.call(new Error), "Error");
+assertThrowsObjectError(() => Map.prototype.has.call(new TypeError), "TypeError");