Skip to content

Instantly share code, notes, and snippets.

@anba
Last active August 29, 2015 13:56
__define[GS]etter__ and __lookup[GS]etter__ specifications

Specifications for __define[GS]etter__ and __lookup[GS]etter__

SpiderMonkey: js/src/builtin/Object.cpp

Object.prototype.__defineGetter__(P, Getter)

  1. Let thisArgument be the this value.
  2. If thisArgument is null or undefined, then
    1. Let realm be the Realm of the running execution context.
    2. Set O to realm.[[globalThis]].
  3. Else let O be ToObject(thisArgument).
  4. If IsCallable(Getter) is false, then throw a TypeError exception.
  5. Let key be ToPropertyKey(P).
  6. ReturnIfAbrupt(key).
  7. Let Attributes be the result of calling ObjectCreate(%ObjectPrototype%).
  8. Call CreateDataProperty(Attributes, "enumerable", true).
  9. Call CreateDataProperty(Attributes, "configurable", true).
  10. Call CreateDataProperty(Attributes, "get", Getter).
  11. Let desc be the result of calling ToPropertyDescriptor(Attributes).
  12. ReturnIfAbrupt(desc).
  13. Let success be the result of DefinePropertyOrThrow(O, key, desc).
  14. ReturnIfAbrupt(success).
  15. Return undefined.

Object.prototype.__defineSetter__(P, Setter)

  1. Let thisArgument be the this value.
  2. If thisArgument is null or undefined, then
    1. Let realm be the Realm of the running execution context.
    2. Set O to realm.[[globalThis]].
  3. Else let O be ToObject(thisArgument).
  4. If IsCallable(Setter) is false, then throw a TypeError exception.
  5. Let key be ToPropertyKey(P).
  6. ReturnIfAbrupt(key).
  7. Let Attributes be the result of calling ObjectCreate(%ObjectPrototype%).
  8. Call CreateDataProperty(Attributes, "enumerable", true).
  9. Call CreateDataProperty(Attributes, "configurable", true).
  10. Call CreateDataProperty(Attributes, "set", Setter).
  11. Let desc be the result of calling ToPropertyDescriptor(Attributes).
  12. ReturnIfAbrupt(desc).
  13. Let success be the result of DefinePropertyOrThrow(O, key, desc).
  14. ReturnIfAbrupt(success).
  15. Return undefined.

Object.prototype.__lookupGetter__(P)

  1. Let key be ToPropertyKey(P).
  2. ReturnIfAbrupt(key).
  3. Let O be ToObject(this value).
  4. ReturnIfAbrupt(O).
  5. Repeat
    1. Let desc be the result of calling the [[GetOwnProperty]] internal method of O passing key as the argument.
    2. ReturnIfAbrupt(desc).
    3. If desc is not undefined, then
      1. If IsAccessorDescriptor(desc) is true, then return desc.[[Get]].
      2. Return undefined.
    4. Let O be the result of calling the [[GetPrototypeOf]] internal method of O with no arguments.
    5. ReturnIfAbrupt(O).
    6. If O is null, return undefined.

Object.prototype.__lookupSetter__(P)

  1. Let key be ToPropertyKey(P).
  2. ReturnIfAbrupt(key).
  3. Let O be ToObject(this value).
  4. ReturnIfAbrupt(O).
  5. Repeat
    1. Let desc be the result of calling the [[GetOwnProperty]] internal method of O passing key as the argument.
    2. ReturnIfAbrupt(desc).
    3. If desc is not undefined, then
      1. If IsAccessorDescriptor(desc) is true, then return desc.[[Set]].
      2. Return undefined.
    4. Let O be the result of calling the [[GetPrototypeOf]] internal method of O with no arguments.
    5. ReturnIfAbrupt(O).
    6. If O is null, return undefined.

JSC: Source/JavaScriptCore/runtime/ObjectPrototype.cpp

Object.prototype.__defineGetter__(P, Getter)

  1. Let O be ToObject(this value).
  2. ReturnIfAbrupt(O).
  3. If IsCallable(Getter) is false, then throw a TypeError exception.
  4. Let desc be the PropertyDescriptor{[[Get]]: Getter, [[Enumerable]]: true, [[Configurable]]: true}.
  5. Let key be ToPropertyKey(P).
  6. ReturnIfAbrupt(key).
  7. Let success be the result of calling the [[DefineOwnProperty]] internal method of O passing key and desc as arguments.
  8. ReturnIfAbrupt(success).
  9. Return undefined.

Object.prototype.__defineSetter__(P, Setter)

  1. Let O be ToObject(this value).
  2. ReturnIfAbrupt(O).
  3. If IsCallable(Setter) is false, then throw a TypeError exception.
  4. Let desc be the PropertyDescriptor{[[Set]]: Setter, [[Enumerable]]: true, [[Configurable]]: true}.
  5. Let key be ToPropertyKey(P).
  6. ReturnIfAbrupt(key).
  7. Let success be the result of calling the [[DefineOwnProperty]] internal method of O passing key and desc as arguments.
  8. ReturnIfAbrupt(success).
  9. Return undefined.

