|
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.2 KB
|
| Rev | Line | |
|---|
| [9af201e] | 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | var $TypeError = require('es-errors/type');
|
|---|
| 4 |
|
|---|
| 5 | var IsArray = require('./IsArray');
|
|---|
| 6 |
|
|---|
| 7 | var isByteValue = require('../helpers/isByteValue');
|
|---|
| 8 |
|
|---|
| 9 | // https://262.ecma-international.org/12.0/#sec-bytelistbitwiseop
|
|---|
| 10 |
|
|---|
| 11 | module.exports = function ByteListBitwiseOp(op, xBytes, yBytes) {
|
|---|
| 12 | if (op !== '&' && op !== '^' && op !== '|') {
|
|---|
| 13 | throw new $TypeError('Assertion failed: `op` must be `&`, `^`, or `|`');
|
|---|
| 14 | }
|
|---|
| 15 | if (!IsArray(xBytes) || !IsArray(yBytes) || xBytes.length !== yBytes.length) {
|
|---|
| 16 | throw new $TypeError('Assertion failed: `xBytes` and `yBytes` must be same-length sequences of byte values (an integer 0-255, inclusive)');
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 | var result = [];
|
|---|
| 20 |
|
|---|
| 21 | for (var i = 0; i < xBytes.length; i += 1) {
|
|---|
| 22 | var xByte = xBytes[i];
|
|---|
| 23 | var yByte = yBytes[i];
|
|---|
| 24 | if (!isByteValue(xByte) || !isByteValue(yByte)) {
|
|---|
| 25 | throw new $TypeError('Assertion failed: `xBytes` and `yBytes` must be same-length sequences of byte values (an integer 0-255, inclusive)');
|
|---|
| 26 | }
|
|---|
| 27 | var resultByte;
|
|---|
| 28 | if (op === '&') {
|
|---|
| 29 | resultByte = xByte & yByte;
|
|---|
| 30 | } else if (op === '^') {
|
|---|
| 31 | resultByte = xByte ^ yByte;
|
|---|
| 32 | } else {
|
|---|
| 33 | resultByte = xByte | yByte;
|
|---|
| 34 | }
|
|---|
| 35 | result[result.length] = resultByte;
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | return result;
|
|---|
| 39 | };
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.