Skip to content

Commit dd76c3e

Browse files
committed
first draft
1 parent 9828929 commit dd76c3e

File tree

6 files changed

+93
-77
lines changed

6 files changed

+93
-77
lines changed

.prettierrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"quoteProps": "consistent",
3+
"singleQuote": true,
4+
"trailingComma": "all"
5+
}

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.codeActionsOnSave": {
4+
"source.fixAll": true
5+
},
6+
"files.associations": {
7+
"/spec.emu": "plain"
8+
}
9+
}

README.md

Lines changed: 65 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,65 @@
1-
# template-for-proposals
2-
3-
A repository template for ECMAScript proposals.
4-
5-
## Before creating a proposal
6-
7-
Please ensure the following:
8-
1. You have read the [process document](https://tc39.github.io/process-document/)
9-
1. You have reviewed the [existing proposals](https://github.com/tc39/proposals/)
10-
1. You are aware that your proposal requires being a member of TC39, or locating a TC39 delegate to "champion" your proposal
11-
12-
## Create your proposal repo
13-
14-
Follow these steps:
15-
1. Click the green ["use this template"](https://github.com/tc39/template-for-proposals/generate) button in the repo header. (Note: Do not fork this repo in GitHub's web interface, as that will later prevent transfer into the TC39 organization)
16-
1. Go to your repo settings “Options” page, under “GitHub Pages”, and set the source to the **main branch** under the root (and click Save, if it does not autosave this setting)
17-
1. check "Enforce HTTPS"
18-
1. On "Options", under "Features", Ensure "Issues" is checked, and disable "Wiki", and "Projects" (unless you intend to use Projects)
19-
1. Under "Merge button", check "automatically delete head branches"
20-
<!--
21-
1. Avoid merge conflicts with build process output files by running:
22-
```sh
23-
git config --local --add merge.output.driver true
24-
git config --local --add merge.output.driver true
25-
```
26-
1. Add a post-rewrite git hook to auto-rebuild the output on every commit:
27-
```sh
28-
cp hooks/post-rewrite .git/hooks/post-rewrite
29-
chmod +x .git/hooks/post-rewrite
30-
```
31-
-->
32-
1. ["How to write a good explainer"][explainer] explains how to make a good first impression.
33-
34-
> Each TC39 proposal should have a `README.md` file which explains the purpose
35-
> of the proposal and its shape at a high level.
36-
>
37-
> ...
38-
>
39-
> The rest of this page can be used as a template ...
40-
41-
Your explainer can point readers to the `index.html` generated from `spec.emu`
42-
via markdown like
43-
44-
```markdown
45-
You can browse the [ecmarkup output](https://ACCOUNT.github.io/PROJECT/)
46-
or browse the [source](https://github.com/ACCOUNT/PROJECT/blob/HEAD/spec.emu).
47-
```
48-
49-
where *ACCOUNT* and *PROJECT* are the first two path elements in your project's Github URL.
50-
For example, for github.com/**tc39**/**template-for-proposals**, *ACCOUNT* is "tc39"
51-
and *PROJECT* is "template-for-proposals".
52-
53-
54-
## Maintain your proposal repo
55-
56-
1. Make your changes to `spec.emu` (ecmarkup uses HTML syntax, but is not HTML, so I strongly suggest not naming it ".html")
57-
1. Any commit that makes meaningful changes to the spec, should run `npm run build` and commit the resulting output.
58-
1. Whenever you update `ecmarkup`, run `npm run build` and commit any changes that come from that dependency.
59-
60-
[explainer]: https://github.com/tc39/how-we-work/blob/HEAD/explainer.md
1+
# proposal-arraybuffer-equals
2+
3+
This is a proposal to add a new method, `equals(b: ArrayBuffer)`, to JavaScript's `ArrayBuffer` class. It has not yet been presented to the JavaScript standards committee.
4+
5+
## The problem
6+
7+
```typescript
8+
const encoder = new TextEncoder();
9+
const input = 'sample';
10+
const a = encoder.encode(input);
11+
const b = encoder.encode(input);
12+
console.log(a === b); // returns false
13+
console.log(a == b); // returns false
14+
```
15+
16+
The re-definition [Abstract Equality Comparison](https://tc39.es/ecma262/#sec-abstract-equality-comparison) or [Strict Equality Comparison](https://tc39.es/ecma262/#sec-strict-equality-comparison) is break change behavior.
17+
18+
So we need to **define a new method**,
19+
20+
## How compare two ArrayBuffer object is equality
21+
22+
To solve this problem, you need to define a method.
23+
24+
```typescript
25+
// The is TypeScript code
26+
function isEquals(a: ArrayBuffer, b: ArrayBuffer) {
27+
if (!(a instanceof ArrayBuffer)) {
28+
throw new TypeError();
29+
} else if (!(b instanceof ArrayBuffer)) {
30+
throw new TypeError();
31+
} else if (a === b) {
32+
return true;
33+
} else if (a.byteLength !== b.byteLength) {
34+
return false;
35+
}
36+
const view1 = new DataView(a);
37+
const view2 = new DataView(b);
38+
for (let i = 0; i < view1.byteLength; i++) {
39+
if (view1.getUint8(i) !== view2.getUint8(i)) {
40+
return false;
41+
}
42+
}
43+
return true;
44+
}
45+
```
46+
47+
## `ArrayBuffer.isEquals`
48+
49+
To do this, we propose a new method, `ArrayBuffer.isEquals(a, b)`, which compare two array buffer is equality (bit-wise)
50+
51+
```typescript
52+
// returns false
53+
ArrayBuffer.isEquals(Uint8Array.of(0), undefined);
54+
// returns false
55+
ArrayBuffer.isEquals(Uint8Array.of(0), null);
56+
// returns false
57+
ArrayBuffer.isEquals(Uint8Array.of(0), Uint8Array.of(0, 1));
58+
// returns true
59+
ArrayBuffer.isEquals(Uint8Array.of(0), Uint8Array.of(0));
60+
// returns true
61+
ArrayBuffer.isEquals(
62+
Uint32Array.from([Number.MAX_SAFE_INTEGER]).buffer,
63+
Uint8Array.of(255, 255, 255, 255).buffer,
64+
);
65+
```

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<link rel="stylesheet" href="./spec.css">
44
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
55
<script src="./spec.js"></script>
6-
<title>Proposal Title Goes Here</title><script type="application/json" id="menu-search-biblio">[{"type":"clause","id":"sec-demo-clause","aoid":null,"title":"This is an emu-clause","titleHTML":"This is an emu-clause","number":"1","namespace":"<no location>","location":"","referencingIds":[],"key":"This is an emu-clause"},{"type":"clause","id":"sec-copyright-and-software-license","aoid":null,"title":"Copyright & Software License","titleHTML":"Copyright &amp; Software License","number":"A","namespace":"<no location>","location":"","referencingIds":[],"key":"Copyright & Software License"}]</script><script>"use strict";
6+
<title>Proposal ArrayBuffer.isEquals</title><script type="application/json" id="menu-search-biblio">[{"type":"clause","id":"sec-demo-clause","aoid":null,"title":"ArrayBuffer.isEquals ( a , b)","titleHTML":"ArrayBuffer.isEquals ( <var>a</var> , <var>b</var>)","number":"1","namespace":"<no location>","location":"","referencingIds":[],"key":"ArrayBuffer.isEquals ( a , b)"},{"type":"clause","id":"sec-copyright-and-software-license","aoid":null,"title":"Copyright & Software License","titleHTML":"Copyright &amp; Software License","number":"A","namespace":"<no location>","location":"","referencingIds":[],"key":"Copyright & Software License"}]</script><script>"use strict";
77
88
function Search(menu) {
99
this.menu = menu;
@@ -1845,17 +1845,17 @@
18451845
display: none;
18461846
}
18471847
}
1848-
</style></head><body><div id="menu-toggle">☰</div><div id="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins</div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-demo-clause" title="This is an emu-clause"><span class="secnum">1</span> This is an emu-clause</a></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright &amp; Software License"><span class="secnum">A</span> Copyright &amp; Software License</a></li></ol></div></div><div id="spec-container"><h1 class="version first">Stage -1 Draft / August 1, 2020</h1><h1 class="title">Proposal Title Goes Here</h1>
1848+
</style></head><body><div id="menu-toggle">☰</div><div id="menu-spacer"></div><div id="menu"><div id="menu-search"><input type="text" id="menu-search-box" placeholder="Search..."><div id="menu-search-results" class="inactive"></div></div><div id="menu-pins"><div class="menu-pane-header">Pins</div><ul id="menu-pins-list"></ul></div><div class="menu-pane-header">Table of Contents</div><div id="menu-toc"><ol class="toc"><li><span class="item-toggle-none"></span><a href="#sec-demo-clause" title="ArrayBuffer.isEquals ( a , b)"><span class="secnum">1</span> ArrayBuffer.isEquals ( <var>a</var> , <var>b</var>)</a></li><li><span class="item-toggle-none"></span><a href="#sec-copyright-and-software-license" title="Copyright &amp; Software License"><span class="secnum">A</span> Copyright &amp; Software License</a></li></ol></div></div><div id="spec-container"><h1 class="version first">Stage -1 Draft / August 4, 2020</h1><h1 class="title">Proposal ArrayBuffer.isEquals</h1>
18491849

18501850
<emu-clause id="sec-demo-clause">
1851-
<h1><span class="secnum">1</span> This is an emu-clause</h1>
1851+
<h1><span class="secnum">1</span> ArrayBuffer.isEquals ( <var>a</var> , <var>b</var>)</h1>
18521852
<p>This is an algorithm:</p>
18531853
<emu-alg><ol><li>Let <var>proposal</var> be <emu-val>undefined</emu-val>.</li><li>If IsAccepted(<var>proposal</var>),<ol><li>Let <var>stage</var> be <emu-val>0</emu-val>.</li></ol></li><li>Else,<ol><li>Let <var>stage</var> be <emu-val>-1</emu-val>.</li></ol></li><li>Return ?&nbsp;<emu-xref aoid="ToString" id="_ref_0"><a href="https://tc39.es/ecma262/#sec-tostring">ToString</a></emu-xref>(<var>proposal</var>).</li></ol></emu-alg>
18541854
</emu-clause><emu-annex id="sec-copyright-and-software-license">
18551855
<h1><span class="secnum">A</span> Copyright &amp; Software License</h1>
18561856

18571857
<h2>Copyright Notice</h2>
1858-
<p>© 2020 Your Name(s) Here</p>
1858+
<p>© 2020 Septs</p>
18591859

18601860
<h2>Software License</h2>
18611861
<p>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.</p>

package.json

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
{
2+
"name": "proposals-arraybuffer-equals",
23
"private": true,
3-
"name": "template-for-proposals",
4-
"description": "A repository template for ECMAScript proposals.",
4+
"description": " for ECMAScript proposals.",
5+
"homepage": "https://github.com/NiceLabs/proposals-arraybuffer-equals",
6+
"repository": "https://github.com/NiceLabs/proposals-arraybuffer-equals",
7+
"license": "MIT",
58
"scripts": {
6-
"start": "npm run build -- --watch",
7-
"build": "ecmarkup spec.emu index.html"
8-
},
9-
"homepage": "https://github.com/tc39/template-for-proposals#readme",
10-
"repository": {
11-
"type": "git",
12-
"url": "git+https://github.com/tc39/template-for-proposals.git"
9+
"build": "ecmarkup spec.emu index.html",
10+
"start": "npm run build -- --watch"
1311
},
14-
"license": "MIT",
1512
"devDependencies": {
1613
"ecmarkup": "^3.25.3"
1714
}

spec.emu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
55
<script src="./spec.js"></script>
66
<pre class="metadata">
7-
title: Proposal Title Goes Here
7+
title: Proposal ArrayBuffer.isEquals
88
stage: -1
9-
contributors: Your Name(s) Here
9+
contributors: Septs
1010
</pre>
1111

1212
<emu-clause id="sec-demo-clause">
13-
<h1>This is an emu-clause</h1>
13+
<h1>ArrayBuffer.isEquals ( _a_ , _b_)</h1>
1414
<p>This is an algorithm:</p>
1515
<emu-alg>
1616
1. Let _proposal_ be *undefined*.

0 commit comments

Comments
 (0)