Sample method, Collator.prototype.compare
(https://tc39.github.io/ecma402/#sec-intl.collator.prototype.compare)
- Let
collator
be this value. - If
Type(collator)
is not Object, throw a TypeError exception. - If
collator
does not have an [[InitializedCollator]] internal slot, throw a TypeError exception. - If
collator
.[[BoundCompare]] is undefined, then a. LetF
be a new built-in function object as defined in 10.3.3.1. b. SetF
.[[Collator]] tocollator
. c. Setcollator
.[[BoundCompare]] toF
. - Return
collator
.[[BoundCompare]].
Similar to NumberFormat.prototype.format
and DateTimeFormat.prototype.format
.
Patterns:
- The object to be operated on is assumed to be the this value.
- If the object isn't a valid object, throw a TypeError.
- If the object has a valid unwrap method, then
x = UnwrapExpectedTypeOfX(x)
, otherwise throw a TypeError if it isn't already a valid object of said type. - If the method doesn't yet exist (it's a bound method stored in an internal slot), make a new function as required from the instruction set pertaining to said method, and set the internal slot to the newly-made function.
- Return the method.
AddBoundMethod(cls, method)
- Let
obj
be the this value. - If
Type(obj)
is not Object, throw a TypeError exception. - If
cls
has an associatedUnwrap
method,obj = cls.Unwrap(obj)
, otherwise ifcls.Valid(obj)
is false, throw a TypeError exception. (Note: This is because there might be different conditions for each class of objects to be valid. In v8, internal slots aren't used for this as it's implemented in a typed environment (C++)). - If
obj
does not havemethod
stored in an internal slot (calledBound || method.name
in this case), a. Initialize a new method of typemethod
. If the method name is passed, another argument should be passed that could be used to construct said method, otherwisemethod
could be an object somewhat like{ name: 'xyz', getInstance: function() {...})
. b. Store a reference toobj
inside the newly-instantiated method. c. Set the internal slot under question to the newly-instantiated method. - Return the value stored at the said internal slot.