From 467a0fe68f633fabde77df94d993c45e840627a0 Mon Sep 17 00:00:00 2001 From: Rezvan Mahdavi Hezaveh Date: Thu, 23 Nov 2023 05:23:25 -0800 Subject: [PATCH] [test262] Add staging tests for isSubsetOf set method This CL adds three tests to staging directory of test262. Bug: v8:13556 Change-Id: Id6e468a0fa29528350a10c94e9dd19c2835788e8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/5055866 Reviewed-by: Liviu Rau Commit-Queue: Liviu Rau Cr-Commit-Position: refs/heads/main@{#91139} --- test/staging/set-is-subset-on-set-like.js | 24 +++++++++++++++ .../set-is-subset-table-receiver-cleared.js | 25 ++++++++++++++++ .../staging/set-is-subset-table-transition.js | 29 +++++++++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 test/staging/set-is-subset-on-set-like.js create mode 100644 test/staging/set-is-subset-table-receiver-cleared.js create mode 100644 test/staging/set-is-subset-table-transition.js diff --git a/test/staging/set-is-subset-on-set-like.js b/test/staging/set-is-subset-on-set-like.js new file mode 100644 index 00000000000..456a4227eb8 --- /dev/null +++ b/test/staging/set-is-subset-on-set-like.js @@ -0,0 +1,24 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Test isSubsetOf set method on a set like with equal size. +features: [set-methods] +---*/ + +const SetLike = { + arr: [42, 44, 45], + size: 3, + keys() { + return this.arr[Symbol.iterator](); + }, + has(key) { + return this.arr.indexOf(key) != -1; + } +}; + +const firstSet = new Set(); +firstSet.add(42); +firstSet.add(43); +firstSet.add(45); + +assert.sameValue(firstSet.isSubsetOf(SetLike), false); diff --git a/test/staging/set-is-subset-table-receiver-cleared.js b/test/staging/set-is-subset-table-receiver-cleared.js new file mode 100644 index 00000000000..ae549c148f4 --- /dev/null +++ b/test/staging/set-is-subset-table-receiver-cleared.js @@ -0,0 +1,25 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Test isSubsetOf set method receiver is cleared. +features: [set-methods] +---*/ + +const firstSet = new Set(); +firstSet.add(42); +firstSet.add(43); + +const otherSet = new Set(); +otherSet.add(42); +otherSet.add(43); +otherSet.add(47); + +Object.defineProperty(otherSet, 'size', { + get: function() { + firstSet.clear(); + return 3; + }, + +}); + +assert.sameValue(firstSet.isSubsetOf(otherSet), true); diff --git a/test/staging/set-is-subset-table-transition.js b/test/staging/set-is-subset-table-transition.js new file mode 100644 index 00000000000..b5641355e2d --- /dev/null +++ b/test/staging/set-is-subset-table-transition.js @@ -0,0 +1,29 @@ +// Copyright (C) 2023 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: Test isSubsetOf set method after table transition in receiver. +features: [set-methods] +---*/ + +const firstSet = new Set(); +firstSet.add(42); +firstSet.add(43); +firstSet.add(44); + +const setLike = { + size: 5, + keys() { + return [1, 2, 3, 4, 5].keys(); + }, + has(key) { + if (key == 42) { + // Cause a table transition in the receiver. + firstSet.clear(); + } + // Return true so we keep iterating the transitioned receiver. + return true; + } +}; + +assert.sameValue(firstSet.isSubsetOf(setLike), true); +assert.sameValue(firstSet.size, 0);