main
Last change
on this file was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago |
Update repo after prototype presentation
|
-
Property mode
set to
100644
|
File size:
1.2 KB
|
Line | |
---|
1 | 'use strict';
|
---|
2 |
|
---|
3 | var callBound = require('call-bind/callBound');
|
---|
4 |
|
---|
5 | var $TypeError = require('es-errors/type');
|
---|
6 |
|
---|
7 | var $push = callBound('Array.prototype.push');
|
---|
8 |
|
---|
9 | var IsArray = require('./IsArray');
|
---|
10 |
|
---|
11 | var isByteValue = require('../helpers/isByteValue');
|
---|
12 |
|
---|
13 | // https://262.ecma-international.org/12.0/#sec-bytelistbitwiseop
|
---|
14 |
|
---|
15 | module.exports = function ByteListBitwiseOp(op, xBytes, yBytes) {
|
---|
16 | if (op !== '&' && op !== '^' && op !== '|') {
|
---|
17 | throw new $TypeError('Assertion failed: `op` must be `&`, `^`, or `|`');
|
---|
18 | }
|
---|
19 | if (!IsArray(xBytes) || !IsArray(yBytes) || xBytes.length !== yBytes.length) {
|
---|
20 | throw new $TypeError('Assertion failed: `xBytes` and `yBytes` must be same-length sequences of byte values (an integer 0-255, inclusive)');
|
---|
21 | }
|
---|
22 |
|
---|
23 | var result = [];
|
---|
24 |
|
---|
25 | for (var i = 0; i < xBytes.length; i += 1) {
|
---|
26 | var xByte = xBytes[i];
|
---|
27 | var yByte = yBytes[i];
|
---|
28 | if (!isByteValue(xByte) || !isByteValue(yByte)) {
|
---|
29 | throw new $TypeError('Assertion failed: `xBytes` and `yBytes` must be same-length sequences of byte values (an integer 0-255, inclusive)');
|
---|
30 | }
|
---|
31 | var resultByte;
|
---|
32 | if (op === '&') {
|
---|
33 | resultByte = xByte & yByte;
|
---|
34 | } else if (op === '^') {
|
---|
35 | resultByte = xByte ^ yByte;
|
---|
36 | } else {
|
---|
37 | resultByte = xByte | yByte;
|
---|
38 | }
|
---|
39 | $push(result, resultByte);
|
---|
40 | }
|
---|
41 |
|
---|
42 | return result;
|
---|
43 | };
|
---|
Note:
See
TracBrowser
for help on using the repository browser.