mirror of
https://github.com/fluencelabs/wasm-bindgen
synced 2025-07-29 19:11:56 +00:00
.cargo
crates
backend
cli
cli-support
futures
gc
js-sys
src
tests
wasm
Array.rs
ArrayBuffer.rs
ArrayIterator.rs
Boolean.rs
DataView.rs
Date.rs
Error.rs
EvalError.rs
Function.js
Function.rs
Generator.js
Generator.rs
Intl.rs
Iterator.js
Iterator.rs
JSON.rs
JsString.js
JsString.rs
Map.rs
MapIterator.rs
Math.rs
Number.rs
Object.js
Object.rs
Promise.rs
Proxy.js
Proxy.rs
RangeError.rs
ReferenceError.rs
Reflect.js
Reflect.rs
RegExp.rs
Set.rs
SetIterator.rs
Symbol.js
Symbol.rs
SyntaxError.rs
TypeError.rs
TypedArray.rs
UriError.rs
WeakMap.rs
WeakSet.rs
WebAssembly.js
WebAssembly.rs
global_fns.rs
main.rs
headless.js
headless.rs
CHANGELOG.md
Cargo.toml
README.md
macro
macro-support
shared
test
test-macro
typescript
wasm-interpreter
web-sys
webidl
webidl-tests
examples
guide
releases
src
tests
.appveyor.yml
.gitattributes
.gitignore
.travis.yml
CHANGELOG.md
CONTRIBUTING.md
Cargo.toml
LICENSE-APACHE
LICENSE-MIT
README.md
build.rs
package.json
publish.rs
128 lines
2.6 KiB
JavaScript
128 lines
2.6 KiB
JavaScript
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", [1, 2, 3]]);
|
|
};
|
|
|
|
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_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]');
|
|
};
|