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.0 KB
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var GetIntrinsic = require('get-intrinsic');
|
---|
| 4 |
|
---|
| 5 | var $Object = require('es-object-atoms');
|
---|
| 6 | var $StringPrototype = GetIntrinsic('%String.prototype%');
|
---|
| 7 | var $SyntaxError = require('es-errors/syntax');
|
---|
| 8 | var $TypeError = require('es-errors/type');
|
---|
[79a0317] | 9 | var setProto = require('set-proto');
|
---|
[d565449] | 10 |
|
---|
| 11 | var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
|
---|
| 12 |
|
---|
| 13 | // https://262.ecma-international.org/6.0/#sec-stringcreate
|
---|
| 14 |
|
---|
| 15 | module.exports = function StringCreate(value, prototype) {
|
---|
| 16 | if (typeof value !== 'string') {
|
---|
| 17 | throw new $TypeError('Assertion failed: `S` must be a String');
|
---|
| 18 | }
|
---|
| 19 |
|
---|
| 20 | var S = $Object(value);
|
---|
| 21 | if (prototype !== $StringPrototype) {
|
---|
| 22 | if (setProto) {
|
---|
| 23 | setProto(S, prototype);
|
---|
| 24 | } else {
|
---|
| 25 | throw new $SyntaxError('StringCreate: a `proto` argument that is not `String.prototype` is not supported in an environment that does not support setting the [[Prototype]]');
|
---|
| 26 | }
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | var length = value.length;
|
---|
| 30 | DefinePropertyOrThrow(S, 'length', {
|
---|
| 31 | '[[Configurable]]': false,
|
---|
| 32 | '[[Enumerable]]': false,
|
---|
| 33 | '[[Value]]': length,
|
---|
| 34 | '[[Writable]]': false
|
---|
| 35 | });
|
---|
| 36 |
|
---|
| 37 | return S;
|
---|
| 38 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.