source: imaps-frontend/node_modules/es-abstract/2016/StringCreate.js@ d565449

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.1 KB
Line 
1'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $Object = require('es-object-atoms');
6var $StringPrototype = GetIntrinsic('%String.prototype%');
7var $SyntaxError = require('es-errors/syntax');
8var $TypeError = require('es-errors/type');
9
10var DefinePropertyOrThrow = require('./DefinePropertyOrThrow');
11
12var setProto = require('../helpers/setProto');
13
14// https://262.ecma-international.org/6.0/#sec-stringcreate
15
16module.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.