|
Last change
on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago |
|
Fix frontend appearance
|
-
Property mode
set to
100644
|
|
File size:
1.3 KB
|
| Line | |
|---|
| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var $SyntaxError = require('es-errors/syntax');
|
|---|
| 4 | var $TypeError = require('es-errors/type');
|
|---|
| 5 |
|
|---|
| 6 | var substring = require('./substring');
|
|---|
| 7 |
|
|---|
| 8 | var isInteger = require('math-intrinsics/isInteger');
|
|---|
| 9 | var isNaN = require('math-intrinsics/isNaN');
|
|---|
| 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 (!isInteger(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 |
|
|---|
| 28 | var n = +('0x' + hexDigits);
|
|---|
| 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.