mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-18 13:21:55 +00:00
build: Internal method linking - plan and basic script
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
## Internal methods
|
||||
|
||||
Examples of Internal methods not being connected -
|
||||
|
||||
1. `[[DefineOwnProperty]]` -
|
||||
|
||||
* /abstract-operations.html#sec-createdataproperty - `7.3.5 CreateDataProperty` - uses generic `O.[[DefineOwnProperty]]`
|
||||
* /ordinary-and-exotic-objects-behaviours.html#sec-array-exotic-objects-defineownproperty-p-desc - `10.4.2.1 [[DefineOwnProperty]]` -Array has custom `[[DefineOwnProperty]]`.
|
||||
* /ordinary-and-exotic-objects-behaviours.html#sec-ordinary-object-internal-methods-and-internal-slots-defineownproperty-p-desc - `10.1.6 [[DefineOwnProperty]]` - Ordinary definition
|
||||
|
||||
2. `[[GetOwnProperty]]` - Similar, defined for proxies
|
||||
|
||||
|
||||
Written in html as (both consumer + definition) -
|
||||
|
||||
<var class="field">[[DefineOwnProperty]]</var>
|
||||
|
||||
How it works internally for references -
|
||||
|
||||
ecmarkup.js - `showReferencesFor(entry)` - uses `entry.referencingIds` from biblio.
|
||||
|
||||
|
||||
Abstract methods list -
|
||||
|
||||
File: /ecmascript-data-types-and-values.html#table-essential-internal-methods
|
||||
|
||||
[[GetPrototypeOf]]
|
||||
[[SetPrototypeOf]]
|
||||
[[IsExtensible]]
|
||||
[[PreventExtensions]]
|
||||
[[GetOwnProperty]]
|
||||
[[DefineOwnProperty]]
|
||||
[[HasProperty]]
|
||||
[[Get]]
|
||||
[[Set]]
|
||||
[[Delete]]
|
||||
[[OwnPropertyKeys]]
|
||||
|
||||
File: /ecmascript-data-types-and-values.html#table-additional-essential-internal-methods-of-function-objects
|
||||
[[Call]]
|
||||
[[Construct]]
|
||||
|
||||
*Connect these to the implementations*
|
||||
|
||||
Regex to search all -
|
||||
```
|
||||
\[\[GetPrototypeOf\]\]|\[\[SetPrototypeOf\]\]|\[\[IsExtensible\]\]|\[\[PreventExtensions\]\]|\[\[GetOwnProperty\]\]|\[\[DefineOwnProperty\]\]|\[\[HasProperty\]\]|\[\[Get\]\]|\[\[Set\]\]|\[\[Delete\]\]|\[\[OwnPropertyKeys\]\]|\[\[Call\]\]|\[\[Construct\]\]
|
||||
```
|
||||
|
||||
Problems -
|
||||
1. `[[Get]]`, `[[Set]]` - are also used as Property Attributes (/ecmascript-data-types-and-values.html#sec-property-attributes). Distinguish them.
|
||||
2. Mark all Property Attributes.
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
#!/usr/bin/env bun
|
||||
import type { CheerioAPI } from "cheerio";
|
||||
import * as cheerio from "cheerio";
|
||||
import { readFileSync, writeFileSync } from "fs";
|
||||
import { fileURLToPath } from "url";
|
||||
|
||||
// Resolve the path to the HTML file (relative to repo root)
|
||||
const htmlUrl = new URL(
|
||||
"../spec-built/multipage/ecmascript-data-types-and-values.html",
|
||||
import.meta.url,
|
||||
);
|
||||
const htmlPath = fileURLToPath(htmlUrl);
|
||||
|
||||
// Load and parse the HTML
|
||||
const htmlString = readFileSync(htmlPath, "utf-8");
|
||||
const htmlCheerioApi = cheerio.load(htmlString);
|
||||
|
||||
/**
|
||||
* Script to add unique `id` attributes to internal method links.
|
||||
*
|
||||
* It scans the ECMA spec HTML tables `#table-essential-internal-methods`
|
||||
* and `#table-additional-essential-internal-methods-of-function-objects`
|
||||
* and adds an `id` to the first `<var class="field">` element found in
|
||||
* the first `<td>` of each row. The generated id follows the pattern:
|
||||
* `ask262-internal-method-<methodName>` where `<methodName>` is the text
|
||||
* content of the `<var>` element with surrounding brackets stripped.
|
||||
*
|
||||
* @param $ - The Cheerio parsing instance.
|
||||
*/
|
||||
function addInternalMethodIds($: CheerioAPI): void {
|
||||
// Find the first <var class="field"> inside the first <td> of each row
|
||||
// in the two internal‑method tables and add a unique `id` attribute.
|
||||
$(
|
||||
"#table-essential-internal-methods tr > td:first-child, " +
|
||||
"#table-additional-essential-internal-methods-of-function-objects tr > td:first-child",
|
||||
).each((_, td: any) => {
|
||||
const $td = $(td);
|
||||
const $var = $td.find("var.field").first();
|
||||
if ($var.length) {
|
||||
const rawText = $var.text().trim();
|
||||
// Remove any square brackets from the extracted text
|
||||
const text = rawText.replace(/[[\]]/g, "");
|
||||
const id = `ask262-internal-method-${text}`;
|
||||
$var.attr("id", id);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Execute core logic
|
||||
addInternalMethodIds(htmlCheerioApi);
|
||||
|
||||
// Write the updated HTML back
|
||||
writeFileSync(htmlPath, htmlCheerioApi.html(), "utf-8");
|
||||
console.log(
|
||||
`Updated ${htmlPath} – added id attributes to <var class="field"> elements.`,
|
||||
);
|
||||
@@ -1212,7 +1212,7 @@
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td>
|
||||
<var class="field">[[GetPrototypeOf]]</var>
|
||||
<var class="field" id="ask262-internal-method-GetPrototypeOf">[[GetPrototypeOf]]</var>
|
||||
</td>
|
||||
<td>
|
||||
( ) <b>→</b> Object | Null
|
||||
@@ -1223,7 +1223,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<var class="field">[[SetPrototypeOf]]</var>
|
||||
<var class="field" id="ask262-internal-method-SetPrototypeOf">[[SetPrototypeOf]]</var>
|
||||
</td>
|
||||
<td>
|
||||
(Object | Null) <b>→</b> Boolean
|
||||
@@ -1234,7 +1234,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<var class="field">[[IsExtensible]]</var>
|
||||
<var class="field" id="ask262-internal-method-IsExtensible">[[IsExtensible]]</var>
|
||||
</td>
|
||||
<td>
|
||||
( ) <b>→</b> Boolean
|
||||
@@ -1245,7 +1245,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<var class="field">[[PreventExtensions]]</var>
|
||||
<var class="field" id="ask262-internal-method-PreventExtensions">[[PreventExtensions]]</var>
|
||||
</td>
|
||||
<td>
|
||||
( ) <b>→</b> Boolean
|
||||
@@ -1256,7 +1256,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<var class="field">[[GetOwnProperty]]</var>
|
||||
<var class="field" id="ask262-internal-method-GetOwnProperty">[[GetOwnProperty]]</var>
|
||||
</td>
|
||||
<td>
|
||||
(<var>propertyKey</var>) <b>→</b> Undefined | <emu-xref href="#sec-property-descriptor-specification-type" id="_ref_1588"><a href="ecmascript-data-types-and-values.html#sec-property-descriptor-specification-type">Property Descriptor</a></emu-xref>
|
||||
@@ -1267,7 +1267,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<var class="field">[[DefineOwnProperty]]</var>
|
||||
<var class="field" id="ask262-internal-method-DefineOwnProperty">[[DefineOwnProperty]]</var>
|
||||
</td>
|
||||
<td>
|
||||
(<var>propertyKey</var>, <var>PropertyDescriptor</var>) <b>→</b> Boolean
|
||||
@@ -1278,7 +1278,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<var class="field">[[HasProperty]]</var>
|
||||
<var class="field" id="ask262-internal-method-HasProperty">[[HasProperty]]</var>
|
||||
</td>
|
||||
<td>
|
||||
(<var>propertyKey</var>) <b>→</b> Boolean
|
||||
@@ -1289,7 +1289,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<var class="field">[[Get]]</var>
|
||||
<var class="field" id="ask262-internal-method-Get">[[Get]]</var>
|
||||
</td>
|
||||
<td>
|
||||
(<var>propertyKey</var>, <var>Receiver</var>) <b>→</b> <em>any</em>
|
||||
@@ -1300,7 +1300,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<var class="field">[[Set]]</var>
|
||||
<var class="field" id="ask262-internal-method-Set">[[Set]]</var>
|
||||
</td>
|
||||
<td>
|
||||
(<var>propertyKey</var>, <var>value</var>, <var>Receiver</var>) <b>→</b> Boolean
|
||||
@@ -1311,7 +1311,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<var class="field">[[Delete]]</var>
|
||||
<var class="field" id="ask262-internal-method-Delete">[[Delete]]</var>
|
||||
</td>
|
||||
<td>
|
||||
(<var>propertyKey</var>) <b>→</b> Boolean
|
||||
@@ -1322,7 +1322,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<var class="field">[[OwnPropertyKeys]]</var>
|
||||
<var class="field" id="ask262-internal-method-OwnPropertyKeys">[[OwnPropertyKeys]]</var>
|
||||
</td>
|
||||
<td>
|
||||
( ) <b>→</b> <emu-xref href="#sec-list-and-record-specification-type" id="_ref_1590"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <emu-xref href="#property-key" id="_ref_1591"><a href="ecmascript-data-types-and-values.html#property-key">property keys</a></emu-xref>
|
||||
@@ -1351,7 +1351,7 @@
|
||||
</thead>
|
||||
<tbody><tr>
|
||||
<td>
|
||||
<var class="field">[[Call]]</var>
|
||||
<var class="field" id="ask262-internal-method-Call">[[Call]]</var>
|
||||
</td>
|
||||
<td>
|
||||
(<em>any</em>, a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_1600"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <em>any</em>) <b>→</b> <em>any</em>
|
||||
@@ -1362,7 +1362,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<var class="field">[[Construct]]</var>
|
||||
<var class="field" id="ask262-internal-method-Construct">[[Construct]]</var>
|
||||
</td>
|
||||
<td>
|
||||
(a <emu-xref href="#sec-list-and-record-specification-type" id="_ref_1602"><a href="ecmascript-data-types-and-values.html#sec-list-and-record-specification-type">List</a></emu-xref> of <em>any</em>, Object) <b>→</b> Object
|
||||
|
||||
Reference in New Issue
Block a user