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 --- js/src/jit-test/tests/warp/function-load-name.js | 100 +++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 js/src/jit-test/tests/warp/function-load-name.js (limited to 'js/src/jit-test/tests/warp/function-load-name.js') diff --git a/js/src/jit-test/tests/warp/function-load-name.js b/js/src/jit-test/tests/warp/function-load-name.js new file mode 100644 index 0000000000..686ed32629 --- /dev/null +++ b/js/src/jit-test/tests/warp/function-load-name.js @@ -0,0 +1,100 @@ +// Test transpiling of LoadFunctionNameResult and cover possible bailout conditions. + +function empty() {} + +// Note: Typically won't use LoadFunctionNameResult, because the "name" +// property will be resolved on the first access. +function testGlobalFunction() { + for (var i = 0; i < 200; ++i) { + assertEq(empty.name, "empty"); + } +} +testGlobalFunction(); + +// Note: Typically won't use LoadFunctionNameResult, because the "name" +// property will be resolved on the first access. +function testInnerFunction() { + function f() {} + for (var i = 0; i < 200; ++i) { + assertEq(f.name, "f"); + } +} +testInnerFunction(); + +function testPerLoopFunction() { + for (var i = 0; i < 200; ++i) { + assertEq(function f(){}.name, "f"); + } +} +testPerLoopFunction(); + +// Note: Typically won't use LoadFunctionNameResult, because the "name" +// property will be resolved on the first access. +function testNativeFunction() { + for (var i = 0; i < 200; ++i) { + assertEq(Math.max.name, "max"); + } +} +testNativeFunction(); + +// Note: Typically won't use LoadFunctionNameResult, because the "name" +// property will be resolved on the first access. +function testSelfHostedFunction() { + for (var i = 0; i < 200; ++i) { + assertEq(Array.prototype.forEach.name, "forEach"); + } +} +testSelfHostedFunction(); + +// Bailout when the name property is resolved. +function testBailoutResolvedName() { + function f1() {} + + // Ensure the name property of |f1| is resolved. + assertEq(f1.name, "f1"); + + var names = ["f", "f1"]; + + for (var i = 0; i < 10; ++i) { + var name = names[0 + (i >= 5)]; + + for (var j = 0; j < 100; ++j) { + var values = [function f(){}, f1]; + var value = values[0 + (i >= 5)]; + + assertEq(value.name, name); + } + } +} +testBailoutResolvedName(); + +// Bailout when the HAS_BOUND_FUNCTION_NAME_PREFIX isn't set. +function testBailoutBoundName() { + function f1() {} + function f2() {} + + var bound = f1.bind(); + + // Ensure the name property of |bound| is resolved. That way new functions + // created through |bound().bind()| will have the HAS_BOUND_FUNCTION_NAME_PREFIX + // flag set. + assertEq(bound.name, "bound f1"); + + // |bound1| and |bound2| have the same shape, but different function flags. + var bound1 = bound.bind(); // HAS_BOUND_FUNCTION_NAME_PREFIX + var bound2 = f2.bind(); // ! HAS_BOUND_FUNCTION_NAME_PREFIX + + var values = [bound1, bound2]; + var names = ["bound bound bound f1", "bound bound f2"]; + + for (var i = 0; i < 10; ++i) { + var value = values[0 + (i >= 5)]; + var name = names[0 + (i >= 5)]; + + for (var j = 0; j < 100; ++j) { + var f = value.bind(); + assertEq(f.name, name); + } + } +} +testBailoutBoundName(); -- cgit v1.2.3