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
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var callBound = require('call-bind/callBound');
|
---|
4 |
|
---|
5 | var $TypeError = require('es-errors/type');
|
---|
6 |
|
---|
7 | var $charAt = callBound('String.prototype.charAt');
|
---|
8 |
|
---|
9 | var isString = require('is-string');
|
---|
10 | var isNegativeZero = require('is-negative-zero');
|
---|
11 | var unbox = require('unbox-primitive');
|
---|
12 |
|
---|
13 | var CanonicalNumericIndexString = require('./CanonicalNumericIndexString');
|
---|
14 | var IsInteger = require('./IsInteger');
|
---|
15 | var IsPropertyKey = require('./IsPropertyKey');
|
---|
16 |
|
---|
17 | // https://262.ecma-international.org/6.0/#sec-stringgetindexproperty
|
---|
18 |
|
---|
19 | module.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.