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.3 KB
|
Rev | Line | |
---|
[d565449] | 1 | 'use strict';
|
---|
| 2 |
|
---|
| 3 | var $SyntaxError = require('es-errors/syntax');
|
---|
| 4 | var $TypeError = require('es-errors/type');
|
---|
| 5 |
|
---|
| 6 | var IsIntegralNumber = require('./IsIntegralNumber');
|
---|
| 7 | var substring = require('./substring');
|
---|
| 8 |
|
---|
[79a0317] | 9 | var isNaN = require('math-intrinsics/isNaN');
|
---|
[d565449] | 10 |
|
---|
| 11 | // https://262.ecma-international.org/14.0/#sec-parsehexoctet
|
---|
| 12 |
|
---|
| 13 | module.exports = function ParseHexOctet(string, position) {
|
---|
| 14 | if (typeof string !== 'string') {
|
---|
| 15 | throw new $TypeError('Assertion failed: `string` must be a String');
|
---|
| 16 | }
|
---|
| 17 | if (!IsIntegralNumber(position) || position < 0) {
|
---|
| 18 | throw new $TypeError('Assertion failed: `position` must be a nonnegative integer');
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | var len = string.length; // step 1
|
---|
| 22 | if ((position + 2) > len) { // step 2
|
---|
| 23 | var error = new $SyntaxError('requested a position on a string that does not contain 2 characters at that position'); // step 2.a
|
---|
| 24 | return [error]; // step 2.b
|
---|
| 25 | }
|
---|
| 26 | var hexDigits = substring(string, position, position + 2); // step 3
|
---|
| 27 |
|
---|
[79a0317] | 28 | var n = +('0x' + hexDigits);
|
---|
[d565449] | 29 | if (isNaN(n)) {
|
---|
| 30 | return [new $SyntaxError('Invalid hexadecimal characters')];
|
---|
| 31 | }
|
---|
| 32 | return n;
|
---|
| 33 |
|
---|
| 34 | /*
|
---|
| 35 | 4. Let _parseResult_ be ParseText(StringToCodePoints(_hexDigits_), |HexDigits[~Sep]|).
|
---|
| 36 | 5. If _parseResult_ is not a Parse Node, return _parseResult_.
|
---|
| 37 | 6. Let _n_ be the unsigned 8-bit value corresponding with the MV of _parseResult_.
|
---|
| 38 | 7. Return _n_.
|
---|
| 39 | */
|
---|
| 40 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.