Share detached JSON provenance with copy checkpoints and finish step-four verification
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import {hasOwnedElementData} from '../canvas-core/element-data.ts';
|
||||
import type {ElementRecord} from '../canvas-core/types.ts';
|
||||
import {hasDetachedJsonData} from '../canvas-core/json-data.ts';
|
||||
import type { Json } from '../canvas-core/types.ts';
|
||||
import { fault, freeze, validJson } from '../canvas-core/values.ts';
|
||||
import {isDataContainer} from '../canvas-core/data-containers.ts';
|
||||
@@ -77,14 +76,14 @@ type Scalar = null|string|number|boolean|undefined|symbol;
|
||||
type Prepared = Scalar | Encoded | {source:object;depth:number;children?:Prepared[];keys?:string[]};
|
||||
// Read unknown objects synchronously, before the first suspension. Shape-owned
|
||||
// containers can include external values; each such occurrence is captured now.
|
||||
// Detached element JSON can also defer after checking its prototype environment.
|
||||
// Detached JSON can also defer after checking its prototype environment.
|
||||
function prepareEncoding(input:unknown) {
|
||||
const normalize=createEncoder(),visiting=new Set<object>();
|
||||
let plainEnvironment:boolean|undefined;
|
||||
const capture=(value:unknown,depth:number,key:string)=>{
|
||||
try{return normalize(value,depth,key);}finally{plainEnvironment=undefined;}
|
||||
};
|
||||
const detached=(value:object)=>hasOwnedElementData(value as ElementRecord)&&(plainEnvironment??=(
|
||||
const detached=(value:object)=>hasDetachedJsonData(value)&&(plainEnvironment??=(
|
||||
Object.getPrototypeOf(Object.prototype)===null&&Object.getPrototypeOf(Array.prototype)===Object.prototype&&
|
||||
!Object.getOwnPropertyDescriptor(Object.prototype,'toJSON')&&!Object.getOwnPropertyDescriptor(Array.prototype,'toJSON')
|
||||
));
|
||||
@@ -99,7 +98,7 @@ function prepareEncoding(input:unknown) {
|
||||
if(typeof value!=='object')return capture(value,depth,key);
|
||||
const cached=immutable.get(value);
|
||||
if(cached){if(depth+cached.height>64)throw fault('invalid_recovery_payload');return cached;}
|
||||
// Detached element JSON has no accessors, custom prototypes or mutable
|
||||
// Detached JSON has no accessors, custom prototypes or mutable
|
||||
// descendants. Its full walk can wait; foreign freezes cannot grant this.
|
||||
if(detached(value))return {source:value,depth};
|
||||
if(!isDataContainer(value))return capture(value,depth,key);
|
||||
|
||||
Reference in New Issue
Block a user