@solidjs/web 2.0.0-rc.20 → 2.0.0-rc.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/server.dev.js +163 -63
- package/dist/server.js +163 -63
- package/dist/server.observe.js +163 -63
- package/dist/web.dev.js +17 -24
- package/dist/web.js +17 -24
- package/dist/web.observe.js +17 -24
- package/frames/dist/server.dev.js +2 -6
- package/frames/dist/server.js +2 -6
- package/frames/dist/server.observe.js +2 -6
- package/package.json +2 -2
- package/serialization/dist/serialization.js +51 -11
- package/serialization/types/index.d.ts +35 -0
- package/serialization/types/serializer.d.ts +35 -0
- package/server-functions/dist/rich-args.js +27 -9
- package/server-functions/dist/server.dev.js +122 -36
- package/server-functions/dist/server.js +122 -36
- package/server-functions/dist/server.observe.js +122 -36
- package/types/frames/serializer.d.ts +35 -0
- package/types/serializer.d.ts +35 -0
- package/types/server-functions/client.d.ts +0 -1
- package/types/server-functions/server.d.ts +0 -1
- package/types/server-functions/uploads.d.ts +3 -0
- package/types/server-mock.d.ts +35 -8
- package/types/server.d.ts +45 -15
|
@@ -1361,7 +1361,19 @@ function createUploadDeserializer(form) {
|
|
|
1361
1361
|
if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0) refuse();
|
|
1362
1362
|
const part = form.get(UPLOAD_FILE_PART + index);
|
|
1363
1363
|
if (!isBlob(part)) refuse();
|
|
1364
|
-
return part;
|
|
1364
|
+
if (node.t === undefined) return part;
|
|
1365
|
+
const type = ctx.deserialize(node.t);
|
|
1366
|
+
if (typeof type !== "string") refuse();
|
|
1367
|
+
if (node.n === undefined) return new Blob([part], {
|
|
1368
|
+
type
|
|
1369
|
+
});
|
|
1370
|
+
const name = ctx.deserialize(node.n);
|
|
1371
|
+
const lastModified = node.l === undefined ? undefined : ctx.deserialize(node.l);
|
|
1372
|
+
if (typeof name !== "string" || typeof lastModified !== "number") refuse();
|
|
1373
|
+
return new File([part], name, {
|
|
1374
|
+
type,
|
|
1375
|
+
lastModified
|
|
1376
|
+
});
|
|
1365
1377
|
}
|
|
1366
1378
|
};
|
|
1367
1379
|
}
|
|
@@ -1459,59 +1471,124 @@ function scopeDeferredResult(value, scope) {
|
|
|
1459
1471
|
return scopeDeferredContents(value, scope);
|
|
1460
1472
|
}
|
|
1461
1473
|
class ScopeFrame {
|
|
1462
|
-
constructor(value, prototype, keys,
|
|
1474
|
+
constructor(value, prototype, keys, i, first) {
|
|
1463
1475
|
this.value = value;
|
|
1464
1476
|
this.prototype = prototype;
|
|
1465
1477
|
this.next = null;
|
|
1466
1478
|
this.keys = keys;
|
|
1467
|
-
this.
|
|
1468
|
-
this.
|
|
1479
|
+
this.i = i;
|
|
1480
|
+
this.first = first;
|
|
1481
|
+
this.descriptors = null;
|
|
1482
|
+
this.snapshotted = false;
|
|
1469
1483
|
this.changed = false;
|
|
1470
1484
|
}
|
|
1471
1485
|
}
|
|
1472
1486
|
function frameShell(frame) {
|
|
1473
|
-
return frame.next ??= frame.keys ? Object.create(frame.prototype, frame.descriptors) : frame.value.slice();
|
|
1487
|
+
return frame.next ??= frame.keys ? Object.create(frame.prototype, frame.descriptors ?? Object.getOwnPropertyDescriptors(frame.value)) : frame.value.slice();
|
|
1488
|
+
}
|
|
1489
|
+
function writableValue(descriptor) {
|
|
1490
|
+
return descriptor !== undefined && "value" in descriptor && descriptor.writable === true ? descriptor.value : undefined;
|
|
1491
|
+
}
|
|
1492
|
+
function carrierSlot(frame, key) {
|
|
1493
|
+
return writableValue(frame.descriptors ? frame.descriptors[key] : Object.getOwnPropertyDescriptor(frame.value, key));
|
|
1494
|
+
}
|
|
1495
|
+
function snapshotFrames(stack) {
|
|
1496
|
+
for (let k = stack.length - 1; k >= 0 && !stack[k].snapshotted; k--) {
|
|
1497
|
+
const frame = stack[k];
|
|
1498
|
+
frame.snapshotted = true;
|
|
1499
|
+
if (frame.keys) frame.descriptors = Object.getOwnPropertyDescriptors(frame.value);
|
|
1500
|
+
}
|
|
1501
|
+
}
|
|
1502
|
+
function isLeaf(value) {
|
|
1503
|
+
return value === null || typeof value !== "object" && typeof value !== "function";
|
|
1504
|
+
}
|
|
1505
|
+
function sharedPrototypesInert() {
|
|
1506
|
+
const {
|
|
1507
|
+
toStringTag,
|
|
1508
|
+
asyncIterator,
|
|
1509
|
+
iterator,
|
|
1510
|
+
hasInstance
|
|
1511
|
+
} = Symbol;
|
|
1512
|
+
return !(Object.hasOwn(Promise, hasInstance) || typeof ReadableStream !== "undefined" && Object.hasOwn(ReadableStream, hasInstance) || Object.hasOwn(Object.prototype, toStringTag) || Object.hasOwn(Object.prototype, asyncIterator) || Object.hasOwn(Object.prototype, iterator) || Object.hasOwn(Array.prototype, toStringTag) || Object.hasOwn(Array.prototype, asyncIterator));
|
|
1513
|
+
}
|
|
1514
|
+
function isInertCarrier(value, prototype, isArray) {
|
|
1515
|
+
const {
|
|
1516
|
+
toStringTag,
|
|
1517
|
+
asyncIterator,
|
|
1518
|
+
iterator
|
|
1519
|
+
} = Symbol;
|
|
1520
|
+
return (isArray ? prototype === Array.prototype : prototype === Object.prototype || prototype === null) && !Object.hasOwn(value, toStringTag) && !Object.hasOwn(value, asyncIterator) && (isArray || !Object.hasOwn(value, iterator)) && typeof value[asyncIterator] !== "function" && (isArray || typeof value[iterator] !== "function");
|
|
1474
1521
|
}
|
|
1475
1522
|
function enterScopeCarrier(value, state) {
|
|
1476
|
-
if (value
|
|
1477
|
-
|
|
1523
|
+
if (isLeaf(value)) return value;
|
|
1524
|
+
const seen = state.seen.get(value);
|
|
1525
|
+
if (seen !== undefined) {
|
|
1478
1526
|
state.cyclic.add(value);
|
|
1479
|
-
const seen = state.seen.get(value);
|
|
1480
1527
|
return seen instanceof ScopeFrame ? frameShell(seen) : seen;
|
|
1481
1528
|
}
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1529
|
+
let isArray = false;
|
|
1530
|
+
let prototype;
|
|
1531
|
+
if (typeof value === "object") {
|
|
1532
|
+
isArray = Array.isArray(value);
|
|
1533
|
+
prototype = Object.getPrototypeOf(value);
|
|
1486
1534
|
}
|
|
1487
|
-
if (
|
|
1488
|
-
|
|
1535
|
+
if (!state.inert || prototype === undefined || !isInertCarrier(value, prototype, isArray)) {
|
|
1536
|
+
snapshotFrames(state.stack);
|
|
1537
|
+
const bound = bindDeferredBody(value, state.scope);
|
|
1538
|
+
if (bound !== value) {
|
|
1539
|
+
state.seen.set(value, bound);
|
|
1540
|
+
return bound;
|
|
1541
|
+
}
|
|
1542
|
+
if (typeof value !== "object") return value;
|
|
1543
|
+
}
|
|
1544
|
+
if (isArray) {
|
|
1489
1545
|
if (Object.isFrozen(value)) {
|
|
1490
1546
|
state.seen.set(value, value);
|
|
1491
1547
|
return value;
|
|
1492
1548
|
}
|
|
1493
|
-
|
|
1549
|
+
let i = 0;
|
|
1550
|
+
let first;
|
|
1551
|
+
while (i < value.length && isLeaf(first = value[i])) i++;
|
|
1552
|
+
if (i === value.length) {
|
|
1553
|
+
state.seen.set(value, value);
|
|
1554
|
+
return value;
|
|
1555
|
+
}
|
|
1556
|
+
const frame = new ScopeFrame(value, null, null, i, first);
|
|
1494
1557
|
state.seen.set(value, frame);
|
|
1495
1558
|
return frame;
|
|
1496
1559
|
}
|
|
1497
|
-
|
|
1498
|
-
|
|
1560
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
1561
|
+
state.seen.set(value, value);
|
|
1562
|
+
return value;
|
|
1563
|
+
}
|
|
1564
|
+
const keys = Object.keys(value);
|
|
1565
|
+
let i = 0;
|
|
1566
|
+
let first;
|
|
1567
|
+
while (i < keys.length && isLeaf(first = writableValue(Object.getOwnPropertyDescriptor(value, keys[i])))) i++;
|
|
1568
|
+
if (i === keys.length) {
|
|
1569
|
+
state.seen.set(value, value);
|
|
1570
|
+
return value;
|
|
1571
|
+
}
|
|
1572
|
+
if (Object.isFrozen(value)) {
|
|
1499
1573
|
state.seen.set(value, value);
|
|
1500
1574
|
return value;
|
|
1501
1575
|
}
|
|
1502
|
-
const frame = new ScopeFrame(value, prototype,
|
|
1576
|
+
const frame = new ScopeFrame(value, prototype, keys, i, first);
|
|
1503
1577
|
state.seen.set(value, frame);
|
|
1504
1578
|
return frame;
|
|
1505
1579
|
}
|
|
1506
1580
|
function scopeDeferredContents(root, scope) {
|
|
1581
|
+
const stack = [];
|
|
1507
1582
|
const state = {
|
|
1508
1583
|
seen: new Map(),
|
|
1509
1584
|
cyclic: new Set(),
|
|
1510
|
-
scope
|
|
1585
|
+
scope,
|
|
1586
|
+
inert: sharedPrototypesInert(),
|
|
1587
|
+
stack
|
|
1511
1588
|
};
|
|
1512
1589
|
const entered = enterScopeCarrier(root, state);
|
|
1513
1590
|
if (!(entered instanceof ScopeFrame)) return entered;
|
|
1514
|
-
|
|
1591
|
+
stack.push(entered);
|
|
1515
1592
|
let delivered = NOTHING;
|
|
1516
1593
|
for (;;) {
|
|
1517
1594
|
const top = stack[stack.length - 1];
|
|
@@ -1520,17 +1597,11 @@ function scopeDeferredContents(root, scope) {
|
|
|
1520
1597
|
while (top.i < length) {
|
|
1521
1598
|
const i = top.i;
|
|
1522
1599
|
let original;
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
writable = "value" in descriptor && descriptor.writable === true;
|
|
1527
|
-
original = writable ? descriptor.value : undefined;
|
|
1600
|
+
if (top.first !== NOTHING) {
|
|
1601
|
+
original = top.first;
|
|
1602
|
+
top.first = NOTHING;
|
|
1528
1603
|
} else {
|
|
1529
|
-
original = top.value[i];
|
|
1530
|
-
}
|
|
1531
|
-
if (!writable) {
|
|
1532
|
-
top.i++;
|
|
1533
|
-
continue;
|
|
1604
|
+
original = top.keys ? carrierSlot(top, top.keys[i]) : top.value[i];
|
|
1534
1605
|
}
|
|
1535
1606
|
let bound;
|
|
1536
1607
|
if (delivered !== NOTHING) {
|
|
@@ -1567,7 +1638,7 @@ function scopeDeferredContents(root, scope) {
|
|
|
1567
1638
|
}
|
|
1568
1639
|
}
|
|
1569
1640
|
function bindDeferredBody(value, scope) {
|
|
1570
|
-
if (value
|
|
1641
|
+
if (isLeaf(value)) return value;
|
|
1571
1642
|
const promised = scope(() => nativePromise(value));
|
|
1572
1643
|
if (promised) {
|
|
1573
1644
|
return promised.then(result => scope(() => scopeDeferredResult(result, scope)));
|
|
@@ -1836,8 +1907,8 @@ function broadcast(fn) {
|
|
|
1836
1907
|
BROADCASTS.add(fn.id);
|
|
1837
1908
|
return ref;
|
|
1838
1909
|
}
|
|
1839
|
-
function encodedArguments(request, argsEncoding, argumentBytes) {
|
|
1840
|
-
if (request.method !== "POST") return argsEncoding ||
|
|
1910
|
+
function encodedArguments(request, url, argsEncoding, argumentBytes) {
|
|
1911
|
+
if (request.method !== "POST") return argsEncoding || url.search;
|
|
1841
1912
|
if (!argumentBytes) return undefined;
|
|
1842
1913
|
return (request.headers.get("content-type") || "") + "\0" + (argsEncoding || "") + "\0" + new TextDecoder("latin1").decode(argumentBytes);
|
|
1843
1914
|
}
|
|
@@ -3368,7 +3439,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
3368
3439
|
id: functionId,
|
|
3369
3440
|
live: !!live,
|
|
3370
3441
|
broadcast: shared || undefined,
|
|
3371
|
-
shareKey: shared ? encodedArguments(request, argsEncoding, argumentBytes) : undefined
|
|
3442
|
+
shareKey: shared ? encodedArguments(request, url, argsEncoding, argumentBytes) : undefined
|
|
3372
3443
|
});
|
|
3373
3444
|
const run = () => serverFunction(...parsed);
|
|
3374
3445
|
return observeInvocation({
|
|
@@ -3438,7 +3509,8 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
3438
3509
|
}
|
|
3439
3510
|
if (!scripted) {
|
|
3440
3511
|
if (handleNoJS) {
|
|
3441
|
-
|
|
3512
|
+
const outcome = result == null && metadata !== undefined ? metadata : result;
|
|
3513
|
+
return withEnvelopeCookies(await handleNoJS(outcome, request, parsed), outcome, metadata);
|
|
3442
3514
|
}
|
|
3443
3515
|
if (result instanceof Response) return result;
|
|
3444
3516
|
return encodeResult(result, headers, status, codec, request.signal, scope);
|
|
@@ -3521,7 +3593,10 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
3521
3593
|
}
|
|
3522
3594
|
headers.set(ERROR_HEADER, "true");
|
|
3523
3595
|
if (!scripted) {
|
|
3524
|
-
if (handleNoJS)
|
|
3596
|
+
if (handleNoJS) {
|
|
3597
|
+
const outcome = x ?? metadata;
|
|
3598
|
+
return withEnvelopeCookies(await handleNoJS(outcome, request, parsed, true), outcome, metadata);
|
|
3599
|
+
}
|
|
3525
3600
|
if (x instanceof Response) return x;
|
|
3526
3601
|
}
|
|
3527
3602
|
if (scripted && status === 304) warnScripted304(functionId);
|
|
@@ -3578,6 +3653,17 @@ function withholdTrace(event) {
|
|
|
3578
3653
|
if (event.response && event.response.committed) return;
|
|
3579
3654
|
traceForEvent(event).emit = false;
|
|
3580
3655
|
}
|
|
3656
|
+
function withEnvelopeCookies(response, outcome, metadata) {
|
|
3657
|
+
if (outcome === metadata || !metadata || !metadata.headers || !(response instanceof Response)) {
|
|
3658
|
+
return response;
|
|
3659
|
+
}
|
|
3660
|
+
const cookies = metadata.headers.getSetCookie ? metadata.headers.getSetCookie() : [];
|
|
3661
|
+
if (!cookies.length) return response;
|
|
3662
|
+
const owned = ownResponse(response);
|
|
3663
|
+
if (owned === response) return response;
|
|
3664
|
+
for (const cookie of cookies) owned.headers.append("Set-Cookie", cookie);
|
|
3665
|
+
return owned;
|
|
3666
|
+
}
|
|
3581
3667
|
function ownResponse(response) {
|
|
3582
3668
|
try {
|
|
3583
3669
|
return new Response(response.body, response);
|
|
@@ -1279,7 +1279,19 @@ function createUploadDeserializer(form) {
|
|
|
1279
1279
|
if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0) refuse();
|
|
1280
1280
|
const part = form.get(UPLOAD_FILE_PART + index);
|
|
1281
1281
|
if (!isBlob(part)) refuse();
|
|
1282
|
-
return part;
|
|
1282
|
+
if (node.t === undefined) return part;
|
|
1283
|
+
const type = ctx.deserialize(node.t);
|
|
1284
|
+
if (typeof type !== "string") refuse();
|
|
1285
|
+
if (node.n === undefined) return new Blob([part], {
|
|
1286
|
+
type
|
|
1287
|
+
});
|
|
1288
|
+
const name = ctx.deserialize(node.n);
|
|
1289
|
+
const lastModified = node.l === undefined ? undefined : ctx.deserialize(node.l);
|
|
1290
|
+
if (typeof name !== "string" || typeof lastModified !== "number") refuse();
|
|
1291
|
+
return new File([part], name, {
|
|
1292
|
+
type,
|
|
1293
|
+
lastModified
|
|
1294
|
+
});
|
|
1283
1295
|
}
|
|
1284
1296
|
};
|
|
1285
1297
|
}
|
|
@@ -1377,59 +1389,124 @@ function scopeDeferredResult(value, scope) {
|
|
|
1377
1389
|
return scopeDeferredContents(value, scope);
|
|
1378
1390
|
}
|
|
1379
1391
|
class ScopeFrame {
|
|
1380
|
-
constructor(value, prototype, keys,
|
|
1392
|
+
constructor(value, prototype, keys, i, first) {
|
|
1381
1393
|
this.value = value;
|
|
1382
1394
|
this.prototype = prototype;
|
|
1383
1395
|
this.next = null;
|
|
1384
1396
|
this.keys = keys;
|
|
1385
|
-
this.
|
|
1386
|
-
this.
|
|
1397
|
+
this.i = i;
|
|
1398
|
+
this.first = first;
|
|
1399
|
+
this.descriptors = null;
|
|
1400
|
+
this.snapshotted = false;
|
|
1387
1401
|
this.changed = false;
|
|
1388
1402
|
}
|
|
1389
1403
|
}
|
|
1390
1404
|
function frameShell(frame) {
|
|
1391
|
-
return frame.next ??= frame.keys ? Object.create(frame.prototype, frame.descriptors) : frame.value.slice();
|
|
1405
|
+
return frame.next ??= frame.keys ? Object.create(frame.prototype, frame.descriptors ?? Object.getOwnPropertyDescriptors(frame.value)) : frame.value.slice();
|
|
1406
|
+
}
|
|
1407
|
+
function writableValue(descriptor) {
|
|
1408
|
+
return descriptor !== undefined && "value" in descriptor && descriptor.writable === true ? descriptor.value : undefined;
|
|
1409
|
+
}
|
|
1410
|
+
function carrierSlot(frame, key) {
|
|
1411
|
+
return writableValue(frame.descriptors ? frame.descriptors[key] : Object.getOwnPropertyDescriptor(frame.value, key));
|
|
1412
|
+
}
|
|
1413
|
+
function snapshotFrames(stack) {
|
|
1414
|
+
for (let k = stack.length - 1; k >= 0 && !stack[k].snapshotted; k--) {
|
|
1415
|
+
const frame = stack[k];
|
|
1416
|
+
frame.snapshotted = true;
|
|
1417
|
+
if (frame.keys) frame.descriptors = Object.getOwnPropertyDescriptors(frame.value);
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
function isLeaf(value) {
|
|
1421
|
+
return value === null || typeof value !== "object" && typeof value !== "function";
|
|
1422
|
+
}
|
|
1423
|
+
function sharedPrototypesInert() {
|
|
1424
|
+
const {
|
|
1425
|
+
toStringTag,
|
|
1426
|
+
asyncIterator,
|
|
1427
|
+
iterator,
|
|
1428
|
+
hasInstance
|
|
1429
|
+
} = Symbol;
|
|
1430
|
+
return !(Object.hasOwn(Promise, hasInstance) || typeof ReadableStream !== "undefined" && Object.hasOwn(ReadableStream, hasInstance) || Object.hasOwn(Object.prototype, toStringTag) || Object.hasOwn(Object.prototype, asyncIterator) || Object.hasOwn(Object.prototype, iterator) || Object.hasOwn(Array.prototype, toStringTag) || Object.hasOwn(Array.prototype, asyncIterator));
|
|
1431
|
+
}
|
|
1432
|
+
function isInertCarrier(value, prototype, isArray) {
|
|
1433
|
+
const {
|
|
1434
|
+
toStringTag,
|
|
1435
|
+
asyncIterator,
|
|
1436
|
+
iterator
|
|
1437
|
+
} = Symbol;
|
|
1438
|
+
return (isArray ? prototype === Array.prototype : prototype === Object.prototype || prototype === null) && !Object.hasOwn(value, toStringTag) && !Object.hasOwn(value, asyncIterator) && (isArray || !Object.hasOwn(value, iterator)) && typeof value[asyncIterator] !== "function" && (isArray || typeof value[iterator] !== "function");
|
|
1392
1439
|
}
|
|
1393
1440
|
function enterScopeCarrier(value, state) {
|
|
1394
|
-
if (value
|
|
1395
|
-
|
|
1441
|
+
if (isLeaf(value)) return value;
|
|
1442
|
+
const seen = state.seen.get(value);
|
|
1443
|
+
if (seen !== undefined) {
|
|
1396
1444
|
state.cyclic.add(value);
|
|
1397
|
-
const seen = state.seen.get(value);
|
|
1398
1445
|
return seen instanceof ScopeFrame ? frameShell(seen) : seen;
|
|
1399
1446
|
}
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1447
|
+
let isArray = false;
|
|
1448
|
+
let prototype;
|
|
1449
|
+
if (typeof value === "object") {
|
|
1450
|
+
isArray = Array.isArray(value);
|
|
1451
|
+
prototype = Object.getPrototypeOf(value);
|
|
1404
1452
|
}
|
|
1405
|
-
if (
|
|
1406
|
-
|
|
1453
|
+
if (!state.inert || prototype === undefined || !isInertCarrier(value, prototype, isArray)) {
|
|
1454
|
+
snapshotFrames(state.stack);
|
|
1455
|
+
const bound = bindDeferredBody(value, state.scope);
|
|
1456
|
+
if (bound !== value) {
|
|
1457
|
+
state.seen.set(value, bound);
|
|
1458
|
+
return bound;
|
|
1459
|
+
}
|
|
1460
|
+
if (typeof value !== "object") return value;
|
|
1461
|
+
}
|
|
1462
|
+
if (isArray) {
|
|
1407
1463
|
if (Object.isFrozen(value)) {
|
|
1408
1464
|
state.seen.set(value, value);
|
|
1409
1465
|
return value;
|
|
1410
1466
|
}
|
|
1411
|
-
|
|
1467
|
+
let i = 0;
|
|
1468
|
+
let first;
|
|
1469
|
+
while (i < value.length && isLeaf(first = value[i])) i++;
|
|
1470
|
+
if (i === value.length) {
|
|
1471
|
+
state.seen.set(value, value);
|
|
1472
|
+
return value;
|
|
1473
|
+
}
|
|
1474
|
+
const frame = new ScopeFrame(value, null, null, i, first);
|
|
1412
1475
|
state.seen.set(value, frame);
|
|
1413
1476
|
return frame;
|
|
1414
1477
|
}
|
|
1415
|
-
|
|
1416
|
-
|
|
1478
|
+
if (prototype !== Object.prototype && prototype !== null) {
|
|
1479
|
+
state.seen.set(value, value);
|
|
1480
|
+
return value;
|
|
1481
|
+
}
|
|
1482
|
+
const keys = Object.keys(value);
|
|
1483
|
+
let i = 0;
|
|
1484
|
+
let first;
|
|
1485
|
+
while (i < keys.length && isLeaf(first = writableValue(Object.getOwnPropertyDescriptor(value, keys[i])))) i++;
|
|
1486
|
+
if (i === keys.length) {
|
|
1487
|
+
state.seen.set(value, value);
|
|
1488
|
+
return value;
|
|
1489
|
+
}
|
|
1490
|
+
if (Object.isFrozen(value)) {
|
|
1417
1491
|
state.seen.set(value, value);
|
|
1418
1492
|
return value;
|
|
1419
1493
|
}
|
|
1420
|
-
const frame = new ScopeFrame(value, prototype,
|
|
1494
|
+
const frame = new ScopeFrame(value, prototype, keys, i, first);
|
|
1421
1495
|
state.seen.set(value, frame);
|
|
1422
1496
|
return frame;
|
|
1423
1497
|
}
|
|
1424
1498
|
function scopeDeferredContents(root, scope) {
|
|
1499
|
+
const stack = [];
|
|
1425
1500
|
const state = {
|
|
1426
1501
|
seen: new Map(),
|
|
1427
1502
|
cyclic: new Set(),
|
|
1428
|
-
scope
|
|
1503
|
+
scope,
|
|
1504
|
+
inert: sharedPrototypesInert(),
|
|
1505
|
+
stack
|
|
1429
1506
|
};
|
|
1430
1507
|
const entered = enterScopeCarrier(root, state);
|
|
1431
1508
|
if (!(entered instanceof ScopeFrame)) return entered;
|
|
1432
|
-
|
|
1509
|
+
stack.push(entered);
|
|
1433
1510
|
let delivered = NOTHING;
|
|
1434
1511
|
for (;;) {
|
|
1435
1512
|
const top = stack[stack.length - 1];
|
|
@@ -1438,17 +1515,11 @@ function scopeDeferredContents(root, scope) {
|
|
|
1438
1515
|
while (top.i < length) {
|
|
1439
1516
|
const i = top.i;
|
|
1440
1517
|
let original;
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
writable = "value" in descriptor && descriptor.writable === true;
|
|
1445
|
-
original = writable ? descriptor.value : undefined;
|
|
1518
|
+
if (top.first !== NOTHING) {
|
|
1519
|
+
original = top.first;
|
|
1520
|
+
top.first = NOTHING;
|
|
1446
1521
|
} else {
|
|
1447
|
-
original = top.value[i];
|
|
1448
|
-
}
|
|
1449
|
-
if (!writable) {
|
|
1450
|
-
top.i++;
|
|
1451
|
-
continue;
|
|
1522
|
+
original = top.keys ? carrierSlot(top, top.keys[i]) : top.value[i];
|
|
1452
1523
|
}
|
|
1453
1524
|
let bound;
|
|
1454
1525
|
if (delivered !== NOTHING) {
|
|
@@ -1485,7 +1556,7 @@ function scopeDeferredContents(root, scope) {
|
|
|
1485
1556
|
}
|
|
1486
1557
|
}
|
|
1487
1558
|
function bindDeferredBody(value, scope) {
|
|
1488
|
-
if (value
|
|
1559
|
+
if (isLeaf(value)) return value;
|
|
1489
1560
|
const promised = scope(() => nativePromise(value));
|
|
1490
1561
|
if (promised) {
|
|
1491
1562
|
return promised.then(result => scope(() => scopeDeferredResult(result, scope)));
|
|
@@ -1754,8 +1825,8 @@ function broadcast(fn) {
|
|
|
1754
1825
|
BROADCASTS.add(fn.id);
|
|
1755
1826
|
return ref;
|
|
1756
1827
|
}
|
|
1757
|
-
function encodedArguments(request, argsEncoding, argumentBytes) {
|
|
1758
|
-
if (request.method !== "POST") return argsEncoding ||
|
|
1828
|
+
function encodedArguments(request, url, argsEncoding, argumentBytes) {
|
|
1829
|
+
if (request.method !== "POST") return argsEncoding || url.search;
|
|
1759
1830
|
if (!argumentBytes) return undefined;
|
|
1760
1831
|
return (request.headers.get("content-type") || "") + "\0" + (argsEncoding || "") + "\0" + new TextDecoder("latin1").decode(argumentBytes);
|
|
1761
1832
|
}
|
|
@@ -3275,7 +3346,7 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
3275
3346
|
id: functionId,
|
|
3276
3347
|
live: !!live,
|
|
3277
3348
|
broadcast: shared || undefined,
|
|
3278
|
-
shareKey: shared ? encodedArguments(request, argsEncoding, argumentBytes) : undefined
|
|
3349
|
+
shareKey: shared ? encodedArguments(request, url, argsEncoding, argumentBytes) : undefined
|
|
3279
3350
|
});
|
|
3280
3351
|
const run = () => serverFunction(...parsed);
|
|
3281
3352
|
return observeInvocation({
|
|
@@ -3345,7 +3416,8 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
3345
3416
|
}
|
|
3346
3417
|
if (!scripted) {
|
|
3347
3418
|
if (handleNoJS) {
|
|
3348
|
-
|
|
3419
|
+
const outcome = result == null && metadata !== undefined ? metadata : result;
|
|
3420
|
+
return withEnvelopeCookies(await handleNoJS(outcome, request, parsed), outcome, metadata);
|
|
3349
3421
|
}
|
|
3350
3422
|
if (result instanceof Response) return result;
|
|
3351
3423
|
return encodeResult(result, headers, status, codec, request.signal, scope);
|
|
@@ -3428,7 +3500,10 @@ async function handleServerFunctionRequest(request, options = {}) {
|
|
|
3428
3500
|
}
|
|
3429
3501
|
headers.set(ERROR_HEADER, "true");
|
|
3430
3502
|
if (!scripted) {
|
|
3431
|
-
if (handleNoJS)
|
|
3503
|
+
if (handleNoJS) {
|
|
3504
|
+
const outcome = x ?? metadata;
|
|
3505
|
+
return withEnvelopeCookies(await handleNoJS(outcome, request, parsed, true), outcome, metadata);
|
|
3506
|
+
}
|
|
3432
3507
|
if (x instanceof Response) return x;
|
|
3433
3508
|
}
|
|
3434
3509
|
if (scripted && status === 304) warnScripted304(functionId);
|
|
@@ -3485,6 +3560,17 @@ function withholdTrace(event) {
|
|
|
3485
3560
|
if (event.response && event.response.committed) return;
|
|
3486
3561
|
traceForEvent(event).emit = false;
|
|
3487
3562
|
}
|
|
3563
|
+
function withEnvelopeCookies(response, outcome, metadata) {
|
|
3564
|
+
if (outcome === metadata || !metadata || !metadata.headers || !(response instanceof Response)) {
|
|
3565
|
+
return response;
|
|
3566
|
+
}
|
|
3567
|
+
const cookies = metadata.headers.getSetCookie ? metadata.headers.getSetCookie() : [];
|
|
3568
|
+
if (!cookies.length) return response;
|
|
3569
|
+
const owned = ownResponse(response);
|
|
3570
|
+
if (owned === response) return response;
|
|
3571
|
+
for (const cookie of cookies) owned.headers.append("Set-Cookie", cookie);
|
|
3572
|
+
return owned;
|
|
3573
|
+
}
|
|
3488
3574
|
function ownResponse(response) {
|
|
3489
3575
|
try {
|
|
3490
3576
|
return new Response(response.body, response);
|