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