Merge remote-tracking branch 'origin/tracking' into custom

This commit is contained in:
roytam1 2023-05-18 09:40:23 +08:00
commit 7338649176
6 changed files with 182 additions and 22 deletions

View file

@ -1210,6 +1210,72 @@ function ArrayAt(index) {
return O[k];
}
// https://github.com/tc39/proposal-array-find-from-last
// Array.prototype.findLast ( predicate, thisArg )
function ArrayFindLast(predicate/*, thisArg*/) {
/* Steps 1. */
var O = ToObject(this);
/* Steps 2. */
var len = ToLength(O.length);
/* Step 3. */
if (arguments.length === 0) {
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, "Array.prototype.findLast");
}
if (!IsCallable(predicate)) {
ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(0, predicate));
}
var T = arguments.length > 1 ? arguments[1] : undefined;
/* Step 4-5. */
for (var k = len - 1; k >= 0; k--) {
/* Steps 5.a-b. */
var kValue = O[k];
/* Steps 5.c-d. */
if (callContentFunction(predicate, T, kValue, k, O)) {
return kValue;
}
}
/* Step 6. */
return undefined;
}
// https://github.com/tc39/proposal-array-find-from-last
// Array.prototype.findLastIndex ( predicate, thisArg )
function ArrayFindLastIndex(predicate/*, thisArg*/) {
/* Steps 1. */
var O = ToObject(this);
/* Steps 2. */
var len = ToLength(O.length);
/* Step 3. */
if (arguments.length === 0) {
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, "Array.prototype.findLastIndex");
}
if (!IsCallable(predicate)) {
ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(0, predicate));
}
var T = arguments.length > 1 ? arguments[1] : undefined;
/* Step 4-5. */
for (var k = len - 1; k >= 0; k--) {
/* Steps 5.a-b. */
var kValue = O[k];
/* Steps 5.c-d. */
if (callContentFunction(predicate, T, kValue, k, O)) {
return k;
}
}
/* Step 6. */
return -1;
}
function ArrayStaticConcat(arr, arg1) {
if (arguments.length < 1)
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, 'Array.concat');

View file

