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
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $TypeError = require('es-errors/type');
|
---|
| 4 |
|
---|
| 5 | var callBound = require('call-bind/callBound');
|
---|
| 6 | var $charAt = callBound('String.prototype.charAt');
|
---|
| 7 | var $stringToString = callBound('String.prototype.toString');
|
---|
| 8 |
|
---|
| 9 | var CanonicalNumericIndexString = require('./CanonicalNumericIndexString');
|
---|
| 10 | var IsInteger = require('./IsInteger');
|
---|
| 11 | var IsPropertyKey = require('./IsPropertyKey');
|
---|
| 12 | var Type = require('./Type');
|
---|
| 13 |
|
---|
| 14 | var isNegativeZero = require('is-negative-zero');
|
---|
| 15 |
|
---|
| 16 | // https://262.ecma-international.org/8.0/#sec-stringgetownproperty
|
---|
| 17 |
|
---|
| 18 | module.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' || !IsInteger(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.