| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -79,6 +79,9 @@ function copyPropsRenamed(src, dest, prefix) { | |||
| 79 | 79 | ReflectDefineProperty(dest, name, desc); | |
| 80 | 80 | if (varargsMethods.includes(name)) { | |
| 81 | 81 | ReflectDefineProperty(dest, `${name}Apply`, { | |
| 82 | + // `src` is bound as the `this` so that the static `this` points | ||
| 83 | + // to the object it was defined on, | ||
| 84 | + // e.g.: `ArrayOfApply` gets a `this` of `Array`: | ||
| 82 | 85 | value: applyBind(desc.value, src), | |
| 83 | 86 | }); | |
| 84 | 87 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -43,6 +43,7 @@ const { | |||
| 43 | 43 | MathCeil, | |
| 44 | 44 | MathFloor, | |
| 45 | 45 | MathMax, | |
| 46 | + MathMaxApply, | ||
| 46 | 47 | NumberIsFinite, | |
| 47 | 48 | NumberIsNaN, | |
| 48 | 49 | ObjectDefineProperty, | |
@@ -626,7 +627,7 @@ Interface.prototype._tabComplete = function(lastKeypressWasTab) { | |||
| 626 | 627 | // Apply/show completions. | |
| 627 | 628 | const completionsWidth = ArrayPrototypeMap(completions, | |
| 628 | 629 | (e) => getStringWidth(e)); | |
| 629 | - const width = MathMax(...completionsWidth) + 2; // 2 space padding | ||
| 630 | + const width = MathMaxApply(completionsWidth) + 2; // 2 space padding | ||
| 630 | 631 | let maxColumns = MathFloor(this.columns / width) || 1; | |
| 631 | 632 | if (maxColumns === Infinity) { | |
| 632 | 633 | maxColumns = 1; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ const { | |||
| 28 | 28 | ArrayPrototypePush, | |
| 29 | 29 | Error, | |
| 30 | 30 | FunctionPrototypeBind, | |
| 31 | - MathMax, | ||
| 31 | + MathMaxApply, | ||
| 32 | 32 | NumberIsFinite, | |
| 33 | 33 | NumberIsNaN, | |
| 34 | 34 | ObjectDefineProperties, | |
@@ -796,7 +796,7 @@ function createConvenienceMethod(ctor, sync) { | |||
| 796 | 796 | }; | |
| 797 | 797 | } | |
| 798 | 798 | ||
| 799 | - const kMaxBrotliParam = MathMax(...ArrayPrototypeMap( | ||
| 799 | + const kMaxBrotliParam = MathMaxApply(ArrayPrototypeMap( | ||
| 800 | 800 | ObjectKeys(constants), | |
| 801 | 801 | (key) => (StringPrototypeStartsWith(key, 'BROTLI_PARAM_') ? | |
| 802 | 802 | constants[key] : | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,74 @@ | |||
| 1 | + // Flags: --expose-internals | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + require('../common'); | ||
| 5 | + | ||
| 6 | + const assert = require('assert'); | ||
| 7 | + const { | ||
| 8 | + ArrayOfApply, | ||
| 9 | + ArrayPrototypePushApply, | ||
| 10 | + ArrayPrototypeUnshiftApply, | ||
| 11 | + MathMaxApply, | ||
| 12 | + MathMinApply, | ||
| 13 | + StringPrototypeConcatApply, | ||
| 14 | + TypedArrayOfApply, | ||
| 15 | + } = require('internal/test/binding').primordials; | ||
| 16 | + | ||
| 17 | + { | ||
| 18 | + const arr1 = [1, 2, 3]; | ||
| 19 | + const arr2 = ArrayOfApply(arr1); | ||
| 20 | + | ||
| 21 | + assert.deepStrictEqual(arr2, arr1); | ||
| 22 | + assert.notStrictEqual(arr2, arr1); | ||
| 23 | + } | ||
| 24 | + | ||
| 25 | + { | ||
| 26 | + const array = [1, 2, 3]; | ||
| 27 | + const i32Array = TypedArrayOfApply(Int32Array, array); | ||
| 28 | + | ||
| 29 | + assert(i32Array instanceof Int32Array); | ||
| 30 | + assert.strictEqual(i32Array.length, array.length); | ||
| 31 | + for (let i = 0, { length } = array; i < length; i++) { | ||
| 32 | + assert.strictEqual(i32Array[i], array[i], `i32Array[${i}] === array[${i}]`); | ||
| 33 | + } | ||
| 34 | + } | ||
| 35 | + | ||
| 36 | + { | ||
| 37 | + const arr1 = [1, 2, 3]; | ||
| 38 | + const arr2 = [4, 5, 6]; | ||
| 39 | + | ||
| 40 | + const expected = [...arr1, ...arr2]; | ||
| 41 | + | ||
| 42 | + assert.strictEqual(ArrayPrototypePushApply(arr1, arr2), expected.length); | ||
| 43 | + assert.deepStrictEqual(arr1, expected); | ||
| 44 | + } | ||
| 45 | + | ||
| 46 | + { | ||
| 47 | + const arr1 = [1, 2, 3]; | ||
| 48 | + const arr2 = [4, 5, 6]; | ||
| 49 | + | ||
| 50 | + const expected = [...arr2, ...arr1]; | ||
| 51 | + | ||
| 52 | + assert.strictEqual(ArrayPrototypeUnshiftApply(arr1, arr2), expected.length); | ||
| 53 | + assert.deepStrictEqual(arr1, expected); | ||
| 54 | + } | ||
| 55 | + | ||
| 56 | + { | ||
| 57 | + const array = [1, 2, 3]; | ||
| 58 | + assert.strictEqual(MathMaxApply(array), 3); | ||
| 59 | + assert.strictEqual(MathMinApply(array), 1); | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + { | ||
| 63 | + let hint; | ||
| 64 | + const obj = { [Symbol.toPrimitive](h) { | ||
| 65 | + hint = h; | ||
| 66 | + return '[object Object]'; | ||
| 67 | + } }; | ||
| 68 | + | ||
| 69 | + const args = ['foo ', obj, ' bar']; | ||
| 70 | + const result = StringPrototypeConcatApply('', args); | ||
| 71 | + | ||
| 72 | + assert.strictEqual(hint, 'string'); | ||
| 73 | + assert.strictEqual(result, 'foo [object Object] bar'); | ||
| 74 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments