11cb0ef41Sopenharmony_ci// Flags: --expose-internals 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_cirequire('../common'); 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst assert = require('assert'); 71cb0ef41Sopenharmony_ciconst { 81cb0ef41Sopenharmony_ci ArrayOfApply, 91cb0ef41Sopenharmony_ci ArrayPrototypePushApply, 101cb0ef41Sopenharmony_ci ArrayPrototypeUnshiftApply, 111cb0ef41Sopenharmony_ci MathMaxApply, 121cb0ef41Sopenharmony_ci MathMinApply, 131cb0ef41Sopenharmony_ci StringPrototypeConcatApply, 141cb0ef41Sopenharmony_ci TypedArrayOfApply, 151cb0ef41Sopenharmony_ci} = require('internal/test/binding').primordials; 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci{ 181cb0ef41Sopenharmony_ci const arr1 = [1, 2, 3]; 191cb0ef41Sopenharmony_ci const arr2 = ArrayOfApply(arr1); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci assert.deepStrictEqual(arr2, arr1); 221cb0ef41Sopenharmony_ci assert.notStrictEqual(arr2, arr1); 231cb0ef41Sopenharmony_ci} 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci{ 261cb0ef41Sopenharmony_ci const array = [1, 2, 3]; 271cb0ef41Sopenharmony_ci const i32Array = TypedArrayOfApply(Int32Array, array); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci assert(i32Array instanceof Int32Array); 301cb0ef41Sopenharmony_ci assert.strictEqual(i32Array.length, array.length); 311cb0ef41Sopenharmony_ci for (let i = 0, { length } = array; i < length; i++) { 321cb0ef41Sopenharmony_ci assert.strictEqual(i32Array[i], array[i], `i32Array[${i}] === array[${i}]`); 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci} 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci{ 371cb0ef41Sopenharmony_ci const arr1 = [1, 2, 3]; 381cb0ef41Sopenharmony_ci const arr2 = [4, 5, 6]; 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci const expected = [...arr1, ...arr2]; 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci assert.strictEqual(ArrayPrototypePushApply(arr1, arr2), expected.length); 431cb0ef41Sopenharmony_ci assert.deepStrictEqual(arr1, expected); 441cb0ef41Sopenharmony_ci} 451cb0ef41Sopenharmony_ci 461cb0ef41Sopenharmony_ci{ 471cb0ef41Sopenharmony_ci const arr1 = [1, 2, 3]; 481cb0ef41Sopenharmony_ci const arr2 = [4, 5, 6]; 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci const expected = [...arr2, ...arr1]; 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci assert.strictEqual(ArrayPrototypeUnshiftApply(arr1, arr2), expected.length); 531cb0ef41Sopenharmony_ci assert.deepStrictEqual(arr1, expected); 541cb0ef41Sopenharmony_ci} 551cb0ef41Sopenharmony_ci 561cb0ef41Sopenharmony_ci{ 571cb0ef41Sopenharmony_ci const array = [1, 2, 3]; 581cb0ef41Sopenharmony_ci assert.strictEqual(MathMaxApply(array), 3); 591cb0ef41Sopenharmony_ci assert.strictEqual(MathMinApply(array), 1); 601cb0ef41Sopenharmony_ci} 611cb0ef41Sopenharmony_ci 621cb0ef41Sopenharmony_ci{ 631cb0ef41Sopenharmony_ci let hint; 641cb0ef41Sopenharmony_ci const obj = { [Symbol.toPrimitive](h) { 651cb0ef41Sopenharmony_ci hint = h; 661cb0ef41Sopenharmony_ci return '[object Object]'; 671cb0ef41Sopenharmony_ci } }; 681cb0ef41Sopenharmony_ci 691cb0ef41Sopenharmony_ci const args = ['foo ', obj, ' bar']; 701cb0ef41Sopenharmony_ci const result = StringPrototypeConcatApply('', args); 711cb0ef41Sopenharmony_ci 721cb0ef41Sopenharmony_ci assert.strictEqual(hint, 'string'); 731cb0ef41Sopenharmony_ci assert.strictEqual(result, 'foo [object Object] bar'); 741cb0ef41Sopenharmony_ci} 75