source: imaps-frontend/node_modules/es-abstract/2015/StringGetIndexProperty.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.3 KB
Line 
1'use strict';
2
3var callBound = require('call-bind/callBound');
4
5var $TypeError = require('es-errors/type');
6
7var $charAt = callBound('String.prototype.charAt');
8
9var isString = require('is-string');
10var isNegativeZero = require('is-negative-zero');
11var unbox = require('unbox-primitive');
12
13var CanonicalNumericIndexString = require('./CanonicalNumericIndexString');
14var IsInteger = require('./IsInteger');
15var IsPropertyKey = require('./IsPropertyKey');
16
17// https://262.ecma-international.org/6.0/#sec-stringgetindexproperty
18
19module.exports = function StringGetIndexProperty(S, P) {
20 if (typeof S === 'string' || !isString(S)) {
21 throw new $TypeError('Assertion failed: `S` must be a boxed String Object');
22 }
23 if (!IsPropertyKey(P)) {
24 throw new $TypeError('Assertion failed: `P` must be a Property Key');
25 }
26
27 if (typeof P !== 'string') {
28 return void undefined;
29 }
30
31 var index = CanonicalNumericIndexString(P);
32 if (typeof index === 'undefined' || !IsInteger(index) || isNegativeZero(index)) {
33 return void undefined;
34 }
35
36 var str = unbox(S);
37 var len = str.length;
38 if (index < 0 || len <= index) {
39 return void undefined;
40 }
41
42 var resultStr = $charAt(str, index);
43
44 return {
45 '[[Configurable]]': false,
46 '[[Enumerable]]': true,
47 '[[Value]]': resultStr,
48 '[[Writable]]': false
49 };
50};
Note: See TracBrowser for help on using the repository browser.