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