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.1 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');
|
---|
| 9 |
|
---|
| 10 | var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
|
---|
| 11 |
|
---|
| 12 | var setProto = require('../helpers/setProto');
|
---|
| 13 |
|
---|
| 14 | // https://262.ecma-international.org/6.0/#sec-stringcreate
|
---|
| 15 |
|
---|
| 16 | module.exports = function StringCreate(value, prototype) {
|
---|
| 17 | if (typeof value !== 'string') {
|
---|
| 18 | throw new $TypeError('Assertion failed: `S` must be a String');
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | var S = $Object(value);
|
---|
| 22 | if (prototype !== $StringPrototype) {
|
---|
| 23 | if (setProto) {
|
---|
| 24 | setProto(S, prototype);
|
---|
| 25 | } else {
|
---|
| 26 | 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]]');
|
---|
| 27 | }
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | var length = value.length;
|
---|
| 31 | DefinePropertyOrThrow(S, 'length', {
|
---|
| 32 | '[[Configurable]]': false,
|
---|
| 33 | '[[Enumerable]]': false,
|
---|
| 34 | '[[Value]]': length,
|
---|
| 35 | '[[Writable]]': false
|
---|
| 36 | });
|
---|
| 37 |
|
---|
| 38 | return S;
|
---|
| 39 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.