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
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
[79a0317] | 4 | var isNegativeZero = require('math-intrinsics/isNegativeZero');
|
---|
[d565449] | 5 |
|
---|
[79a0317] | 6 | var callBound = require('call-bound');
|
---|
[d565449] | 7 | var $charAt = callBound('String.prototype.charAt');
|
---|
| 8 | var $stringToString = callBound('String.prototype.toString');
|
---|
| 9 |
|
---|
| 10 | var CanonicalNumericIndexString = require('./CanonicalNumericIndexString');
|
---|
| 11 | var IsIntegralNumber = require('./IsIntegralNumber');
|
---|
| 12 |
|
---|
[79a0317] | 13 | var isObject = require('../helpers/isObject');
|
---|
| 14 | var isPropertyKey = require('../helpers/isPropertyKey');
|
---|
[d565449] | 15 |
|
---|
| 16 | // https://262.ecma-international.org/12.0/#sec-stringgetownproperty
|
---|
| 17 |
|
---|
| 18 | module.exports = function StringGetOwnProperty(S, P) {
|
---|
| 19 | var str;
|
---|
[79a0317] | 20 | if (isObject(S)) {
|
---|
[d565449] | 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 | }
|
---|
[79a0317] | 28 | if (!isPropertyKey(P)) {
|
---|
| 29 | throw new $TypeError('Assertion failed: P is not a Property Key');
|
---|
[d565449] | 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.