source: imaps-frontend/node_modules/es-abstract/2024/StringGetOwnProperty.js@ 79a0317

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.3 KB
Line 
1'use strict';
2
3var $TypeError = require('es-errors/type');
4var isNegativeZero = require('math-intrinsics/isNegativeZero');
5
6var callBound = require('call-bound');
7var $charAt = callBound('String.prototype.charAt');
8var $stringToString = callBound('String.prototype.toString');
9
10var CanonicalNumericIndexString = require('./CanonicalNumericIndexString');
11var IsIntegralNumber = require('./IsIntegralNumber');
12
13var isObject = require('../helpers/isObject');
14var isPropertyKey = require('../helpers/isPropertyKey');
15
16// https://262.ecma-international.org/12.0/#sec-stringgetownproperty
17
18module.exports = function StringGetOwnProperty(S, P) {
19 var str;
20 if (isObject(S)) {
21 try {
22 str = $stringToString(S);
23 } catch (e) { /**/ }
24 }
25 if (typeof str !== 'string') {
26 throw new $TypeError('Assertion failed: `S` must be a boxed string object');
27 }
28 if (!isPropertyKey(P)) {
29 throw new $TypeError('Assertion failed: P is not a Property Key');
30 }
31 if (typeof P !== 'string') {
32 return void undefined;
33 }
34 var index = CanonicalNumericIndexString(P);
35 var len = str.length;
36 if (typeof index === 'undefined' || !IsIntegralNumber(index) || isNegativeZero(index) || index < 0 || len <= index) {
37 return void undefined;
38 }
39 var resultStr = $charAt(S, index);
40 return {
41 '[[Configurable]]': false,
42 '[[Enumerable]]': true,
43 '[[Value]]': resultStr,
44 '[[Writable]]': false
45 };
46};
Note: See TracBrowser for help on using the repository browser.