9.1.2.1 OrdinarySetPrototypeOf ( O, V )
当使用对象 O 和值 V 调用抽象操作 OrdinarySetPrototypeOf 时,采取以下步骤:
- 断言:Type(V) 为 Object 类型或为 null。
- 使 extensible 变为 O.[[Extensible]]。
- 使 current 变为 O.[[Prototype]]。
- 如果 SameValue(V, current) 为 true,则返回 true。
- 如果 extensible 为 false,返回 false。
- 使 p 变为 V。
- 使done 变为 false。
- 当 done 为 false 时重复,
a. 如果 p 为 null,使 done 变为 true。
b. 否则如果 SameValue(p, O) 为 true,返回 false。
c. 否则,
i. 如果 p 的 [[GetPrototypeOf]] 内部方法不是 9.1.1 中定义的普通对象内部方法,则让 done 变为 true。
ii. 否则,使 p 变为 p.[[Prototype]]。
9.设置 O.[[Prototype]] 为V。
- 返回 true。
注意:步骤 8 中的循环确保在任何原型链中不存在仅包括使用 [[GetPrototypeOf]] 和 [[SetPrototypeOf]] 的普通对象定义的对象的循环。