|
| 1 | +// Copyright (C) 2024 Justin Dorfman. All rights reserved. |
| 2 | +// This code is governed by the BSD license found in the LICENSE file. |
| 3 | +/*--- |
| 4 | +esid: sec-addrestrictedfunctionproperties |
| 5 | +description: > |
| 6 | + Function.prototype.arguments is an accessor property whose set and get |
| 7 | + functions are both %ThrowTypeError%. |
| 8 | +info: | |
| 9 | + 2. Let _thrower_ be _realm_.[[Intrinsics]].[[%ThrowTypeError%]]. |
| 10 | + 3. Perform ! DefinePropertyOrThrow(_F_, *"caller"*, PropertyDescriptor { [[Get]]: _thrower_, [[Set]]: _thrower_, [[Enumerable]]: *false*, [[Configurable]]: *true* }). |
| 11 | + 4. Perform ! DefinePropertyOrThrow(_F_, *"arguments"*, PropertyDescriptor { [[Get]]: _thrower_, [[Set]]: _thrower_, [[Enumerable]]: *false*, [[Configurable]]: *true* }). |
| 12 | +includes: [propertyHelper.js, wellKnownIntrinsicObjects.js] |
| 13 | +---*/ |
| 14 | + |
| 15 | +const argumentsDesc = Object.getOwnPropertyDescriptor(Function.prototype, 'arguments'); |
| 16 | + |
| 17 | +verifyProperty( |
| 18 | + Function.prototype, |
| 19 | + "arguments", |
| 20 | + { enumerable: false, configurable: true }, |
| 21 | + { restore: true } |
| 22 | +); |
| 23 | + |
| 24 | +assert.sameValue(typeof argumentsDesc.get, "function", |
| 25 | + "Function.prototype.arguments has function getter"); |
| 26 | +assert.sameValue(typeof argumentsDesc.set, "function", |
| 27 | + "Function.prototype.arguments has function setter"); |
| 28 | +assert.sameValue(argumentsDesc.get, argumentsDesc.set, |
| 29 | + "Function.prototype.arguments property getter/setter are the same function"); |
| 30 | + |
| 31 | +var throwTypeError; |
| 32 | +WellKnownIntrinsicObjects.forEach(function(record) { |
| 33 | + if (record.name === "%ThrowTypeError%") { |
| 34 | + throwTypeError = record.value; |
| 35 | + } |
| 36 | +}); |
| 37 | +if (throwTypeError) { |
| 38 | + assert.sameValue(argumentsDesc.set, throwTypeError, "Function.prototype.arguments getter is %ThrowTypeError%"); |
| 39 | +} |
| 40 | +assert.throws(TypeError, function() { |
| 41 | + return Function.prototype.arguments; |
| 42 | +}); |
| 43 | +assert.throws(TypeError, function() { |
| 44 | + Function.prototype.arguments = arguments; |
| 45 | +}); |
0 commit comments