js-on-sx: Array.prototype includes/find/some/every/reverse + Object fallbacks
Array: includes, find, findIndex, some, every, reverse via
tail-recursive helpers.
Object: hasOwnProperty, isPrototypeOf, propertyIsEnumerable,
toString, valueOf, toLocaleString fallback in js-invoke-method
when js-get-prop returns undefined. Lets o.hasOwnProperty('k')
work on plain dicts.
376/378 unit (+13), 148/148 slice unchanged.
This commit is contained in:
@@ -951,6 +951,36 @@ cat > "$TMPFILE" << 'EPOCHS'
|
||||
(epoch 1605)
|
||||
(eval "(js-eval \"var r=0; switch(1){case 1: r=10; case 2: r=20; break;} r\")")
|
||||
|
||||
;; ── Phase 11.array: more Array.prototype ────────────────────────
|
||||
(epoch 1700)
|
||||
(eval "(js-eval \"[1,2,3].includes(2)\")")
|
||||
(epoch 1701)
|
||||
(eval "(js-eval \"[1,2,3].includes(5)\")")
|
||||
(epoch 1702)
|
||||
(eval "(js-eval \"[1,2,3].find((x)=>x>1)\")")
|
||||
(epoch 1703)
|
||||
(eval "(js-eval \"[1,2,3].findIndex((x)=>x>1)\")")
|
||||
(epoch 1704)
|
||||
(eval "(js-eval \"[1,2,3].some((x)=>x>2)\")")
|
||||
(epoch 1705)
|
||||
(eval "(js-eval \"[1,2,3].some((x)=>x>5)\")")
|
||||
(epoch 1706)
|
||||
(eval "(js-eval \"[1,2,3].every((x)=>x>0)\")")
|
||||
(epoch 1707)
|
||||
(eval "(js-eval \"[1,2,3].every((x)=>x>2)\")")
|
||||
(epoch 1708)
|
||||
(eval "(js-eval \"[1,2,3].reverse().join(',')\")")
|
||||
|
||||
;; ── Phase 11.objmethod: hasOwnProperty + toString ───────────────
|
||||
(epoch 1800)
|
||||
(eval "(js-eval \"var o = {x:1}; o.hasOwnProperty('x')\")")
|
||||
(epoch 1801)
|
||||
(eval "(js-eval \"var o = {x:1}; o.hasOwnProperty('y')\")")
|
||||
(epoch 1802)
|
||||
(eval "(js-eval \"({}).toString()\")")
|
||||
(epoch 1803)
|
||||
(eval "(js-eval \"({x:1}).valueOf().x\")")
|
||||
|
||||
EPOCHS
|
||||
|
||||
OUTPUT=$(timeout 180 "$SX_SERVER" < "$TMPFILE" 2>/dev/null)
|
||||
@@ -1458,6 +1488,23 @@ check 1603 "switch fallthrough stops on break" '12'
|
||||
check 1604 "switch on string" '"yes"'
|
||||
check 1605 "switch fallthrough chains" '20'
|
||||
|
||||
# ── Phase 11.array: more Array.prototype ────────────────────────
|
||||
check 1700 "Array.includes yes" 'true'
|
||||
check 1701 "Array.includes no" 'false'
|
||||
check 1702 "Array.find" '2'
|
||||
check 1703 "Array.findIndex" '1'
|
||||
check 1704 "Array.some yes" 'true'
|
||||
check 1705 "Array.some no" 'false'
|
||||
check 1706 "Array.every yes" 'true'
|
||||
check 1707 "Array.every no" 'false'
|
||||
check 1708 "Array.reverse" '"3,2,1"'
|
||||
|
||||
# ── Phase 11.objmethod: hasOwnProperty ──────────────────────────
|
||||
check 1800 "hasOwnProperty yes" 'true'
|
||||
check 1801 "hasOwnProperty no" 'false'
|
||||
check 1802 "({}).toString()" '"[object Object]"'
|
||||
check 1803 "obj.valueOf().x" '1'
|
||||
|
||||
TOTAL=$((PASS + FAIL))
|
||||
if [ $FAIL -eq 0 ]; then
|
||||
echo "✓ $PASS/$TOTAL JS-on-SX tests passed"
|
||||
|
||||
Reference in New Issue
Block a user