source: imaps-frontend/node_modules/es-abstract/2022/Set.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.2 KB
RevLine 
[d565449]1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var IsPropertyKey = require('./IsPropertyKey');
6var SameValue = require('./SameValue');
7var Type = require('./Type');
8
9// IE 9 does not throw in strict mode when writability/configurability/extensibility is violated
10var noThrowOnStrictViolation = (function () {
11 try {
12 delete [].length;
13 return true;
14 } catch (e) {
15 return false;
16 }
17}());
18
19// https://262.ecma-international.org/6.0/#sec-set-o-p-v-throw
20
21module.exports = function Set(O, P, V, Throw) {
22 if (Type(O) !== 'Object') {
23 throw new $TypeError('Assertion failed: `O` must be an Object');
24 }
25 if (!IsPropertyKey(P)) {
26 throw new $TypeError('Assertion failed: `P` must be a Property Key');
27 }
28 if (typeof Throw !== 'boolean') {
29 throw new $TypeError('Assertion failed: `Throw` must be a Boolean');
30 }
31 if (Throw) {
32 O[P] = V; // eslint-disable-line no-param-reassign
33 if (noThrowOnStrictViolation && !SameValue(O[P], V)) {
34 throw new $TypeError('Attempted to assign to readonly property.');
35 }
36 return true;
37 }
38 try {
39 O[P] = V; // eslint-disable-line no-param-reassign
40 return noThrowOnStrictViolation ? SameValue(O[P], V) : true;
41 } catch (e) {
42 return false;
43 }
44
45};
Note: See TracBrowser for help on using the repository browser.