diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..97f7f0b --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +index.html -diff merge=ours + diff --git a/README.md b/README.md index ce5468f..8242396 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ECMAScript Proposal, specs, and reference implementation for `Error.isError` Spec drafted by [@ljharb](https://github.com/ljharb). -This proposal is currently [withdrawn from stage 0](https://github.com/tc39/ecma262/withdrawn-proposals.md) of the [process](https://tc39.github.io/process-document/). +This proposal is currently Stage 1 of the [process](https://tc39.github.io/process-document/). ## Rationale I brought up concerns to the committee about `Symbol.toStringTag`, and how previously reliable and unspoofable `Object#toString` calls would now no longer be reliable. The committee consensus was that as long as there were prototype methods for all builtins that, at the least, threw an error when an internal slot was not present, that would be sufficient to serve as a reliable branding test. @@ -12,5 +12,13 @@ However, the internal slot for `Error` instances (and its subclasses) is only ch `instanceof Error`, of course, is unreliable because it will provide a false negative with a cross-realm (eg, from an iframe, or node's `vm` modules) `Error` instance. +## Use cases + +This list is not exhaustive. + + - debugging: it is very helpful to humans, even if not always to programs, to know what kind of thing a value is. Knowing if something is a "real" native error is thus valuable information to make available, including to error-reporting libraries. + - serialization: platforms such as [RunKit](https://runkit.com/) need to serialize values safely and reconstruct them or describe them in the user’s browser. brand checking is critical for this. + - structuredClone: this HTML method, which is also in node, brand-checks, and has special behavior for native Errors. JS programs need a way to know in advance if this behavior will be applied + ## Spec -You can view the spec in [markdown format](spec.md) or rendered as [HTML](http://ljharb.github.io/proposal-is-error/). +You can view the spec rendered as [HTML](https://tc39.es/proposal-is-error/). diff --git a/index.html b/index.html index c0e07ea..389fe8d 100644 --- a/index.html +++ b/index.html @@ -1,87 +1,3270 @@ + +Error.isError - Error.isError - - - - - - -

Stage 0 (withdrawn) Draft / March 29, 2016

-

Error.isError

- -

1IsError( argument )#

-

When the - IsError abstract operation is called with argument argument, the following steps are taken:

- -
    -
  1. If - Type(argument) is not Object, return - false.
  2. -
  3. If argument has an [[ErrorData]] internal slot, return - true.
  4. -
  5. If argument is a Proxy exotic object, then -
      -
    1. If the value of the [[ProxyHandler]] internal slot of argument is - null, throw a TypeError exception.
    2. -
    3. Let target be the value of the [[ProxyTarget]] internal slot of argument.
    4. -
    5. Return - IsError(target).
    6. -
    -
  6. -
  7. Return - false. -
  8. -
-
-
- -

2Error.isError( arg )#

-

When the - isError function is called with argument arg, the following steps are taken:

- -
    -
  1. Return - IsError(arg). -
  2. -
-
-
- -

ACopyright & Software License#

+ activate(el) { + clearTimeout(this.deactiveTimeout); + Toolbox.deactivate(); + this.$alternativeId = el.id; + let numSdos = Object.keys(sdoMap[this.$alternativeId] || {}).length; + this.$displayLink.textContent = 'Syntax-Directed Operations (' + numSdos + ')'; + this.$outer.classList.add('active'); + let top = el.offsetTop - this.$outer.offsetHeight; + let left = el.offsetLeft + 50 - 10; // 50px = padding-left(=75px) + text-indent(=-25px) + this.$outer.setAttribute('style', 'left: ' + left + 'px; top: ' + top + 'px'); + if (top < document.body.scrollTop) { + this.$container.scrollIntoView(); + } + }, + + deactivate() { + clearTimeout(this.deactiveTimeout); + this.$outer.classList.remove('active'); + }, +}; + +document.addEventListener('DOMContentLoaded', () => { + if (typeof sdoMap == 'undefined') { + console.error('could not find sdo map'); + return; + } + sdoBox.init(); + + let insideTooltip = false; + sdoBox.$outer.addEventListener('pointerenter', () => { + insideTooltip = true; + }); + sdoBox.$outer.addEventListener('pointerleave', () => { + insideTooltip = false; + sdoBox.deactivate(); + }); + + sdoBox.deactiveTimeout = null; + [].forEach.call(document.querySelectorAll('emu-grammar[type=definition] emu-rhs'), node => { + node.addEventListener('pointerenter', function () { + sdoBox.activate(this); + }); + + node.addEventListener('pointerleave', () => { + sdoBox.deactiveTimeout = setTimeout(() => { + if (!insideTooltip) { + sdoBox.deactivate(); + } + }, 500); + }); + }); + + document.addEventListener( + 'keydown', + debounce(e => { + if (e.code === 'Escape') { + sdoBox.deactivate(); + } + }), + ); +}); + +'use strict'; +function Search(menu) { + this.menu = menu; + this.$search = document.getElementById('menu-search'); + this.$searchBox = document.getElementById('menu-search-box'); + this.$searchResults = document.getElementById('menu-search-results'); + + this.loadBiblio(); + + document.addEventListener('keydown', this.documentKeydown.bind(this)); + + this.$searchBox.addEventListener( + 'keydown', + debounce(this.searchBoxKeydown.bind(this), { stopPropagation: true }), + ); + this.$searchBox.addEventListener( + 'keyup', + debounce(this.searchBoxKeyup.bind(this), { stopPropagation: true }), + ); + + // Perform an initial search if the box is not empty. + if (this.$searchBox.value) { + this.search(this.$searchBox.value); + } +} + +Search.prototype.loadBiblio = function () { + if (typeof biblio === 'undefined') { + console.error('could not find biblio'); + this.biblio = { refToClause: {}, entries: [] }; + } else { + this.biblio = biblio; + this.biblio.clauses = this.biblio.entries.filter(e => e.type === 'clause'); + this.biblio.byId = this.biblio.entries.reduce((map, entry) => { + map[entry.id] = entry; + return map; + }, {}); + let refParentClause = Object.create(null); + this.biblio.refParentClause = refParentClause; + let refsByClause = this.biblio.refsByClause; + Object.keys(refsByClause).forEach(clause => { + refsByClause[clause].forEach(ref => { + refParentClause[ref] = clause; + }); + }); + } +}; + +Search.prototype.documentKeydown = function (e) { + if (e.key === '/') { + e.preventDefault(); + e.stopPropagation(); + this.triggerSearch(); + } +}; + +Search.prototype.searchBoxKeydown = function (e) { + e.stopPropagation(); + e.preventDefault(); + if (e.keyCode === 191 && e.target.value.length === 0) { + e.preventDefault(); + } else if (e.keyCode === 13) { + e.preventDefault(); + this.selectResult(); + } +}; + +Search.prototype.searchBoxKeyup = function (e) { + if (e.keyCode === 13 || e.keyCode === 9) { + return; + } + + this.search(e.target.value); +}; + +Search.prototype.triggerSearch = function () { + if (this.menu.isVisible()) { + this._closeAfterSearch = false; + } else { + this._closeAfterSearch = true; + this.menu.show(); + } + + this.$searchBox.focus(); + this.$searchBox.select(); +}; +// bit 12 - Set if the result starts with searchString +// bits 8-11: 8 - number of chunks multiplied by 2 if cases match, otherwise 1. +// bits 1-7: 127 - length of the entry +// General scheme: prefer case sensitive matches with fewer chunks, and otherwise +// prefer shorter matches. +function relevance(result) { + let relevance = 0; + + relevance = Math.max(0, 8 - result.match.chunks) << 7; + + if (result.match.caseMatch) { + relevance *= 2; + } + + if (result.match.prefix) { + relevance += 2048; + } + + relevance += Math.max(0, 255 - result.key.length); + + return relevance; +} + +Search.prototype.search = function (searchString) { + if (searchString === '') { + this.displayResults([]); + this.hideSearch(); + return; + } else { + this.showSearch(); + } + + if (searchString.length === 1) { + this.displayResults([]); + return; + } + + let results; + + if (/^[\d.]*$/.test(searchString)) { + results = this.biblio.clauses + .filter(clause => clause.number.substring(0, searchString.length) === searchString) + .map(clause => ({ key: getKey(clause), entry: clause })); + } else { + results = []; + + for (let i = 0; i < this.biblio.entries.length; i++) { + let entry = this.biblio.entries[i]; + let key = getKey(entry); + if (!key) { + // biblio entries without a key aren't searchable + continue; + } + + let match = fuzzysearch(searchString, key); + if (match) { + results.push({ key, entry, match }); + } + } + + results.forEach(result => { + result.relevance = relevance(result, searchString); + }); + + results = results.sort((a, b) => b.relevance - a.relevance); + } + + if (results.length > 50) { + results = results.slice(0, 50); + } + + this.displayResults(results); +}; +Search.prototype.hideSearch = function () { + this.$search.classList.remove('active'); +}; + +Search.prototype.showSearch = function () { + this.$search.classList.add('active'); +}; + +Search.prototype.selectResult = function () { + let $first = this.$searchResults.querySelector('li:first-child a'); + + if ($first) { + document.location = $first.getAttribute('href'); + } + + this.$searchBox.value = ''; + this.$searchBox.blur(); + this.displayResults([]); + this.hideSearch(); + + if (this._closeAfterSearch) { + this.menu.hide(); + } +}; + +Search.prototype.displayResults = function (results) { + if (results.length > 0) { + this.$searchResults.classList.remove('no-results'); + + let html = ''; + + this.$searchResults.innerHTML = html; + } else { + this.$searchResults.innerHTML = ''; + this.$searchResults.classList.add('no-results'); + } +}; + +function getKey(item) { + if (item.key) { + return item.key; + } + switch (item.type) { + case 'clause': + return item.title || item.titleHTML; + case 'production': + return item.name; + case 'op': + return item.aoid; + case 'term': + return item.term; + case 'table': + case 'figure': + case 'example': + case 'note': + return item.caption; + case 'step': + return item.id; + default: + throw new Error("Can't get key for " + item.type); + } +} + +function Menu() { + this.$toggle = document.getElementById('menu-toggle'); + this.$menu = document.getElementById('menu'); + this.$toc = document.querySelector('menu-toc > ol'); + this.$pins = document.querySelector('#menu-pins'); + this.$pinList = document.getElementById('menu-pins-list'); + this.$toc = document.querySelector('#menu-toc > ol'); + this.$specContainer = document.getElementById('spec-container'); + this.search = new Search(this); + + this._pinnedIds = {}; + this.loadPinEntries(); + + // unpin all button + document + .querySelector('#menu-pins .unpin-all') + .addEventListener('click', this.unpinAll.bind(this)); + + // individual unpinning buttons + this.$pinList.addEventListener('click', this.pinListClick.bind(this)); + + // toggle menu + this.$toggle.addEventListener('click', this.toggle.bind(this)); + + // keydown events for pinned clauses + document.addEventListener('keydown', this.documentKeydown.bind(this)); + + // toc expansion + let tocItems = this.$menu.querySelectorAll('#menu-toc li'); + for (let i = 0; i < tocItems.length; i++) { + let $item = tocItems[i]; + $item.addEventListener('click', event => { + $item.classList.toggle('active'); + event.stopPropagation(); + }); + } + + // close toc on toc item selection + let tocLinks = this.$menu.querySelectorAll('#menu-toc li > a'); + for (let i = 0; i < tocLinks.length; i++) { + let $link = tocLinks[i]; + $link.addEventListener('click', event => { + this.toggle(); + event.stopPropagation(); + }); + } + + // update active clause on scroll + window.addEventListener('scroll', debounce(this.updateActiveClause.bind(this))); + this.updateActiveClause(); + + // prevent menu scrolling from scrolling the body + this.$toc.addEventListener('wheel', e => { + let target = e.currentTarget; + let offTop = e.deltaY < 0 && target.scrollTop === 0; + if (offTop) { + e.preventDefault(); + } + let offBottom = e.deltaY > 0 && target.offsetHeight + target.scrollTop >= target.scrollHeight; + + if (offBottom) { + e.preventDefault(); + } + }); +} + +Menu.prototype.documentKeydown = function (e) { + e.stopPropagation(); + if (e.keyCode === 80) { + this.togglePinEntry(); + } else if (e.keyCode >= 48 && e.keyCode < 58) { + this.selectPin((e.keyCode - 9) % 10); + } +}; + +Menu.prototype.updateActiveClause = function () { + this.setActiveClause(findActiveClause(this.$specContainer)); +}; + +Menu.prototype.setActiveClause = function (clause) { + this.$activeClause = clause; + this.revealInToc(this.$activeClause); +}; + +Menu.prototype.revealInToc = function (path) { + let current = this.$toc.querySelectorAll('li.revealed'); + for (let i = 0; i < current.length; i++) { + current[i].classList.remove('revealed'); + current[i].classList.remove('revealed-leaf'); + } + + current = this.$toc; + let index = 0; + outer: while (index < path.length) { + let children = current.children; + for (let i = 0; i < children.length; i++) { + if ('#' + path[index].id === children[i].children[1].hash) { + children[i].classList.add('revealed'); + if (index === path.length - 1) { + children[i].classList.add('revealed-leaf'); + let rect = children[i].getBoundingClientRect(); + // this.$toc.getBoundingClientRect().top; + let tocRect = this.$toc.getBoundingClientRect(); + if (rect.top + 10 > tocRect.bottom) { + this.$toc.scrollTop = + this.$toc.scrollTop + (rect.top - tocRect.bottom) + (rect.bottom - rect.top); + } else if (rect.top < tocRect.top) { + this.$toc.scrollTop = this.$toc.scrollTop - (tocRect.top - rect.top); + } + } + current = children[i].querySelector('ol'); + index++; + continue outer; + } + } + console.log('could not find location in table of contents', path); + break; + } +}; + +function findActiveClause(root, path) { + path = path || []; + + let visibleClauses = getVisibleClauses(root, path); + let midpoint = Math.floor(window.innerHeight / 2); + + for (let [$clause, path] of visibleClauses) { + let { top: clauseTop, bottom: clauseBottom } = $clause.getBoundingClientRect(); + let isFullyVisibleAboveTheFold = + clauseTop > 0 && clauseTop < midpoint && clauseBottom < window.innerHeight; + if (isFullyVisibleAboveTheFold) { + return path; + } + } + + visibleClauses.sort(([, pathA], [, pathB]) => pathB.length - pathA.length); + for (let [$clause, path] of visibleClauses) { + let { top: clauseTop, bottom: clauseBottom } = $clause.getBoundingClientRect(); + let $header = $clause.querySelector('h1'); + let clauseStyles = getComputedStyle($clause); + let marginTop = Math.max( + 0, + parseInt(clauseStyles['margin-top']), + parseInt(getComputedStyle($header)['margin-top']), + ); + let marginBottom = Math.max(0, parseInt(clauseStyles['margin-bottom'])); + let crossesMidpoint = + clauseTop - marginTop <= midpoint && clauseBottom + marginBottom >= midpoint; + if (crossesMidpoint) { + return path; + } + } + + return path; +} + +function getVisibleClauses(root, path) { + let childClauses = getChildClauses(root); + path = path || []; + + let result = []; + + let seenVisibleClause = false; + for (let $clause of childClauses) { + let { top: clauseTop, bottom: clauseBottom } = $clause.getBoundingClientRect(); + let isPartiallyVisible = + (clauseTop > 0 && clauseTop < window.innerHeight) || + (clauseBottom > 0 && clauseBottom < window.innerHeight) || + (clauseTop < 0 && clauseBottom > window.innerHeight); + + if (isPartiallyVisible) { + seenVisibleClause = true; + let innerPath = path.concat($clause); + result.push([$clause, innerPath]); + result.push(...getVisibleClauses($clause, innerPath)); + } else if (seenVisibleClause) { + break; + } + } + + return result; +} + +function* getChildClauses(root) { + for (let el of root.children) { + switch (el.nodeName) { + // descend into + case 'EMU-IMPORT': + yield* getChildClauses(el); + break; + + // accept , , and + case 'EMU-CLAUSE': + case 'EMU-INTRO': + case 'EMU-ANNEX': + yield el; + } + } +} + +Menu.prototype.toggle = function () { + this.$menu.classList.toggle('active'); +}; + +Menu.prototype.show = function () { + this.$menu.classList.add('active'); +}; + +Menu.prototype.hide = function () { + this.$menu.classList.remove('active'); +}; + +Menu.prototype.isVisible = function () { + return this.$menu.classList.contains('active'); +}; + +Menu.prototype.showPins = function () { + this.$pins.classList.add('active'); +}; + +Menu.prototype.hidePins = function () { + this.$pins.classList.remove('active'); +}; + +Menu.prototype.addPinEntry = function (id) { + let entry = this.search.biblio.byId[id]; + if (!entry) { + // id was deleted after pin (or something) so remove it + delete this._pinnedIds[id]; + this.persistPinEntries(); + return; + } + + let text; + if (entry.type === 'clause') { + let prefix; + if (entry.number) { + prefix = entry.number + ' '; + } else { + prefix = ''; + } + text = `${prefix}${entry.titleHTML}`; + } else { + text = getKey(entry); + } + + let link = `${text}`; + this.$pinList.innerHTML += `
  • ${link}
  • `; + + if (Object.keys(this._pinnedIds).length === 0) { + this.showPins(); + } + this._pinnedIds[id] = true; + this.persistPinEntries(); +}; + +Menu.prototype.removePinEntry = function (id) { + let item = this.$pinList.querySelector(`li[data-section-id="${id}"]`); + this.$pinList.removeChild(item); + delete this._pinnedIds[id]; + if (Object.keys(this._pinnedIds).length === 0) { + this.hidePins(); + } + + this.persistPinEntries(); +}; + +Menu.prototype.unpinAll = function () { + for (let id of Object.keys(this._pinnedIds)) { + this.removePinEntry(id); + } +}; + +Menu.prototype.pinListClick = function (event) { + if (event?.target?.classList.contains('unpin')) { + let id = event.target.parentNode.dataset.sectionId; + if (id) { + this.removePinEntry(id); + } + } +}; + +Menu.prototype.persistPinEntries = function () { + try { + if (!window.localStorage) return; + } catch (e) { + return; + } + + localStorage.pinEntries = JSON.stringify(Object.keys(this._pinnedIds)); +}; + +Menu.prototype.loadPinEntries = function () { + try { + if (!window.localStorage) return; + } catch (e) { + return; + } + + let pinsString = window.localStorage.pinEntries; + if (!pinsString) return; + let pins = JSON.parse(pinsString); + for (let i = 0; i < pins.length; i++) { + this.addPinEntry(pins[i]); + } +}; + +Menu.prototype.togglePinEntry = function (id) { + if (!id) { + id = this.$activeClause[this.$activeClause.length - 1].id; + } + + if (this._pinnedIds[id]) { + this.removePinEntry(id); + } else { + this.addPinEntry(id); + } +}; + +Menu.prototype.selectPin = function (num) { + document.location = this.$pinList.children[num].children[0].href; +}; + +let menu; + +document.addEventListener('DOMContentLoaded', init); + +function debounce(fn, opts) { + opts = opts || {}; + let timeout; + return function (e) { + if (opts.stopPropagation) { + e.stopPropagation(); + } + let args = arguments; + if (timeout) { + clearTimeout(timeout); + } + timeout = setTimeout(() => { + timeout = null; + fn.apply(this, args); + }, 150); + }; +} + +let CLAUSE_NODES = ['EMU-CLAUSE', 'EMU-INTRO', 'EMU-ANNEX']; +function findContainer($elem) { + let parentClause = $elem.parentNode; + while (parentClause && CLAUSE_NODES.indexOf(parentClause.nodeName) === -1) { + parentClause = parentClause.parentNode; + } + return parentClause; +} + +function findLocalReferences(parentClause, name) { + let vars = parentClause.querySelectorAll('var'); + let references = []; + + for (let i = 0; i < vars.length; i++) { + let $var = vars[i]; + + if ($var.innerHTML === name) { + references.push($var); + } + } + + return references; +} + +let REFERENCED_CLASSES = Array.from({ length: 7 }, (x, i) => `referenced${i}`); +function chooseHighlightIndex(parentClause) { + let counts = REFERENCED_CLASSES.map($class => parentClause.getElementsByClassName($class).length); + // Find the earliest index with the lowest count. + let minCount = Infinity; + let index = null; + for (let i = 0; i < counts.length; i++) { + if (counts[i] < minCount) { + minCount = counts[i]; + index = i; + } + } + return index; +} + +function toggleFindLocalReferences($elem) { + let parentClause = findContainer($elem); + let references = findLocalReferences(parentClause, $elem.innerHTML); + if ($elem.classList.contains('referenced')) { + references.forEach($reference => { + $reference.classList.remove('referenced', ...REFERENCED_CLASSES); + }); + } else { + let index = chooseHighlightIndex(parentClause); + references.forEach($reference => { + $reference.classList.add('referenced', `referenced${index}`); + }); + } +} + +function installFindLocalReferences() { + document.addEventListener('click', e => { + if (e.target.nodeName === 'VAR') { + toggleFindLocalReferences(e.target); + } + }); +} + +document.addEventListener('DOMContentLoaded', installFindLocalReferences); + +// The following license applies to the fuzzysearch function +// The MIT License (MIT) +// Copyright © 2015 Nicolas Bevacqua +// Copyright © 2016 Brian Terlson +// Permission is hereby granted, free of charge, to any person obtaining a copy of +// this software and associated documentation files (the "Software"), to deal in +// the Software without restriction, including without limitation the rights to +// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +// the Software, and to permit persons to whom the Software is furnished to do so, +// subject to the following conditions: + +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. + +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +function fuzzysearch(searchString, haystack, caseInsensitive) { + let tlen = haystack.length; + let qlen = searchString.length; + let chunks = 1; + let finding = false; + + if (qlen > tlen) { + return false; + } + + if (qlen === tlen) { + if (searchString === haystack) { + return { caseMatch: true, chunks: 1, prefix: true }; + } else if (searchString.toLowerCase() === haystack.toLowerCase()) { + return { caseMatch: false, chunks: 1, prefix: true }; + } else { + return false; + } + } + + let j = 0; + outer: for (let i = 0; i < qlen; i++) { + let nch = searchString[i]; + while (j < tlen) { + let targetChar = haystack[j++]; + if (targetChar === nch) { + finding = true; + continue outer; + } + if (finding) { + chunks++; + finding = false; + } + } + + if (caseInsensitive) { + return false; + } + + return fuzzysearch(searchString.toLowerCase(), haystack.toLowerCase(), true); + } + + return { caseMatch: !caseInsensitive, chunks, prefix: j <= qlen }; +} + +let referencePane = { + init() { + this.$container = document.createElement('div'); + this.$container.setAttribute('id', 'references-pane-container'); + + let $spacer = document.createElement('div'); + $spacer.setAttribute('id', 'references-pane-spacer'); + $spacer.classList.add('menu-spacer'); + + this.$pane = document.createElement('div'); + this.$pane.setAttribute('id', 'references-pane'); + + this.$container.appendChild($spacer); + this.$container.appendChild(this.$pane); + + this.$header = document.createElement('div'); + this.$header.classList.add('menu-pane-header'); + this.$headerText = document.createElement('span'); + this.$header.appendChild(this.$headerText); + this.$headerRefId = document.createElement('a'); + this.$header.appendChild(this.$headerRefId); + this.$header.addEventListener('pointerdown', e => { + this.dragStart(e); + }); + + this.$closeButton = document.createElement('span'); + this.$closeButton.setAttribute('id', 'references-pane-close'); + this.$closeButton.addEventListener('click', () => { + this.deactivate(); + }); + this.$header.appendChild(this.$closeButton); + + this.$pane.appendChild(this.$header); + this.$tableContainer = document.createElement('div'); + this.$tableContainer.setAttribute('id', 'references-pane-table-container'); + + this.$table = document.createElement('table'); + this.$table.setAttribute('id', 'references-pane-table'); + + this.$tableBody = this.$table.createTBody(); + + this.$tableContainer.appendChild(this.$table); + this.$pane.appendChild(this.$tableContainer); + + if (menu != null) { + menu.$specContainer.appendChild(this.$container); + } + }, + + activate() { + this.$container.classList.add('active'); + }, + + deactivate() { + this.$container.classList.remove('active'); + this.state = null; + }, + + showReferencesFor(entry) { + this.activate(); + this.state = { type: 'ref', id: entry.id }; + this.$headerText.textContent = 'References to '; + let newBody = document.createElement('tbody'); + let previousId; + let previousCell; + let dupCount = 0; + this.$headerRefId.innerHTML = getKey(entry); + this.$headerRefId.setAttribute('href', makeLinkToId(entry.id)); + this.$headerRefId.style.display = 'inline'; + (entry.referencingIds || []) + .map(id => { + let cid = menu.search.biblio.refParentClause[id]; + let clause = menu.search.biblio.byId[cid]; + if (clause == null) { + throw new Error('could not find clause for id ' + cid); + } + return { id, clause }; + }) + .sort((a, b) => sortByClauseNumber(a.clause, b.clause)) + .forEach(record => { + if (previousId === record.clause.id) { + previousCell.innerHTML += ` (${dupCount + 2})`; + dupCount++; + } else { + let row = newBody.insertRow(); + let cell = row.insertCell(); + cell.innerHTML = record.clause.number; + cell = row.insertCell(); + cell.innerHTML = `${record.clause.titleHTML}`; + previousCell = cell; + previousId = record.clause.id; + dupCount = 0; + } + }, this); + this.$table.removeChild(this.$tableBody); + this.$tableBody = newBody; + this.$table.appendChild(this.$tableBody); + this.autoSize(); + }, + + showSDOs(sdos, alternativeId) { + let rhs = document.getElementById(alternativeId); + let parentName = rhs.parentNode.getAttribute('name'); + let colons = rhs.parentNode.querySelector('emu-geq'); + rhs = rhs.cloneNode(true); + rhs.querySelectorAll('emu-params,emu-constraints').forEach(e => { + e.remove(); + }); + rhs.querySelectorAll('[id]').forEach(e => { + e.removeAttribute('id'); + }); + rhs.querySelectorAll('a').forEach(e => { + e.parentNode.replaceChild(document.createTextNode(e.textContent), e); + }); + + this.$headerText.innerHTML = `Syntax-Directed Operations for
    ${parentName} ${colons.outerHTML} `; + this.$headerText.querySelector('a').append(rhs); + this.showSDOsBody(sdos, alternativeId); + }, + + showSDOsBody(sdos, alternativeId) { + this.activate(); + this.state = { type: 'sdo', id: alternativeId, html: this.$headerText.innerHTML }; + this.$headerRefId.style.display = 'none'; + let newBody = document.createElement('tbody'); + Object.keys(sdos).forEach(sdoName => { + let pair = sdos[sdoName]; + let clause = pair.clause; + let ids = pair.ids; + let first = ids[0]; + let row = newBody.insertRow(); + let cell = row.insertCell(); + cell.innerHTML = clause; + cell = row.insertCell(); + let html = '' + sdoName + ''; + for (let i = 1; i < ids.length; ++i) { + html += ' (' + (i + 1) + ')'; + } + cell.innerHTML = html; + }); + this.$table.removeChild(this.$tableBody); + this.$tableBody = newBody; + this.$table.appendChild(this.$tableBody); + this.autoSize(); + }, + + autoSize() { + this.$tableContainer.style.height = + Math.min(250, this.$table.getBoundingClientRect().height) + 'px'; + }, + + dragStart(pointerDownEvent) { + let startingMousePos = pointerDownEvent.clientY; + let startingHeight = this.$tableContainer.getBoundingClientRect().height; + let moveListener = pointerMoveEvent => { + if (pointerMoveEvent.buttons === 0) { + removeListeners(); + return; + } + let desiredHeight = startingHeight - (pointerMoveEvent.clientY - startingMousePos); + this.$tableContainer.style.height = Math.max(0, desiredHeight) + 'px'; + }; + let listenerOptions = { capture: true, passive: true }; + let removeListeners = () => { + document.removeEventListener('pointermove', moveListener, listenerOptions); + this.$header.removeEventListener('pointerup', removeListeners, listenerOptions); + this.$header.removeEventListener('pointercancel', removeListeners, listenerOptions); + }; + document.addEventListener('pointermove', moveListener, listenerOptions); + this.$header.addEventListener('pointerup', removeListeners, listenerOptions); + this.$header.addEventListener('pointercancel', removeListeners, listenerOptions); + }, +}; + +let Toolbox = { + init() { + this.$outer = document.createElement('div'); + this.$outer.classList.add('toolbox-container'); + this.$container = document.createElement('div'); + this.$container.classList.add('toolbox'); + this.$outer.appendChild(this.$container); + this.$permalink = document.createElement('a'); + this.$permalink.textContent = 'Permalink'; + this.$pinLink = document.createElement('a'); + this.$pinLink.textContent = 'Pin'; + this.$pinLink.setAttribute('href', '#'); + this.$pinLink.addEventListener('click', e => { + e.preventDefault(); + e.stopPropagation(); + menu.togglePinEntry(this.entry.id); + this.$pinLink.textContent = menu._pinnedIds[this.entry.id] ? 'Unpin' : 'Pin'; + }); + + this.$refsLink = document.createElement('a'); + this.$refsLink.setAttribute('href', '#'); + this.$refsLink.addEventListener('click', e => { + e.preventDefault(); + e.stopPropagation(); + referencePane.showReferencesFor(this.entry); + }); + this.$container.appendChild(this.$permalink); + this.$container.appendChild(document.createTextNode(' ')); + this.$container.appendChild(this.$pinLink); + this.$container.appendChild(document.createTextNode(' ')); + this.$container.appendChild(this.$refsLink); + document.body.appendChild(this.$outer); + }, + + activate(el, entry, target) { + if (el === this._activeEl) return; + sdoBox.deactivate(); + this.active = true; + this.entry = entry; + this.$pinLink.textContent = menu._pinnedIds[entry.id] ? 'Unpin' : 'Pin'; + this.$outer.classList.add('active'); + this.top = el.offsetTop - this.$outer.offsetHeight; + this.left = el.offsetLeft - 10; + this.$outer.setAttribute('style', 'left: ' + this.left + 'px; top: ' + this.top + 'px'); + this.updatePermalink(); + this.updateReferences(); + this._activeEl = el; + if (this.top < document.body.scrollTop && el === target) { + // don't scroll unless it's a small thing (< 200px) + this.$outer.scrollIntoView(); + } + }, + + updatePermalink() { + this.$permalink.setAttribute('href', makeLinkToId(this.entry.id)); + }, + + updateReferences() { + this.$refsLink.textContent = `References (${(this.entry.referencingIds || []).length})`; + }, + + activateIfMouseOver(e) { + let ref = this.findReferenceUnder(e.target); + if (ref && (!this.active || e.pageY > this._activeEl.offsetTop)) { + let entry = menu.search.biblio.byId[ref.id]; + this.activate(ref.element, entry, e.target); + } else if ( + this.active && + (e.pageY < this.top || e.pageY > this._activeEl.offsetTop + this._activeEl.offsetHeight) + ) { + this.deactivate(); + } + }, + + findReferenceUnder(el) { + while (el) { + let parent = el.parentNode; + if (el.nodeName === 'EMU-RHS' || el.nodeName === 'EMU-PRODUCTION') { + return null; + } + if ( + el.nodeName === 'H1' && + parent.nodeName.match(/EMU-CLAUSE|EMU-ANNEX|EMU-INTRO/) && + parent.id + ) { + return { element: el, id: parent.id }; + } else if (el.nodeName === 'EMU-NT') { + if ( + parent.nodeName === 'EMU-PRODUCTION' && + parent.id && + parent.id[0] !== '_' && + parent.firstElementChild === el + ) { + // return the LHS non-terminal element + return { element: el, id: parent.id }; + } + return null; + } else if ( + el.nodeName.match(/EMU-(?!CLAUSE|XREF|ANNEX|INTRO)|DFN/) && + el.id && + el.id[0] !== '_' + ) { + if ( + el.nodeName === 'EMU-FIGURE' || + el.nodeName === 'EMU-TABLE' || + el.nodeName === 'EMU-EXAMPLE' + ) { + // return the figcaption element + return { element: el.children[0].children[0], id: el.id }; + } else { + return { element: el, id: el.id }; + } + } + el = parent; + } + }, + + deactivate() { + this.$outer.classList.remove('active'); + this._activeEl = null; + this.active = false; + }, +}; + +function sortByClauseNumber(clause1, clause2) { + let c1c = clause1.number.split('.'); + let c2c = clause2.number.split('.'); + + for (let i = 0; i < c1c.length; i++) { + if (i >= c2c.length) { + return 1; + } + + let c1 = c1c[i]; + let c2 = c2c[i]; + let c1cn = Number(c1); + let c2cn = Number(c2); + + if (Number.isNaN(c1cn) && Number.isNaN(c2cn)) { + if (c1 > c2) { + return 1; + } else if (c1 < c2) { + return -1; + } + } else if (!Number.isNaN(c1cn) && Number.isNaN(c2cn)) { + return -1; + } else if (Number.isNaN(c1cn) && !Number.isNaN(c2cn)) { + return 1; + } else if (c1cn > c2cn) { + return 1; + } else if (c1cn < c2cn) { + return -1; + } + } + + if (c1c.length === c2c.length) { + return 0; + } + return -1; +} + +function makeLinkToId(id) { + let hash = '#' + id; + if (typeof idToSection === 'undefined' || !idToSection[id]) { + return hash; + } + let targetSec = idToSection[id]; + return (targetSec === 'index' ? './' : targetSec + '.html') + hash; +} + +function doShortcut(e) { + if (!(e.target instanceof HTMLElement)) { + return; + } + let target = e.target; + let name = target.nodeName.toLowerCase(); + if (name === 'textarea' || name === 'input' || name === 'select' || target.isContentEditable) { + return; + } + if (e.altKey || e.ctrlKey || e.metaKey) { + return; + } + if (e.key === 'm' && usesMultipage) { + let pathParts = location.pathname.split('/'); + let hash = location.hash; + if (pathParts[pathParts.length - 2] === 'multipage') { + if (hash === '') { + let sectionName = pathParts[pathParts.length - 1]; + if (sectionName.endsWith('.html')) { + sectionName = sectionName.slice(0, -5); + } + if (idToSection['sec-' + sectionName] !== undefined) { + hash = '#sec-' + sectionName; + } + } + location = pathParts.slice(0, -2).join('/') + '/' + hash; + } else { + location = 'multipage/' + hash; + } + } else if (e.key === 'u') { + document.documentElement.classList.toggle('show-ao-annotations'); + } else if (e.key === '?') { + document.getElementById('shortcuts-help').classList.toggle('active'); + } +} + +function init() { + if (document.getElementById('menu') == null) { + return; + } + menu = new Menu(); + let $container = document.getElementById('spec-container'); + $container.addEventListener( + 'mouseover', + debounce(e => { + Toolbox.activateIfMouseOver(e); + }), + ); + document.addEventListener( + 'keydown', + debounce(e => { + if (e.code === 'Escape') { + if (Toolbox.active) { + Toolbox.deactivate(); + } + document.getElementById('shortcuts-help').classList.remove('active'); + } + }), + ); +} + +document.addEventListener('keypress', doShortcut); + +document.addEventListener('DOMContentLoaded', () => { + Toolbox.init(); + referencePane.init(); +}); + +// preserve state during navigation + +function getTocPath(li) { + let path = []; + let pointer = li; + while (true) { + let parent = pointer.parentElement; + if (parent == null) { + return null; + } + let index = [].indexOf.call(parent.children, pointer); + if (index == -1) { + return null; + } + path.unshift(index); + pointer = parent.parentElement; + if (pointer == null) { + return null; + } + if (pointer.id === 'menu-toc') { + break; + } + if (pointer.tagName !== 'LI') { + return null; + } + } + return path; +} + +function activateTocPath(path) { + try { + let pointer = document.getElementById('menu-toc'); + for (let index of path) { + pointer = pointer.querySelector('ol').children[index]; + } + pointer.classList.add('active'); + } catch (e) { + // pass + } +} + +function getActiveTocPaths() { + return [...menu.$menu.querySelectorAll('.active')].map(getTocPath).filter(p => p != null); +} + +function initTOCExpansion(visibleItemLimit) { + // Initialize to a reasonable amount of TOC expansion: + // * Expand any full-breadth nesting level up to visibleItemLimit. + // * Expand any *single-item* level while under visibleItemLimit (even if that pushes over it). + + // Limit to initialization by bailing out if any parent item is already expanded. + const tocItems = Array.from(document.querySelectorAll('#menu-toc li')); + if (tocItems.some(li => li.classList.contains('active') && li.querySelector('li'))) { + return; + } + + const selfAndSiblings = maybe => Array.from(maybe?.parentNode.children ?? []); + let currentLevelItems = selfAndSiblings(tocItems[0]); + let availableCount = visibleItemLimit - currentLevelItems.length; + while (availableCount > 0 && currentLevelItems.length) { + const nextLevelItems = currentLevelItems.flatMap(li => selfAndSiblings(li.querySelector('li'))); + availableCount -= nextLevelItems.length; + if (availableCount > 0 || currentLevelItems.length === 1) { + // Expand parent items of the next level down (i.e., current-level items with children). + for (const ol of new Set(nextLevelItems.map(li => li.parentNode))) { + ol.closest('li').classList.add('active'); + } + } + currentLevelItems = nextLevelItems; + } +} + +function initState() { + if (typeof menu === 'undefined' || window.navigating) { + return; + } + const storage = typeof sessionStorage !== 'undefined' ? sessionStorage : Object.create(null); + if (storage.referencePaneState != null) { + let state = JSON.parse(storage.referencePaneState); + if (state != null) { + if (state.type === 'ref') { + let entry = menu.search.biblio.byId[state.id]; + if (entry != null) { + referencePane.showReferencesFor(entry); + } + } else if (state.type === 'sdo') { + let sdos = sdoMap[state.id]; + if (sdos != null) { + referencePane.$headerText.innerHTML = state.html; + referencePane.showSDOsBody(sdos, state.id); + } + } + delete storage.referencePaneState; + } + } + + if (storage.activeTocPaths != null) { + document.querySelectorAll('#menu-toc li.active').forEach(li => li.classList.remove('active')); + let active = JSON.parse(storage.activeTocPaths); + active.forEach(activateTocPath); + delete storage.activeTocPaths; + } else { + initTOCExpansion(20); + } + + if (storage.searchValue != null) { + let value = JSON.parse(storage.searchValue); + menu.search.$searchBox.value = value; + menu.search.search(value); + delete storage.searchValue; + } + + if (storage.tocScroll != null) { + let tocScroll = JSON.parse(storage.tocScroll); + menu.$toc.scrollTop = tocScroll; + delete storage.tocScroll; + } +} + +document.addEventListener('DOMContentLoaded', initState); + +window.addEventListener('pageshow', initState); + +window.addEventListener('beforeunload', () => { + if (!window.sessionStorage || typeof menu === 'undefined') { + return; + } + sessionStorage.referencePaneState = JSON.stringify(referencePane.state || null); + sessionStorage.activeTocPaths = JSON.stringify(getActiveTocPaths()); + sessionStorage.searchValue = JSON.stringify(menu.search.$searchBox.value); + sessionStorage.tocScroll = JSON.stringify(menu.$toc.scrollTop); +}); + +'use strict'; + +// Manually prefix algorithm step list items with hidden counter representations +// corresponding with their markers so they get selected and copied with content. +// We read list-style-type to avoid divergence with the style sheet, but +// for efficiency assume that all lists at the same nesting depth use the same +// style (except for those associated with replacement steps). +// We also precompute some initial items for each supported style type. +// https://w3c.github.io/csswg-drafts/css-counter-styles/ + +const lowerLetters = Array.from({ length: 26 }, (_, i) => + String.fromCharCode('a'.charCodeAt(0) + i), +); +// Implement the lower-alpha 'alphabetic' algorithm, +// adjusting for indexing from 0 rather than 1. +// https://w3c.github.io/csswg-drafts/css-counter-styles/#simple-alphabetic +// https://w3c.github.io/csswg-drafts/css-counter-styles/#alphabetic-system +const lowerAlphaTextForIndex = i => { + let S = ''; + for (const N = lowerLetters.length; i >= 0; i--) { + S = lowerLetters[i % N] + S; + i = Math.floor(i / N); + } + return S; +}; + +const weightedLowerRomanSymbols = Object.entries({ + m: 1000, + cm: 900, + d: 500, + cd: 400, + c: 100, + xc: 90, + l: 50, + xl: 40, + x: 10, + ix: 9, + v: 5, + iv: 4, + i: 1, +}); +// Implement the lower-roman 'additive' algorithm, +// adjusting for indexing from 0 rather than 1. +// https://w3c.github.io/csswg-drafts/css-counter-styles/#simple-numeric +// https://w3c.github.io/csswg-drafts/css-counter-styles/#additive-system +const lowerRomanTextForIndex = i => { + let value = i + 1; + let S = ''; + for (const [symbol, weight] of weightedLowerRomanSymbols) { + if (!value) break; + if (weight > value) continue; + const reps = Math.floor(value / weight); + S += symbol.repeat(reps); + value -= weight * reps; + } + return S; +}; + +// Memoize pure index-to-text functions with an exposed cache for fast retrieval. +const makeCounter = (pureGetTextForIndex, precomputeCount = 30) => { + const cache = Array.from({ length: precomputeCount }, (_, i) => pureGetTextForIndex(i)); + const getTextForIndex = i => { + if (i >= cache.length) cache[i] = pureGetTextForIndex(i); + return cache[i]; + }; + return { getTextForIndex, cache }; +}; + +const counterByStyle = { + __proto__: null, + decimal: makeCounter(i => String(i + 1)), + 'lower-alpha': makeCounter(lowerAlphaTextForIndex), + 'upper-alpha': makeCounter(i => lowerAlphaTextForIndex(i).toUpperCase()), + 'lower-roman': makeCounter(lowerRomanTextForIndex), + 'upper-roman': makeCounter(i => lowerRomanTextForIndex(i).toUpperCase()), +}; +const fallbackCounter = makeCounter(() => '?'); +const counterByDepth = []; + +function addStepNumberText( + ol, + depth = 0, + special = [...ol.classList].some(c => c.startsWith('nested-')), +) { + let counter = !special && counterByDepth[depth]; + if (!counter) { + const counterStyle = getComputedStyle(ol)['list-style-type']; + counter = counterByStyle[counterStyle]; + if (!counter) { + console.warn('unsupported list-style-type', { + ol, + counterStyle, + id: ol.closest('[id]')?.getAttribute('id'), + }); + counterByStyle[counterStyle] = fallbackCounter; + counter = fallbackCounter; + } + if (!special) { + counterByDepth[depth] = counter; + } + } + const { cache, getTextForIndex } = counter; + let i = (Number(ol.getAttribute('start')) || 1) - 1; + for (const li of ol.children) { + const marker = document.createElement('span'); + marker.textContent = `${i < cache.length ? cache[i] : getTextForIndex(i)}. `; + marker.setAttribute('aria-hidden', 'true'); + const attributesContainer = li.querySelector('.attributes-tag'); + if (attributesContainer == null) { + li.prepend(marker); + } else { + attributesContainer.insertAdjacentElement('afterend', marker); + } + for (const sublist of li.querySelectorAll(':scope > ol')) { + addStepNumberText(sublist, depth + 1, special); + } + i++; + } +} + +document.addEventListener('DOMContentLoaded', () => { + document.querySelectorAll('emu-alg > ol').forEach(ol => { + addStepNumberText(ol); + }); +}); + +'use strict'; + +// Update superscripts to not suffer misinterpretation when copied and pasted as plain text. +// For example, +// * Replace `103` with +// `103` +// so it gets pasted as `10**3` rather than `103`. +// * Replace `10-x` with +// `10-x` +// so it gets pasted as `10**-x` rather than `10-x`. +// * Replace `2a + 1` with +// `2**(a + 1)` +// so it gets pasted as `2**(a + 1)` rather than `2a + 1`. + +function makeExponentPlainTextSafe(sup) { + // Change a only if it appears to be an exponent: + // * text-only and contains only mathematical content (not e.g. `1st`) + // * contains only s and internal links (e.g. + // `2(_y_)`) + const isText = [...sup.childNodes].every(node => node.nodeType === 3); + const text = sup.textContent; + if (isText) { + if (!/^[0-9. 𝔽ℝℤ()=*×/÷±+\u2212-]+$/u.test(text)) { + return; + } + } else { + if (sup.querySelector('*:not(var, emu-xref, :scope emu-xref a)')) { + return; + } + } + + let prefix = '**'; + let suffix = ''; + + // Add wrapping parentheses unless they are already present + // or this is a simple (possibly signed) integer or single-variable exponent. + const skipParens = + /^[±+\u2212-]?(?:[0-9]+|\p{ID_Start}\p{ID_Continue}*)$/u.test(text) || + // Split on parentheses and remember them; the resulting parts must + // start and end empty (i.e., with open/close parentheses) + // and increase depth to 1 only at the first parenthesis + // to e.g. wrap `(a+1)*(b+1)` but not `((a+1)*(b+1))`. + text + .trim() + .split(/([()])/g) + .reduce((depth, s, i, parts) => { + if (s === '(') { + return depth > 0 || i === 1 ? depth + 1 : NaN; + } else if (s === ')') { + return depth > 0 ? depth - 1 : NaN; + } else if (s === '' || (i > 0 && i < parts.length - 1)) { + return depth; + } + return NaN; + }, 0) === 0; + if (!skipParens) { + prefix += '('; + suffix += ')'; + } + + sup.insertAdjacentHTML('beforebegin', ``); + if (suffix) { + sup.insertAdjacentHTML('afterend', ``); + } +} + +document.addEventListener('DOMContentLoaded', () => { + document.querySelectorAll('sup:not(.text)').forEach(sup => { + makeExponentPlainTextSafe(sup); + }); +}); + +let sdoMap = JSON.parse(`{}`); +let biblio = JSON.parse(`{"refsByClause":{"sec-error.iserror":["_ref_0"],"sec-iserror":["_ref_1"]},"entries":[{"type":"clause","id":"sec-error.iserror","title":"Error.isError ( arg )","titleHTML":"Error.isError ( arg )","number":"20.5.2.1"},{"type":"clause","id":"sec-properties-of-the-error-constructor","titleHTML":"Properties of the Error Constructor","number":"20.5.2"},{"type":"op","aoid":"IsError","refId":"sec-iserror"},{"type":"clause","id":"sec-iserror","title":"IsError ( argument )","titleHTML":"IsError ( argument )","number":"20.5.8.2","referencingIds":["_ref_0","_ref_1"]},{"type":"clause","id":"sec-abstract-operations-for-error-objects","titleHTML":"Abstract Operations for Error Objects","number":"20.5.8"},{"type":"clause","id":"sec-error-objects","titleHTML":"Error Objects","number":"20.5"},{"type":"clause","id":"sec-fundamental-objects","titleHTML":"Fundamental Objects","number":"20"},{"type":"clause","id":"sec-copyright-and-software-license","title":"Copyright & Software License","titleHTML":"Copyright & Software License","number":"A"}]}`); +;let usesMultipage = false
    +
      +
    • Toggle shortcuts help?
    • +
    • Toggle "can call user code" annotationsu
    • + +
    • Jump to search box/
    • +
    • Toggle pinning of the current clausep
    • +
    • Jump to nth pin1-9
    • +

    Stage 1 Draft / April 10, 2024

    Error.isError

    + + +

    20 Fundamental Objects

    + + +

    20.5 Error Objects

    + + +

    20.5.2 Properties of the Error Constructor

    + + +

    20.5.2.1 Error.isError ( arg )

    + +
    1. Return ? IsError(arg).
    +
    +
    + + +

    20.5.8 Abstract Operations for Error Objects

    + + +

    20.5.8.2 IsError ( argument )

    +

    The abstract operation IsError takes argument argument (an Ecmascript language value) and returns either a normal completion containing a Boolean, or a throw completion. It returns a boolean indicating whether the argument is a built-in Error instance or not. It performs the following steps when called:

    + +
    1. If argument is not an Object, return false.
    2. If argument has an [[ErrorData]] internal slot, return true.
    3. If argument is a Proxy exotic object, then
      1. If argument.[[ProxyHandler]] is null, throw a TypeError exception.
      2. Let target be argument.[[ProxyTarget]].
      3. Return ? IsError(target).
    4. Return false.
    +
    +
    +
    +
    +

    A Copyright & Software License

    + +

    Copyright Notice

    +

    © 2024 Jordan Harband

    -

    Software License

    -

    All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT http://www.ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

    +

    Software License

    +

    All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

    -

    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    +

    Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

    -
      -
    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    2. -
    3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    4. -
    5. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.
    6. -
    +
      +
    1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
    2. +
    3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
    4. +
    5. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.
    6. +
    -

    THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    +

    THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    -
    - \ No newline at end of file + +
    \ No newline at end of file diff --git a/package.json b/package.json index 384401b..318730c 100644 --- a/package.json +++ b/package.json @@ -3,12 +3,14 @@ "version": "0.0.0", "description": "ECMAScript spec proposal for Error.isError", "scripts": { - "build": "ecmarkup spec.emu --js=spec.js --css=spec.css | js-beautify -f - --type=html -t > index.html", - "prepublish": "npm run build && echo >&2 'no publishing' && exit 255" + "prepublish": "npm run build && echo >&2 'no publishing' && exit 255", + "start": "npm run build-loose -- --watch", + "build": "npm run build-loose -- --strict", + "build-loose": "ecmarkup --load-biblio @tc39/ecma262-biblio --verbose spec.emu index.html --lint-spec" }, "repository": { "type": "git", - "url": "git+https://github.com/ljharb/proposal-is-error.git" + "url": "git+https://github.com/tc39/proposal-is-error.git" }, "keywords": [ "Error.isError", @@ -22,12 +24,11 @@ "author": "Jordan Harband ", "license": "MIT", "bugs": { - "url": "https://github.com/ljharb/proposal-is-error/issues" + "url": "https://github.com/tc39/proposal-is-error/issues" }, - "homepage": "https://github.com/ljharb/proposal-is-error#readme", - "dependencies": {}, + "homepage": "https://github.com/tc39/proposal-is-error#readme", "devDependencies": { - "ecmarkup": "^2.8.3", - "js-beautify": "^1.5.10" + "@tc39/ecma262-biblio": "^2.1.2719", + "ecmarkup": "^18.3.1" } } diff --git a/spec.css b/spec.css deleted file mode 100644 index 3e125bb..0000000 --- a/spec.css +++ /dev/null @@ -1,546 +0,0 @@ -body { - font-size: 18px; - line-height: 1.5; - font-family: Cambria, Palatino Linotype, Palatino, Liberation Serif, serif; - padding: 0; - color: #333; - margin: 0 2% 0 31%; -} - -body.oldtoc { - margin: 0 auto; -} - -a { - text-decoration: none; - color: #206ca7; -} - -a:visited { - color: #206ca7; -} - -a:hover { - text-decoration: underline; - color: #239dee; -} - - -code { - font-weight: bold; - font-family: Consolas, Monaco, monospace; - white-space: pre; -} - -pre code { - font-weight: inherit; -} - -pre code.hljs { - background-color: #fff; - margin: 0; - padding: 0; -} - -ol.toc { - list-style: none; - padding-left: 0; -} - -ol.toc ol.toc { - padding-left: 2ex; - list-style: none; -} - -var { - color: #2aa198; - transition: background-color 0.25s ease; - cursor: pointer; -} - -var.referenced { - background-color: #ffff33; -} - -emu-const { - font-family: sans-serif; -} - -emu-val { - font-weight: bold; -} -emu-alg ol, emu-alg ol ol ol ol { - list-style-type: decimal; -} - -emu-alg ol ol, emu-alg ol ol ol ol ol { - list-style-type: lower-alpha; -} - -emu-alg ol ol ol, ol ol ol ol ol ol { - list-style-type: lower-roman; -} - -emu-eqn { - display: block; - margin-left: 4em; -} - -emu-eqn div:first-child { - margin-left: -2em; -} - -emu-eqn.inline { - display: inline; - margin: 0; - white-space: nowrap; -} - -emu-note { - display: block; - margin: 1em 0 1em 6em; - color: #666; -} - -emu-note span.note { - text-transform: uppercase; - margin-left: -6em; - display: block; - float: left; -} - -emu-example { - display: block; - margin: 1em 3em; -} - -emu-example figure figcaption { - margin-top: 0.5em; - text-align: left; -} - -emu-production { - display: block; - margin-top: 1em; - margin-bottom: 1em; - margin-left: 5ex; -} - - -emu-grammar.inline, emu-production.inline, -emu-grammar.inline emu-production emu-rhs, emu-production.inline emu-rhs { - display: inline; -} - -emu-grammar[collapsed] emu-production, emu-production[collapsed] { - margin: 0; -} - -emu-grammar[collapsed] emu-production emu-rhs, emu-production[collapsed] emu-rhs { - display: inline; - padding-left: 1ex; -} - -emu-constraints { - font-size: .75em; - margin-right: 1ex; -} - -emu-gann { - margin-right: 1ex; -} - -emu-gann emu-t:last-child, -emu-gann emu-nt:last-child { - margin-right: 0; -} - -emu-geq { - margin-left: 1ex; - font-weight: bold; -} - -emu-oneof { - font-weight: bold; - margin-left: 1ex; -} - -emu-nt { - display: inline-block; - font-style: italic; - white-space: nowrap; - text-indent: 0; -} - -emu-nt a, emu-nt a:visited { - color: #333; -} - -emu-rhs emu-nt { - margin-right: 1ex; -} - -emu-t { - display: inline-block; - font-family: monospace; - font-weight: bold; - white-space: nowrap; - text-indent: 0; -} - -emu-production emu-t { - margin-right: 1ex; -} - -emu-rhs { - display: block; - padding-left: 75px; - text-indent: -25px; -} - -emu-mods { - font-size: .85em; - vertical-align: sub; - font-style: normal; - font-weight: normal; -} - -emu-production[collapsed] emu-mods { - display: none; -} - -emu-params, emu-opt { - margin-right: 1ex; - font-family: monospace; -} - -emu-params, emu-constraints { - color: #2aa198; -} - -emu-opt { - color: #b58900; -} - -emu-gprose { - font-size: 0.9em; - font-family: Helvetica, Arial, sans-serif; -} - -h1.shortname { - color: #f60; - font-size: 1.5em; - margin: 0; -} -h1.version { - color: #f60; - font-size: 1.5em; - margin: 0; -} -h1.title { - margin-top: 0; - color: #f60; -} -h1, h2, h3, h4, h5, h6 { - position: relative; -} -h1 .secnum { - position: absolute; - text-align: right; - right: 100%; - margin-right: 1ex; - white-space: nowrap; -} - -h1 { font-size: 2.67em; } -h2 { font-size: 2em; } -h3 { font-size: 1.56em; } -h4 { font-size: 1.25em; } -h5 { font-size: 1.11em; } -h6 { font-size: 1em; } - -h1 span.utils, -h2 span.utils, -h3 span.utils, -h4 span.utils, -h5 span.utils, -h6 span.utils { - padding-left: 1em; -} - -h1 span.utils span.anchor a, -h2 span.utils span.anchor a, -h3 span.utils span.anchor a, -h4 span.utils span.anchor a, -h5 span.utils span.anchor a, -h6 span.utils span.anchor a { - color: #ccc; - text-decoration: none; -} - -h1 span.utils span.anchor a:hover, -h2 span.utils span.anchor a:hover, -h3 span.utils span.anchor a:hover, -h4 span.utils span.anchor a:hover, -h5 span.utils span.anchor a:hover, -h6 span.utils span.anchor a:hover { - color: #333; -} - -emu-intro h1, emu-clause h1, emu-annex h1 { font-size: 2em; } -emu-intro h2, emu-clause h2, emu-annex h2 { font-size: 1.56em; } -emu-intro h3, emu-clause h3, emu-annex h3 { font-size: 1.25em; } -emu-intro h4, emu-clause h4, emu-annex h4 { font-size: 1.11em; } -emu-intro h5, emu-clause h5, emu-annex h5 { font-size: 1em; } -emu-intro h6, emu-clause h6, emu-annex h6 { font-size: 0.9em; } -emu-intro emu-intro h1, emu-clause emu-clause h1, emu-annex emu-annex h1 { font-size: 1.56em; } -emu-intro emu-intro h2, emu-clause emu-clause h2, emu-annex emu-annex h2 { font-size: 1.25em; } -emu-intro emu-intro h3, emu-clause emu-clause h3, emu-annex emu-annex h3 { font-size: 1.11em; } -emu-intro emu-intro h4, emu-clause emu-clause h4, emu-annex emu-annex h4 { font-size: 1em; } -emu-intro emu-intro h5, emu-clause emu-clause h5, emu-annex emu-annex h5 { font-size: 0.9em; } -emu-intro emu-intro emu-intro h1, emu-clause emu-clause emu-clause h1, emu-annex emu-annex emu-annex h1 { font-size: 1.25em; } -emu-intro emu-intro emu-intro h2, emu-clause emu-clause emu-clause h2, emu-annex emu-annex emu-annex h2 { font-size: 1.11em; } -emu-intro emu-intro emu-intro h3, emu-clause emu-clause emu-clause h3, emu-annex emu-annex emu-annex h3 { font-size: 1em; } -emu-intro emu-intro emu-intro h4, emu-clause emu-clause emu-clause h4, emu-annex emu-annex emu-annex h4 { font-size: 0.9em; } -emu-intro emu-intro emu-intro emu-intro h1, emu-clause emu-clause emu-clause emu-clause h1, emu-annex emu-annex emu-annex emu-annex h1 { font-size: 1.11em; } -emu-intro emu-intro emu-intro emu-intro h2, emu-clause emu-clause emu-clause emu-clause h2, emu-annex emu-annex emu-annex emu-annex h2 { font-size: 1em; } -emu-intro emu-intro emu-intro emu-intro h3, emu-clause emu-clause emu-clause emu-clause h3, emu-annex emu-annex emu-annex emu-annex h3 { font-size: 0.9em; } -emu-intro emu-intro emu-intro emu-intro emu-intro h1, emu-clause emu-clause emu-clause emu-clause emu-clause h1, emu-annex emu-annex emu-annex emu-annex emu-annex h1 { font-size: 1em; } -emu-intro emu-intro emu-intro emu-intro emu-intro h2, emu-clause emu-clause emu-clause emu-clause emu-clause h2, emu-annex emu-annex emu-annex emu-annex emu-annex h2 { font-size: 0.9em; } -emu-intro emu-intro emu-intro emu-intro emu-intro emu-intro h1, emu-clause emu-clause emu-clause emu-clause emu-clause emu-clause h1, emu-annex emu-annex emu-annex emu-annex emu-annex emu-annex h1 { font-size: 0.9em } - -emu-clause { - display: block; -} - -/* Figures and tables */ -figure { display: block; margin: 1em 0 3em 0; } -figure object { display: block; margin: 0 auto; } -figure table.real-table { margin: 0 auto; } -figure figcaption { - display: block; - color: #555555; - font-weight: bold; - text-align: center; -} - -emu-table table { - margin: 0 auto; -} - -emu-table table, table.real-table { - border-collapse: collapse; -} - -emu-table td, emu-table th, table.real-table td, table.real-table th { - border: 1px solid black; - padding: 0.4em; - vertical-align: baseline; -} -emu-table th, emu-table thead td, table.real-table th { - background-color: #eeeeee; -} - -/* Note: the left content edges of table.lightweight-table >tbody >tr >td - and div.display line up. */ -table.lightweight-table { - border-collapse: collapse; - margin: 0 0 0 1.5em; -} -table.lightweight-table td, table.lightweight-table th { - border: none; - padding: 0 0.5em; - vertical-align: baseline; -} - -/* diff styles */ -ins { - background-color: #e0f8e0; - text-decoration: none; - border-bottom: 1px solid #396; -} - -ins.block { - display: block; -} - -del { - background-color: #fee; -} - -del.block { - display: block; -} - -/* Menu Styles */ -#menu-toggle { - font-size: 2em; - - position: fixed; - top: 0; - left: 0; - width: 1.5em; - height: 1.5em; - z-index: 3; - visibility: hidden; - - background-color: #111; - color: #B6C8E4; - - line-height: 1.5em; - text-align: center; - -webkit-touch-callout: none; - -webkit-user-select: none; - -khtml-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none;; - - cursor: pointer; -} - -#menu { - position: fixed; - left: 0; - top: 0; - height: 100%; - width: 24%; - z-index: 2; - overflow-x: hidden; - overflow-y: auto; - box-sizing: border-box; - - background-color: #111; - - transition: opacity 0.1s linear; -} - -#menu.active { - display: block; - opacity: 1; -} - -#menu-toc > ol { - padding: 0; -} - -#menu-toc > ol , #menu-toc > ol ol { - list-style-type: none; -} - -#menu-toc > ol ol { - padding-left: 0.75em; -} - -#menu-toc li { - text-overflow: ellipsis; - overflow: hidden; - white-space: nowrap; -} - -#menu-toc .item-toggle { - display: inline-block; - transform: rotate(-45deg) translate(-5px, -5px); - transition: transform 0.1s ease; - width: 1em; - - color: #555F6E; - - -webkit-touch-callout: none; - -webkit-user-select: none; - -khtml-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none;; - - cursor: pointer; -} - -#menu-toc .item-toggle-none { - display: inline-block; - width: 1em; -} - -#menu-toc li.active > .item-toggle { - transform: rotate(45deg) translate(-5px, -5px); -} - -#menu-toc li > ol { - display: none; -} - -#menu-toc li.active > ol { - display: block; -} - -#menu-toc li > a { - padding-left: 0.25em; - color: #B6C8E4; -} - -#menu-search { - color: #B6C8E4; -} - -#menu-search-box { - display: block; - width: 90%; - margin: 5px auto; - font-size: 1em; - padding: 2px; -} - -#menu-search-results.inactive { - display: none; -} - -#menu-search-results ul { - list-style-type: square; - padding: 0 0 0 35px; - margin: 0; -} - -#menu-search-results li { - white-space: nowrap; -} - -#menu-search-results a { - color: #b6c8e4; -} - -@media (max-width: 1366px) { - body { - margin: 0 0 0 150px; - } - - #menu { - display: none; - padding-top: 3em; - width: 323px; - } - - #menu-toggle { - visibility: visible; - } -} - -@media only screen and (max-width: 800px) { - body { - margin: 2em 10px 0 10px; - } - - #menu { - width: 100%; - } - - h1 .secnum { - display: inline; - position: inherit; - left: 0; - right: 0; - } - - h1 .secnum:empty { - margin: 0; padding: 0; - } -} diff --git a/spec.emu b/spec.emu index 561a73f..166f046 100644 --- a/spec.emu +++ b/spec.emu @@ -1,30 +1,53 @@ - - - - -

    IsError( argument )

    -

    When the *IsError* abstract operation is called with argument _argument_, the following steps are taken:

    - - 1. If Type(_argument_) is not Object, return *false*. - 1. If _argument_ has an [[ErrorData]] internal slot, return *true*. - 1. If _argument_ is a Proxy exotic object, then - 1. If the value of the [[ProxyHandler]] internal slot of _argument_ is *null*, throw a _TypeError_ exception. - 1. Let _target_ be the value of the [[ProxyTarget]] internal slot of _argument_. - 1. Return IsError(_target_). - 1. Return *false*. - -
    - -

    Error.isError( arg )

    -

    When the *isError* function is called with argument _arg_, the following steps are taken:

    - - 1. Return IsError(_arg_). - + + +

    Fundamental Objects

    + + +

    Error Objects

    + + +

    Properties of the Error Constructor

    + + +

    Error.isError ( _arg_ )

    + + + 1. Return ? IsError(_arg_). + +
    +
    + + +

    Abstract Operations for Error Objects

    + + +

    + IsError( + _argument_: an Ecmascript language value, + ): either a normal completion containing a Boolean, or a throw completion +

    +
    +
    description
    +
    It returns a boolean indicating whether the argument is a built-in Error instance or not.
    +
    + + + 1. If _argument_ is not an Object, return *false*. + 1. If _argument_ has an [[ErrorData]] internal slot, return *true*. + 1. If _argument_ is a Proxy exotic object, then + 1. If _argument_.[[ProxyHandler]] is *null*, throw a TypeError exception. + 1. Let _target_ be _argument_.[[ProxyTarget]]. + 1. Return ? IsError(_target_). + 1. Return *false*. + +
    +
    +
    diff --git a/spec.js b/spec.js deleted file mode 100644 index ebb938a..0000000 --- a/spec.js +++ /dev/null @@ -1,288 +0,0 @@ -"use strict"; - -function Menu() { - this.$toggle = document.getElementById('menu-toggle'); - this.$menu = document.getElementById('menu'); - this.$searchBox = document.getElementById('menu-search-box'); - this.$searchResults = document.getElementById('menu-search-results'); - this.initSearch(); - - this.$toggle.addEventListener('click', this.toggle.bind(this)); - - this.$searchBox.addEventListener('keydown', function (e) { - if (e.keyCode === 191 && e.target.value.length === 0) { - e.preventDefault(); - e.stopPropagation(); - } else if (e.keyCode === 13) { - e.preventDefault(); - e.stopPropagation(); - this.selectResult(); - } - }.bind(this)); - - this.$searchBox.addEventListener('keyup', debounce(function (e) { - e.stopPropagation(); - this.search(e.target.value); - }.bind(this))); - - - var tocItems = this.$menu.querySelectorAll('#menu-toc li'); - for (var i = 0; i < tocItems.length; i++) { - var $item = tocItems[i]; - $item.addEventListener('click', function($item, event) { - $item.classList.toggle('active'); - event.stopPropagation(); - }.bind(null, $item)); - } - - var tocLinks = this.$menu.querySelectorAll('#menu-toc li > a'); - for (var i = 0; i < tocLinks.length; i++) { - var $link = tocLinks[i]; - $link.addEventListener('click', function(event) { - this.toggle(); - event.stopPropagation(); - }.bind(this)); - } -} - -Menu.prototype.toggle = function () { - this.$menu.classList.toggle('active'); -} - -Menu.prototype.show = function () { - this.$menu.classList.add('active'); -} - -Menu.prototype.hide = function () { - this.$menu.classList.remove('active'); -} - -Menu.prototype.isVisible = function() { - return this.$menu.classList.contains('active'); -} - -Menu.prototype.initSearch = function () { - var $biblio = document.getElementById('menu-search-biblio'); - if (!$biblio) { - this.biblio = {}; - } else { - this.biblio = JSON.parse($biblio.textContent); - } - - document.addEventListener('keydown', function (e) { - if (e.keyCode === 191) { - e.preventDefault(); - e.stopPropagation(); - - if(this.isVisible()) { - this._closeAfterSearch = false; - } else { - this._closeAfterSearch = true; - this.show(); - } - - this.show(); - this.$searchBox.focus(); - } - }.bind(this)) -} - -Menu.prototype.search = function (needle) { - if (needle.length < 2) { - this.hideSearch(); - } else { - this.showSearch(); - } - - needle = needle.toLowerCase(); - - var results = {}; - var seenClauses = {}; - - results.ops = Object.keys(this.biblio.ops).map(function (k) { - return this.biblio.ops[k]; - }.bind(this)).filter(function(op) { - return fuzzysearch(needle, op.aoid.toLowerCase()); - }); - - results.ops.forEach(function(op) { - seenClauses[op.id] = true; - }); - - results.productions = Object.keys(this.biblio.productions).map(function (k) { - return this.biblio.productions[k]; - }.bind(this)).filter(function(prod) { - return fuzzysearch(needle, prod.name.toLowerCase()); - }); - - results.clauses = Object.keys(this.biblio.clauses).map(function (k) { - return this.biblio.clauses[k]; - }.bind(this)).filter(function(clause) { - return !seenClauses[clause.id] && (clause.number.indexOf(needle) === 0 || fuzzysearch(needle, clause.title.toLowerCase())); - }); - - if (results.length > 50) { - results = results.slice(0, 50); - } - - this.displayResults(results); -} - -Menu.prototype.displayResults = function (results) { - var totalResults = Object.keys(results).reduce(function (sum, record) { return sum + record.length }, 0); - - if (totalResults > 0) { - this.$searchResults.classList.remove('no-results'); - - var html = '' - - this.$searchResults.innerHTML = html; - } else { - this.$searchResults.classList.add('no-results'); - } -} - -Menu.prototype.hideSearch = function () { - this.$searchResults.classList.add('inactive'); -} - -Menu.prototype.showSearch = function () { - this.$searchResults.classList.remove('inactive'); -} - -Menu.prototype.selectResult = function () { - var $first = this.$searchResults.querySelector('li:first-child a'); - - if ($first) { - document.location = $first.getAttribute('href'); - } - - this.$searchBox.value = ''; - this.$searchBox.blur(); - this.hideSearch(); - - if (this._closeAfterSearch) { - this.hide(); - } -} - -function init() { - var menu = new Menu(); -} - -document.addEventListener('DOMContentLoaded', init); - -function debounce(fn) { - var timeout; - return function() { - var args = arguments; - if (timeout) { - clearTimeout(timeout); - } - timeout = setTimeout(function() { - timeout = null; - fn.apply(this, args); - }.bind(this), 150); - } -} - -// The following license applies to the fuzzysearch function -// The MIT License (MIT) -// Copyright © 2015 Nicolas Bevacqua -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: - -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. - -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -function fuzzysearch (needle, haystack) { - var tlen = haystack.length; - var qlen = needle.length; - if (qlen > tlen) { - return false; - } - if (qlen === tlen) { - return needle === haystack; - } - outer: for (var i = 0, j = 0; i < qlen; i++) { - var nch = needle.charCodeAt(i); - while (j < tlen) { - if (haystack.charCodeAt(j++) === nch) { - continue outer; - } - } - return false; - } - return true; -} -var CLAUSE_NODES = ['EMU-CLAUSE', 'EMU-INTRO', 'EMU-ANNEX']; -function findLocalReferences ($elem) { - var name = $elem.innerHTML; - var references = []; - - var parentClause = $elem.parentNode; - while (parentClause && CLAUSE_NODES.indexOf(parentClause.nodeName) === -1) { - parentClause = parentClause.parentNode; - } - - if(!parentClause) return; - - var vars = parentClause.querySelectorAll('var'); - - for (var i = 0; i < vars.length; i++) { - var $var = vars[i]; - - if ($var.innerHTML === name) { - references.push($var); - } - } - - return references; -} - -function toggleFindLocalReferences($elem) { - var references = findLocalReferences($elem); - if ($elem.classList.contains('referenced')) { - references.forEach(function ($reference) { - $reference.classList.remove('referenced'); - }); - } else { - references.forEach(function ($reference) { - $reference.classList.add('referenced'); - }); - } -} - -function installFindLocalReferences () { - document.addEventListener('click', function (e) { - if (e.target.nodeName === 'VAR') { - toggleFindLocalReferences(e.target); - } - }); -} - -document.addEventListener('DOMContentLoaded', installFindLocalReferences); diff --git a/spec.md b/spec.md deleted file mode 100644 index c3018d0..0000000 --- a/spec.md +++ /dev/null @@ -1,13 +0,0 @@ -# IsError Abstract Operation - 1. If Type(_argument_) is not Object, return **false**. - 1. If _argument_ has an [[ErrorData]] internal slot, return **true**. - 1. If _argument_ is a Proxy exotic object, then - 1. If the value of the [[ProxyHandler]] internal slot of _argument_ is **null**, throw a _TypeError_ exception. - 1. Let _target_ be the value of the [[ProxyTarget]] internal slot of _argument_. - 1. Return IsError(_target_). - 1. Return **false**. - -# Error.isError( arg ) - -When the _isError_ function is called with argument _arg_, the following steps are taken: - 1. Return IsError(_arg_).