diff options
Diffstat (limited to 'js/src/jit-test/tests/arguments/function_dot_caller_restrictions.js')
-rw-r--r-- | js/src/jit-test/tests/arguments/function_dot_caller_restrictions.js | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/arguments/function_dot_caller_restrictions.js b/js/src/jit-test/tests/arguments/function_dot_caller_restrictions.js new file mode 100644 index 0000000000..414f348eb6 --- /dev/null +++ b/js/src/jit-test/tests/arguments/function_dot_caller_restrictions.js @@ -0,0 +1,78 @@ + +function g() { } +function strict() { + "use strict"; +} + +let bound = g.bind(); +let arrow = x => 0; + +async function fn_async() { } +function * fn_generator() { } + +let o = { + mtd() {}, + get x() {}, + set x(v) {}, +}; + +class Base { } +class Derived extends Base { } + +function asm_mod() { + "use asm"; + function mtd() {} + return { mtd: mtd } +} + +let asm_fun = (new asm_mod).mtd; + +let builtin_selfhost = [].sort; +let builtin_native = Math.sin; + +let dot_caller = Object.getOwnPropertyDescriptor(Function.__proto__, + "caller").get; + +// Returns true if fn.caller is allowed +function check(fn) { + try { + (function() { + fn.caller; + })(); + } + catch (e) { + assertEq(e instanceof TypeError, true); + return false; + } + return true; +} + +// Normal sloppy functions are allowed, even if they also are intended as +// asm.js. +assertEq(check(g), true); +assertEq(check(asm_mod), true); +assertEq(check(asm_fun), true); + +// Most others are not +assertEq(check(strict), false); +assertEq(check(bound), false); +assertEq(check(arrow), false); +assertEq(check(fn_async), false); +assertEq(check(fn_generator), false); +assertEq(check(o.mtd), false) +assertEq(check(Object.getOwnPropertyDescriptor(o, "x").get), false) +assertEq(check(Object.getOwnPropertyDescriptor(o, "x").set), false) +assertEq(check(Base), false); +assertEq(check(Derived), false); +assertEq(check(builtin_selfhost), false); +assertEq(check(builtin_native), false); +assertEq(check(dot_caller), false); + +// Have a native invoke .caller on our behalf. +function foo() { + function inner() { + return callFunctionFromNativeFrame(dot_caller.bind(inner)) + } + return inner(); +} +assertEq(foo, foo()); |