1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// Flags: --expose-internals
'use strict';
require('../common');
const assert = require('assert');
const {
ArrayOfApply,
ArrayPrototypePushApply,
ArrayPrototypeUnshiftApply,
MathMaxApply,
MathMinApply,
StringPrototypeConcatApply,
TypedArrayOfApply,
} = require('internal/test/binding').primordials;
{
const arr1 = [1, 2, 3];
const arr2 = ArrayOfApply(arr1);
assert.deepStrictEqual(arr2, arr1);
assert.notStrictEqual(arr2, arr1);
}
{
const array = [1, 2, 3];
const i32Array = TypedArrayOfApply(Int32Array, array);
assert(i32Array instanceof Int32Array);
assert.strictEqual(i32Array.length, array.length);
for (let i = 0, { length } = array; i < length; i++) {
assert.strictEqual(i32Array[i], array[i], `i32Array[${i}] === array[${i}]`);
}
}
{
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const expected = [...arr1, ...arr2];
assert.strictEqual(ArrayPrototypePushApply(arr1, arr2), expected.length);
assert.deepStrictEqual(arr1, expected);
}
{
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const expected = [...arr2, ...arr1];
assert.strictEqual(ArrayPrototypeUnshiftApply(arr1, arr2), expected.length);
assert.deepStrictEqual(arr1, expected);
}
{
const array = [1, 2, 3];
assert.strictEqual(MathMaxApply(array), 3);
assert.strictEqual(MathMinApply(array), 1);
}
{
let hint;
const obj = { [Symbol.toPrimitive](h) {
hint = h;
return '[object Object]';
} };
const args = ['foo ', obj, ' bar'];
const result = StringPrototypeConcatApply('', args);
assert.strictEqual(hint, 'string');
assert.strictEqual(result, 'foo [object Object] bar');
}
|