9.1.2.1 OrdinarySetPrototypeOf ( O, V )

当使用对象 O 和值 V 调用抽象操作 OrdinarySetPrototypeOf 时,采取以下步骤:

  1. 断言:Type(V) 为 Object 类型或为 null
  2. 使 extensible 变为 O.[[Extensible]]。
  3. 使 current 变为 O.[[Prototype]]。
  4. 如果 SameValue(V, current) 为 true,则返回 true
  5. 如果 extensible false,返回 false
  6. 使 p 变为 V
  7. 使done 变为 false
  8. 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

  1. 返回 true

注意:步骤 8 中的循环确保在任何原型链中不存在仅包括使用 [[GetPrototypeOf]] 和 [[SetPrototypeOf]] 的普通对象定义的对象的循环。

results matching ""

    No results matching ""