Search code examples
javascriptecmascript-6prototypeabstract

Is there any way of accessing internal abstract operations in ES6 Javascript?


The ES6 specification states that abstract operations are not part of the language, but they are used internally. Some of these operations, such as CreateHTML look generally useful... Is there really no way of accessing them? No deep prototype hackery to get at these functions?


Solution

  • When one is describing the semantics of a programming language / API it is really important to get everything right and non-ambiguous. Imagine now that you are describing how should String.prototype.fontcolor(color) work. That's part of the API that you need define so you must be rigorous about it and you start listing requirements:

    1. If the string is empty, then...
    2. If the color is empty, then...
    3. If the color is not a valid color, then...
    4. ...

    Now if you have repeating requirements for multiple functions, then you can generalize those requirements and just tell whoever's implementing the standard to apply the requirements to some other function (e.g. 'Requirements 1 and 2 also hold for String.prototype.fontsize'). Instead of just saying 'Requirements 1 and 2 also hold for...' you can define the public API operations using an abstract operation e.g. 'Call RequirementsForStringPrototypeAcceptingOneArgument and exit if it returns false' where RequirementsForStringPrototypeAcceptingOneArgument contains req. 1 and 2.

    Note that those requirements themselves are not part of the API. There aren't designed to be and there's no need for them to be - there are just a tool for avoiding repetition in the standard. The implementation may really choose to have a CreateHTML function somewhere but it may as well just put a bunch of if statements if they deem it better. Thus, no, there's no way to access these operations as

    1. The implementation may not have such a function in the first place.
    2. There's no reason for the implementation to expose them.
    3. Even if they did expose some helper internal function, they have no reason to expose it with the name mentioned in the standard or have it do the exact same thing as in the standard - it's all internal details to the implementation.