diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-04 12:41:41 +0000 |
commit | 10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87 (patch) | |
tree | bdffd5d80c26cf4a7a518281a204be1ace85b4c1 /vendor/js-sys/tests/wasm/Symbol.js | |
parent | Releasing progress-linux version 1.70.0+dfsg1-9~progress7.99u1. (diff) | |
download | rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.tar.xz rustc-10ee2acdd26a7f1298c6f6d6b7af9b469fe29b87.zip |
Merging upstream version 1.70.0+dfsg2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'vendor/js-sys/tests/wasm/Symbol.js')
-rw-r--r-- | vendor/js-sys/tests/wasm/Symbol.js | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/vendor/js-sys/tests/wasm/Symbol.js b/vendor/js-sys/tests/wasm/Symbol.js new file mode 100644 index 000000000..a66691fd9 --- /dev/null +++ b/vendor/js-sys/tests/wasm/Symbol.js @@ -0,0 +1,162 @@ +const assert = require('assert'); + +exports.test_has_instance = function(sym) { + class Array1 { + static [sym](instance) { + return Array.isArray(instance); + } + } + + assert.equal(typeof sym, "symbol"); + assert.ok([] instanceof Array1); +}; + +exports.test_is_concat_spreadable = function(sym) { + const alpha = ['a', 'b', 'c']; + const numeric = [1, 2, 3]; + let alphaNumeric = alpha.concat(numeric); + + assert.deepEqual(alphaNumeric, ["a", "b", "c", 1, 2, 3]); + + numeric[sym] = false; + alphaNumeric = alpha.concat(numeric); + + assert.deepEqual(alphaNumeric, ["a", "b", "c", numeric]); +}; + +exports.test_iterator = function(sym) { + const iterable1 = new Object(); + + iterable1[sym] = function* () { + yield 1; + yield 2; + yield 3; + }; + + assert.deepEqual([...iterable1], [1, 2, 3]); +}; + +exports.test_async_iterator = async function(sym) { + const iterable1 = new Object(); + + iterable1[sym] = function () { + let done = false; + + return { + next() { + if (done) { + return Promise.resolve({ + done: true, + value: 1 + }); + + } else { + done = true; + + return Promise.resolve({ + done: false, + value: 0 + }); + } + } + }; + }; + + const values = []; + + for await (let value of iterable1) { + values.push(value); + } + + assert.deepEqual(values, [0]); +}; + +exports.test_match = function(sym) { + const regexp1 = /foo/; + assert.throws(() => '/foo/'.startsWith(regexp1)); + + regexp1[sym] = false; + + assert.ok('/foo/'.startsWith(regexp1)); + + assert.equal('/baz/'.endsWith(regexp1), false); +}; + +exports.test_replace = function(sym) { + class Replace1 { + constructor(value) { + this.value = value; + } + [sym](string) { + return `s/${string}/${this.value}/g`; + } + } + + assert.equal('foo'.replace(new Replace1('bar')), 's/foo/bar/g'); +}; + +exports.test_search = function(sym) { + class Search1 { + constructor(value) { + this.value = value; + } + + [sym](string) { + return string.indexOf(this.value); + } + } + + assert.equal('foobar'.search(new Search1('bar')), 3); +}; + +exports.test_species = function(sym) { + class Array1 extends Array { + static get [sym]() { return Array; } + } + + const a = new Array1(1, 2, 3); + const mapped = a.map(x => x * x); + + assert.equal(mapped instanceof Array1, false); + + assert.ok(mapped instanceof Array); +}; + +exports.test_split = function(sym) { + class Split1 { + constructor(value) { + this.value = value; + } + + [sym](string) { + var index = string.indexOf(this.value); + return this.value + string.substr(0, index) + "/" + + string.substr(index + this.value.length); + } + } + + assert.equal('foobar'.split(new Split1('foo')), 'foo/bar'); +}; + +exports.test_to_primitive = function(sym) { + const object1 = { + [sym](hint) { + if (hint == 'number') { + return 42; + } + return null; + } + }; + + assert.equal(+object1, 42); +}; + +exports.test_to_string_tag = function(sym) { + class ValidatorClass { + get [sym]() { + return 'Validator'; + } + } + + assert.equal(Object.prototype.toString.call(new ValidatorClass()), '[object Validator]'); +}; |