Object.prototype.__lookupGetter__(P)

  1. Let O be ToObject(this value).
  2. ReturnIfAbrupt(O).
  3. Let key be ToPropertyKey(P).
  4. ReturnIfAbrupt(key).
  5. Repeat
    1. Let desc be the result of calling the [[GetOwnProperty]] internal method of O passing key as the argument.
    2. ReturnIfAbrupt(desc).
    3. If desc is not undefined, then
      1. If IsAccessorDescriptor(desc) is true, then return desc.[[Get]].
      2. Return undefined.
    4. Let O be the result of calling the [[GetPrototypeOf]] internal method of O with no arguments.
    5. ReturnIfAbrupt(O).
    6. If O is null, return undefined.

Object.prototype.__lookupSetter__(P)

  1. Let O be ToObject(this value).
  2. ReturnIfAbrupt(O).
  3. Let key be ToPropertyKey(P).
  4. ReturnIfAbrupt(key).
  5. Repeat
    1. Let desc be the result of calling the [[GetOwnProperty]] internal method of O passing key as the argument.
    2. ReturnIfAbrupt(desc).
    3. If desc is not undefined, then
      1. If IsAccessorDescriptor(desc) is true, then return desc.[[Set]].
      2. Return undefined.
    4. Let O be the result of calling the [[GetPrototypeOf]] internal method of O with no arguments.
    5. ReturnIfAbrupt(O).
    6. If O is null, return undefined.

V8: src/v8natives.js

Object.prototype.__defineGetter__(P, Getter)

  1. Let thisArgument be the this value.
  2. If thisArgument is null or undefined, then
    1. Let realm be the Realm of the running execution context.
    2. Set O to realm.[[globalThis]].
  3. Else let O be ToObject(thisArgument).
  4. If IsCallable(Getter) is false, then throw a TypeError exception.
  5. Let desc be the PropertyDescriptor{[[Get]]: Getter, [[Enumerable]]: true, [[Configurable]]: true}.
  6. Let key be ToPropertyKey(P).
  7. ReturnIfAbrupt(key).
  8. Let success be the result of calling the [[DefineOwnProperty]] internal method of O passing key and desc as arguments.
  9. ReturnIfAbrupt(success).
  10. Return undefined.

Object.prototype.__defineSetter__(P, Setter)

  1. Let thisArgument be the this value.
  2. If thisArgument is null or undefined, then
    1. Let realm be the Realm of the running execution context.
    2. Set O to realm.[[globalThis]].
  3. Else let O be ToObject(thisArgument).
  4. If IsCallable(Setter) is false, then throw a TypeError exception.
  5. Let desc be the PropertyDescriptor{[[Set]]: Setter, [[Enumerable]]: true, [[Configurable]]: true}.
  6. Let key be ToPropertyKey(P).
  7. ReturnIfAbrupt(key).
  8. Let success be the result of calling the [[DefineOwnProperty]] internal method of O passing key and desc as arguments.
  9. ReturnIfAbrupt(success).
  10. Return undefined.

Object.prototype.__lookupGetter__(P)

  1. Let thisArgument be the this value.
  2. If thisArgument is null or undefined, then
    1. Let realm be the Realm of the running execution context.
    2. Set O to realm.[[globalThis]].
  3. Else let O be ToObject(thisArgument).
  4. Let key be ToPropertyKey(P).
  5. ReturnIfAbrupt(key).
  6. Repeat
    1. Let desc be the result of calling the [[GetOwnProperty]] internal method of O passing key as the argument.
    2. ReturnIfAbrupt(desc).
    3. If desc is not undefined, then
      1. If IsAccessorDescriptor(desc) is true, then return desc.[[Get]].
    4. Let O be the result of calling the [[GetPrototypeOf]] internal method of O with no arguments.
    5. ReturnIfAbrupt(O).
    6. If O is null, return undefined.

Object.prototype.__lookupSetter__(P)

  1. Let thisArgument be the this value.
  2. If thisArgument is null or undefined, then
    1. Let realm be the Realm of the running execution context.
    2. Set O to realm.[[globalThis]].
  3. Else let O be ToObject(thisArgument).
  4. Let key be ToPropertyKey(P).
  5. ReturnIfAbrupt(key).
  6. Repeat
    1. Let desc be the result of calling the [[GetOwnProperty]] internal method of O passing key as the argument.
    2. ReturnIfAbrupt(desc).
    3. If desc is not undefined, then 4. If IsAccessorDescriptor(desc) is true, then return desc.[[Set]].
    4. Let O be the result of calling the [[GetPrototypeOf]] internal method of O with no arguments.
    5. ReturnIfAbrupt(O).
    6. If O is null, return undefined.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment