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

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

Update repo after prototype presentation

  • Property mode set to 100644
File size: 1.3 KB
RevLine 
[d565449]1'use strict';
2
3var $TypeError = require('es-errors/type');
4
5var callBound = require('call-bind/callBound');
6var $charAt = callBound('String.prototype.charAt');
7var $stringToString = callBound('String.prototype.toString');
8
9var CanonicalNumericIndexString = require('./CanonicalNumericIndexString');
10var IsIntegralNumber = require('./IsIntegralNumber');
11var IsPropertyKey = require('./IsPropertyKey');
12var Type = require('./Type');
13
14var isNegativeZero = require('is-negative-zero');
15
16// https://262.ecma-international.org/12.0/#sec-stringgetownproperty
17
18module.exports = function StringGetOwnProperty(S, P) {
19 var str;
20 if (Type(S) === 'Object') {
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: IsPropertyKey(P) is not true');
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.