summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2023-01-13 01:48:18 +0100
committerGitHub <noreply@github.com>2023-01-13 01:48:18 +0100
commitf5847a95667aa00caa4956609e2e74fdeadee9d5 (patch)
tree1c31b1ca74eff05342b86cb9678d6a1ded7ff533
parentb4f32c8d14a7d4a274a24f631a84e79e7401ae41 (diff)
fix(webidl): properly implement setlike (#17363)
-rw-r--r--ext/webgpu/src/01_webgpu.js59
-rw-r--r--ext/webidl/00_webidl.js112
2 files changed, 119 insertions, 52 deletions
diff --git a/ext/webgpu/src/01_webgpu.js b/ext/webgpu/src/01_webgpu.js
index 02bdc6562..792267bda 100644
--- a/ext/webgpu/src/01_webgpu.js
+++ b/ext/webgpu/src/01_webgpu.js
@@ -34,14 +34,9 @@
SafeArrayIterator,
SafePromiseAll,
Set,
- SetPrototypeEntries,
- SetPrototypeForEach,
SetPrototypeHas,
- SetPrototypeKeys,
- SetPrototypeValues,
Symbol,
SymbolFor,
- SymbolIterator,
TypeError,
Uint32Array,
Uint32ArrayPrototype,
@@ -602,60 +597,20 @@
function createGPUSupportedFeatures(features) {
/** @type {GPUSupportedFeatures} */
- const adapterFeatures = webidl.createBranded(GPUSupportedFeatures);
- adapterFeatures[_features] = new Set(features);
- return adapterFeatures;
+ const supportedFeatures = webidl.createBranded(GPUSupportedFeatures);
+ supportedFeatures[webidl.setlikeInner] = new Set(features);
+ return webidl.setlike(
+ supportedFeatures,
+ GPUSupportedFeaturesPrototype,
+ true,
+ );
}
class GPUSupportedFeatures {
- /** @type {Set<string>} */
- [_features];
-
constructor() {
webidl.illegalConstructor();
}
- /** @return {IterableIterator<[string, string]>} */
- entries() {
- webidl.assertBranded(this, GPUSupportedFeaturesPrototype);
- return SetPrototypeEntries(this[_features]);
- }
-
- /** @return {void} */
- forEach(callbackfn, thisArg) {
- webidl.assertBranded(this, GPUSupportedFeaturesPrototype);
- SetPrototypeForEach(this[_features], callbackfn, thisArg);
- }
-
- /** @return {boolean} */
- has(value) {
- webidl.assertBranded(this, GPUSupportedFeaturesPrototype);
- return SetPrototypeHas(this[_features], value);
- }
-
- /** @return {IterableIterator<string>} */
- keys() {
- webidl.assertBranded(this, GPUSupportedFeaturesPrototype);
- return SetPrototypeKeys(this[_features]);
- }
-
- /** @return {IterableIterator<string>} */
- values() {
- webidl.assertBranded(this, GPUSupportedFeaturesPrototype);
- return SetPrototypeValues(this[_features]);
- }
-
- /** @return {number} */
- get size() {
- webidl.assertBranded(this, GPUSupportedFeaturesPrototype);
- return this[_features].size;
- }
-
- [SymbolIterator]() {
- webidl.assertBranded(this, GPUSupportedFeaturesPrototype);
- return this[_features][SymbolIterator]();
- }
-
[SymbolFor("Deno.privateCustomInspect")](inspect) {
return `${this.constructor.name} ${
inspect([...new SafeArrayIterator(this.values())])
diff --git a/ext/webidl/00_webidl.js b/ext/webidl/00_webidl.js
index 4f51edfed..a71993c87 100644
--- a/ext/webidl/00_webidl.js
+++ b/ext/webidl/00_webidl.js
@@ -61,6 +61,14 @@
ReflectOwnKeys,
RegExpPrototypeTest,
Set,
+ SetPrototypeEntries,
+ SetPrototypeForEach,
+ SetPrototypeKeys,
+ SetPrototypeValues,
+ SetPrototypeHas,
+ SetPrototypeClear,
+ SetPrototypeDelete,
+ SetPrototypeAdd,
// TODO(lucacasonato): add SharedArrayBuffer to primordials
// SharedArrayBuffer,
String,
@@ -1048,6 +1056,108 @@
});
}
+ const setlikeInner = Symbol("[[set]]");
+
+ // Ref: https://webidl.spec.whatwg.org/#es-setlike
+ function setlike(obj, objPrototype, readonly) {
+ ObjectDefineProperties(obj, {
+ size: {
+ configurable: true,
+ enumerable: true,
+ get() {
+ assertBranded(this, objPrototype);
+ return obj[setlikeInner].size;
+ },
+ },
+ [SymbolIterator]: {
+ configurable: true,
+ enumerable: false,
+ writable: true,
+ value() {
+ assertBranded(this, objPrototype);
+ return obj[setlikeInner][SymbolIterator]();
+ },
+ },
+ entries: {
+ configurable: true,
+ enumerable: true,
+ writable: true,
+ value() {
+ assertBranded(this, objPrototype);
+ return SetPrototypeEntries(obj[setlikeInner]);
+ },
+ },
+ keys: {
+ configurable: true,
+ enumerable: true,
+ writable: true,
+ value() {
+ assertBranded(this, objPrototype);
+ return SetPrototypeKeys(obj[setlikeInner]);
+ },
+ },
+ values: {
+ configurable: true,
+ enumerable: true,
+ writable: true,
+ value() {
+ assertBranded(this, objPrototype);
+ return SetPrototypeValues(obj[setlikeInner]);
+ },
+ },
+ forEach: {
+ configurable: true,
+ enumerable: true,
+ writable: true,
+ value(callbackfn, thisArg) {
+ assertBranded(this, objPrototype);
+ return SetPrototypeForEach(obj[setlikeInner], callbackfn, thisArg);
+ },
+ },
+ has: {
+ configurable: true,
+ enumerable: true,
+ writable: true,
+ value(value) {
+ assertBranded(this, objPrototype);
+ return SetPrototypeHas(obj[setlikeInner], value);
+ },
+ },
+ });
+
+ if (!readonly) {
+ ObjectDefineProperties(obj, {
+ add: {
+ configurable: true,
+ enumerable: true,
+ writable: true,
+ value(value) {
+ assertBranded(this, objPrototype);
+ return SetPrototypeAdd(obj[setlikeInner], value);
+ },
+ },
+ delete: {
+ configurable: true,
+ enumerable: true,
+ writable: true,
+ value(value) {
+ assertBranded(this, objPrototype);
+ return SetPrototypeDelete(obj[setlikeInner], value);
+ },
+ },
+ clear: {
+ configurable: true,
+ enumerable: true,
+ writable: true,
+ value() {
+ assertBranded(this, objPrototype);
+ return SetPrototypeClear(obj[setlikeInner]);
+ },
+ },
+ });
+ }
+ }
+
window.__bootstrap ??= {};
window.__bootstrap.webidl = {
type,
@@ -1068,5 +1178,7 @@
illegalConstructor,
mixinPairIterable,
configurePrototype,
+ setlike,
+ setlikeInner,
};
})(this);