Projekt

Obecné

Profil

Stáhnout (952 Bajtů) Statistiky
| Větev: | Revize:
1
'use strict';
2

    
3
var GetIntrinsic = require('../GetIntrinsic');
4

    
5
var $TypeError = GetIntrinsic('%TypeError%');
6

    
7
var isPrefixOf = require('../helpers/isPrefixOf');
8

    
9
// var callBound = require('../helpers/callBound');
10

    
11
// var $charAt = callBound('String.prototype.charAt');
12

    
13
var Type = require('./Type');
14

    
15
// https://www.ecma-international.org/ecma-262/9.0/#sec-isstringprefix
16

    
17
module.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
};
(50-50/117)