blob: 4958544ce29f0d6987b4aac1af97e934a4e92c22 [file] [log] [blame]
Leo Repp58b9f112021-11-22 11:57:47 +01001'use strict';
2
3var GetIntrinsic = require('get-intrinsic');
4
5var $TypeError = GetIntrinsic('%TypeError%');
6
7var isPrefixOf = require('../helpers/isPrefixOf');
8
9// var callBound = require('call-bind/callBound');
10
11// var $charAt = callBound('String.prototype.charAt');
12
13var Type = require('./Type');
14
15// https://262.ecma-international.org/9.0/#sec-isstringprefix
16
17module.exports = function IsStringPrefix(p, q) {
18 if (Type(p) !== 'String') {
19 throw new $TypeError('Assertion failed: "p" must be a String');
20 }
21
22 if (Type(q) !== 'String') {
23 throw new $TypeError('Assertion failed: "q" must be a String');
24 }
25
26 return isPrefixOf(p, q);
27 /*
28 if (p === q || p === '') {
29 return true;
30 }
31
32 var pLength = p.length;
33 var qLength = q.length;
34 if (pLength >= qLength) {
35 return false;
36 }
37
38 // assert: pLength < qLength
39
40 for (var i = 0; i < pLength; i += 1) {
41 if ($charAt(p, i) !== $charAt(q, i)) {
42 return false;
43 }
44 }
45 return true;
46 */
47};