@ -1347,6 +1347,91 @@ function TypedArrayAt(index) {
return obj[k];
}
// https://github.com/tc39/proposal-array-find-from-last
// %TypedArray%.prototype.findLast ( predicate, thisArg )
function TypedArrayFindLast(predicate/*, thisArg*/) {
// Step 1.
var O = this;
// Step 2.
var isTypedArray = IsTypedArrayEnsuringArrayBuffer(O);
// If we got here, `this` is either a typed array or a wrapper for one.
// Step 3.
var len;
if (isTypedArray) {
len = TypedArrayLength(O);
} else {
len = callFunction(CallTypedArrayMethodIfWrapped, O, "TypedArrayLengthMethod");
}
// Step 4.
if (arguments.length === 0) {
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, "%TypedArray%.prototype.findLast");
}
if (!IsCallable(predicate)) {
ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(0, predicate));
}
var thisArg = arguments.length > 1 ? arguments[1] : void 0;
// Steps 5-6.
for (var k = len - 1; k >= 0; k--) {
// Steps 6.a-b.
var kValue = O[k];
// Steps 6.c-d.
if (callContentFunction(predicate, thisArg, kValue, k, O)) {
return kValue;
}
}
// Step 7.
return undefined;
}
// https://github.com/tc39/proposal-array-find-from-last
// %TypedArray%.prototype.findLastIndex ( predicate, thisArg )
function TypedArrayFindLastIndex(predicate/*, thisArg*/) {
// Step 1.
var O = this;
// Step 2.
var isTypedArray = IsTypedArrayEnsuringArrayBuffer(O);
// If we got here, `this` is either a typed array or a wrapper for one.
// Step 3.
var len;
if (isTypedArray) {
len = TypedArrayLength(O);
} else {
len = callFunction(CallTypedArrayMethodIfWrapped, O, "TypedArrayLengthMethod");
}
// Step 4.
if (arguments.length === 0) {
ThrowTypeError(JSMSG_MISSING_FUN_ARG, 0, "%TypedArray%.prototype.findLastIndex");
}
if (!IsCallable(predicate)) {
ThrowTypeError(JSMSG_NOT_FUNCTION, DecompileArg(0, predicate));
}
var thisArg = arguments.length > 1 ? arguments[1] : void 0;
// Steps 5-6.
for (var k = len - 1; k >= 0; k--) {
// Steps 6.a-f.
if (callContentFunction(predicate, thisArg, O[k], k, O)) {
return k;
}
}
// Step 7.
return -1;
}
// ES6 draft rev30 (2014/12/24) 22.2.3.30 %TypedArray%.prototype.values()
function TypedArrayValues() {
// Step 1.

View file

@ -3191,6 +3191,10 @@ static const JSFunctionSpec array_methods[] = {
/* ES2022 additions */
JS_SELF_HOSTED_FN("at", "ArrayAt", 1,0),
/* ES2023 proposals */
JS_SELF_HOSTED_FN("findLast", "ArrayFindLast", 1,0),
JS_SELF_HOSTED_FN("findLastIndex", "ArrayFindLastIndex", 1,0),
JS_FS_END
};
@ -3356,6 +3360,8 @@ array_proto_finish(JSContext* cx, JS::HandleObject ctor, JS::HandleObject proto)
!DefineProperty(cx, unscopables, cx->names().fill, value) ||
!DefineProperty(cx, unscopables, cx->names().find, value) ||
!DefineProperty(cx, unscopables, cx->names().findIndex, value) ||
!DefineProperty(cx, unscopables, cx->names().findLast, value) ||
!DefineProperty(cx, unscopables, cx->names().findLastIndex, value) ||
!DefineProperty(cx, unscopables, cx->names().flat, value) ||
!DefineProperty(cx, unscopables, cx->names().flatMap, value) ||
!DefineProperty(cx, unscopables, cx->names().includes, value) ||

View file

@ -408,12 +408,15 @@ if CONFIG['ENABLE_TRACE_LOGGING']:
'vm/TraceLoggingTypes.cpp',
]
jit_ioncheck1_deunified_sources = []
jit_ioncheck2_deunified_sources = []
jit_ioncheck3_deunified_sources = []
if not CONFIG['ENABLE_ION']:
jit_ioncheck1_deunified_sources = [
jit_ioncheck1_deunified_sources += [
'jit/none/Trampoline-none.cpp'
]
elif CONFIG['JS_CODEGEN_X86'] or CONFIG['JS_CODEGEN_X64']:
jit_ioncheck1_deunified_sources = [
jit_ioncheck1_deunified_sources += [
'jit/x86-shared/Architecture-x86-shared.cpp',
'jit/x86-shared/Assembler-x86-shared.cpp',
'jit/x86-shared/AssemblerBuffer-x86-shared.cpp',
@ -426,7 +429,7 @@ elif CONFIG['JS_CODEGEN_X86'] or CONFIG['JS_CODEGEN_X64']:
'jit/x86-shared/MoveEmitter-x86-shared.cpp',
]
if CONFIG['JS_CODEGEN_X64']:
jit_ioncheck2_deunified_sources = [
jit_ioncheck2_deunified_sources += [
'jit/x64/Assembler-x64.cpp',
'jit/x64/Bailouts-x64.cpp',
'jit/x64/BaselineCompiler-x64.cpp',
@ -438,7 +441,7 @@ elif CONFIG['JS_CODEGEN_X86'] or CONFIG['JS_CODEGEN_X64']:
'jit/x64/Trampoline-x64.cpp',
]
else:
jit_ioncheck2_deunified_sources = [
jit_ioncheck2_deunified_sources += [
'jit/x86/Assembler-x86.cpp',
'jit/x86/Bailouts-x86.cpp',
'jit/x86/BaselineCompiler-x86.cpp',
@ -450,7 +453,7 @@ elif CONFIG['JS_CODEGEN_X86'] or CONFIG['JS_CODEGEN_X64']:
'jit/x86/Trampoline-x86.cpp',
]
elif CONFIG['JS_CODEGEN_ARM']:
jit_ioncheck1_deunified_sources = [
jit_ioncheck1_deunified_sources += [
'jit/arm/Architecture-arm.cpp',
'jit/arm/Assembler-arm.cpp',
'jit/arm/Bailouts-arm.cpp',
@ -466,16 +469,16 @@ elif CONFIG['JS_CODEGEN_ARM']:
'jit/arm/Trampoline-arm.cpp',
]
if CONFIG['JS_SIMULATOR_ARM']:
jit_ioncheck2_deunified_sources = [
jit_ioncheck2_deunified_sources += [
'jit/arm/Simulator-arm.cpp'
]
elif CONFIG['OS_ARCH'] == 'Darwin':
jit_ioncheck2_deunified_sources = [
jit_ioncheck2_deunified_sources += [
'jit/arm/llvm-compiler-rt/arm/aeabi_idivmod.S',
'jit/arm/llvm-compiler-rt/arm/aeabi_uidivmod.S',
]
elif CONFIG['JS_CODEGEN_ARM64']:
jit_ioncheck1_deunified_sources = [
jit_ioncheck1_deunified_sources += [
'jit/arm64/Architecture-arm64.cpp',
'jit/arm64/Assembler-arm64.cpp',
'jit/arm64/Bailouts-arm64.cpp',
@ -498,14 +501,14 @@ elif CONFIG['JS_CODEGEN_ARM64']:
'jit/arm64/vixl/Utils-vixl.cpp'
]
if CONFIG['JS_SIMULATOR_ARM64']:
jit_ioncheck2_deunified_sources = [
jit_ioncheck2_deunified_sources += [
'jit/arm64/vixl/Debugger-vixl.cpp',
'jit/arm64/vixl/Logic-vixl.cpp',
'jit/arm64/vixl/MozSimulator-vixl.cpp',
'jit/arm64/vixl/Simulator-vixl.cpp'
]
elif CONFIG['JS_CODEGEN_MIPS32'] or CONFIG['JS_CODEGEN_MIPS64']:
jit_ioncheck1_deunified_sources = [
jit_ioncheck1_deunified_sources += [
'jit/mips-shared/Architecture-mips-shared.cpp',
'jit/mips-shared/Assembler-mips-shared.cpp',
'jit/mips-shared/Bailouts-mips-shared.cpp',
@ -517,7 +520,7 @@ elif CONFIG['JS_CODEGEN_MIPS32'] or CONFIG['JS_CODEGEN_MIPS64']:
'jit/mips-shared/MoveEmitter-mips-shared.cpp',
]
if CONFIG['JS_CODEGEN_MIPS32']:
jit_ioncheck2_deunified_sources = [
jit_ioncheck2_deunified_sources += [
'jit/mips32/Architecture-mips32.cpp',
'jit/mips32/Assembler-mips32.cpp',
'jit/mips32/Bailouts-mips32.cpp',
@ -531,11 +534,11 @@ elif CONFIG['JS_CODEGEN_MIPS32'] or CONFIG['JS_CODEGEN_MIPS64']:
'jit/mips32/Trampoline-mips32.cpp',
]
if CONFIG['JS_SIMULATOR_MIPS32']:
jit_ioncheck3_deunified_sources = [
jit_ioncheck3_deunified_sources += [
'jit/mips32/Simulator-mips32.cpp'
]
elif CONFIG['JS_CODEGEN_MIPS64']:
jit_ioncheck2_deunified_sources = [
jit_ioncheck2_deunified_sources += [
'jit/mips64/Architecture-mips64.cpp',
'jit/mips64/Assembler-mips64.cpp',
'jit/mips64/Bailouts-mips64.cpp',
@ -549,7 +552,7 @@ elif CONFIG['JS_CODEGEN_MIPS32'] or CONFIG['JS_CODEGEN_MIPS64']:
'jit/mips64/Trampoline-mips64.cpp',
]
if CONFIG['JS_SIMULATOR_MIPS64']:
jit_ioncheck3_deunified_sources = [
jit_ioncheck3_deunified_sources += [
'jit/mips64/Simulator-mips64.cpp'
]
@ -641,20 +644,16 @@ if CONFIG['JS_LTO']:
if CONFIG['JS_POSIX_NSPR']:
SOURCES += posix_nspr_deunified_sources
SOURCES += jit_ioncheck1_deunified_sources
if CONFIG['ENABLE_ION']:
SOURCES += jit_ioncheck2_deunified_sources
if CONFIG['JS_CODEGEN_MIPS32'] or CONFIG['JS_CODEGEN_MIPS64']:
SOURCES += jit_ioncheck3_deunified_sources
SOURCES += jit_ioncheck2_deunified_sources
SOURCES += jit_ioncheck3_deunified_sources
else:
FILES_PER_UNIFIED_FILE = 6
UNIFIED_SOURCES += main_deunified_sources
if CONFIG['JS_POSIX_NSPR']:
UNIFIED_SOURCES += posix_nspr_deunified_sources
UNIFIED_SOURCES += jit_ioncheck1_deunified_sources
if CONFIG['ENABLE_ION']:
UNIFIED_SOURCES += jit_ioncheck2_deunified_sources
if CONFIG['JS_CODEGEN_MIPS32'] or CONFIG['JS_CODEGEN_MIPS64']:
UNIFIED_SOURCES += jit_ioncheck3_deunified_sources
UNIFIED_SOURCES += jit_ioncheck2_deunified_sources
UNIFIED_SOURCES += jit_ioncheck3_deunified_sources
USE_LIBS += [
'nspr',

View file

@ -135,6 +135,8 @@
macro(finally, finally_, "finally") \
macro(find, find, "find") \
macro(findIndex, findIndex, "findIndex") \
macro(findLast, findLast, "findLast") \
macro(findLastIndex, findLastIndex, "findLastIndex") \
macro(firstDayOfWeek, firstDayOfWeek, "firstDayOfWeek") \
macro(fix, fix, "fix") \
macro(flags, flags, "flags") \

View file

@ -1486,6 +1486,8 @@ TypedArrayObject::protoFunctions[] = {
JS_SELF_HOSTED_FN("filter", "TypedArrayFilter", 1, 0),
JS_SELF_HOSTED_FN("find", "TypedArrayFind", 1, 0),
JS_SELF_HOSTED_FN("findIndex", "TypedArrayFindIndex", 1, 0),
JS_SELF_HOSTED_FN("findLast", "TypedArrayFindLast", 1, 0),
JS_SELF_HOSTED_FN("findLastIndex", "TypedArrayFindLastIndex", 1, 0),
JS_SELF_HOSTED_FN("forEach", "TypedArrayForEach", 1, 0),
JS_SELF_HOSTED_FN("indexOf", "TypedArrayIndexOf", 2, 0),
JS_SELF_HOSTED_FN("join", "TypedArrayJoin", 1, 0),