From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../tests/proxy/testDirectProxySetFailure.js | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 js/src/jit-test/tests/proxy/testDirectProxySetFailure.js (limited to 'js/src/jit-test/tests/proxy/testDirectProxySetFailure.js') diff --git a/js/src/jit-test/tests/proxy/testDirectProxySetFailure.js b/js/src/jit-test/tests/proxy/testDirectProxySetFailure.js new file mode 100644 index 0000000000..3646fc69b3 --- /dev/null +++ b/js/src/jit-test/tests/proxy/testDirectProxySetFailure.js @@ -0,0 +1,32 @@ +// Test handling of false return from a handler.set() hook. + +load(libdir + "asserts.js"); + +var obj = {x: 1}; +var p = new Proxy(obj, { + set(target, key, value, receiver) { return false; } +}); + +// Failing to set a property is a no-op in non-strict code. +assertEq(p.x = 2, 2); +assertEq(obj.x, 1); + +// It's a TypeError in strict mode code. +assertThrowsInstanceOf(() => { "use strict"; p.x = 2; }, TypeError); +assertEq(obj.x, 1); + +// Even if the value doesn't change. +assertThrowsInstanceOf(() => { "use strict"; p.x = 1; }, TypeError); +assertEq(obj.x, 1); + +// Even if the target property doesn't already exist. +assertThrowsInstanceOf(() => { "use strict"; p.z = 1; }, TypeError); +assertEq("z" in obj, false); + +// [].sort() mutates its operand only by doing strict [[Set]] calls. +var arr = ["not", "already", "in", "order"]; +var p2 = new Proxy(arr, { + set(target, key, value, receiver) { return false; } +}); +assertThrowsInstanceOf(() => p2.sort(), TypeError); +assertDeepEq(arr, ["not", "already", "in", "order"]); -- cgit v1.2.3