| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,6 +6,12 @@ const { | |||
| 6 | 6 | StringPrototypeEndsWith, | |
| 7 | 7 | } = primordials; | |
| 8 | 8 | ||
| 9 | + const { | ||
| 10 | + codes: { | ||
| 11 | + ERR_OUT_OF_RANGE, | ||
| 12 | + }, | ||
| 13 | + } = require('internal/errors'); | ||
| 14 | + | ||
| 9 | 15 | const colors = require('internal/util/colors'); | |
| 10 | 16 | ||
| 11 | 17 | const kNopLinesToCollapse = 5; | |
@@ -29,7 +35,15 @@ function myersDiff(actual, expected, checkCommaDisparity = false) { | |||
| 29 | 35 | const actualLength = actual.length; | |
| 30 | 36 | const expectedLength = expected.length; | |
| 31 | 37 | const max = actualLength + expectedLength; | |
| 32 | - // TODO(BridgeAR): Cap the input in case the values go beyond the limit of 2^31 - 1. | ||
| 38 | + | ||
| 39 | + if (max > 2 ** 31 - 1) { | ||
| 40 | + throw new ERR_OUT_OF_RANGE( | ||
| 41 | + 'myersDiff input size', | ||
| 42 | + '< 2^31', | ||
| 43 | + max, | ||
| 44 | + ); | ||
| 45 | + } | ||
| 46 | + | ||
| 33 | 47 | const v = new Int32Array(2 * max + 1); | |
| 34 | 48 | const trace = []; | |
| 35 | 49 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,25 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + const { myersDiff } = require('internal/assert/myers_diff'); | ||
| 8 | + | ||
| 9 | + { | ||
| 10 | + const arr1 = { length: 2 ** 31 - 1 }; | ||
| 11 | + const arr2 = { length: 2 }; | ||
| 12 | + const max = arr1.length + arr2.length; | ||
| 13 | + assert.throws( | ||
| 14 | + () => { | ||
| 15 | + myersDiff(arr1, arr2); | ||
| 16 | + }, | ||
| 17 | + common.expectsError({ | ||
| 18 | + code: 'ERR_OUT_OF_RANGE', | ||
| 19 | + name: 'RangeError', | ||
| 20 | + message: 'The value of "myersDiff input size" ' + | ||
| 21 | + 'is out of range. It must be < 2^31. ' + | ||
| 22 | + `Received ${max}` | ||
| 23 | + }) | ||
| 24 | + ); | ||
| 25 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments